gssapi_openssl.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2006 University of Chicago
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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  * we need to distinguish between a token
00056  * created by us using get_mic vs one using
00057  * the SSL application data
00058  * We use this in wrap and unwrap
00059  * Future versions of SSL may use this
00060  *
00061  * Our wrapped buffer (integrity only) has
00062  *
00063  *  byte  type[1]          = SSL3_RT_GSSAPI_OPENSSL
00064  *  byte  version_major[1] = 0x03
00065  *  byte  version_minor[1] = 0
00066  *  byte  mic_length[2]    = 2 byte length of following mic 
00067  * 
00068  *  byte  mic_seq[8]           = 8 byte sequence number
00069  *  byte  mic_data_length[4]   = 4 byte length of data 
00070  *  byte  hash[*]          = the hash of variable length
00071  *
00072  *  byte  data[*]          = the data being wrapped. 
00073  */
00074 
00075 #define SSL3_RT_GSSAPI_OPENSSL                   26
00076 
00077 /* These conversions macros are taken from SSL */
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 /* Compare OIDs */
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     /* gss_buffer_desc  name_buffer ; */
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 typedef struct gss_cred_id_desc_struct {
00161     globus_gsi_cred_handle_t            cred_handle;
00162     gss_name_desc *                     globusid;
00163     gss_cred_usage_t                    cred_usage;
00164     SSL_CTX *                           ssl_context;
00165     gss_OID                             mech;
00166 } gss_cred_id_desc;
00167 
00168 typedef struct gss_ctx_id_desc_struct{
00169     globus_mutex_t                      mutex;
00170     globus_gsi_callback_data_t          callback_data;
00171     gss_cred_id_desc *                  peer_cred_handle;
00172     gss_cred_id_desc *                  cred_handle;
00173     gss_cred_id_desc *                  deleg_cred_handle;
00174     globus_gsi_proxy_handle_t           proxy_handle;
00175     OM_uint32                           ret_flags;
00176     OM_uint32                           req_flags;
00177     OM_uint32                           ctx_flags;
00178     int                                 cred_obtained;
00179     gss_OID                             mech;
00180 #if OPENSSL_VERSION_NUMBER >= 0x10000100L
00181 
00182     uint64_t                            mac_read_sequence;
00184     uint64_t                            mac_write_sequence;
00186     unsigned char *                     mac_key;
00191     unsigned char *                     mac_iv_fixed;
00192 #endif
00193     SSL *                               gss_ssl; 
00194     BIO *                               gss_rbio;
00195     BIO *                               gss_wbio;
00196     BIO *                               gss_sslbio;
00197     gss_con_st_t                        gss_state;
00198     int                                 locally_initiated;
00199     gss_delegation_state_t              delegation_state;
00200     gss_OID_set                         extension_oids;
00201 } gss_ctx_id_desc;
00202 
00203 extern
00204 const gss_OID_desc * const              gss_mech_globus_gssapi_openssl;
00205 
00206 extern
00207 const gss_OID_desc * const              gss_mech_globus_gssapi_openssl_micv2;
00208 
00209 extern
00210 const gss_OID_desc * const              gss_proxycertinfo_extension;
00211 
00212 extern
00213 gss_OID_desc *                          gss_nt_host_ip;
00214 
00215 extern
00216 gss_OID_desc *                          gss_nt_x509;
00217 
00218 extern
00219 globus_bool_t                           globus_i_backward_compatible_mic;
00220 extern
00221 globus_bool_t                           globus_i_accept_backward_compatible_mic;
00222 
00223 #define GLOBUS_GSS_C_NT_HOST_IP         gss_nt_host_ip
00224 #define GLOBUS_GSS_C_NT_X509            gss_nt_x509
00225 
00226 extern
00227 globus_thread_once_t                    once_control;
00228 
00229 void
00230 globus_l_gsi_gssapi_activate_once(void);
00231 
00232 OM_uint32
00233 globus_i_gss_get_hash(
00234     OM_uint32                          *minor_status,
00235     const gss_ctx_id_t                  context_handle,
00236     const EVP_MD **                     hash,
00237     const EVP_CIPHER **                 cipher);
00238 
00239 
00240 OM_uint32
00241 globus_i_gssapi_gsi_gmac(
00242     OM_uint32 *                         minor_status,
00243     const EVP_CIPHER *                  evp_cipher,
00244     const unsigned char *               iv,
00245     const unsigned char *               key,
00246     const gss_buffer_desc              *message_buffer,
00247     unsigned char                       tag[static 16]);
00248 
00249 #endif /* GSSAPI_OPENSSL_H */

Generated on 10 Mar 2017 for globus_gssapi_gsi by  doxygen 1.4.7