From: Paul Eggert Date: Tue, 26 Apr 2011 06:17:52 +0000 (-0700) Subject: Merge from mainline. X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~215 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=671875dac181f7f1337f21d013a9c3d5f235ddf2;p=emacs.git Merge from mainline. --- 671875dac181f7f1337f21d013a9c3d5f235ddf2 diff --cc ChangeLog index 64aad9e278a,3a729327bf3..f67a5bf0b55 --- a/ChangeLog +++ b/ChangeLog @@@ -1,21 -1,12 +1,28 @@@ - 2011-04-22 Paul Eggert ++2011-04-26 Paul Eggert + + * configure.in: Suppress unnecessary checks for size_t. + (AC_TYPE_SIZE_T): Define an empty macro, to suppress obsolescent test. + (size_t): Do not check for this, and do not typedef. This code + is never exercised now. + - 2011-04-21 Paul Eggert - + * Makefile.in (GNULIB_MODULES): Add strtoumax. + This is needed for the new integer-reading code in lread.c. + It automatically pulls in the following gnulib files, which + are used on old-fashioned platforms that don't have strtoumax: + lib/inttypes.in.h, lib/strtoimax.c, lib/strtol.c, lib/strtoul.c, + lib/strtoull.c, lib/strtoumax.c, lib/verify.h, m4/inttypes.m4, + m4/strtoull.m4, m4/strtoumax.m4. + * .bzrignore: Add lib/inttypes.h. + + 2011-04-24 Teodor Zlatanov + + * configure.in: Check for GnuTLS certificate verify callbacks. + + 2011-04-20 Stefan Monnier + + * Makefile.in (config.status): Don't erase in case of error. + In case it disappeared, rebuild it with `configure'. + 2011-04-20 Ken Brown * configure.in (use_mmap_for_buffers): Set to yes on Cygwin. diff --cc src/ChangeLog index 87e703b3dab,1985cdc3768..6614375a7c6 --- a/src/ChangeLog +++ b/src/ChangeLog @@@ -1,193 -1,173 +1,357 @@@ - 2011-04-25 Paul Eggert ++2011-04-26 Paul Eggert + + lisp.h: Fix a problem with aliasing and vector headers. + GCC 4.6.0 optimizes based on type-based alias analysis. For + example, if b is of type struct buffer * and v of type struct + Lisp_Vector *, then gcc -O2 was incorrectly assuming that &b->size + != &v->size, and therefore "v->size = 1; b->size = 2; return + v->size;" must therefore return 1. This assumption is incorrect + for Emacs, since it type-puns struct Lisp_Vector * with many other + types. To fix this problem, this patch adds a new type struct + vectorlike_header that documents the constraints on layout of vectors + and pseudovectors, and helps optimizing compilers not get fooled + by Emacs's type punning. It also adds the macros XSETTYPED_PVECTYPE + XSETTYPED_PSEUDOVECTOR, TYPED_PSEUDOVECTORP, for similar reasons. + * lisp.h (XSETTYPED_PVECTYPE): New macro, specifying the name of + the size member. + (XSETPVECTYPE): Rewrite in terms of new macro. + (XSETPVECTYPESIZE): New macro, specifying both type and size. + This is a bit clearer, and further avoids the possibility of + undesirable aliasing. + (XSETTYPED_PSEUDOVECTOR): New macro, specifying the size. + (XSETPSEUDOVECTOR): Rewrite in terms of XSETTYPED_PSEUDOVECTOR. + (XSETSUBR): Rewrite in terms of XSETTYPED_PSEUDOVECTOR and XSIZE, + since Lisp_Subr is a special case (no "next" field). + (ASIZE): Now uses header.size rather than size. All + previous uses of XVECTOR (foo)->size replaced to use this macro, + to avoid the hassle of writing XVECTOR (foo)->header.size. + (struct vectorlike_header): New type. + (TYPED_PSEUDOVECTORP): New macro, also specifying the C type of the + object, to help avoid aliasing. + (PSEUDOVECTORP): Rewrite in terms of TYPED_PSEUDOVECTORP. + (SUBRP): Likewise, since Lisp_Subr is a special case. + * lisp.h (struct Lisp_Vector, struct Lisp_Char_Table): + (struct Lisp_Sub_Char_Table, struct Lisp_Bool_Vector): + (struct Lisp_Hash_Table): Combine first two members into a single + struct vectorlike_header member. All uses of "size" and "next" members + changed to be "header.size" and "header.next". + * buffer.h (struct buffer): Likewise. + * font.h (struct font_spec, struct font_entity, struct font): Likewise. + * frame.h (struct frame): Likewise. + * process.h (struct Lisp_Process): Likewise. + * termhooks.h (struct terminal): Likewise. + * window.c (struct save_window_data, struct saved_window): Likewise. + * window.h (struct window): Likewise. + * alloc.c (allocate_buffer, Fmake_bool_vector, allocate_pseudovector): + Use XSETPVECTYPESIZE, not XSETPVECTYPE, to avoid aliasing problems. + * buffer.c (init_buffer_once): Likewise. + * lread.c (defsubr): Use XSETTYPED_PVECTYPE, since Lisp_Subr is a + special case. + * process.c (Fformat_network_address): Use local var for size, + for brevity. + - 2011-04-24 Paul Eggert - + * bytecode.c (exec_byte_code): Don't use XVECTOR before CHECK_VECTOR. + - 2011-04-21 Paul Eggert - + Make the Lisp reader and string-to-float more consistent. + * data.c (atof): Remove decl; no longer used or needed. + (digit_to_number): Move to lread.c. + (Fstring_to_number): Use new string_to_number function, to be + consistent with how the Lisp reader treats infinities and NaNs. + Do not assume that floating-point numbers represent EMACS_INT + without losing information; this is not true on most 64-bit hosts. + Avoid double-rounding errors, by insisting on integers when + parsing non-base-10 numbers, as the documentation specifies. + * lisp.h (string_to_number): New decl, replacing ... + (isfloat_string): Remove. + * lread.c: Include , for uintmax_t and strtoumax. + (read1): Do not accept +. and -. as integers; this + appears to have been a coding error. Similarly, do not accept + strings like +-1e0 as floating point numbers. Do not report + overflow for integer overflows unless the base is not 10 which + means we have no simple and reliable way to continue. + Break out the floating-point parsing into a new + function string_to_number, so that Fstring_to_number parses + floating point numbers consistently with the Lisp reader. + (digit_to_number): Moved here from data.c. Make it static inline. + (E_CHAR, EXP_INT): Remove, replacing with ... + (E_EXP): New macro, to solve the "1.0e+" problem mentioned below. + (string_to_number): New function, replacing isfloat_string. + This function checks for valid syntax and produces the resulting + Lisp float number too. Rework it so that string-to-number + no longer mishandles examples like "1.0e+". Use strtoumax, + so that overflow for non-base-10 numbers is reported only when + there's no portable and simple way to convert to floating point. + - 2011-04-20 Paul Eggert - + * textprop.c (set_text_properties_1): Rewrite for clarity, + and to avoid GCC warning about integer overflow. + + * intervals.h (struct interval): Use EMACS_INT for members + where EMACS_UINT might cause problems. See + . + (CHECK_TOTAL_LENGTH): Remove cast to EMACS_INT; no longer needed. + * intervals.c (interval_deletion_adjustment): Now returns EMACS_INT. + All uses changed. + (offset_intervals): Tell GCC not to worry about length overflow + when negating a negative length. + + * alloc.c (overrun_check_malloc, overrun_check_realloc): Now static. + (overrun_check_free): Likewise. + + * alloc.c (SDATA_SIZE) [!GC_CHECK_STRING_BYTES]: Avoid runtime check + in the common case where SDATA_DATA_OFFSET is a multiple of Emacs + word size. + + * gnutls.c: Fix problems found by GCC 4.6.0 on Ubuntu 10.10. + (gnutls_make_error): Rename local to avoid shadowing. + (gnutls_emacs_global_deinit): ifdef out; not used. + (Fgnutls_boot): Use const for pointer to readonly storage. + Comment out unused local. Fix pointer signedness problems. + + * lread.c (openp): Don't stuff size_t into an 'int'. + Use <= on length, not < on length + 1, to avoid GCC 4.6.0 warning + about possible signed overflow. + + * gtkutil.c: Fix problems found by GCC 4.6.0 on Ubuntu 10.10. + (GDK_KEY_g): Don't define if already defined. + (xg_prepare_tooltip): Avoid pointer signedness problem. + (xg_set_toolkit_scroll_bar_thumb): Redo to avoid two casts. + + * process.c (Fnetwork_interface_info): Avoid left-shift undefined + behavior with 1 << 31. GCC 4.6.0 warns about this on 32-bit hosts. + + * xfns.c (Fx_window_property): Simplify a bit, + to make a bit faster and to avoid GCC 4.6.0 warning. + * xselect.c (x_get_window_property, x_handle_dnd_message): Likewise. + + * fns.c (internal_equal): Don't assume size_t fits in int. + + * alloc.c (compact_small_strings): Tighten assertion a little. + + Replace pEd with more-general pI, and fix some printf arg casts. + * lisp.h (pI): New macro, generalizing old pEd macro to other + conversion specifiers. For example, use "...%"pI"d..." rather + than "...%"pEd"...". + (pEd): Remove. All uses replaced with similar uses of pI. + * src/m/amdx86-64.h, src/m/ia64.h, src/m/ibms390x.h: Likewise. + * alloc.c (check_pure_size): Don't overflow by converting size to int. + * bidi.c (bidi_dump_cached_states): Use pI to avoid cast. + * data.c (Fnumber_to_string): Use pI instead of if-then-else-abort. + * dbusbind.c (xd_append_arg): Use pI to avoid cast. + (Fdbus_method_return_internal, Fdbus_method_error_internal): Likewise. + * font.c (font_unparse_xlfd): Avoid potential buffer overrun on + 64-bit hosts. + (font_unparse_xlfd, font_unparse_fcname): Use pI to avoid casts. + * keyboard.c (record_char, modify_event_symbol): Use pI to avoid casts. + * print.c (safe_debug_print, print_object): Likewise. + (print_object): Don't overflow by converting EMACS_INT or EMACS_UINT + to int. + Use pI instead of if-then-else-abort. Use %p to avoid casts, + avoiding the 0 flag, which is not portable. + * process.c (Fmake_network_process): Use pI to avoid cast. + * region-cache.c (pp_cache): Likewise. + * xdisp.c (decode_mode_spec): Likewise. + * xrdb.c (x_load_resources) [USE_MOTIF]: Use pI to avoid undefined + behavior on 64-bit hosts with printf arg. + * xselect.c (x_queue_event): Use %p to avoid casts, avoiding 0 flag. + (x_stop_queuing_selection_requests): Likewise. + (x_get_window_property): Don't truncate byte count to an 'int' + when tracing. + + * frame.c (frame_name_fnn_p): Get rid of strtol, which isn't right + here, since it parses constructs like leading '-' and spaces, + which are not wanted; and it overflows with large numbers. + Instead, simply match F[0-9]+, which is what is wanted anyway. + + * alloc.c: Remove unportable assumptions about struct layout. + (SDATA_SELECTOR, SDATA_DATA_OFFSET): New macros. + (SDATA_OF_STRING, SDATA_SIZE, allocate_string_data): + (allocate_vectorlike, make_pure_vector): Use the new macros, + plus offsetof, to remove unportable assumptions about struct layout. + These assumptions hold on all porting targets that I know of, but + they are not guaranteed, they're easy to remove, and removing them + makes further changes easier. + + * alloc.c (BLOCK BYTES): Fix typo by changing "ablock" to "ablocks". + This doesn't fix a bug but makes the code clearer. + (string_overrun_cookie): Now const. Use initializers that + don't formally overflow signed char, to avoid warnings. + (allocate_string_data) [GC_CHECK_STRING_OVERRUN]: Fix typo that + can cause Emacs to crash when string overrun checking is enabled. + (allocate_buffer): Don't assume sizeof (struct buffer) is a + multiple of sizeof (EMACS_INT); it need not be, if + alignof(EMACS_INT) < sizeof (EMACS_INT). + (check_sblock, check_string_bytes, check_string_free_list): Protoize. + + 2011-04-25 Dan Nicolaescu + + * alloc.c (check_sblock, check_string_bytes) + (check_string_free_list): Convert to standard C. + + 2011-04-25 Teodor Zlatanov + + * w32.c (emacs_gnutls_push): Fix typo. + + 2011-04-25 Eli Zaretskii + + * gnutls.c (emacs_gnutls_handshake): Avoid compiler warnings about + "cast to pointer from integer of different size". + + Improve doprnt and its use in verror. (Bug#8545) + * doprnt.c (doprnt): Document the set of format control sequences + supported by the function. Use SAFE_ALLOCA instead of always + using `alloca'. + + * eval.c (verror): Don't limit the buffer size at size_max-1, that + is one byte too soon. Don't use xrealloc; instead xfree and + xmalloc anew. + + 2011-04-24 Teodor Zlatanov + + * gnutls.h: Add GNUTLS_STAGE_CALLBACKS enum to denote we're in the + callbacks stage. + + * gnutls.c: Renamed global_initialized to + gnutls_global_initialized. Added internals for the + :verify-hostname-error, :verify-error, and :verify-flags + parameters of `gnutls-boot' and documented those parameters in the + docstring. Start callback support. + (emacs_gnutls_handshake): Add Woe32 support. Retry handshake + unless a fatal error occured. Call gnutls_alert_send_appropriate + on error. Return error code. + (emacs_gnutls_write): Call emacs_gnutls_handle_error. + (emacs_gnutls_read): Likewise. + (Fgnutls_boot): Return handshake error code. + (emacs_gnutls_handle_error): New function. + (wsaerror_to_errno): Likewise. + + * w32.h (emacs_gnutls_pull): Add prototype. + (emacs_gnutls_push): Likewise. + + * w32.c (emacs_gnutls_pull): New function for GnuTLS on Woe32. + (emacs_gnutls_push): Likewise. + + 2011-04-24 Claudio Bley (tiny change) + + * process.c (wait_reading_process_output): Check if GnuTLS + buffered some data internally if no FDs are set for TLS + connections. + + * makefile.w32-in (OBJ2): Add gnutls.$(O). + (LIBS): Link to USER_LIBS. + ($(BLD)/gnutls.$(0)): New target. + + 2011-04-24 Eli Zaretskii + + * xdisp.c (handle_single_display_spec): Rename the + display_replaced_before_p argument into display_replaced_p, to + make it consistent with the commentary. Fix typos in the + commentary. + + * textprop.c (syms_of_textprop): Remove dead code. + (copy_text_properties): Delete obsolete commentary about an + interface that was deleted long ago. Fix typos in the description + of arguments. + + * msdos.c (XMenuActivate, XMenuAddSelection): Adjust argument list + to changes in oldXMenu/XMenu.h from 2011-04-16. + : Constify. + (IT_menu_make_room): menu->help_text is now `const char **'; + adjust. + + * msdos.h (XMenuActivate, XMenuAddSelection): Adjust prototypes + to changes in oldXMenu/XMenu.h from 2011-04-16. + (struct XMenu): Declare `help_text' `const char **'. + + * xfaces.c : Make extern again. + + * syntax.c: Include sys/types.h before including regex.h, as + required by Posix. + + * doc.c (get_doc_string): Improve the format passed to `error'. + + * doprnt.c (doprnt): Improve commentary. + + * term.c (init_tty) [MSDOS]: Fix 1st argument to maybe_fatal. + + * Makefile.in (TAGS): Depend on $(M_FILE) and $(S_FILE), and scan + them with etags. + + * makefile.w32-in (globals.h): Add a dummy recipe, to make any + changes in globals.h immediately force recompilation. + (TAGS): Depend on $(CURDIR)/m/intel386.h and + $(CURDIR)/s/ms-w32.h. + (TAGS-gmake): Scan $(CURDIR)/m/intel386.h and $(CURDIR)/s/ms-w32.h. + + * character.c (Fchar_direction): Function deleted. + (syms_of_character): Don't defsubr it. + : Deleted. + + 2011-04-23 Eli Zaretskii + + Fix doprnt so it could be used again safely in `verror'. (Bug#8435) + * doprnt.c: Include limits.h. + (SIZE_MAX): New macro. + (doprnt): Return a size_t value. 2nd arg is now size_t. Many + local variables are now size_t instead of int or unsigned. + Improve overflow protection. Support `l' modifier for integer + conversions. Support %l conversion. Don't assume an EMACS_INT + argument for integer conversions and for %c. + + * lisp.h (doprnt): Restore prototype. + + * makefile.w32-in ($(BLD)/callint.$(O)): Depend on + $(SRC)/character.h. + + * Makefile.in (base_obj): Add back doprnt.o. + + * deps.mk (doprnt.o): Add back prerequisites. + (callint.o): Depend on character.h. + + * eval.c (internal_lisp_condition_case): Include the handler + representation in the error message. + (verror): Call doprnt instead of vsnprintf. Fix an off-by-one bug + when breaking from the loop. + + * xdisp.c (vmessage): Call doprnt instead of vsnprintf. + + * callint.c (Fcall_interactively): When displaying error message + about invalid control letter, pass the character's codepoint, not + a pointer to its multibyte form. Improve display of the character + in octal and display also its hex code. + + * character.c (char_string): Use %x to display the (unsigned) + codepoint of an invalid character, to avoid displaying a bogus + negative value. + + * font.c (check_otf_features): Pass SDATA of SYMBOL_NAME to + `error', not SYMBOL_NAME itself. + + * coding.c (Fencode_sjis_char, Fencode_big5_char): Use %c for + character arguments to `error'. + + * charset.c (check_iso_charset_parameter): Fix incorrect argument + to `error' in error message about FINAL_CHAR argument. Make sure + FINAL_CHAR is a character, and use %c when it is passed as + argument to `error'. + + 2011-04-23 Eli Zaretskii + + * s/ms-w32.h (localtime): Redirect to sys_localtime. + + * w32.c: Include . + (sys_localtime): New function. + + 2011-04-23 Chong Yidong + + * xdisp.c (init_xdisp): Initialize echo_area_window (Bug#6451). + + * buffer.c (syms_of_buffer): Doc fix (Bug#6902). + + 2011-04-23 Samuel Thibault (tiny change) + + * sysdep.c (wait_for_termination): On GNU Hurd, kill returns -1 on + zombies (Bug#8467). + 2011-04-19 Eli Zaretskii * syntax.h (SETUP_SYNTAX_TABLE_FOR_OBJECT): Fix setting of diff --cc src/charset.c index 9a7a56d9379,e7435c292e2..52c2ebdcc4e --- a/src/charset.c +++ b/src/charset.c @@@ -1436,20 -1436,16 +1436,16 @@@ check_iso_charset_parameter (Lisp_Objec { CHECK_NATNUM (dimension); CHECK_NATNUM (chars); - CHECK_NATNUM (final_char); + CHECK_CHARACTER (final_char); if (XINT (dimension) > 3) - error ("Invalid DIMENSION %"pEd", it should be 1, 2, or 3", + error ("Invalid DIMENSION %"pI"d, it should be 1, 2, or 3", XINT (dimension)); if (XINT (chars) != 94 && XINT (chars) != 96) - error ("Invalid CHARS %"pEd", it should be 94 or 96", XINT (chars)); + error ("Invalid CHARS %"pI"d, it should be 94 or 96", XINT (chars)); if (XINT (final_char) < '0' || XINT (final_char) > '~') - { - unsigned char str[MAX_MULTIBYTE_LENGTH + 1]; - int len = CHAR_STRING (XINT (chars), str); - str[len] = '\0'; - error ("Invalid FINAL-CHAR %s, it should be `0'..`~'", str); - } + error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", + (int)XINT (final_char)); } diff --cc src/gnutls.c index 38932c9fa47,975fe655072..ea0a9857035 --- a/src/gnutls.c +++ b/src/gnutls.c @@@ -287,20 -395,7 +396,8 @@@ emacs_gnutls_global_deinit (void return gnutls_make_error (GNUTLS_E_SUCCESS); } +#endif - static void - gnutls_log_function (int level, const char* string) - { - message ("gnutls.c: [%d] %s", level, string); - } - - static void - gnutls_log_function2 (int level, const char* string, const char* extra) - { - message ("gnutls.c: [%d] %s %s", level, string, extra); - } - DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 3, 0, doc: /* Initialize GnuTLS client for process PROC with TYPE+PROPLIST. Currently only client mode is supported. Returns a success/failure @@@ -343,25 -461,40 +463,40 @@@ one trustfile (usually a CA bundle). * gnutls_certificate_credentials_t x509_cred; gnutls_anon_client_credentials_t anon_cred; Lisp_Object global_init; - char* priority_string_ptr = "NORMAL"; /* default priority string. */ + char const *priority_string_ptr = "NORMAL"; /* default priority string. */ Lisp_Object tail; + int peer_verification; + char* c_hostname; /* Placeholders for the property list elements. */ Lisp_Object priority_string; Lisp_Object trustfiles; Lisp_Object keyfiles; - Lisp_Object callbacks; + /* Lisp_Object callbacks; */ Lisp_Object loglevel; + Lisp_Object hostname; + Lisp_Object verify_flags; + Lisp_Object verify_error; + Lisp_Object verify_hostname_error; CHECK_PROCESS (proc); CHECK_SYMBOL (type); CHECK_LIST (proplist); - priority_string = Fplist_get (proplist, Qgnutls_bootprop_priority); - trustfiles = Fplist_get (proplist, Qgnutls_bootprop_trustfiles); - keyfiles = Fplist_get (proplist, Qgnutls_bootprop_keyfiles); - /* callbacks = Fplist_get (proplist, Qgnutls_bootprop_callbacks); */ - loglevel = Fplist_get (proplist, Qgnutls_bootprop_loglevel); + hostname = Fplist_get (proplist, Qgnutls_bootprop_hostname); + priority_string = Fplist_get (proplist, Qgnutls_bootprop_priority); + trustfiles = Fplist_get (proplist, Qgnutls_bootprop_trustfiles); + keyfiles = Fplist_get (proplist, Qgnutls_bootprop_keyfiles); - callbacks = Fplist_get (proplist, Qgnutls_bootprop_callbacks); ++ /* callbacks = Fplist_get (proplist, Qgnutls_bootprop_callbacks); */ + loglevel = Fplist_get (proplist, Qgnutls_bootprop_loglevel); + verify_flags = Fplist_get (proplist, Qgnutls_bootprop_verify_flags); + verify_error = Fplist_get (proplist, Qgnutls_bootprop_verify_error); + verify_hostname_error = Fplist_get (proplist, Qgnutls_bootprop_verify_hostname_error); + + if (!STRINGP (hostname)) + error ("gnutls-boot: invalid :hostname parameter"); + + c_hostname = SSDATA (hostname); state = XPROCESS (proc)->gnutls_state; XPROCESS (proc)->gnutls_p = 1; @@@ -544,9 -702,113 +704,113 @@@ GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET; - emacs_gnutls_handshake (XPROCESS (proc)); + ret = emacs_gnutls_handshake (XPROCESS (proc)); - return gnutls_make_error (GNUTLS_E_SUCCESS); + if (ret < GNUTLS_E_SUCCESS) + return gnutls_make_error (ret); + + /* Now verify the peer, following + http://www.gnu.org/software/gnutls/manual/html_node/Verifying-peer_0027s-certificate.html. + The peer should present at least one certificate in the chain; do a + check of the certificate's hostname with + gnutls_x509_crt_check_hostname() against :hostname. */ + + ret = gnutls_certificate_verify_peers2 (state, &peer_verification); + + if (ret < GNUTLS_E_SUCCESS) + return gnutls_make_error (ret); - ++ + if (XINT (loglevel) > 0 && peer_verification & GNUTLS_CERT_INVALID) - message ("%s certificate could not be verified.", ++ message ("%s certificate could not be verified.", + c_hostname); - ++ + if (peer_verification & GNUTLS_CERT_REVOKED) + GNUTLS_LOG2 (1, max_log_level, "certificate was revoked (CRL):", + c_hostname); - ++ + if (peer_verification & GNUTLS_CERT_SIGNER_NOT_FOUND) + GNUTLS_LOG2 (1, max_log_level, "certificate signer was not found:", + c_hostname); - ++ + if (peer_verification & GNUTLS_CERT_SIGNER_NOT_CA) + GNUTLS_LOG2 (1, max_log_level, "certificate signer is not a CA:", + c_hostname); + + if (peer_verification & GNUTLS_CERT_INSECURE_ALGORITHM) + GNUTLS_LOG2 (1, max_log_level, + "certificate was signed with an insecure algorithm:", + c_hostname); + + if (peer_verification & GNUTLS_CERT_NOT_ACTIVATED) + GNUTLS_LOG2 (1, max_log_level, "certificate is not yet activated:", + c_hostname); + + if (peer_verification & GNUTLS_CERT_EXPIRED) + GNUTLS_LOG2 (1, max_log_level, "certificate has expired:", + c_hostname); + + if (peer_verification != 0) + { + if (NILP (verify_hostname_error)) + { + GNUTLS_LOG2 (1, max_log_level, "certificate validation failed:", + c_hostname); + } + else + { + error ("Certificate validation failed %s, verification code %d", + c_hostname, peer_verification); + } + } + + /* Up to here the process is the same for X.509 certificates and + OpenPGP keys. From now on X.509 certificates are assumed. This + can be easily extended to work with openpgp keys as well. */ + if (gnutls_certificate_type_get (state) == GNUTLS_CRT_X509) + { + ret = gnutls_x509_crt_init (&gnutls_verify_cert); + + if (ret < GNUTLS_E_SUCCESS) + return gnutls_make_error (ret); + - gnutls_verify_cert_list = ++ gnutls_verify_cert_list = + gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size); + + if (NULL == gnutls_verify_cert_list) + { + error ("No x509 certificate was found!\n"); + } + + /* We only check the first certificate in the given chain. */ + ret = gnutls_x509_crt_import (gnutls_verify_cert, + &gnutls_verify_cert_list[0], + GNUTLS_X509_FMT_DER); + + if (ret < GNUTLS_E_SUCCESS) + { + gnutls_x509_crt_deinit (gnutls_verify_cert); + return gnutls_make_error (ret); + } + + if (!gnutls_x509_crt_check_hostname (gnutls_verify_cert, c_hostname)) + { + if (NILP (verify_hostname_error)) + { + GNUTLS_LOG2 (1, max_log_level, "x509 certificate does not match:", + c_hostname); + } + else + { + gnutls_x509_crt_deinit (gnutls_verify_cert); + error ("The x509 certificate does not match \"%s\"", + c_hostname); + } + } + + gnutls_x509_crt_deinit (gnutls_verify_cert); + } + + return gnutls_make_error (ret); } DEFUN ("gnutls-bye", Fgnutls_bye,