upload -> upload-tarballs
[gnutls.git] / tests / cve-2009-1416.c
blobbb20b0c8134d006c8004b34c52212626d05c3e99
1 /*
2 * Copyright (C) 2009-2012 Free Software Foundation, Inc.
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>
43 #include <string.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 ();
57 ret = gnutls_x509_privkey_init (&key);
58 if (ret < 0)
59 return 1;
61 ret = gnutls_x509_privkey_generate (key, GNUTLS_PK_DSA, 512, 0);
62 if (ret < 0)
63 return 1;
65 ret = gnutls_x509_privkey_export_dsa_raw (key, &p, &q, &g, &y, &x);
66 if (ret < 0)
67 return 1;
69 if (q.size == 3 && memcmp (q.data, "\x01\x00\x01", 3) == 0)
71 printf ("buggy\n");
72 return 1;
75 gnutls_free (p.data);
76 gnutls_free (q.data);
77 gnutls_free (g.data);
78 gnutls_free (y.data);
79 gnutls_free (x.data);
81 gnutls_x509_privkey_deinit (key);
82 gnutls_global_deinit ();
84 return 0;