globus_gssapi_gsi  11.13
 All Files Functions Variables Enumerations Modules Pages
globus_i_gsi_gss_utils.h
1 /*
2  * Copyright 1999-2006 University of Chicago
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef GLOBUS_I_GSI_GSS_UTILS_H
18 #define GLOBUS_I_GSI_GSS_UTILS_H
19 
20 #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
21 
25 #endif
26 
27 #include "gssapi.h"
28 #include "gssapi_openssl.h"
29 
30 /* ERROR MACROS */
31 
32 #define GLOBUS_GSI_GSSAPI_ERROR_RESULT(_MIN_RESULT_, _MIN_, \
33  _ERRSTR_) \
34  if (_MIN_RESULT_ != NULL) \
35  { \
36  char * tmpstr = \
37  globus_common_create_string _ERRSTR_; \
38  *_MIN_RESULT_ = (OM_uint32) globus_i_gsi_gssapi_error_result( \
39  _MIN_, __FILE__, _function_name_, \
40  __LINE__, tmpstr, NULL); \
41  globus_libc_free(tmpstr); \
42  }
43 
44 #define GLOBUS_GSI_GSSAPI_OPENSSL_ERROR_RESULT(_MIN_RESULT_, \
45  _ERRORTYPE_, _ERRORSTR_) \
46  { \
47  char * tmpstr = \
48  globus_common_create_string _ERRORSTR_; \
49  *_MIN_RESULT_ = \
50  (OM_uint32) globus_i_gsi_gssapi_openssl_error_result( \
51  _ERRORTYPE_, __FILE__, _function_name_, __LINE__, tmpstr, NULL); \
52  globus_libc_free(tmpstr); \
53  }
54 
55 #define GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT(_MIN_RESULT_, _TOP_RESULT_, \
56  _ERRORTYPE_) \
57  *_MIN_RESULT_ = (OM_uint32) globus_i_gsi_gssapi_error_chain_result( \
58  (globus_result_t)_TOP_RESULT_, \
59  _ERRORTYPE_, __FILE__, \
60  _function_name_, __LINE__, NULL, NULL)
61 
62 #define GLOBUS_GSI_GSSAPI_LONG_ERROR_RESULT(_MIN_RESULT_, _MIN_, \
63  _ERRSTR_, _LONG_DESC_) \
64  { \
65  char * tmpstr = \
66  globus_common_create_string _ERRSTR_; \
67  *_MIN_RESULT_ = (OM_uint32) globus_i_gsi_gssapi_error_result( \
68  _MIN_, __FILE__, _function_name_, \
69  __LINE__, tmpstr, _LONG_DESC_); \
70  globus_libc_free(tmpstr); \
71  }
72 
73 #define GLOBUS_GSI_GSSAPI_OPENSSL_LONG_ERROR_RESULT(_MIN_RESULT_, \
74  _ERRORTYPE_, \
75  _ERRORSTR_, \
76  _LONG_DESC_) \
77  { \
78  char * tmpstr = \
79  globus_common_create_string _ERRORSTR_; \
80  *_MIN_RESULT_ = \
81  (OM_uint32) globus_i_gsi_gssapi_openssl_error_result( \
82  _ERRORTYPE_, __FILE__, _function_name_, \
83  __LINE__, tmpstr, _LONG_DESC_); \
84  globus_libc_free(tmpstr); \
85  }
86 
87 #define GLOBUS_GSI_GSSAPI_LONG_ERROR_CHAIN_RESULT(_MIN_RESULT_, _TOP_RESULT_, \
88  _ERRORTYPE_, _LONG_DESC_) \
89  *_MIN_RESULT_ = (OM_uint32) globus_i_gsi_gssapi_error_chain_result( \
90  (globus_result_t)_TOP_RESULT_, \
91  _ERRORTYPE_, __FILE__, \
92  _function_name_, __LINE__, NULL, _LONG_DESC_)
93 
94 #define GLOBUS_GSI_GSSAPI_MALLOC_ERROR(_MIN_RESULT_) \
95  { \
96  char * _tmp_str_ = \
97  globus_l_gsi_gssapi_error_strings[ \
98  GLOBUS_GSI_GSSAPI_ERROR_OUT_OF_MEMORY]; \
99  *_MIN_RESULT_ = (OM_uint32) globus_error_put( \
100  globus_error_wrap_errno_error( \
101  GLOBUS_GSI_GSSAPI_MODULE, \
102  errno, \
103  GLOBUS_GSI_GSSAPI_ERROR_OUT_OF_MEMORY, \
104  __FILE__, \
105  _function_name_, \
106  __LINE__, \
107  "%s", \
108  _tmp_str_)); \
109  }
110 
111 #define GLOBUS_GSI_GSSAPI_ERRNO_ERROR_RESULT(_MIN_RESULT_, \
112  _ERRORTYPE_, _ERRORSTR_) \
113  { \
114  char * _tmp_str_ = \
115  globus_common_create_string _ERRORSTR_; \
116  *_MIN_RESULT_ = (OM_uint32) globus_error_put( \
117  globus_error_wrap_errno_error( \
118  GLOBUS_GSI_GSSAPI_MODULE, \
119  errno, \
120  _ERRORTYPE_, \
121  __FILE__, \
122  _function_name_, \
123  __LINE__, \
124  "%s", \
125  _tmp_str_)); \
126  globus_libc_free(_tmp_str_); \
127  }
128 
129 
130 /* DEBUG MACROS */
131 
132 extern int globus_i_gsi_gssapi_debug_level;
133 extern FILE * globus_i_gsi_gssapi_debug_fstream;
134 extern globus_mutex_t globus_i_gssapi_activate_mutex;
135 extern globus_bool_t globus_i_gssapi_active;
136 
137 
138 #ifdef BUILD_DEBUG
139 
140 #define GLOBUS_I_GSI_GSSAPI_DEBUG(_LEVEL_) \
141  (globus_i_gsi_gssapi_debug_level >= (_LEVEL_))
142 
143 #define GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF(_LEVEL_, _MESSAGE_) \
144 { \
145  if (GLOBUS_I_GSI_GSSAPI_DEBUG(_LEVEL_)) \
146  { \
147  globus_libc_fprintf _MESSAGE_; \
148  } \
149 }
150 
151 #define GLOBUS_I_GSI_GSSAPI_DEBUG_FNPRINTF(_LEVEL_, _MESSAGE_) \
152 { \
153  if (GLOBUS_I_GSI_GSSAPI_DEBUG(_LEVEL_)) \
154  { \
155  char * _tmp_str_ = \
156  globus_common_create_nstring _MESSAGE_; \
157  globus_libc_fprintf(globus_i_gsi_gssapi_debug_fstream, \
158  "%s", _tmp_str_); \
159  globus_libc_free(_tmp_str_); \
160  } \
161 }
162 
163 #define GLOBUS_I_GSI_GSSAPI_DEBUG_PRINT(_LEVEL_, _MESSAGE_) \
164 { \
165  if (GLOBUS_I_GSI_GSSAPI_DEBUG(_LEVEL_)) \
166  { \
167  globus_libc_fprintf( \
168  globus_i_gsi_gssapi_debug_fstream, \
169  "%s", _MESSAGE_); \
170  } \
171 }
172 
173 #define GLOBUS_I_GSI_GSSAPI_DEBUG_PRINT_OBJECT(_LEVEL_, _TYPE_, _OBJ_) \
174 { \
175  if (GLOBUS_I_GSI_GSSAPI_DEBUG(_LEVEL_)) \
176  { \
177  _TYPE_##_print_fp( \
178  globus_i_gsi_gssapi_debug_fstream, \
179  _OBJ_); \
180  } \
181 }
182 
183 #else
184 
185 #define GLOBUS_I_GSI_GSSAPI_DEBUG(_LEVEL_) 0
186 #define GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF(_LEVEL_, _MESSAGE_)
187 #define GLOBUS_I_GSI_GSSAPI_DEBUG_FNPRINTF(_LEVEL_, _MESSAGE_)
188 #define GLOBUS_I_GSI_GSSAPI_DEBUG_PRINT(_LEVEL_, _MESSAGE_)
189 #define GLOBUS_I_GSI_GSSAPI_DEBUG_PRINT_OBJECT(_LEVEL,_TYPE_, _OBJ_)
190 
191 #endif
192 
193 #define GLOBUS_I_GSI_GSSAPI_DEBUG_ENTER \
194  GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF( \
195  1, (globus_i_gsi_gssapi_debug_fstream, \
196  "%s entering\n", _function_name_))
197 
198 #define GLOBUS_I_GSI_GSSAPI_DEBUG_EXIT \
199  GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF( \
200  1, (globus_i_gsi_gssapi_debug_fstream, \
201  "%s exiting: major_status=%d\n", \
202  _function_name_, (int)major_status))
203 
204 #define GLOBUS_I_GSI_GSSAPI_INTERNAL_DEBUG_EXIT \
205  GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF( \
206  1, (globus_i_gsi_gssapi_debug_fstream, \
207  "%s exiting\n", \
208  _function_name_))
209 
210 extern int globus_i_gsi_gssapi_force_tls;
211 
212 typedef enum
213 {
214  GLOBUS_I_GSI_GSS_DEFAULT_CONTEXT,
215  GLOBUS_I_GSI_GSS_ANON_CONTEXT
216 } globus_i_gsi_gss_context_type_t;
217 
218 OM_uint32
219 globus_i_gsi_gss_copy_name_to_name(
220  OM_uint32 * minor_status,
221  gss_name_desc ** output,
222  const gss_name_desc * input);
223 
224 OM_uint32
225 globus_i_gsi_gss_create_and_fill_context(
226  OM_uint32 * minor_status,
227  gss_ctx_id_desc ** context_handle,
228  gss_cred_id_desc * cred_handle,
229  const gss_cred_usage_t cred_usage,
230  OM_uint32 req_flags);
231 
232 OM_uint32
233 globus_i_gsi_gss_create_anonymous_cred(
234  OM_uint32 * minor_status,
235  gss_cred_id_t * output_cred_handle,
236  const gss_cred_usage_t cred_usage);
237 
238 OM_uint32
239 globus_i_gsi_gss_cred_read_bio(
240  OM_uint32 * minor_status,
241  const gss_cred_usage_t cred_usage,
242  gss_cred_id_t * cred_id_handle,
243  BIO * bp);
244 
245 OM_uint32
246 globus_i_gsi_gss_cred_read(
247  OM_uint32 * minor_status,
248  const gss_cred_usage_t cred_usage,
249  gss_cred_id_t * cred_handle,
250  const X509_NAME * desired_subject);
251 
252 OM_uint32
253 globus_i_gsi_gss_create_cred(
254  OM_uint32 * minor_status,
255  const gss_cred_usage_t cred_usage,
256  gss_cred_id_t * output_cred_handle_P,
257  globus_gsi_cred_handle_t * cred_handle);
258 
259 int globus_i_gsi_gss_verify_extensions_callback(
260  globus_gsi_callback_data_t callback_data,
261  X509_EXTENSION * extension);
262 
263 OM_uint32
264 globus_i_gsi_gss_handshake(
265  OM_uint32 * minor_status,
266  gss_ctx_id_desc * context_handle);
267 
268 OM_uint32
269 globus_i_gsi_gss_get_token(
270  OM_uint32 * minor_status,
271  const gss_ctx_id_desc * context_handle,
272  BIO * bio,
273  const gss_buffer_t output_token);
274 
275 OM_uint32
276 globus_i_gsi_gss_put_token(
277  OM_uint32 * minor_status,
278  const gss_ctx_id_desc * context_handle,
279  BIO * bio,
280  const gss_buffer_t input_token);
281 
282 OM_uint32
283 globus_i_gsi_gss_retrieve_peer(
284  OM_uint32 * minor_status,
285  gss_ctx_id_desc * context_handle,
286  const gss_cred_usage_t cred_usage);
287 
288 #if LINK_WITH_INTERNAL_OPENSSL_API
289 OM_uint32
290 globus_i_gsi_gss_SSL_write_bio(
291  OM_uint32 * minor_status,
292  gss_ctx_id_desc * context,
293  BIO * bp);
294 
295 OM_uint32
296 globus_i_gsi_gss_SSL_read_bio(
297  OM_uint32 * minor_status,
298  gss_ctx_id_desc * context,
299  BIO * bp);
300 #endif
301 
302 OM_uint32
303 globus_i_gsi_gss_get_context_goodtill(
304  OM_uint32 * minor_status,
305  gss_ctx_id_t context,
306  time_t * goodtill);
307 
308 OM_uint32
309 globus_i_gsi_gssapi_init_ssl_context(
310  OM_uint32 * minor_status,
311  gss_cred_id_t credential,
312  globus_i_gsi_gss_context_type_t anon_ctx);
313 
314 globus_result_t
315 globus_i_gsi_gssapi_openssl_error_result(
316  int error_type,
317  const char * filename,
318  const char * function_name,
319  int line_number,
320  const char * short_desc,
321  const char * long_desc);
322 
323 globus_result_t
324 globus_i_gsi_gssapi_error_result(
325  const OM_uint32 minor_status,
326  const char * filename,
327  const char * function_name,
328  int line_number,
329  const char * short_desc,
330  const char * long_desc);
331 
332 globus_result_t
333 globus_i_gsi_gssapi_error_chain_result(
334  globus_result_t chain_result,
335  int error_type,
336  const char * filename,
337  const char * function_name,
338  int line_number,
339  const char * short_desc,
340  const char * long_desc);
341 
342 globus_result_t
343 globus_i_gsi_gssapi_error_join_chains_result(
344  globus_result_t outer_error,
345  globus_result_t inner_error);
346 
347 OM_uint32
348 globus_i_gsi_gssapi_get_hostname(
349  OM_uint32 * minor_status,
350  gss_name_desc * name);
351 
352 
353 typedef enum
354 {
355  GSS_I_COMPATIBILITY_HYBRID,
356  GSS_I_COMPATIBILITY_STRICT_GT2,
357  GSS_I_COMPATIBILITY_STRICT_RFC2818
358 }
359 gss_i_name_compatibility_mode_t;
360 
361 extern gss_i_name_compatibility_mode_t gss_i_name_compatibility_mode;
362 
363 #endif /* GLOBUS_I_GSI_GSS_UTILS_H */
GSS API OpenSSL.