From: Nikos Mavrogiannopoulos Date: Sat, 19 Oct 2013 07:33:14 +0000 (+0200) Subject: Added gnutls_certificate_get_crt_raw() to return the raw certificate as present in... X-Git-Tag: gnutls_3_2_5~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=75cb5d1e0805f00a03bc0d5f185fa8467a10af4b;p=thirdparty%2Fgnutls.git Added gnutls_certificate_get_crt_raw() to return the raw certificate as present in the credentials structure. --- diff --git a/NEWS b/NEWS index 8054156292..22e2745309 100644 --- a/NEWS +++ b/NEWS @@ -15,7 +15,7 @@ See the end for copying conditions. --inline-commands-prefix and --inline-commands options. Patch by Raj Raman. ** API and ABI modifications: -No changes since last version. +gnutls_certificate_get_crt_raw: Added * Version 3.2.4 (released 2013-08-31) diff --git a/lib/gnutls_cert.c b/lib/gnutls_cert.c index 3697836af0..285d5dffbc 100644 --- a/lib/gnutls_cert.c +++ b/lib/gnutls_cert.c @@ -119,6 +119,42 @@ gnutls_certificate_get_issuer (gnutls_certificate_credentials_t sc, return gnutls_x509_trust_list_get_issuer(sc->tlist, cert, issuer, flags); } +/** + * gnutls_certificate_get_crt_raw: + * @sc: is a #gnutls_certificate_credentials_t structure. + * @idx1: the index of the certificate if multiple are present + * @idx2: the index in the certificate list. Zero gives the server's certificate. + * @cert: Will hold the DER encoded certificate. + * + * This function will return the DER encoded certificate of the + * server or any other certificate on its certificate chain (based on @idx2). + * The returned data should be treated as constant and only accessible during the lifetime + * of @sc. + * + * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a + * negative error value. In case the indexes are out of bounds %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE + * is returned. + * + * Since: 3.2.5 + **/ +int +gnutls_certificate_get_crt_raw (gnutls_certificate_credentials_t sc, + unsigned idx1, + unsigned idx2, + gnutls_datum_t * cert) +{ + if (idx1 >= sc->ncerts) + return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE); + + if (idx2 >= sc->certs[idx1].cert_list_length) + return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE); + + cert->data = sc->certs[idx1].cert_list[idx2].cert.data; + cert->size = sc->certs[idx1].cert_list[idx2].cert.size; + + return 0; +} + /** * gnutls_certificate_free_ca_names: * @sc: is a #gnutls_certificate_credentials_t structure. diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in index 25fb7fdc2d..6c56879353 100644 --- a/lib/includes/gnutls/gnutls.h.in +++ b/lib/includes/gnutls/gnutls.h.in @@ -1297,6 +1297,9 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t session); int gnutls_certificate_get_issuer (gnutls_certificate_credentials_t sc, gnutls_x509_crt_t cert, gnutls_x509_crt_t* issuer, unsigned int flags); + + int gnutls_certificate_get_crt_raw (gnutls_certificate_credentials_t sc, unsigned idx1, + unsigned idx2, gnutls_datum_t * cert); void gnutls_certificate_free_keys (gnutls_certificate_credentials_t sc); void gnutls_certificate_free_cas (gnutls_certificate_credentials_t sc);