Fix symbol export rules.
[gnutls.git] / tests / cve-2009-1416.c
blobb63734494948656642271a3ffe3eaa40854d5199
1 /*
2 * Copyright (C) 2009 Free Software Foundation
4 * Author: Simon Josefsson
6 * This file is part of GNUTLS.
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.
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.
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
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
28 * Small code to reproduce the CVE-2009-1416 bad DSA key problem.
30 * Build it using:
32 * gcc -o cve-2009-1416 cve-2009-1416.c -lgnutls
34 * If your gnutls library is OK then running it will print 'success!'.
36 * If your gnutls library is buggy then running it will print 'buggy'.
40 #include <stdio.h>
41 #include <stdarg.h>
42 #include <stdlib.h>
44 #include <gcrypt.h>
45 #include <gnutls/gnutls.h>
46 #include <gnutls/x509.h>
48 int
49 main (void)
51 gnutls_x509_privkey_t key;
52 gnutls_datum_t p, q, g, y, x;
53 int ret;
55 gnutls_global_init ();
56 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
58 ret = gnutls_x509_privkey_init (&key);
59 if (ret < 0)
60 return 1;
62 ret = gnutls_x509_privkey_generate (key, GNUTLS_PK_DSA, 512, 0);
63 if (ret < 0)
64 return 1;
66 ret = gnutls_x509_privkey_export_dsa_raw (key, &p, &q, &g, &y, &x);
67 if (ret < 0)
68 return 1;
70 if (q.size == 3 && memcmp (q.data, "\x01\x00\x01", 3) == 0)
72 printf ("buggy\n");
73 return 1;
75 else
76 printf ("success!\n");
78 gnutls_free (p.data);
79 gnutls_free (q.data);
80 gnutls_free (g.data);
81 gnutls_free (y.data);
82 gnutls_free (x.data);
84 gnutls_x509_privkey_deinit (key);
85 gnutls_global_deinit ();
87 return 0;