From: Nikos Mavrogiannopoulos Date: Fri, 4 Oct 2002 19:09:59 +0000 (+0000) Subject: Corrected bug which prevented gnutls_certificate_get_ours() from working. X-Git-Tag: gnutls_0_5_9~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=99d8771ebe64df0fa74eb5f09688ebe9d400ca80;p=thirdparty%2Fgnutls.git Corrected bug which prevented gnutls_certificate_get_ours() from working. Added gnutls_certificate_get_our_issuer() function. --- diff --git a/NEWS b/NEWS index 4d75c6d17d..a57dc984f8 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ Version 0.5.9 - Added gnutls_x509_extract_key_pk_algorithm() function which extracts the private key type. +- Corrected some code which worked fine in gcc 3.2, but not with any + other compiler. Version 0.5.8 (25/09/2002) - Updated documentation. diff --git a/doc/TODO b/doc/TODO index 7d4c3af96d..c40dd5d63f 100644 --- a/doc/TODO +++ b/doc/TODO @@ -4,7 +4,7 @@ in order to avoid having people working on the same thing. Current list: + Add ability to read PKCS-12 structures (certificate and private key) -* Add functions to parse DER encoded private keys +* Add more functions to parse DER encoded private keys * Add support for the certificate authenticated SRP cipher suites * Add option to read the SRP parameters using a callback (server side) * Add functions to generate SRP parameters and SRP verifiers diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c index 2ad6449fad..e26780baec 100644 --- a/lib/gnutls_state.c +++ b/lib/gnutls_state.c @@ -125,7 +125,6 @@ void _gnutls_handshake_internal_state_clear( gnutls_session session) { session->internals.extensions_sent_size = 0; /* by default no selected certificate */ - session->internals.selected_cert_index = -1; session->internals.proposed_record_size = DEFAULT_MAX_RECORD_SIZE; session->internals.adv_version_major = 0; session->internals.adv_version_minor = 0; diff --git a/lib/gnutls_ui.c b/lib/gnutls_ui.c index 5779268e56..98b7a5793f 100644 --- a/lib/gnutls_ui.c +++ b/lib/gnutls_ui.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001 Nikos Mavroyanopoulos + * Copyright (C) 2001,2002 Nikos Mavroyanopoulos * * This file is part of GNUTLS. * @@ -181,7 +181,7 @@ int gnutls_dh_get_peers_public_bits(gnutls_session session) * gnutls_certificate_get_ours - This function returns the raw certificate sent in the last handshake * @session: is a gnutls session * - * This function will return the raw certificate list as sent to the peer, + * This function will return the certificate as sent to the peer, * in the last handshake. These certificates are in raw format. * In X.509 this is a certificate list. In OpenPGP this is a single * certificate. @@ -202,9 +202,46 @@ const gnutls_datum *gnutls_certificate_get_ours(gnutls_session session) } index = session->internals.selected_cert_index; - if (index < 0) return NULL; /* no certificate */ + if (index < 0) { + gnutls_assert(); + return NULL; /* no certificate */ + } - return &cred->cert_list[index]->raw; + return &cred->cert_list[index][0].raw; +} + +/** + * gnutls_certificate_get_our_issuer - This function returns the raw certificate sent in the last handshake + * @session: is a gnutls session + * + * This function will return the raw certificate of our issuer as sent to the peer, + * in the last handshake. This certificate is in raw format. + * This has no meaning for OpenPGP keys. + * Returns NULL in case of an error, or if no certificate was found. + * + **/ +const gnutls_datum *gnutls_certificate_get_our_issuer(gnutls_session session) +{ + const gnutls_certificate_credentials cred; + int index; + + CHECK_AUTH(GNUTLS_CRD_CERTIFICATE, NULL); + + cred = _gnutls_get_cred(session->gnutls_key, GNUTLS_CRD_CERTIFICATE, NULL); + if (cred == NULL) { + gnutls_assert(); + return NULL; + } + + index = session->internals.selected_cert_index; + if (index < 0) { + gnutls_assert(); + return NULL; /* no certificate */ + } + + if (cred->cert_list_length[index]-1 > 0) + return &cred->cert_list[index][cred->cert_list_length[index]-1].raw; + else return NULL; } /** diff --git a/lib/gnutls_ui.h b/lib/gnutls_ui.h index 2a9cb4a4c2..7bb997d789 100644 --- a/lib/gnutls_ui.h +++ b/lib/gnutls_ui.h @@ -100,6 +100,7 @@ int gnutls_x509_verify_certificate( const gnutls_datum* cert_list, int cert_list /* get data from the session */ const gnutls_datum* gnutls_certificate_get_peers( gnutls_session, int* list_size); const gnutls_datum *gnutls_certificate_get_ours( gnutls_session session); +const gnutls_datum *gnutls_certificate_get_our_issuer(gnutls_session session); time_t gnutls_certificate_activation_time_peers(gnutls_session session); time_t gnutls_certificate_expiration_time_peers(gnutls_session session);