Tizen 2.0 Release
[external/libgnutls26.git] / tests / certificate_set_x509_crl.c
1 /*
2  * Copyright (C) 2006, 2007, 2010 Free Software Foundation, Inc.
3  *
4  * Author: Simon Josefsson
5  *
6  * This file is part of GnuTLS.
7  *
8  * GnuTLS is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * GnuTLS is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with GnuTLS; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <gnutls/gnutls.h>
31 #include <gnutls/x509.h>
32
33 static char crl[] =
34   "-----BEGIN X509 CRL-----\n"
35   "MIIB9DCCAV8CAQEwCwYJKoZIhvcNAQEFMIIBCDEXMBUGA1UEChMOVmVyaVNpZ24s\n"
36   "IEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsxRjBEBgNVBAsT\n"
37   "PXd3dy52ZXJpc2lnbi5jb20vcmVwb3NpdG9yeS9SUEEgSW5jb3JwLiBieSBSZWYu\n"
38   "LExJQUIuTFREKGMpOTgxHjAcBgNVBAsTFVBlcnNvbmEgTm90IFZhbGlkYXRlZDEm\n"
39   "MCQGA1UECxMdRGlnaXRhbCBJRCBDbGFzcyAxIC0gTmV0c2NhcGUxGDAWBgNVBAMU\n"
40   "D1NpbW9uIEpvc2Vmc3NvbjEiMCAGCSqGSIb3DQEJARYTc2ltb25Aam9zZWZzc29u\n"
41   "Lm9yZxcNMDYxMjI3MDgwMjM0WhcNMDcwMjA3MDgwMjM1WjAjMCECEC4QNwPfRoWd\n"
42   "elUNpllhhTgXDTA2MTIyNzA4MDIzNFowCwYJKoZIhvcNAQEFA4GBAD0zX+J2hkcc\n"
43   "Nbrq1Dn5IKL8nXLgPGcHv1I/le1MNo9t1ohGQxB5HnFUkRPAY82fR6Epor4aHgVy\n"
44   "b+5y+neKN9Kn2mPF4iiun+a4o26CjJ0pArojCL1p8T0yyi9Xxvyc/ezaZ98HiIyP\n"
45   "c3DGMNR+oUmSjKZ0jIhAYmeLxaPHfQwR\n" "-----END X509 CRL-----\n";
46
47 /* Test regression of bug reported by Max Kellermann <max@duempel.org>
48    in Message-ID: <20061211075202.GA1517@roonstrasse.net> to the
49    gnutls-dev@gnupg.org list. */
50
51 int
52 main (void)
53 {
54   int rc;
55   gnutls_certificate_credentials_t crt;
56   gnutls_datum_t crldatum = { crl, strlen (crl) };
57   gnutls_x509_crl_t crl;
58
59   rc = gnutls_global_init ();
60   if (rc)
61     {
62       printf ("gnutls_global_init rc %d: %s\n", rc, gnutls_strerror (rc));
63       return 1;
64     }
65
66   rc = gnutls_certificate_allocate_credentials (&crt);
67   if (rc)
68     {
69       printf ("gnutls_certificate_allocate_credentials rc %d: %s\n",
70               rc, gnutls_strerror (rc));
71       return 1;
72     }
73
74   rc = gnutls_certificate_set_x509_crl_mem (crt, &crldatum,
75                                             GNUTLS_X509_FMT_PEM);
76   if (rc != 1)
77     {
78       printf ("gnutls_certificate_set_x509_crl_mem num %d\n", rc);
79       return 1;
80     }
81
82   rc = gnutls_x509_crl_init (&crl);
83   if (rc)
84     {
85       printf ("gnutls_x509_crl_init rc %d: %s\n", rc, gnutls_strerror (rc));
86       return 1;
87     }
88
89   rc = gnutls_x509_crl_import (crl, &crldatum, GNUTLS_X509_FMT_PEM);
90   if (rc)
91     {
92       printf ("gnutls_x509_crl_import rc %d: %s\n", rc, gnutls_strerror (rc));
93       return 1;
94     }
95
96   rc = gnutls_certificate_set_x509_crl (crt, &crl, 1);
97   if (rc)
98     {
99       printf ("gnutls_certificate_set_x509_crl rc %d: %s\n",
100               rc, gnutls_strerror (rc));
101       return 1;
102     }
103
104   gnutls_x509_crl_deinit (crl);
105
106   gnutls_certificate_free_credentials (crt);
107
108   gnutls_global_deinit ();
109
110   return 0;
111 }