diff options
| author | Lars Magne Ingebrigtsen | 2010-09-27 18:44:31 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2010-09-27 18:44:31 +0200 |
| commit | 8ed70bf3167e37c8c15fb3d3286dfb1eb696a85a (patch) | |
| tree | 6a774f238b22a7bfe1dae8477d02c91907c63a42 | |
| parent | bedf4aabcfdeeb65a8e6050b1f192cbd679a4172 (diff) | |
| download | emacs-8ed70bf3167e37c8c15fb3d3286dfb1eb696a85a.tar.gz emacs-8ed70bf3167e37c8c15fb3d3286dfb1eb696a85a.zip | |
Add gnutls logging and clean up various gnutls bits.
From: Teodor Zlatanov <tzz@lifelogs.com>
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/net/gnutls.el | 14 | ||||
| -rw-r--r-- | src/ChangeLog | 15 | ||||
| -rw-r--r-- | src/gnutls.c | 57 | ||||
| -rw-r--r-- | src/gnutls.h | 2 | ||||
| -rw-r--r-- | src/process.c | 1 | ||||
| -rw-r--r-- | src/process.h | 5 |
7 files changed, 83 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3d66ee0984c..a19c80c0d1b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2010-09-27 Teodor Zlatanov <tzz@lifelogs.com> | ||
| 2 | |||
| 3 | * net/gnutls.el (gnutls, gnutls-log-level): Add group and custom | ||
| 4 | variable. | ||
| 5 | (starttls-negotiate): Use it. | ||
| 6 | |||
| 1 | 2010-09-27 Lars Magne Ingebrigtsen <larsi@gnus.org> | 7 | 2010-09-27 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 8 | ||
| 3 | * net/gnutls.el (starttls-negotiate): Stop looping when we get a t | 9 | * net/gnutls.el (starttls-negotiate): Stop looping when we get a t |
diff --git a/lisp/net/gnutls.el b/lisp/net/gnutls.el index b393d237d90..6a2d5aff68f 100644 --- a/lisp/net/gnutls.el +++ b/lisp/net/gnutls.el | |||
| @@ -32,6 +32,16 @@ | |||
| 32 | 32 | ||
| 33 | ;;; Code: | 33 | ;;; Code: |
| 34 | 34 | ||
| 35 | (defgroup gnutls nil | ||
| 36 | "Emacs interface to the GnuTLS library." | ||
| 37 | :prefix "gnutls-" | ||
| 38 | :group 'net-utils) | ||
| 39 | |||
| 40 | (defcustom gnutls-log-level 2 | ||
| 41 | "Logging level to be used by `starttls-negotiate' and GnuTLS." | ||
| 42 | :type 'integer | ||
| 43 | :group 'gnutls) | ||
| 44 | |||
| 35 | (defun open-ssl-stream (name buffer host service) | 45 | (defun open-ssl-stream (name buffer host service) |
| 36 | "Open a SSL connection for a service to a host. | 46 | "Open a SSL connection for a service to a host. |
| 37 | Returns a subprocess-object to represent the connection. | 47 | Returns a subprocess-object to represent the connection. |
| @@ -72,7 +82,9 @@ CREDENTIALS-FILE is a filename with meaning dependent on CREDENTIALS." | |||
| 72 | ret) | 82 | ret) |
| 73 | 83 | ||
| 74 | (gnutls-message-maybe | 84 | (gnutls-message-maybe |
| 75 | (setq ret (gnutls-boot proc priority-string credentials credentials-file)) | 85 | (setq ret (gnutls-boot proc priority-string |
| 86 | credentials credentials-file | ||
| 87 | nil nil gnutls-log-level)) | ||
| 76 | "boot: %s") | 88 | "boot: %s") |
| 77 | 89 | ||
| 78 | (when (gnutls-errorp ret) | 90 | (when (gnutls-errorp ret) |
diff --git a/src/ChangeLog b/src/ChangeLog index ca9bc2599a0..18f71f31dde 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2010-09-27 Teodor Zlatanov <tzz@lifelogs.com> | ||
| 2 | |||
| 3 | * gnutls.c (gnutls_log_function): Show level and "gnutls.c" | ||
| 4 | prefix. | ||
| 5 | (Fgnutls_boot): Use changed process members. Use log level with a | ||
| 6 | function parameter to set it. Bring back Emacs-level debugging | ||
| 7 | messages at log level 1 and 2. | ||
| 8 | |||
| 9 | * process.c (make_process): Initialize gnutls_log_level. | ||
| 10 | |||
| 11 | * process.h: Add gnutls_log_level and rename x509_cred and | ||
| 12 | anon_cred to have the gnutls_ prefix for consistency. | ||
| 13 | |||
| 14 | * gnutls.h (GNUTLS_LOG): Add convenience macro. | ||
| 15 | |||
| 1 | 2010-09-27 Juanma Barranquero <lekktu@gmail.com> | 16 | 2010-09-27 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 17 | ||
| 3 | * w32.c (g_b_init_get_sid_identifier_authority) | 18 | * w32.c (g_b_init_get_sid_identifier_authority) |
diff --git a/src/gnutls.c b/src/gnutls.c index 5d8a946fa9a..c2d664ff97e 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -220,11 +220,12 @@ Lisp_Object gnutls_emacs_global_deinit (void) | |||
| 220 | return gnutls_make_error (GNUTLS_E_SUCCESS); | 220 | return gnutls_make_error (GNUTLS_E_SUCCESS); |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | static void gnutls_log_function (int level, const char* string) { | 223 | static void gnutls_log_function (int level, const char* string) |
| 224 | message("debug: %s", string); | 224 | { |
| 225 | message("gnutls.c: [%d] %s", level, string); | ||
| 225 | } | 226 | } |
| 226 | 227 | ||
| 227 | DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 6, 0, | 228 | DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 7, 0, |
| 228 | doc: /* Initializes client-mode GnuTLS for process PROC. | 229 | doc: /* Initializes client-mode GnuTLS for process PROC. |
| 229 | Currently only client mode is supported. Returns a success/failure | 230 | Currently only client mode is supported. Returns a success/failure |
| 230 | value you can check with `gnutls-errorp'. | 231 | value you can check with `gnutls-errorp'. |
| @@ -234,6 +235,10 @@ TYPE is either `gnutls-anon' or `gnutls-x509pki'. | |||
| 234 | TRUSTFILE is a PEM encoded trust file for `gnutls-x509pki'. | 235 | TRUSTFILE is a PEM encoded trust file for `gnutls-x509pki'. |
| 235 | KEYFILE is ... for `gnutls-x509pki' (TODO). | 236 | KEYFILE is ... for `gnutls-x509pki' (TODO). |
| 236 | CALLBACK is ... for `gnutls-x509pki' (TODO). | 237 | CALLBACK is ... for `gnutls-x509pki' (TODO). |
| 238 | LOGLEVEL is the debug level requested from GnuTLS, try 4. | ||
| 239 | |||
| 240 | LOGLEVEL will be set for this process AND globally for GnuTLS. So if | ||
| 241 | you set it higher or lower at any point, it affects global debugging. | ||
| 237 | 242 | ||
| 238 | Note that the priority is set on the client. The server does not use | 243 | Note that the priority is set on the client. The server does not use |
| 239 | the protocols's priority except for disabling protocols that were not | 244 | the protocols's priority except for disabling protocols that were not |
| @@ -247,10 +252,13 @@ Each authentication type may need additional information in order to | |||
| 247 | work. For X.509 PKI (`gnutls-x509pki'), you need TRUSTFILE and | 252 | work. For X.509 PKI (`gnutls-x509pki'), you need TRUSTFILE and |
| 248 | KEYFILE and optionally CALLBACK. */) | 253 | KEYFILE and optionally CALLBACK. */) |
| 249 | (Lisp_Object proc, Lisp_Object priority_string, Lisp_Object type, | 254 | (Lisp_Object proc, Lisp_Object priority_string, Lisp_Object type, |
| 250 | Lisp_Object trustfile, Lisp_Object keyfile, Lisp_Object callback) | 255 | Lisp_Object trustfile, Lisp_Object keyfile, Lisp_Object callback, |
| 256 | Lisp_Object loglevel) | ||
| 251 | { | 257 | { |
| 252 | int ret = GNUTLS_E_SUCCESS; | 258 | int ret = GNUTLS_E_SUCCESS; |
| 253 | 259 | ||
| 260 | int max_log_level = 0; | ||
| 261 | |||
| 254 | /* TODO: GNUTLS_X509_FMT_DER is also an option. */ | 262 | /* TODO: GNUTLS_X509_FMT_DER is also an option. */ |
| 255 | int file_format = GNUTLS_X509_FMT_PEM; | 263 | int file_format = GNUTLS_X509_FMT_PEM; |
| 256 | 264 | ||
| @@ -267,8 +275,14 @@ KEYFILE and optionally CALLBACK. */) | |||
| 267 | 275 | ||
| 268 | state = XPROCESS (proc)->gnutls_state; | 276 | state = XPROCESS (proc)->gnutls_state; |
| 269 | 277 | ||
| 270 | //gnutls_global_set_log_level(4); | 278 | if (NUMBERP (loglevel)) |
| 271 | //gnutls_global_set_log_function(gnutls_log_function); | 279 | { |
| 280 | message ("setting up log level %d", XINT (loglevel)); | ||
| 281 | gnutls_global_set_log_function (gnutls_log_function); | ||
| 282 | gnutls_global_set_log_level (XINT (loglevel)); | ||
| 283 | max_log_level = XINT (loglevel); | ||
| 284 | XPROCESS (proc)->gnutls_log_level = max_log_level; | ||
| 285 | } | ||
| 272 | 286 | ||
| 273 | /* always initialize globals. */ | 287 | /* always initialize globals. */ |
| 274 | global_init = gnutls_emacs_global_init (); | 288 | global_init = gnutls_emacs_global_init (); |
| @@ -278,14 +292,18 @@ KEYFILE and optionally CALLBACK. */) | |||
| 278 | /* deinit and free resources. */ | 292 | /* deinit and free resources. */ |
| 279 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC) | 293 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC) |
| 280 | { | 294 | { |
| 295 | GNUTLS_LOG (1, max_log_level, "deallocating credentials"); | ||
| 296 | |||
| 281 | if (EQ (type, Qgnutls_x509pki)) | 297 | if (EQ (type, Qgnutls_x509pki)) |
| 282 | { | 298 | { |
| 283 | x509_cred = XPROCESS (proc)->x509_cred; | 299 | GNUTLS_LOG (2, max_log_level, "deallocating x509 credentials"); |
| 300 | x509_cred = XPROCESS (proc)->gnutls_x509_cred; | ||
| 284 | gnutls_certificate_free_credentials (x509_cred); | 301 | gnutls_certificate_free_credentials (x509_cred); |
| 285 | } | 302 | } |
| 286 | else if (EQ (type, Qgnutls_anon)) | 303 | else if (EQ (type, Qgnutls_anon)) |
| 287 | { | 304 | { |
| 288 | anon_cred = XPROCESS (proc)->anon_cred; | 305 | GNUTLS_LOG (2, max_log_level, "deallocating anon credentials"); |
| 306 | anon_cred = XPROCESS (proc)->gnutls_anon_cred; | ||
| 289 | gnutls_anon_free_client_credentials (anon_cred); | 307 | gnutls_anon_free_client_credentials (anon_cred); |
| 290 | } | 308 | } |
| 291 | else | 309 | else |
| @@ -296,21 +314,26 @@ KEYFILE and optionally CALLBACK. */) | |||
| 296 | 314 | ||
| 297 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) | 315 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) |
| 298 | { | 316 | { |
| 317 | GNUTLS_LOG (1, max_log_level, "deallocating x509 credentials"); | ||
| 299 | Fgnutls_deinit (proc); | 318 | Fgnutls_deinit (proc); |
| 300 | } | 319 | } |
| 301 | } | 320 | } |
| 302 | 321 | ||
| 303 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; | 322 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; |
| 304 | 323 | ||
| 324 | GNUTLS_LOG (1, max_log_level, "allocating credentials"); | ||
| 325 | |||
| 305 | if (EQ (type, Qgnutls_x509pki)) | 326 | if (EQ (type, Qgnutls_x509pki)) |
| 306 | { | 327 | { |
| 307 | x509_cred = XPROCESS (proc)->x509_cred; | 328 | GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); |
| 329 | x509_cred = XPROCESS (proc)->gnutls_x509_cred; | ||
| 308 | if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) | 330 | if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) |
| 309 | memory_full (); | 331 | memory_full (); |
| 310 | } | 332 | } |
| 311 | else if (EQ (type, Qgnutls_anon)) | 333 | else if (EQ (type, Qgnutls_anon)) |
| 312 | { | 334 | { |
| 313 | anon_cred = XPROCESS (proc)->anon_cred; | 335 | GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); |
| 336 | anon_cred = XPROCESS (proc)->gnutls_anon_cred; | ||
| 314 | if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) | 337 | if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) |
| 315 | memory_full (); | 338 | memory_full (); |
| 316 | } | 339 | } |
| @@ -329,6 +352,7 @@ KEYFILE and optionally CALLBACK. */) | |||
| 329 | { | 352 | { |
| 330 | if (STRINGP (trustfile)) | 353 | if (STRINGP (trustfile)) |
| 331 | { | 354 | { |
| 355 | GNUTLS_LOG (1, max_log_level, "setting the trustfile"); | ||
| 332 | ret = gnutls_certificate_set_x509_trust_file | 356 | ret = gnutls_certificate_set_x509_trust_file |
| 333 | (x509_cred, | 357 | (x509_cred, |
| 334 | XSTRING (trustfile)->data, | 358 | XSTRING (trustfile)->data, |
| @@ -340,6 +364,7 @@ KEYFILE and optionally CALLBACK. */) | |||
| 340 | 364 | ||
| 341 | if (STRINGP (keyfile)) | 365 | if (STRINGP (keyfile)) |
| 342 | { | 366 | { |
| 367 | GNUTLS_LOG (1, max_log_level, "setting the keyfile"); | ||
| 343 | ret = gnutls_certificate_set_x509_crl_file | 368 | ret = gnutls_certificate_set_x509_crl_file |
| 344 | (x509_cred, | 369 | (x509_cred, |
| 345 | XSTRING (keyfile)->data, | 370 | XSTRING (keyfile)->data, |
| @@ -352,6 +377,8 @@ KEYFILE and optionally CALLBACK. */) | |||
| 352 | 377 | ||
| 353 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; | 378 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; |
| 354 | 379 | ||
| 380 | GNUTLS_LOG (1, max_log_level, "gnutls_init"); | ||
| 381 | |||
| 355 | ret = gnutls_init (&state, GNUTLS_CLIENT); | 382 | ret = gnutls_init (&state, GNUTLS_CLIENT); |
| 356 | 383 | ||
| 357 | if (ret < GNUTLS_E_SUCCESS) | 384 | if (ret < GNUTLS_E_SUCCESS) |
| @@ -361,6 +388,8 @@ KEYFILE and optionally CALLBACK. */) | |||
| 361 | 388 | ||
| 362 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT; | 389 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT; |
| 363 | 390 | ||
| 391 | GNUTLS_LOG (1, max_log_level, "setting the priority string"); | ||
| 392 | |||
| 364 | ret = gnutls_priority_set_direct(state, | 393 | ret = gnutls_priority_set_direct(state, |
| 365 | (char*) SDATA (priority_string), | 394 | (char*) SDATA (priority_string), |
| 366 | NULL); | 395 | NULL); |
| @@ -393,8 +422,8 @@ KEYFILE and optionally CALLBACK. */) | |||
| 393 | if (ret < GNUTLS_E_SUCCESS) | 422 | if (ret < GNUTLS_E_SUCCESS) |
| 394 | return gnutls_make_error (ret); | 423 | return gnutls_make_error (ret); |
| 395 | 424 | ||
| 396 | XPROCESS (proc)->anon_cred = anon_cred; | 425 | XPROCESS (proc)->gnutls_anon_cred = anon_cred; |
| 397 | XPROCESS (proc)->x509_cred = x509_cred; | 426 | XPROCESS (proc)->gnutls_x509_cred = x509_cred; |
| 398 | XPROCESS (proc)->gnutls_cred_type = type; | 427 | XPROCESS (proc)->gnutls_cred_type = type; |
| 399 | 428 | ||
| 400 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET; | 429 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET; |
| @@ -449,6 +478,7 @@ or `gnutls-e-interrupted'. In that case you may resume the handshake | |||
| 449 | { | 478 | { |
| 450 | gnutls_session_t state; | 479 | gnutls_session_t state; |
| 451 | int ret; | 480 | int ret; |
| 481 | int max_log_level = XPROCESS (proc)->gnutls_log_level; | ||
| 452 | 482 | ||
| 453 | CHECK_PROCESS (proc); | 483 | CHECK_PROCESS (proc); |
| 454 | state = XPROCESS (proc)->gnutls_state; | 484 | state = XPROCESS (proc)->gnutls_state; |
| @@ -473,11 +503,10 @@ or `gnutls-e-interrupted'. In that case you may resume the handshake | |||
| 473 | ret = gnutls_handshake (state); | 503 | ret = gnutls_handshake (state); |
| 474 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED; | 504 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED; |
| 475 | 505 | ||
| 476 | if (GNUTLS_E_SUCCESS == ret || ret == 0) | 506 | if (GNUTLS_E_SUCCESS == ret) |
| 477 | { | 507 | { |
| 478 | /* here we're finally done. */ | 508 | /* here we're finally done. */ |
| 479 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY; | 509 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY; |
| 480 | return Qt; | ||
| 481 | } | 510 | } |
| 482 | 511 | ||
| 483 | return gnutls_make_error (ret); | 512 | return gnutls_make_error (ret); |
diff --git a/src/gnutls.h b/src/gnutls.h index 3a9030ba454..d63555a8a94 100644 --- a/src/gnutls.h +++ b/src/gnutls.h | |||
| @@ -46,6 +46,8 @@ typedef enum | |||
| 46 | 46 | ||
| 47 | #define GNUTLS_PROCESS_USABLE(proc) (GNUTLS_INITSTAGE(proc) >= GNUTLS_STAGE_READY) | 47 | #define GNUTLS_PROCESS_USABLE(proc) (GNUTLS_INITSTAGE(proc) >= GNUTLS_STAGE_READY) |
| 48 | 48 | ||
| 49 | #define GNUTLS_LOG(level, max, string) if (level <= max) { gnutls_log_function (level, "(Emacs) " string); } | ||
| 50 | |||
| 49 | int | 51 | int |
| 50 | emacs_gnutls_write (int fildes, gnutls_session_t state, char *buf, | 52 | emacs_gnutls_write (int fildes, gnutls_session_t state, char *buf, |
| 51 | unsigned int nbyte); | 53 | unsigned int nbyte); |
diff --git a/src/process.c b/src/process.c index 70cc8250add..cf16027b30a 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -671,6 +671,7 @@ make_process (Lisp_Object name) | |||
| 671 | 671 | ||
| 672 | #ifdef HAVE_GNUTLS | 672 | #ifdef HAVE_GNUTLS |
| 673 | p->gnutls_initstage = GNUTLS_STAGE_EMPTY; | 673 | p->gnutls_initstage = GNUTLS_STAGE_EMPTY; |
| 674 | p->gnutls_log_level = 0; | ||
| 674 | #endif | 675 | #endif |
| 675 | 676 | ||
| 676 | /* If name is already in use, modify it until it is unused. */ | 677 | /* If name is already in use, modify it until it is unused. */ |
diff --git a/src/process.h b/src/process.h index d6e842cfbbc..a28bf090ba9 100644 --- a/src/process.h +++ b/src/process.h | |||
| @@ -133,8 +133,9 @@ struct Lisp_Process | |||
| 133 | #ifdef HAVE_GNUTLS | 133 | #ifdef HAVE_GNUTLS |
| 134 | gnutls_initstage_t gnutls_initstage; | 134 | gnutls_initstage_t gnutls_initstage; |
| 135 | gnutls_session_t gnutls_state; | 135 | gnutls_session_t gnutls_state; |
| 136 | gnutls_certificate_client_credentials x509_cred; | 136 | gnutls_certificate_client_credentials gnutls_x509_cred; |
| 137 | gnutls_anon_client_credentials_t anon_cred; | 137 | gnutls_anon_client_credentials_t gnutls_anon_cred; |
| 138 | int gnutls_log_level; | ||
| 138 | #endif | 139 | #endif |
| 139 | }; | 140 | }; |
| 140 | 141 | ||