00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef GSSAPI_OPENSSL_H
00018 #define GSSAPI_OPENSSL_H
00019
00026 #include "globus_config.h"
00027 #include "globus_common.h"
00028
00029 #include "gssapi.h"
00030 #include "globus_gsi_gss_constants.h"
00031
00032 #include "globus_gsi_callback.h"
00033 #include "globus_gsi_proxy.h"
00034 #include "globus_gsi_credential.h"
00035
00036 #include <stdio.h>
00037 #include "openssl/ssl.h"
00038 #include "openssl/err.h"
00039 #include "openssl/bio.h"
00040 #include "openssl/pem.h"
00041 #include "openssl/x509.h"
00042 #include "openssl/x509v3.h"
00043 #include "openssl/stack.h"
00044
00045 #define GLOBUS_I_GSI_GSSAPI_IMPL_VERSION 1
00046
00047 #define GSS_I_CTX_INITIALIZED 1
00048 #define GSS_I_DISALLOW_ENCRYPTION 2
00049 #define GSS_I_PROTECTION_FAIL_ON_CONTEXT_EXPIRATION 4
00050 #define GSS_I_APPLICATION_WILL_HANDLE_EXTENSIONS 8
00051
00052 #define GSS_C_QOP_GLOBUS_GSSAPI_OPENSSL_BIG 1
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #define SSL3_RT_GSSAPI_OPENSSL 26
00076
00077
00078
00079 #define L2N(LONG_VAL, CHAR_ARRAY) \
00080 { \
00081 unsigned char * _char_array_ = CHAR_ARRAY; \
00082 *(_char_array_++) = (unsigned char) (((LONG_VAL) >> 24) & 0xff); \
00083 *(_char_array_++) = (unsigned char) (((LONG_VAL) >> 16) & 0xff); \
00084 *(_char_array_++) = (unsigned char) (((LONG_VAL) >> 8) & 0xff); \
00085 *(_char_array_++) = (unsigned char) (((LONG_VAL)) & 0xff); \
00086 }
00087
00088 #define N2L(CHAR_ARRAY, LONG_VAL) \
00089 { \
00090 const unsigned char * _char_array_ = CHAR_ARRAY; \
00091 (LONG_VAL) = ((*(_char_array_++)) << 24) & 0xff000000; \
00092 (LONG_VAL) |= ((*(_char_array_++)) << 16) & 0xff0000; \
00093 (LONG_VAL) |= ((*(_char_array_++)) << 8) & 0xff00; \
00094 (LONG_VAL) |= ((*(_char_array_++)) & 0xff); \
00095 }
00096
00097 #define N2S(CHAR_ARRAY, SHORT) \
00098 { \
00099 char * _char_array_ = CHAR_ARRAY; \
00100 (SHORT) = ((unsigned int) (*(_char_array_++))) << 8; \
00101 (SHORT) |= ((unsigned int) (*(_char_array_++))); \
00102 }
00103
00104 #define S2N(SHORT, CHAR_ARRAY) \
00105 { \
00106 char * _char_array_ = CHAR_ARRAY; \
00107 *(_char_array_++) = (unsigned char) (((SHORT) >> 8) & 0xff); \
00108 *(_char_array_++) = (unsigned char) ((SHORT) & 0xff); \
00109 }
00110
00111 #define U642N(U64VAL, CHAR_ARRAY) \
00112 { \
00113 unsigned char * _char_array_ = CHAR_ARRAY; \
00114 *(_char_array_++) = (unsigned char) (((U64VAL) >> 56) & 0xff); \
00115 *(_char_array_++) = (unsigned char) (((U64VAL) >> 48) & 0xff); \
00116 *(_char_array_++) = (unsigned char) (((U64VAL) >> 40) & 0xff); \
00117 *(_char_array_++) = (unsigned char) (((U64VAL) >> 32) & 0xff); \
00118 *(_char_array_++) = (unsigned char) (((U64VAL) >> 24) & 0xff); \
00119 *(_char_array_++) = (unsigned char) (((U64VAL) >> 16) & 0xff); \
00120 *(_char_array_++) = (unsigned char) (((U64VAL) >> 8) & 0xff); \
00121 *(_char_array_++) = (unsigned char) (((U64VAL) ) & 0xff); \
00122 }
00123
00124 #define N2U64(CHAR_ARRAY, U64VAL) \
00125 { \
00126 const unsigned char * _char_array_ = CHAR_ARRAY; \
00127 uint64_t _u64val_ = 0; \
00128 _u64val_ = (((uint64_t)(*(_char_array_++))) << 56) & 0xff00000000000000; \
00129 _u64val_ = (((uint64_t)(*(_char_array_++))) << 48) & 0xff000000000000; \
00130 _u64val_ = (((uint64_t)(*(_char_array_++))) << 40) & 0xff0000000000; \
00131 _u64val_ = (((uint64_t)(*(_char_array_++))) << 32) & 0xff00000000; \
00132 _u64val_ = (((uint64_t)(*(_char_array_++))) << 24) & 0xff000000; \
00133 _u64val_ = (((uint64_t)(*(_char_array_++))) << 16) & 0xff0000; \
00134 _u64val_ = (((uint64_t)(*(_char_array_++))) << 8) & 0xff00; \
00135 _u64val_ = (((uint64_t)(*(_char_array_++))) ) & 0xff; \
00136 (U64VAL) = _u64val_; \
00137 }
00138
00139
00140 #define g_OID_equal(o1, o2) \
00141 (((o1) == (o2)) || \
00142 ((o1) && (o2) && \
00143 ((o1)->length == (o2)->length) && \
00144 (memcmp((o1)->elements,(o2)->elements,(int) (o1)->length) == 0)))
00145
00146 typedef struct gss_name_desc_struct {
00147
00148 gss_OID name_oid;
00149
00150 X509_NAME * x509n;
00151 char * x509n_oneline;
00152 GENERAL_NAMES * subjectAltNames;
00153 char * user_name;
00154 char * service_name;
00155 char * host_name;
00156 char * ip_address;
00157 char * ip_name;
00158 } gss_name_desc;
00159
00160
00161 typedef struct gss_cred_id_desc_struct {
00162 globus_gsi_cred_handle_t cred_handle;
00163 gss_name_desc * globusid;
00164 gss_cred_usage_t cred_usage;
00165 SSL_CTX * ssl_context;
00166 gss_OID mech;
00167 } gss_cred_id_desc;
00168
00169 typedef struct gss_ctx_id_desc_struct{
00170 globus_mutex_t mutex;
00171 globus_gsi_callback_data_t callback_data;
00172 gss_cred_id_desc * peer_cred_handle;
00173 gss_cred_id_desc * cred_handle;
00174 gss_cred_id_desc * deleg_cred_handle;
00175 globus_gsi_proxy_handle_t proxy_handle;
00176 OM_uint32 ret_flags;
00177 OM_uint32 req_flags;
00178 OM_uint32 ctx_flags;
00179 int cred_obtained;
00180 gss_OID mech;
00181 #if OPENSSL_VERSION_NUMBER >= 0x10000100L
00182
00183 uint64_t mac_read_sequence;
00185 uint64_t mac_write_sequence;
00187 unsigned char * mac_key;
00192 unsigned char * mac_iv_fixed;
00193 #endif
00194 SSL * gss_ssl;
00195 BIO * gss_rbio;
00196 BIO * gss_wbio;
00197 BIO * gss_sslbio;
00198 gss_con_st_t gss_state;
00199 int locally_initiated;
00200 gss_delegation_state_t delegation_state;
00201 gss_OID_set extension_oids;
00202 gss_cred_id_t *sni_credentials;
00203 size_t sni_credentials_count;
00204 char *sni_servername;
00205 unsigned char *alpn;
00206 size_t alpn_length;
00207 } gss_ctx_id_desc;
00208
00209 extern
00210 const gss_OID_desc * const gss_mech_globus_gssapi_openssl;
00211
00212 extern
00213 const gss_OID_desc * const gss_mech_globus_gssapi_openssl_micv2;
00214
00215 extern
00216 const gss_OID_desc * const gss_proxycertinfo_extension;
00217
00218 extern
00219 gss_OID_desc * gss_nt_host_ip;
00220
00221 extern
00222 gss_OID_desc * gss_nt_x509;
00223
00224 extern
00225 const gss_OID_desc * const gss_ext_server_name_oid;
00226
00227 extern
00228 const gss_OID_desc * const gss_ext_alpn_oid;
00229
00230
00231 extern
00232 globus_bool_t globus_i_backward_compatible_mic;
00233 extern
00234 globus_bool_t globus_i_accept_backward_compatible_mic;
00235
00236 #define GLOBUS_GSS_C_NT_HOST_IP gss_nt_host_ip
00237 #define GLOBUS_GSS_C_NT_X509 gss_nt_x509
00238
00239 extern
00240 globus_thread_once_t once_control;
00241
00242 void
00243 globus_l_gsi_gssapi_activate_once(void);
00244
00245 OM_uint32
00246 globus_i_gss_get_hash(
00247 OM_uint32 *minor_status,
00248 const gss_ctx_id_t context_handle,
00249 const EVP_MD ** hash,
00250 const EVP_CIPHER ** cipher);
00251
00252
00253 OM_uint32
00254 globus_i_gssapi_gsi_gmac(
00255 OM_uint32 * minor_status,
00256 const EVP_CIPHER * evp_cipher,
00257 const unsigned char * iv,
00258 const unsigned char * key,
00259 const gss_buffer_desc *message_buffer,
00260 unsigned char tag[static 16]);
00261
00262 #endif