Add `.gitignore'.
[gnutls.git] / tests / certificate_set_x509_crl.c
blob7c4ee0a0a25c4974cd5ef3f9dd74d46b6592243b
1 /*
2 * Copyright (C) 2006, 2007 Free Software Foundation, Inc.
4 * Author: Simon Josefsson
6 * This file is part of GNUTLS.
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library 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 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <gnutls/gnutls.h>
33 #include <gnutls/x509.h>
35 static char crl[] =
36 "-----BEGIN X509 CRL-----\n"
37 "MIIB9DCCAV8CAQEwCwYJKoZIhvcNAQEFMIIBCDEXMBUGA1UEChMOVmVyaVNpZ24s\n"
38 "IEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsxRjBEBgNVBAsT\n"
39 "PXd3dy52ZXJpc2lnbi5jb20vcmVwb3NpdG9yeS9SUEEgSW5jb3JwLiBieSBSZWYu\n"
40 "LExJQUIuTFREKGMpOTgxHjAcBgNVBAsTFVBlcnNvbmEgTm90IFZhbGlkYXRlZDEm\n"
41 "MCQGA1UECxMdRGlnaXRhbCBJRCBDbGFzcyAxIC0gTmV0c2NhcGUxGDAWBgNVBAMU\n"
42 "D1NpbW9uIEpvc2Vmc3NvbjEiMCAGCSqGSIb3DQEJARYTc2ltb25Aam9zZWZzc29u\n"
43 "Lm9yZxcNMDYxMjI3MDgwMjM0WhcNMDcwMjA3MDgwMjM1WjAjMCECEC4QNwPfRoWd\n"
44 "elUNpllhhTgXDTA2MTIyNzA4MDIzNFowCwYJKoZIhvcNAQEFA4GBAD0zX+J2hkcc\n"
45 "Nbrq1Dn5IKL8nXLgPGcHv1I/le1MNo9t1ohGQxB5HnFUkRPAY82fR6Epor4aHgVy\n"
46 "b+5y+neKN9Kn2mPF4iiun+a4o26CjJ0pArojCL1p8T0yyi9Xxvyc/ezaZ98HiIyP\n"
47 "c3DGMNR+oUmSjKZ0jIhAYmeLxaPHfQwR\n"
48 "-----END X509 CRL-----\n";
50 /* Test regression of bug reported by Max Kellermann <max@duempel.org>
51 in Message-ID: <20061211075202.GA1517@roonstrasse.net> to the
52 gnutls-dev@gnupg.org list. */
54 int
55 main (void)
57 int rc;
58 gnutls_certificate_credentials_t crt;
59 gnutls_datum_t crldatum = { crl, strlen (crl) };
60 gnutls_x509_crl_t crl;
62 rc = gnutls_global_init ();
63 if (rc)
65 printf ("gnutls_global_init rc %d: %s\n", rc, gnutls_strerror (rc));
66 return 1;
69 rc = gnutls_certificate_allocate_credentials (&crt);
70 if (rc)
72 printf ("gnutls_certificate_allocate_credentials rc %d: %s\n",
73 rc, gnutls_strerror (rc));
74 return 1;
77 rc = gnutls_certificate_set_x509_crl_mem (crt, &crldatum,
78 GNUTLS_X509_FMT_PEM);
79 if (rc != 1)
81 printf ("gnutls_certificate_set_x509_crl_mem num %d\n", rc);
82 return 1;
85 rc = gnutls_x509_crl_init (&crl);
86 if (rc)
88 printf ("gnutls_x509_crl_init rc %d: %s\n", rc, gnutls_strerror (rc));
89 return 1;
92 rc = gnutls_x509_crl_import (crl, &crldatum, GNUTLS_X509_FMT_PEM);
93 if (rc)
95 printf ("gnutls_x509_crl_import rc %d: %s\n", rc, gnutls_strerror (rc));
96 return 1;
99 rc = gnutls_certificate_set_x509_crl (crt, &crl, 1);
100 if (rc)
102 printf ("gnutls_certificate_set_x509_crl rc %d: %s\n",
103 rc, gnutls_strerror (rc));
104 return 1;
107 gnutls_x509_crl_deinit (crl);
109 gnutls_certificate_free_credentials (crt);
111 gnutls_global_deinit ();
113 return 0;