|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2008-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Joe Orton
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* 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 is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* 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 GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit Service |
4684c1 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Parts copied from GnuTLS example programs. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
#include <stdlib.h>
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
#include <sys/types.h>
|
|
Packit Service |
4684c1 |
#include <unistd.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/x509.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const char cert_pem[] =
|
|
Packit Service |
4684c1 |
"-----BEGIN CERTIFICATE-----\n"
|
|
Packit Service |
4684c1 |
"MIICHjCCAYmgAwIBAgIERiYdNzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
|
|
Packit Service |
4684c1 |
"VExTIHRlc3QgQ0EwHhcNMDcwNDE4MTMyOTI3WhcNMDgwNDE3MTMyOTI3WjAdMRsw\n"
|
|
Packit Service |
4684c1 |
"GQYDVQQDExJHbnVUTFMgdGVzdCBjbGllbnQwgZwwCwYJKoZIhvcNAQEBA4GMADCB\n"
|
|
Packit Service |
4684c1 |
"iAKBgLtmQ/Xyxde2jMzF3/WIO7HJS2oOoa0gUEAIgKFPXKPQ+GzP5jz37AR2ExeL\n"
|
|
Packit Service |
4684c1 |
"ZIkiW8DdU3w77XwEu4C5KL6Om8aOoKUSy/VXHqLnu7czSZ/ju0quak1o/8kR4jKN\n"
|
|
Packit Service |
4684c1 |
"zj2AC41179gAgY8oBAOgIo1hBAf6tjd9IQdJ0glhaZiQo1ipAgMBAAGjdjB0MAwG\n"
|
|
Packit Service |
4684c1 |
"A1UdEwEB/wQCMAAwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDwYDVR0PAQH/BAUDAweg\n"
|
|
Packit Service |
4684c1 |
"ADAdBgNVHQ4EFgQUTLkKm/odNON+3svSBxX+odrLaJEwHwYDVR0jBBgwFoAU6Twc\n"
|
|
Packit Service |
4684c1 |
"+62SbuYGpFYsouHAUyfI8pUwCwYJKoZIhvcNAQEFA4GBALujmBJVZnvaTXr9cFRJ\n"
|
|
Packit Service |
4684c1 |
"jpfc/3X7sLUsMvumcDE01ls/cG5mIatmiyEU9qI3jbgUf82z23ON/acwJf875D3/\n"
|
|
Packit Service |
4684c1 |
"U7jyOsBJ44SEQITbin2yUeJMIm1tievvdNXBDfW95AM507ShzP12sfiJkJfjjdhy\n"
|
|
Packit Service |
4684c1 |
"dc8Siq5JojruiMizAf0pA7in\n" "-----END CERTIFICATE-----\n";
|
|
Packit Service |
4684c1 |
static const gnutls_datum_t cert_datum = { (unsigned char *) cert_pem,
|
|
Packit Service |
4684c1 |
sizeof(cert_pem)
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_t cert;
|
|
Packit Service |
4684c1 |
gnutls_x509_dn_t sdn, dn2;
|
|
Packit Service |
4684c1 |
unsigned char buf[8192], buf2[8192];
|
|
Packit Service |
4684c1 |
size_t buflen, buf2len;
|
|
Packit Service |
4684c1 |
gnutls_datum_t datum;
|
|
Packit Service |
4684c1 |
int rv;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
global_init();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_x509_crt_init(&cert) != 0)
|
|
Packit Service |
4684c1 |
fail("cert init failure\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_x509_crt_import(cert, &cert_datum, GNUTLS_X509_FMT_PEM)
|
|
Packit Service |
4684c1 |
!= 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: could not import PEM cert\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_x509_crt_get_subject(cert, &sdn) != 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: could not get subject DN.\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
buflen = sizeof buf;
|
|
Packit Service |
4684c1 |
rv = gnutls_x509_dn_export(sdn, GNUTLS_X509_FMT_DER, buf, &buflen);
|
|
Packit Service |
4684c1 |
if (rv != 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: could not export subject DN: %s\n",
|
|
Packit Service |
4684c1 |
gnutls_strerror(rv));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_x509_dn_init(&dn2) != 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: DN init.\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
datum.data = buf;
|
|
Packit Service |
4684c1 |
datum.size = buflen;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (gnutls_x509_dn_import(dn2, &datum) != 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: re-import subject DN.\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
buf2len = sizeof buf2;
|
|
Packit Service |
4684c1 |
rv = gnutls_x509_dn_export(dn2, GNUTLS_X509_FMT_DER, buf2,
|
|
Packit Service |
4684c1 |
&buf2len);
|
|
Packit Service |
4684c1 |
if (rv != 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: could not export subject DN: %s\n",
|
|
Packit Service |
4684c1 |
gnutls_strerror(rv));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (buflen == buf2len && memcmp(buf, buf2, buflen) != 0)
|
|
Packit Service |
4684c1 |
fail("FAIL: export/import/export differ.\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_x509_dn_deinit(dn2);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_x509_crt_deinit(cert);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_deinit();
|
|
Packit Service |
4684c1 |
}
|