summaryrefslogtreecommitdiff
path: root/tests/pgps2kgnu.c
blob: 0c646e9751f79d6674e7308ae32204ea14b3d971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (C) 2008-2012 Free Software Foundation, Inc.
 *
 * Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>

 * pgps2kgnu: test GNU extensions to the OpenPGP S2K specification.
 *            at the moment, we just test the "GNU dummy" S2K
 *            extension.

 *
 * This file is part of GnuTLS.
 *
 * GnuTLS is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * GnuTLS is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GnuTLS; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
#include <gnutls/openpgp.h>

static char dummy_key[] =
  "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
  "Version: GnuPG v1.4.9 (GNU/Linux)\n"
  "\n"
  "lQCVBEO3YdABBACRqqEnucag4+vyZny2M67Pai5+5suIRRvY+Ly8Ms5MvgCi3EVV\n"
  "xT05O/+0ShiRaf+QicCOFrhbU9PZzzU+seEvkeW2UCu4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gq08qNzHBpXSYXXJ3JuWcL1/awUqp3tE1I6zZ0hZ38Ia6\n"
  "SdBMN88idnhDPqPoiKUEGAECAA8FAkO3YdACGyAFCQHhM4AACgkQQZUwSa4UDezm\n"
  "vQP/ZhK+2ly9oI2z7ZcNC/BJRch0/ybQ3haahII8pXXmOThpZohr/LUgoWgCZdXg\n"
  "vP6yiszNk2tIs8KphCAw7Lw/qzDC2hEORjWO4f46qk73RAgSqG/GyzI4ltWiDhqn\n"
  "vnQCFl3+QFSe4zinqykHnLwGPMXv428d/ZjkIc2ju8dRsn4=\n"
  "=CR5w\n" "-----END PGP PRIVATE KEY BLOCK-----\n";

/* Test capability of reading the gnu-dummy OpenPGP S2K extension. 
   See: doc/DETAILS from gnupg
        http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00023.html
*/

static void
tls_log_func (int level, const char *str)
{
  fprintf (stderr, "|<%d>| %s", level, str);
}

int
main (int argc, char** argv)
{
  int rc;
  gnutls_datum_t keydatum =
    { (unsigned char *) dummy_key, strlen (dummy_key) };
  gnutls_openpgp_privkey_t key;

  if (argc > 1)
    {
      gnutls_global_set_log_function (tls_log_func);
      gnutls_global_set_log_level (9);
    }

  rc = gnutls_global_init ();
  if (rc)
    {
      printf ("gnutls_global_init rc %d: %s\n", rc, gnutls_strerror (rc));
      return 1;
    }

  rc = gnutls_openpgp_privkey_init (&key);
  if (rc)
    {
      printf ("gnutls_openpgp_privkey_init rc %d: %s\n",
              rc, gnutls_strerror (rc));
      return 1;
    }

  rc = gnutls_openpgp_privkey_import (key, &keydatum,
                                      GNUTLS_OPENPGP_FMT_BASE64, NULL, 0);
  if (rc)
    {
      printf ("gnutls_openpgp_privkey_import rc %d: %s\n",
              rc, gnutls_strerror (rc));
      return 1;
    }

  gnutls_openpgp_privkey_deinit (key);

  gnutls_global_deinit ();

  return 0;
}