2 * Copyright (C) 2006-2012 Free Software Foundation, Inc.
3 * Author: Simon Josefsson, Howard Chu
5 * This file is part of GnuTLS.
7 * GnuTLS is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuTLS is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GnuTLS; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 #include <gnutls/gnutls.h>
29 #include <gnutls/x509.h>
33 "-----BEGIN CERTIFICATE-----\n"
34 "MIIE6zCCA9OgAwIBAgIBdjANBgkqhkiG9w0BAQUFADBQMQswCQYDVQQGEwJTRTEf\n"
35 "MB0GA1UEChMWU3RvY2tob2xtcyB1bml2ZXJzaXRldDEgMB4GA1UEAxMXU3RvY2to\n"
36 "b2xtIFVuaXZlcnNpdHkgQ0EwHhcNMDYwMzIyMDkxNTI4WhcNMDcwMzIyMDkxNTI4\n"
37 "WjBDMQswCQYDVQQGEwJTRTEfMB0GA1UEChMWU3RvY2tob2xtcyB1bml2ZXJzaXRl\n"
38 "dDETMBEGA1UEAxMKc2lwMS5zdS5zZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC\n"
39 "gYEArUzXTD36ZK7CwZJH/faUNTcdaqM7JyiZsfrO703d7cT/bJ3wKxT8trOOh/Ou\n"
40 "WwgGFX2+r7ykun3aIUXUuD13Yle/yHqH/4g9vWX7UeFCBlSI0tAxnlqt0QqlPgSd\n"
41 "GLHcoO4PPyjon9jj0A/zpJGZHiRUCooo63YqE9MYfr5HBfkCAwEAAaOCAl8wggJb\n"
42 "MAsGA1UdDwQEAwIF4DAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwHQYD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qYje7MCcN+ZR\n"
58 "nUBo6U2NZ06/QEUFm+uUIhZ8IGM1gLehC7Q3G4+d4c38CDJxQnSPOgWiXuSvhhQm\n"
59 "KDsbrKzRaeBRh5eEJbTkA8Dp0Emb0UrkRVhixeg97stxUcATAjdGljJ9MLnuHXnI\n"
60 "7ihGdUfg5q/105vpsQpO\n" "-----END CERTIFICATE-----\n";
62 #define MAX_DATA_SIZE 1024
68 gnutls_datum_t derCert
= { (void*)pem
, sizeof (pem
) };
69 gnutls_x509_crt_t cert
;
70 size_t data_len
= MAX_DATA_SIZE
;
71 char data
[MAX_DATA_SIZE
];
72 unsigned int critical
= 0;
73 int alt_name_count
= 0;
75 ret
= gnutls_global_init ();
77 fail ("init %d\n", ret
);
79 ret
= gnutls_x509_crt_init (&cert
);
81 fail ("crt_init %d\n", ret
);
83 ret
= gnutls_x509_crt_import (cert
, &derCert
, GNUTLS_X509_FMT_PEM
);
85 fail ("crt_import %d\n", ret
);
87 for (alt_name_count
= 0;; ++alt_name_count
)
90 gnutls_x509_crt_get_issuer_alt_name (cert
, alt_name_count
, data
,
91 &data_len
, &critical
);
92 if (ret
== GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
)
96 fail ("get_issuer_alt_name: %d\n", ret
);
98 // TODO: print out / check results
99 if (GNUTLS_SAN_URI
== ret
)
101 if (strcmp (data
, "http://ca.su.se") != 0)
103 fail ("unexpected issuer GNUTLS_SAN_URI: %s\n", data
);
106 else if (GNUTLS_SAN_RFC822NAME
== ret
)
108 if (strcmp (data
, "ca@su.se") != 0)
110 fail ("unexpected issuer GNUTLS_SAN_RFC822NAME: %s\n", data
);
115 fail ("unexpected alt name type: %d\n", ret
);
117 data_len
= MAX_DATA_SIZE
;
120 if (alt_name_count
!= 2)
122 fail ("unexpected number of alt names: %i\n", alt_name_count
);
128 gnutls_x509_crt_deinit (cert
);
129 gnutls_global_deinit ();