Mercurial > emacs
comparison src/gnutls.c @ 110606:b4f4c3e9b976
Add debugging to the gnutls library, and finish handshaking when it's done.
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Mon, 27 Sep 2010 16:35:22 +0200 |
parents | 9d94d76ce611 |
children | 06497cf3e920 |
comparison
equal
deleted
inserted
replaced
110605:5bd3c6bdbcb0 | 110606:b4f4c3e9b976 |
---|---|
219 global_initialized = 0; | 219 global_initialized = 0; |
220 | 220 |
221 return gnutls_make_error (GNUTLS_E_SUCCESS); | 221 return gnutls_make_error (GNUTLS_E_SUCCESS); |
222 } | 222 } |
223 | 223 |
224 static void gnutls_log_function (int level, const char* string) { | |
225 message("debug: %s", string); | |
226 } | |
227 | |
224 DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 6, 0, | 228 DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 6, 0, |
225 doc: /* Initializes client-mode GnuTLS for process PROC. | 229 doc: /* Initializes client-mode GnuTLS for process PROC. |
226 Currently only client mode is supported. Returns a success/failure | 230 Currently only client mode is supported. Returns a success/failure |
227 value you can check with `gnutls-errorp'. | 231 value you can check with `gnutls-errorp'. |
228 | 232 |
262 CHECK_SYMBOL (type); | 266 CHECK_SYMBOL (type); |
263 CHECK_STRING (priority_string); | 267 CHECK_STRING (priority_string); |
264 | 268 |
265 state = XPROCESS (proc)->gnutls_state; | 269 state = XPROCESS (proc)->gnutls_state; |
266 | 270 |
271 gnutls_global_set_log_level(4); | |
272 gnutls_global_set_log_function(gnutls_log_function); | |
273 | |
267 /* always initialize globals. */ | 274 /* always initialize globals. */ |
268 global_init = gnutls_emacs_global_init (); | 275 global_init = gnutls_emacs_global_init (); |
269 if (! NILP (Fgnutls_errorp (global_init))) | 276 if (! NILP (Fgnutls_errorp (global_init))) |
270 return global_init; | 277 return global_init; |
271 | 278 |
272 /* deinit and free resources. */ | 279 /* deinit and free resources. */ |
273 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC) | 280 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC) |
274 { | 281 { |
275 message ("gnutls: deallocating certificates"); | |
276 | |
277 if (EQ (type, Qgnutls_x509pki)) | 282 if (EQ (type, Qgnutls_x509pki)) |
278 { | 283 { |
279 message ("gnutls: deallocating x509 certificates"); | |
280 | |
281 x509_cred = XPROCESS (proc)->x509_cred; | 284 x509_cred = XPROCESS (proc)->x509_cred; |
282 gnutls_certificate_free_credentials (x509_cred); | 285 gnutls_certificate_free_credentials (x509_cred); |
283 } | 286 } |
284 else if (EQ (type, Qgnutls_anon)) | 287 else if (EQ (type, Qgnutls_anon)) |
285 { | 288 { |
286 message ("gnutls: deallocating anon certificates"); | |
287 | |
288 anon_cred = XPROCESS (proc)->anon_cred; | 289 anon_cred = XPROCESS (proc)->anon_cred; |
289 gnutls_anon_free_client_credentials (anon_cred); | 290 gnutls_anon_free_client_credentials (anon_cred); |
290 } | 291 } |
291 else | 292 else |
292 { | 293 { |
294 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; | 295 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; |
295 } | 296 } |
296 | 297 |
297 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) | 298 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) |
298 { | 299 { |
299 message ("gnutls: deinitializing"); | |
300 | |
301 Fgnutls_deinit (proc); | 300 Fgnutls_deinit (proc); |
302 } | 301 } |
303 } | 302 } |
304 | 303 |
305 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; | 304 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; |
306 | 305 |
307 message ("gnutls: allocating credentials"); | |
308 | |
309 if (EQ (type, Qgnutls_x509pki)) | 306 if (EQ (type, Qgnutls_x509pki)) |
310 { | 307 { |
311 message ("gnutls: allocating x509 credentials"); | |
312 | |
313 x509_cred = XPROCESS (proc)->x509_cred; | 308 x509_cred = XPROCESS (proc)->x509_cred; |
314 if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) | 309 if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) |
315 memory_full (); | 310 memory_full (); |
316 } | 311 } |
317 else if (EQ (type, Qgnutls_anon)) | 312 else if (EQ (type, Qgnutls_anon)) |
318 { | 313 { |
319 message ("gnutls: allocating anon credentials"); | |
320 | |
321 anon_cred = XPROCESS (proc)->anon_cred; | 314 anon_cred = XPROCESS (proc)->anon_cred; |
322 if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) | 315 if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) |
323 memory_full (); | 316 memory_full (); |
324 } | 317 } |
325 else | 318 else |
330 | 323 |
331 if (ret < GNUTLS_E_SUCCESS) | 324 if (ret < GNUTLS_E_SUCCESS) |
332 return gnutls_make_error (ret); | 325 return gnutls_make_error (ret); |
333 | 326 |
334 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC; | 327 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC; |
335 | |
336 message ("gnutls: setting the trustfile"); | |
337 | 328 |
338 if (EQ (type, Qgnutls_x509pki)) | 329 if (EQ (type, Qgnutls_x509pki)) |
339 { | 330 { |
340 if (STRINGP (trustfile)) | 331 if (STRINGP (trustfile)) |
341 { | 332 { |
344 XSTRING (trustfile)->data, | 335 XSTRING (trustfile)->data, |
345 file_format); | 336 file_format); |
346 | 337 |
347 if (ret < GNUTLS_E_SUCCESS) | 338 if (ret < GNUTLS_E_SUCCESS) |
348 return gnutls_make_error (ret); | 339 return gnutls_make_error (ret); |
349 | |
350 message ("gnutls: processed %d CA certificates", ret); | |
351 } | 340 } |
352 | |
353 message ("gnutls: setting the keyfile"); | |
354 | 341 |
355 if (STRINGP (keyfile)) | 342 if (STRINGP (keyfile)) |
356 { | 343 { |
357 ret = gnutls_certificate_set_x509_crl_file | 344 ret = gnutls_certificate_set_x509_crl_file |
358 (x509_cred, | 345 (x509_cred, |
359 XSTRING (keyfile)->data, | 346 XSTRING (keyfile)->data, |
360 file_format); | 347 file_format); |
361 | 348 |
362 if (ret < GNUTLS_E_SUCCESS) | 349 if (ret < GNUTLS_E_SUCCESS) |
363 return gnutls_make_error (ret); | 350 return gnutls_make_error (ret); |
364 | |
365 message ("gnutls: processed %d CRL(s)", ret); | |
366 } | 351 } |
367 } | 352 } |
368 | 353 |
369 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; | 354 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; |
370 | |
371 message ("gnutls: gnutls_init"); | |
372 | 355 |
373 ret = gnutls_init (&state, GNUTLS_CLIENT); | 356 ret = gnutls_init (&state, GNUTLS_CLIENT); |
374 | 357 |
375 if (ret < GNUTLS_E_SUCCESS) | 358 if (ret < GNUTLS_E_SUCCESS) |
376 return gnutls_make_error (ret); | 359 return gnutls_make_error (ret); |
377 | 360 |
378 XPROCESS (proc)->gnutls_state = state; | 361 XPROCESS (proc)->gnutls_state = state; |
379 | 362 |
380 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT; | 363 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT; |
381 | |
382 message ("gnutls: setting the priority string"); | |
383 | 364 |
384 ret = gnutls_priority_set_direct(state, | 365 ret = gnutls_priority_set_direct(state, |
385 (char*) SDATA (priority_string), | 366 (char*) SDATA (priority_string), |
386 NULL); | 367 NULL); |
387 | 368 |
488 XPROCESS (proc)->outfd); | 469 XPROCESS (proc)->outfd); |
489 | 470 |
490 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; | 471 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; |
491 } | 472 } |
492 | 473 |
493 message ("gnutls: handshake: handshaking"); | |
494 ret = gnutls_handshake (state); | 474 ret = gnutls_handshake (state); |
495 | |
496 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED; | 475 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED; |
497 | 476 |
498 if (GNUTLS_E_SUCCESS == ret) | 477 if (GNUTLS_E_SUCCESS == ret || ret == 0) |
499 { | 478 { |
500 /* here we're finally done. */ | 479 /* here we're finally done. */ |
501 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY; | 480 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY; |
481 return Qt; | |
502 } | 482 } |
503 | 483 |
504 return gnutls_make_error (ret); | 484 return gnutls_make_error (ret); |
505 } | 485 } |
506 | 486 |