|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2002-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS-EXTRA.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS-extra is free software: you can redistribute it and/or modify
|
|
Packit Service |
4684c1 |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS-extra is distributed in the hope that it will be useful,
|
|
Packit Service |
4684c1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
4684c1 |
* GNU General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This file includes all functions that were in the 0.5.x and 0.8.x
|
|
Packit Service |
4684c1 |
* gnutls API. They are now implemented over the new certificate parsing
|
|
Packit Service |
4684c1 |
* API.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <string.h> /* memset */
|
|
Packit Service |
4684c1 |
#include <x509/x509_int.h>
|
|
Packit Service |
4684c1 |
#include <libtasn1.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/x509.h>
|
|
Packit Service |
4684c1 |
#include <openssl_compat.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/*-
|
|
Packit Service |
4684c1 |
* gnutls_x509_extract_certificate_dn:
|
|
Packit Service |
4684c1 |
* @cert: should contain an X.509 DER encoded certificate
|
|
Packit Service |
4684c1 |
* @ret: a pointer to a structure to hold the peer's name
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will return the name of the certificate holder. The name is gnutls_x509_dn structure and
|
|
Packit Service |
4684c1 |
* is a obtained by the peer's certificate. If the certificate send by the
|
|
Packit Service |
4684c1 |
* peer is invalid, or in any other failure this function returns error.
|
|
Packit Service |
4684c1 |
* Returns a negative error code in case of an error.
|
|
Packit Service |
4684c1 |
-*/
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
gnutls_x509_extract_certificate_dn(const gnutls_datum_t * cert,
|
|
Packit Service |
4684c1 |
gnutls_x509_dn * ret)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_t xcert;
|
|
Packit Service |
4684c1 |
int result;
|
|
Packit Service |
4684c1 |
size_t len;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
result = gnutls_x509_crt_init(&xcert);
|
|
Packit Service |
4684c1 |
if (result < 0)
|
|
Packit Service |
4684c1 |
return result;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
result = gnutls_x509_crt_import(xcert, cert, GNUTLS_X509_FMT_DER);
|
|
Packit Service |
4684c1 |
if (result < 0) {
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_deinit(xcert);
|
|
Packit Service |
4684c1 |
return result;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->country);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert, GNUTLS_OID_X520_COUNTRY_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->country, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->organization);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_ORGANIZATION_NAME, 0,
|
|
Packit Service |
4684c1 |
0, ret->organization, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->organizational_unit_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->organizational_unit_name,
|
|
Packit Service |
4684c1 |
&len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->common_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert, GNUTLS_OID_X520_COMMON_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->common_name, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->locality_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert, GNUTLS_OID_X520_LOCALITY_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->locality_name, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->state_or_province_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->state_or_province_name,
|
|
Packit Service |
4684c1 |
&len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->email);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_dn_by_oid(xcert, GNUTLS_OID_PKCS9_EMAIL, 0, 0,
|
|
Packit Service |
4684c1 |
ret->email, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_deinit(xcert);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/*-
|
|
Packit Service |
4684c1 |
* gnutls_x509_extract_certificate_issuer_dn:
|
|
Packit Service |
4684c1 |
* @cert: should contain an X.509 DER encoded certificate
|
|
Packit Service |
4684c1 |
* @ret: a pointer to a structure to hold the issuer's name
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will return the name of the issuer stated in the certificate. The name is a gnutls_x509_dn structure and
|
|
Packit Service |
4684c1 |
* is a obtained by the peer's certificate. If the certificate send by the
|
|
Packit Service |
4684c1 |
* peer is invalid, or in any other failure this function returns error.
|
|
Packit Service |
4684c1 |
* Returns a negative error code in case of an error.
|
|
Packit Service |
4684c1 |
-*/
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
gnutls_x509_extract_certificate_issuer_dn(const gnutls_datum_t * cert,
|
|
Packit Service |
4684c1 |
gnutls_x509_dn * ret)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_t xcert;
|
|
Packit Service |
4684c1 |
int result;
|
|
Packit Service |
4684c1 |
size_t len;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
result = gnutls_x509_crt_init(&xcert);
|
|
Packit Service |
4684c1 |
if (result < 0)
|
|
Packit Service |
4684c1 |
return result;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
result = gnutls_x509_crt_import(xcert, cert, GNUTLS_X509_FMT_DER);
|
|
Packit Service |
4684c1 |
if (result < 0) {
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_deinit(xcert);
|
|
Packit Service |
4684c1 |
return result;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->country);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_COUNTRY_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->country, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->organization);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_ORGANIZATION_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->organization,
|
|
Packit Service |
4684c1 |
&len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->organizational_unit_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME,
|
|
Packit Service |
4684c1 |
0, 0,
|
|
Packit Service |
4684c1 |
ret->organizational_unit_name,
|
|
Packit Service |
4684c1 |
&len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->common_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_COMMON_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->common_name, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->locality_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_LOCALITY_NAME,
|
|
Packit Service |
4684c1 |
0, 0, ret->locality_name,
|
|
Packit Service |
4684c1 |
&len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->state_or_province_name);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert,
|
|
Packit Service |
4684c1 |
GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME,
|
|
Packit Service |
4684c1 |
0, 0,
|
|
Packit Service |
4684c1 |
ret->state_or_province_name,
|
|
Packit Service |
4684c1 |
&len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
len = sizeof(ret->email);
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_get_issuer_dn_by_oid(xcert, GNUTLS_OID_PKCS9_EMAIL,
|
|
Packit Service |
4684c1 |
0, 0, ret->email, &len;;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_deinit(xcert);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|