|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2008-2016 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
* Copyright (C) 2016 Red Hat, Inc.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Author: Nikos Mavrogiannopoulos
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This file is part of GnuTLS.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit |
aea12f |
* under the terms of the GNU General Public License as published by
|
|
Packit |
aea12f |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
aea12f |
* (at your option) any later version.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit |
aea12f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
* General Public License for more details.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* You should have received a copy of the GNU General Public License
|
|
Packit |
aea12f |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit |
aea12f |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#ifdef HAVE_CONFIG_H
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <stdlib.h>
|
|
Packit |
aea12f |
#include <stdio.h>
|
|
Packit |
aea12f |
#include <time.h>
|
|
Packit |
aea12f |
#include <string.h>
|
|
Packit |
aea12f |
#include <gnutls/gnutls.h>
|
|
Packit |
aea12f |
#include <gnutls/x509.h>
|
|
Packit |
aea12f |
#include <assert.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "utils.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "cert-common.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static unsigned char saved_crt_pem[] =
|
|
Packit |
aea12f |
"-----BEGIN CERTIFICATE-----\n"
|
|
Packit Service |
991b93 |
"MIICWjCCAcOgAwIBAgIDChEAMA0GCSqGSIb3DQEBCwUAMCsxDjAMBgNVBAMTBW5p\n"
|
|
Packit |
aea12f |
"a29zMRkwFwYDVQQKExBub25lIHRvLCBtZW50aW9uMCAXDTA4MDMzMTIyMDAwMFoY\n"
|
|
Packit |
aea12f |
"Dzk5OTkxMjMxMjM1OTU5WjArMQ4wDAYDVQQDEwVuaWtvczEZMBcGA1UEChMQbm9u\n"
|
|
Packit |
aea12f |
"ZSB0bywgbWVudGlvbjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAu2ZD9fLF\n"
|
|
Packit |
aea12f |
"17aMzMXf9Yg7sclLag6hrSBQQAiAoU9co9D4bM/mPPfsBHYTF4tkiSJbwN1TfDvt\n"
|
|
Packit |
aea12f |
"fAS7gLkovo6bxo6gpRLL9Vceoue7tzNJn+O7Sq5qTWj/yRHiMo3OPYALjXXv2ACB\n"
|
|
Packit Service |
991b93 |
"jygEA6AijWEEB/q2N30hB0nSCWFpmJCjWKkCAwEAAYEFAAABAgOCBQAEAwIBo3ww\n"
|
|
Packit Service |
991b93 |
"ejAMBgNVHRMBAf8EAjAAMA8GA1UdDwEB/wQFAwMHgAAwNwYDVR0RBDAwLogEKgME\n"
|
|
Packit Service |
991b93 |
"BYIReG4tLW14YWE0YXM2ZC5jb22BE3Rlc3RAeG4tLWt4YXdoay5vcmcwIAYDVR0l\n"
|
|
Packit Service |
991b93 |
"AQH/BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMA0GCSqGSIb3DQEBCwUAA4GBADzP\n"
|
|
Packit Service |
991b93 |
"piA0s50R+oM/OWcHrARRMFhmOv8oj4mQeXjePCUJub8CDj1XnZwseIY9K9IU6Lxm\n"
|
|
Packit Service |
991b93 |
"43p7kw1jFzPRBJyuZC5X92AdG1meR1RKd91M3VEvn2cgfesX7/MbhZIYJ8ZD2S1L\n"
|
|
Packit Service |
991b93 |
"rqzVabXTZjKdHT727mCJdqzjDh7CFmb9Q2ZU6jDR\n"
|
|
Packit |
aea12f |
"-----END CERTIFICATE-----\n";
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
const gnutls_datum_t saved_crt = { saved_crt_pem, sizeof(saved_crt_pem)-1 };
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static void tls_log_func(int level, const char *str)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
fprintf(stderr, "|<%d>| %s", level, str);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static time_t mytime(time_t * t)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
time_t then = 1207000800;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (t)
|
|
Packit |
aea12f |
*t = then;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return then;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#define REGISTERED_OID "1.2.3.4.5"
|
|
Packit Service |
991b93 |
|
|
Packit |
aea12f |
void doit(void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
gnutls_x509_privkey_t pkey;
|
|
Packit |
aea12f |
gnutls_x509_crt_t crt;
|
|
Packit |
aea12f |
gnutls_x509_crt_t crt2;
|
|
Packit |
aea12f |
const char *err = NULL;
|
|
Packit |
aea12f |
unsigned char buf[64];
|
|
Packit |
aea12f |
unsigned char large_buf[5*1024];
|
|
Packit Service |
991b93 |
unsigned int status, san_type;
|
|
Packit |
aea12f |
gnutls_datum_t out;
|
|
Packit Service |
991b93 |
size_t s = 0, i;
|
|
Packit |
aea12f |
int ret;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = global_init();
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("global_init\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_global_set_time_function(mytime);
|
|
Packit |
aea12f |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
gnutls_global_set_log_level(4711);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_init(&crt;;
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_init\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_init(&crt2);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_init\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_import(crt2, &server_ecc_cert, GNUTLS_X509_FMT_PEM);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_import\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_privkey_init(&pkey);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_privkey_init\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_privkey_import(pkey, &key_dat, GNUTLS_X509_FMT_PEM);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_privkey_import\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Setup CRT */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_version(crt, 3);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_version\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_serial(crt, "\x0a\x11\x00", 3);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_serial\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_expiration_time(crt, -1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("error\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_activation_time(crt, mytime(0));
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("error\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_key(crt, pkey);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_key\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_basic_constraints(crt, 0, -1);
|
|
Packit |
aea12f |
if (ret < 0) {
|
|
Packit |
aea12f |
fail("error\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_key_usage(crt, GNUTLS_KEY_DIGITAL_SIGNATURE);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_key_usage %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_dn(crt, "o = none to\\, mention,cn = nikos", &err;;
|
|
Packit |
aea12f |
if (ret < 0) {
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_dn: %s, %s\n", gnutls_strerror(ret), err);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_DNSNAME,
|
|
Packit |
aea12f |
"foo", 3, 1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_RFC822NAME,
|
|
Packit |
aea12f |
"foo@bar.org", strlen("foo@bar.org"), 1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_RFC822NAME,
|
|
Packit |
aea12f |
"ινβάλιντ@bar.org", strlen("ινβάλιντ@bar.org"), 1);
|
|
Packit |
aea12f |
if (ret != GNUTLS_E_INVALID_UTF8_EMAIL)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_IPADDRESS,
|
|
Packit |
aea12f |
"\xc1\x5c\x96\x3", 4, 1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_IPADDRESS,
|
|
Packit |
aea12f |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 16, 1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_DNSNAME,
|
|
Packit |
aea12f |
"apa", 3, 0);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_REGISTERED_ID,
|
|
Packit Service |
991b93 |
REGISTERED_OID, strlen(REGISTERED_OID), 0);
|
|
Packit Service |
991b93 |
if (ret != 0)
|
|
Packit Service |
991b93 |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit Service |
991b93 |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_DNSNAME,
|
|
Packit |
aea12f |
"απαλό.com", strlen("απαλό.com"), 1);
|
|
Packit |
aea12f |
#if defined(HAVE_LIBIDN2) || defined(HAVE_LIBIDN)
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_RFC822NAME,
|
|
Packit |
aea12f |
"test@νίκο.org", strlen("test@νίκο.org"), 1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name\n");
|
|
Packit |
aea12f |
#else
|
|
Packit |
aea12f |
if (ret != GNUTLS_E_UNIMPLEMENTED_FEATURE)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_subject_alt_name: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_key_purpose_oid(crt, 0, NULL, &s, NULL);
|
|
Packit |
aea12f |
if (ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_get_key_purpose_oid %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
ret =
|
|
Packit |
aea12f |
gnutls_x509_crt_set_key_purpose_oid(crt,
|
|
Packit |
aea12f |
GNUTLS_KP_TLS_WWW_SERVER,
|
|
Packit |
aea12f |
0);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_key_purpose_oid %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_key_purpose_oid(crt, 0, NULL, &s, NULL);
|
|
Packit |
aea12f |
if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_get_key_purpose_oid %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
ret =
|
|
Packit |
aea12f |
gnutls_x509_crt_set_key_purpose_oid(crt,
|
|
Packit |
aea12f |
GNUTLS_KP_TLS_WWW_CLIENT,
|
|
Packit |
aea12f |
1);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_key_purpose_oid2 %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* in the end this will be ignored as the issuer will be set
|
|
Packit |
aea12f |
* by gnutls_x509_crt_sign2() */
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_issuer_dn(crt, "cn = my CA, o = big\\, and one", &err;;
|
|
Packit |
aea12f |
if (ret < 0) {
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_set_issuer_dn: %s, %s\n", gnutls_strerror(ret), err);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define ISSUER_UNIQUE_ID "\x00\x01\x02\x03"
|
|
Packit |
aea12f |
#define SUBJECT_UNIQUE_ID "\x04\x03\x02\x01"
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_issuer_unique_id(crt, ISSUER_UNIQUE_ID, sizeof(ISSUER_UNIQUE_ID)-1);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("error: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_set_subject_unique_id(crt, SUBJECT_UNIQUE_ID, sizeof(SUBJECT_UNIQUE_ID)-1);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("error: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Sign and finalize the certificate */
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_sign2(crt, crt, pkey, GNUTLS_DIG_SHA256, 0);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_sign2: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_print(crt, GNUTLS_CRT_PRINT_FULL, &out;;
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_print\n");
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
printf("crt: %.*s\n", out.size, out.data);
|
|
Packit |
aea12f |
gnutls_free(out.data);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Verify whether selected input is present */
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_extension_info(crt, 0, NULL, &s, NULL);
|
|
Packit |
aea12f |
if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_get_extension_info2: %s\n", strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_extension_data(crt, 0, NULL, &s);
|
|
Packit |
aea12f |
if (ret != 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_get_extension_data: %s\n", strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_raw_issuer_dn(crt, &out;;
|
|
Packit |
aea12f |
if (ret < 0 || out.size == 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_get_raw_issuer_dn: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (out.size != 45 ||
|
|
Packit |
aea12f |
memcmp(out.data, "\x30\x2b\x31\x0e\x30\x0c\x06\x03\x55\x04\x03\x13\x05\x6e\x69\x6b\x6f\x73\x31\x19\x30\x17\x06\x03\x55\x04\x0a\x13\x10\x6e\x6f\x6e\x65\x20\x74\x6f\x2c\x20\x6d\x65\x6e\x74\x69\x6f\x6e", 45) != 0) {
|
|
Packit |
aea12f |
hexprint(out.data, out.size);
|
|
Packit |
aea12f |
fail("issuer DN comparison failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
gnutls_free(out.data);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = sizeof(buf);
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_issuer_unique_id(crt, (void*)buf, &s);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("error: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (s != sizeof(ISSUER_UNIQUE_ID)-1 ||
|
|
Packit |
aea12f |
memcmp(buf, ISSUER_UNIQUE_ID, s) != 0) {
|
|
Packit |
aea12f |
fail("issuer unique id comparison failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
s = sizeof(buf);
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_subject_unique_id(crt, (void*)buf, &s);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("error: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (s != sizeof(SUBJECT_UNIQUE_ID)-1 ||
|
|
Packit |
aea12f |
memcmp(buf, SUBJECT_UNIQUE_ID, s) != 0) {
|
|
Packit |
aea12f |
fail("subject unique id comparison failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_get_raw_dn(crt, &out;;
|
|
Packit |
aea12f |
if (ret < 0 || out.size == 0)
|
|
Packit |
aea12f |
fail("gnutls_x509_crt_get_raw_dn: %s\n", gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (out.size != 45 ||
|
|
Packit |
aea12f |
memcmp(out.data, "\x30\x2b\x31\x0e\x30\x0c\x06\x03\x55\x04\x03\x13\x05\x6e\x69\x6b\x6f\x73\x31\x19\x30\x17\x06\x03\x55\x04\x0a\x13\x10\x6e\x6f\x6e\x65\x20\x74\x6f\x2c\x20\x6d\x65\x6e\x74\x69\x6f\x6e", 45) != 0) {
|
|
Packit |
aea12f |
fail("DN comparison failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
gnutls_free(out.data);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_equals(crt, crt);
|
|
Packit |
aea12f |
if (ret == 0) {
|
|
Packit |
aea12f |
fail("equality test failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_equals(crt, crt2);
|
|
Packit |
aea12f |
if (ret != 0) {
|
|
Packit |
aea12f |
fail("equality test failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_x509_crt_verify(crt, &crt, 1, 0, &status);
|
|
Packit |
aea12f |
if (ret < 0) {
|
|
Packit |
aea12f |
fail("verification failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (status != 0) {
|
|
Packit |
aea12f |
fail("verification status failed\n");
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
assert(gnutls_x509_crt_export2(crt, GNUTLS_X509_FMT_PEM, &out) >= 0);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
fprintf(stderr, "%s\n", out.data);
|
|
Packit |
aea12f |
#if defined(HAVE_LIBIDN2)
|
|
Packit |
aea12f |
assert(out.size == saved_crt.size);
|
|
Packit |
aea12f |
assert(memcmp(out.data, saved_crt.data, out.size)==0);
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* test behavior of gnutls_x509_crt_export on varios corner cases */
|
|
Packit |
aea12f |
s = 0;
|
|
Packit |
aea12f |
assert(gnutls_x509_crt_export(crt, GNUTLS_X509_FMT_PEM, NULL, &s) == GNUTLS_E_SHORT_MEMORY_BUFFER);
|
|
Packit |
aea12f |
assert(s == out.size+1);
|
|
Packit |
aea12f |
s = sizeof(buf);
|
|
Packit |
aea12f |
assert(gnutls_x509_crt_export(crt, GNUTLS_X509_FMT_PEM, buf, &s) == GNUTLS_E_SHORT_MEMORY_BUFFER);
|
|
Packit |
aea12f |
assert(s == out.size+1);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* check whether the PEM output matches gnutls_x509_crt_export2 */
|
|
Packit |
aea12f |
s = sizeof(large_buf);
|
|
Packit |
aea12f |
assert(gnutls_x509_crt_export(crt, GNUTLS_X509_FMT_PEM, large_buf, &s) == 0);
|
|
Packit |
aea12f |
assert(s == out.size);
|
|
Packit |
aea12f |
assert(memcmp(large_buf, out.data, out.size) == 0);
|
|
Packit |
aea12f |
gnutls_free(out.data);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* check whether the der out length differs */
|
|
Packit |
aea12f |
s = sizeof(large_buf);
|
|
Packit |
aea12f |
assert(gnutls_x509_crt_export(crt, GNUTLS_X509_FMT_DER, large_buf, &s) == 0);
|
|
Packit |
aea12f |
assert(gnutls_x509_crt_export2(crt, GNUTLS_X509_FMT_DER, &out) >= 0);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
assert(s == out.size);
|
|
Packit |
aea12f |
assert(memcmp(large_buf, out.data, out.size) == 0);
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
/* verify some values written in the original cert */
|
|
Packit Service |
991b93 |
gnutls_x509_crt_deinit(crt2);
|
|
Packit Service |
991b93 |
ret = gnutls_x509_crt_init(&crt2);
|
|
Packit Service |
991b93 |
if (ret != 0)
|
|
Packit Service |
991b93 |
fail("gnutls_x509_crt_init\n");
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
ret = gnutls_x509_crt_import(crt2, &out, GNUTLS_X509_FMT_DER);
|
|
Packit Service |
991b93 |
if (ret != 0)
|
|
Packit Service |
991b93 |
fail("gnutls_x509_crt_import\n");
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
i = 0;
|
|
Packit Service |
991b93 |
do {
|
|
Packit Service |
991b93 |
s = sizeof(buf);
|
|
Packit Service |
991b93 |
ret = gnutls_x509_crt_get_subject_alt_name2(crt2, i++, buf, &s, &san_type, NULL);
|
|
Packit Service |
991b93 |
if (ret < 0)
|
|
Packit Service |
991b93 |
fail("gnutls_x509_crt_get_subject_alt_name2: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
991b93 |
} while (san_type != GNUTLS_SAN_REGISTERED_ID);
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
assert(san_type == GNUTLS_SAN_REGISTERED_ID);
|
|
Packit Service |
991b93 |
assert(s == strlen(REGISTERED_OID));
|
|
Packit Service |
991b93 |
assert(memcmp(buf, REGISTERED_OID, s) == 0);
|
|
Packit Service |
991b93 |
|
|
Packit |
aea12f |
gnutls_free(out.data);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_x509_crt_deinit(crt);
|
|
Packit |
aea12f |
gnutls_x509_crt_deinit(crt2);
|
|
Packit |
aea12f |
gnutls_x509_privkey_deinit(pkey);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_global_deinit();
|
|
Packit |
aea12f |
}
|