Tizen 2.0 Release
[external/libgnutls26.git] / tests / pgps2kgnu.c
1 /*
2  * Copyright (C) 2008, 2010 Free Software Foundation, Inc.
3  *
4  * Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
5
6  * pgps2kgnu: test GNU extensions to the OpenPGP S2K specification.
7  *            at the moment, we just test the "GNU dummy" S2K
8  *            extension.
9
10  *
11  * This file is part of GnuTLS.
12  *
13  * GnuTLS is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * GnuTLS is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with GnuTLS; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <gnutls/gnutls.h>
36 #include <gnutls/openpgp.h>
37
38 static char dummy_key[] =
39   "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
40   "Version: GnuPG v1.4.9 (GNU/Linux)\n"
41   "\n"
42   "lQCVBEO3YdABBACRqqEnucag4+vyZny2M67Pai5+5suIRRvY+Ly8Ms5MvgCi3EVV\n"
43   "xT05O/+0ShiRaf+QicCOFrhbU9PZzzU+seEvkeW2UCu4dQfILkmj+HBEIltGnHr3\n"
44   "G0yegHj5pnqrcezERURf2e17gGFWX91cXB9Cm721FPXczuKraphKwCA9PwARAQAB\n"
45   "/gNlAkdOVQG0OURlbW9uc3RyYXRpb24gS2V5IGZvciBTMksgR05VIGV4dGVuc2lv\n"
46   "biAxMDAxIC0tIGdudS1kdW1teYi8BBMBAgAmBQJDt2HQAhsDBQkB4TOABgsJCAcD\n"
47   "AgQVAggDBBYCAwECHgECF4AACgkQQZUwSa4UDezTOQP/TMQXUVrWzHYZGopoPZ2+\n"
48   "ZS3qddiznBHsgb7MGYg1KlTiVJSroDUBCHIUJvdQKZV9zrzrFl47D07x6hGyUPHV\n"
49   "aZXvuITW8t1o5MMHkCy3pmJ2KgfDvdUxrBvLfgPMICA4c6zA0mWquee43syEW9NY\n"
50   "g3q61iPlQwD1J1kX1wlimLCdAdgEQ7dh0AEEANAwa63zlQbuy1Meliy8otwiOa+a\n"
51   "mH6pxxUgUNggjyjO5qx+rl25mMjvGIRX4/L1QwIBXJBVi3SgvJW1COZxZqBYqj9U\n"
52   "8HVT07mWKFEDf0rZLeUE2jTm16cF9fcW4DQhW+sfYm+hi2sY3HeMuwlUBK9KHfW2\n"
53   "+bGeDzVZ4pqfUEudABEBAAEAA/0bemib+wxub9IyVFUp7nPobjQC83qxLSNzrGI/\n"
54   "RHzgu/5CQi4tfLOnwbcQsLELfker2hYnjsLrT9PURqK4F7udrWEoZ1I1LymOtLG/\n"
55   "4tNZ7Mnul3wRC2tCn7FKx8sGJwGh/3li8vZ6ALVJAyOia5TZ/buX0+QZzt6+hPKk\n"
56   "7MU1WQIA4bUBjtrsqDwro94DvPj3/jBnMZbXr6WZIItLNeVDUcM8oHL807Am97K1\n"
57   "ueO/f6v1sGAHG6lVPTmtekqPSTWBfwIA7CGFvEyvSALfB8NUa6jtk27NCiw0csql\n"
58   "kuhCmwXGMVOiryKEfegkIahf2bAd/gnWHPrpWp7bUE20v8YoW22I4wIAhnm5Wr5Q\n"
59   "Sy7EHDUxmJm5TzadFp9gq08qNzHBpXSYXXJ3JuWcL1/awUqp3tE1I6zZ0hZ38Ia6\n"
60   "SdBMN88idnhDPqPoiKUEGAECAA8FAkO3YdACGyAFCQHhM4AACgkQQZUwSa4UDezm\n"
61   "vQP/ZhK+2ly9oI2z7ZcNC/BJRch0/ybQ3haahII8pXXmOThpZohr/LUgoWgCZdXg\n"
62   "vP6yiszNk2tIs8KphCAw7Lw/qzDC2hEORjWO4f46qk73RAgSqG/GyzI4ltWiDhqn\n"
63   "vnQCFl3+QFSe4zinqykHnLwGPMXv428d/ZjkIc2ju8dRsn4=\n"
64   "=CR5w\n" "-----END PGP PRIVATE KEY BLOCK-----\n";
65
66 /* Test capability of reading the gnu-dummy OpenPGP S2K extension. 
67    See: doc/DETAILS from gnupg
68         http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00023.html
69 */
70
71 int
72 main (void)
73 {
74   int rc;
75   gnutls_datum_t keydatum =
76     { (unsigned char *) dummy_key, strlen (dummy_key) };
77   gnutls_openpgp_privkey_t key;
78
79   rc = gnutls_global_init ();
80   if (rc)
81     {
82       printf ("gnutls_global_init rc %d: %s\n", rc, gnutls_strerror (rc));
83       return 1;
84     }
85
86   rc = gnutls_openpgp_privkey_init (&key);
87   if (rc)
88     {
89       printf ("gnutls_openpgp_privkey_init rc %d: %s\n",
90               rc, gnutls_strerror (rc));
91       return 1;
92     }
93
94   rc = gnutls_openpgp_privkey_import (key, &keydatum,
95                                       GNUTLS_OPENPGP_FMT_BASE64, NULL, 0);
96   if (rc)
97     {
98       printf ("gnutls_openpgp_privkey_import rc %d: %s\n",
99               rc, gnutls_strerror (rc));
100       return 1;
101     }
102
103   gnutls_openpgp_privkey_deinit (key);
104
105   gnutls_global_deinit ();
106
107   return 0;
108 }