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