~ubuntu-branches/ubuntu/quantal/gnutls26/quantal

« back to all changes in this revision

Viewing changes to src/certtool.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation
3
 
 *
4
 
 * This file is part of GNUTLS.
5
 
 *
6
 
 * GNUTLS is free software: you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
 
2
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuTLS.
 
5
 *
 
6
 * GnuTLS is free software: you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License as published by
8
8
 * the Free Software Foundation, either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
 
 * GNUTLS is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
 
11
 * GnuTLS is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 * along with this program.  If not, see
 
18
 * <http://www.gnu.org/licenses/>.
18
19
 */
19
20
 
20
21
#include <config.h>
 
22
 
21
23
#include <gnutls/gnutls.h>
22
24
#include <gnutls/extra.h>
 
25
#include <gnutls/x509.h>
 
26
#include <gnutls/openpgp.h>
 
27
#include <gnutls/pkcs12.h>
 
28
 
23
29
#include <gcrypt.h>
24
30
 
25
31
#include <stdio.h>
26
32
#include <stdlib.h>
27
33
#include <string.h>
28
34
#include <ctype.h>
29
 
#include <gnutls/x509.h>
30
 
#include <gnutls/openpgp.h>
31
35
#include <time.h>
32
 
#include "certtool-gaa.h"
33
 
#include "certtool-common.h"
34
 
#include <gnutls/pkcs12.h>
35
36
#include <unistd.h>
36
 
#include <certtool-cfg.h>
37
 
#include <gcrypt.h>
38
37
#include <errno.h>
39
38
#include <sys/types.h>
40
39
#include <sys/stat.h>
46
45
#include <progname.h>
47
46
#include <version-etc.h>
48
47
 
 
48
#include <certtool-cfg.h>
 
49
#include "certtool-gaa.h"
 
50
#include "certtool-common.h"
 
51
 
49
52
static void print_crl_info (gnutls_x509_crl_t crl, FILE * out);
50
53
int generate_prime (int bits, int how);
51
54
void pkcs7_info (void);
127
130
}
128
131
 
129
132
static void
130
 
print_dsa_pkey (gnutls_datum * x, gnutls_datum * y, gnutls_datum * p,
131
 
                gnutls_datum * q, gnutls_datum * g)
 
133
print_dsa_pkey (gnutls_datum_t * x, gnutls_datum_t * y, gnutls_datum_t * p,
 
134
                gnutls_datum_t * q, gnutls_datum_t * g)
132
135
{
133
136
  fprintf (outfile, "private key:");
134
137
  print_hex_datum (x);
143
146
}
144
147
 
145
148
static void
146
 
print_rsa_pkey (gnutls_datum * m, gnutls_datum * e, gnutls_datum * d,
147
 
                gnutls_datum * p, gnutls_datum * q, gnutls_datum * u)
 
149
print_rsa_pkey (gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d,
 
150
                gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u)
148
151
{
149
152
  fprintf (outfile, "modulus:");
150
153
  print_hex_datum (m);
169
172
  if (info.dsa)
170
173
    {
171
174
      key_type = GNUTLS_PK_DSA;
172
 
      /* FIXME: Remove me once we depend on 1.3.x */
173
 
      if (info.bits > 1024 && gcry_check_version ("1.3.1") == NULL)
174
 
        info.bits = 1024;
 
175
      if (info.bits > 1024)
 
176
        {
 
177
          fprintf (stderr,
 
178
                   "It is suggested for compatibility with other implementations to use DSA keys bit length 1024\n");
 
179
        }
175
180
    }
176
181
  else
177
182
    key_type = GNUTLS_PK_RSA;
195
200
  return key;
196
201
}
197
202
 
 
203
static int
 
204
cipher_to_flags (const char *cipher)
 
205
{
 
206
  if (strcasecmp (cipher, "3des") == 0)
 
207
    {
 
208
      return GNUTLS_PKCS_USE_PBES2_3DES;
 
209
    }
 
210
  else if (strcasecmp (cipher, "3des-pkcs12") == 0)
 
211
    {
 
212
      return GNUTLS_PKCS_USE_PKCS12_3DES;
 
213
    }
 
214
  else if (strcasecmp (cipher, "arcfour") == 0)
 
215
    {
 
216
      return GNUTLS_PKCS_USE_PKCS12_ARCFOUR;
 
217
    }
 
218
  else if (strcasecmp (cipher, "aes-128") == 0)
 
219
    {
 
220
      return GNUTLS_PKCS_USE_PBES2_AES_128;
 
221
    }
 
222
  else if (strcasecmp (cipher, "aes-192") == 0)
 
223
    {
 
224
      return GNUTLS_PKCS_USE_PBES2_AES_192;
 
225
    }
 
226
  else if (strcasecmp (cipher, "aes-256") == 0)
 
227
    {
 
228
      return GNUTLS_PKCS_USE_PBES2_AES_256;
 
229
    }
 
230
  else if (strcasecmp (cipher, "rc2-40") == 0)
 
231
    {
 
232
      return GNUTLS_PKCS_USE_PKCS12_RC2_40;
 
233
    }
 
234
 
 
235
  error (EXIT_FAILURE, 0, "Unknown cipher %s\n", cipher);
 
236
  return -1;
 
237
}
 
238
 
 
239
 
198
240
static void
199
241
print_private_key (gnutls_x509_privkey_t key)
200
242
{
220
262
      if (info.export)
221
263
        flags = GNUTLS_PKCS_USE_PKCS12_RC2_40;
222
264
      else
223
 
        flags = GNUTLS_PKCS_USE_PKCS12_3DES;
 
265
        flags = cipher_to_flags (info.pkcs_cipher);
224
266
 
225
267
      if ((pass = get_confirmed_pass (true)) == NULL || *pass == '\0')
226
268
        flags = GNUTLS_PKCS_PLAIN;
301
343
          get_cn_crt_set (crt);
302
344
          get_uid_crt_set (crt);
303
345
          get_oid_crt_set (crt);
304
 
          get_key_purpose_set( crt);
 
346
          get_key_purpose_set (crt);
305
347
 
306
348
          if (!batch)
307
349
            fprintf (stderr,
501
543
                error (EXIT_FAILURE, 0, "key_kp: %s",
502
544
                       gnutls_strerror (result));
503
545
            }
 
546
 
 
547
          result = get_ipsec_ike_status ();
 
548
          if (result)
 
549
            {
 
550
              result =
 
551
                gnutls_x509_crt_set_key_purpose_oid (crt,
 
552
                                                     GNUTLS_KP_IPSEC_IKE,
 
553
                                                     0);
 
554
              if (result < 0)
 
555
                error (EXIT_FAILURE, 0, "key_kp: %s",
 
556
                       gnutls_strerror (result));
 
557
            }
504
558
        }
505
559
 
506
560
      if (usage != 0)
919
973
    }
920
974
 
921
975
#ifdef gcry_fips_mode_active
 
976
  /* Libgcrypt manual says that gcry_version_check must be called
 
977
     before calling gcry_fips_mode_active. */
 
978
  gcry_check_version (NULL);
922
979
  if (gcry_fips_mode_active ())
923
980
    {
924
981
      ret = gnutls_register_md5_handler ();
930
987
 
931
988
  gnutls_global_set_log_function (tls_log_func);
932
989
  gnutls_global_set_log_level (info.debug);
933
 
  if (info.debug > 1) printf("Setting log level to %d\n", info.debug);
 
990
  if (info.debug > 1)
 
991
    printf ("Setting log level to %d\n", info.debug);
934
992
 
935
993
  if ((ret = gnutls_global_init ()) < 0)
936
994
    error (EXIT_FAILURE, 0, "global_init: %s", gnutls_strerror (ret));
1116
1174
    }
1117
1175
 
1118
1176
 
1119
 
  ret = gnutls_openpgp_crt_verify_self(crt, 0, &verify_status);
1120
 
  if (ret < 0) 
 
1177
  ret = gnutls_openpgp_crt_verify_self (crt, 0, &verify_status);
 
1178
  if (ret < 0)
1121
1179
    {
1122
 
      error (EXIT_FAILURE, 0, "verify signature error: %s", gnutls_strerror (ret));
 
1180
      error (EXIT_FAILURE, 0, "verify signature error: %s",
 
1181
             gnutls_strerror (ret));
1123
1182
    }
1124
1183
 
1125
1184
  if (verify_status & GNUTLS_CERT_INVALID)
1128
1187
    }
1129
1188
  else
1130
1189
    {
1131
 
      fprintf (outfile, "Self Signature verification: ok (%x)\n\n", verify_status);
 
1190
      fprintf (outfile, "Self Signature verification: ok (%x)\n\n",
 
1191
               verify_status);
1132
1192
    }
1133
1193
 
1134
1194
  size = sizeof (buffer);
1418
1478
  int ret;
1419
1479
  size_t size;
1420
1480
 
1421
 
  ret = gnutls_x509_crq_print (crq, GNUTLS_CRT_PRINT_FULL, &cinfo);
1422
 
  if (ret < 0)
1423
 
    error (EXIT_FAILURE, 0, "crq_print: %s", gnutls_strerror (ret));
1424
 
 
1425
 
  fprintf (out, "%s\n", cinfo.data);
1426
 
 
1427
 
  gnutls_free (cinfo.data);
 
1481
  if (info.outcert_format == GNUTLS_X509_FMT_PEM)
 
1482
    {
 
1483
      ret = gnutls_x509_crq_print (crq, GNUTLS_CRT_PRINT_FULL, &cinfo);
 
1484
      if (ret < 0)
 
1485
        error (EXIT_FAILURE, 0, "crq_print: %s", gnutls_strerror (ret));
 
1486
 
 
1487
      fprintf (out, "%s\n", cinfo.data);
 
1488
 
 
1489
      gnutls_free (cinfo.data);
 
1490
    }
1428
1491
 
1429
1492
  size = sizeof (buffer);
1430
 
  ret = gnutls_x509_crq_export (crq, GNUTLS_X509_FMT_PEM, buffer, &size);
 
1493
  ret = gnutls_x509_crq_export (crq, info.outcert_format, buffer, &size);
1431
1494
  if (ret < 0)
1432
1495
    error (EXIT_FAILURE, 0, "crq_export: %s", gnutls_strerror (ret));
1433
1496
 
1489
1552
  /* If we failed to import the certificate previously try PKCS #8 */
1490
1553
  if (info.pkcs8 || ret == GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR)
1491
1554
    {
1492
 
      /* first try to import the key without asking any password */
 
1555
      if (info.pass)
 
1556
        pass = info.pass;
 
1557
      else
 
1558
        pass = get_pass ();
1493
1559
      ret = gnutls_x509_privkey_import_pkcs8 (key, &pem,
1494
 
                                              info.incert_format,
1495
 
                                              NULL, GNUTLS_PKCS_PLAIN);
1496
 
      if (ret < 0)
1497
 
        {
1498
 
          if (info.pass)
1499
 
            pass = info.pass;
1500
 
          else
1501
 
            pass = get_pass ();
1502
 
          ret = gnutls_x509_privkey_import_pkcs8 (key, &pem,
1503
 
                                                  info.incert_format,
1504
 
                                                  pass, 0);
1505
 
        }
 
1560
                                              info.incert_format, pass, 0);
1506
1561
    }
1507
1562
  if (ret < 0)
1508
1563
    error (EXIT_FAILURE, 0, "import error: %s", gnutls_strerror (ret));
1890
1945
        error (EXIT_FAILURE, 0, "set_pass: %s", gnutls_strerror (ret));
1891
1946
    }
1892
1947
 
1893
 
  ca_status = get_ca_status ();
1894
 
  if (ca_status)
1895
 
    path_len = get_path_len ();
1896
 
  else
1897
 
    path_len = -1;
1898
 
 
1899
 
  ret = gnutls_x509_crq_set_basic_constraints (crq, ca_status, path_len);
1900
 
  if (ret < 0)
1901
 
    error (EXIT_FAILURE, 0, "set_basic_constraints: %s",
1902
 
           gnutls_strerror (ret));
1903
 
 
1904
 
 
1905
 
  ret = get_sign_status (1);
1906
 
  if (ret)
1907
 
    usage |= GNUTLS_KEY_DIGITAL_SIGNATURE;
1908
 
 
1909
 
  ret = get_encrypt_status (1);
1910
 
  if (ret)
1911
 
    usage |= GNUTLS_KEY_KEY_ENCIPHERMENT;
1912
 
  else
1913
 
    usage |= GNUTLS_KEY_DIGITAL_SIGNATURE;
1914
 
 
1915
 
  if (ca_status)
1916
 
    {
1917
 
      ret = get_cert_sign_status ();
1918
 
      if (ret)
1919
 
        usage |= GNUTLS_KEY_KEY_CERT_SIGN;
1920
 
 
1921
 
      ret = get_crl_sign_status ();
1922
 
      if (ret)
1923
 
        usage |= GNUTLS_KEY_CRL_SIGN;
1924
 
 
1925
 
      ret = get_code_sign_status ();
1926
 
      if (ret)
1927
 
        {
1928
 
          ret =
1929
 
            gnutls_x509_crq_set_key_purpose_oid (crq,
1930
 
                                                 GNUTLS_KP_CODE_SIGNING, 0);
1931
 
          if (ret < 0)
1932
 
            error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
1933
 
        }
1934
 
 
1935
 
      ret = get_ocsp_sign_status ();
1936
 
      if (ret)
1937
 
        {
1938
 
          ret =
1939
 
            gnutls_x509_crq_set_key_purpose_oid (crq,
1940
 
                                                 GNUTLS_KP_OCSP_SIGNING, 0);
1941
 
          if (ret < 0)
1942
 
            error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
1943
 
        }
1944
 
 
1945
 
      ret = get_time_stamp_status ();
1946
 
      if (ret)
1947
 
        {
1948
 
          ret =
1949
 
            gnutls_x509_crq_set_key_purpose_oid (crq,
1950
 
                                                 GNUTLS_KP_TIME_STAMPING, 0);
1951
 
          if (ret < 0)
1952
 
            error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
1953
 
        }
1954
 
 
1955
 
    }
1956
 
 
1957
 
  ret = gnutls_x509_crq_set_key_usage (crq, usage);
1958
 
  if (ret < 0)
1959
 
    error (EXIT_FAILURE, 0, "key_usage: %s", gnutls_strerror (ret));
1960
 
 
1961
 
  ret = get_tls_client_status ();
1962
 
  if (ret != 0)
1963
 
    {
1964
 
      ret = gnutls_x509_crq_set_key_purpose_oid (crq,
1965
 
                                                 GNUTLS_KP_TLS_WWW_CLIENT, 0);
1966
 
      if (ret < 0)
1967
 
        error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
1968
 
    }
1969
 
 
1970
 
  ret = get_tls_server_status ();
1971
 
  if (ret != 0)
1972
 
    {
1973
 
      ret = gnutls_x509_crq_set_key_purpose_oid (crq,
1974
 
                                                 GNUTLS_KP_TLS_WWW_SERVER, 0);
1975
 
      if (ret < 0)
1976
 
        error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
1948
  if (info.crq_extensions != 0)
 
1949
    {
 
1950
      ca_status = get_ca_status ();
 
1951
      if (ca_status)
 
1952
        path_len = get_path_len ();
 
1953
      else
 
1954
        path_len = -1;
 
1955
 
 
1956
      ret = gnutls_x509_crq_set_basic_constraints (crq, ca_status, path_len);
 
1957
      if (ret < 0)
 
1958
        error (EXIT_FAILURE, 0, "set_basic_constraints: %s",
 
1959
               gnutls_strerror (ret));
 
1960
 
 
1961
      ret = get_sign_status (1);
 
1962
      if (ret)
 
1963
        usage |= GNUTLS_KEY_DIGITAL_SIGNATURE;
 
1964
 
 
1965
      ret = get_encrypt_status (1);
 
1966
      if (ret)
 
1967
        usage |= GNUTLS_KEY_KEY_ENCIPHERMENT;
 
1968
      else
 
1969
        usage |= GNUTLS_KEY_DIGITAL_SIGNATURE;
 
1970
 
 
1971
      if (ca_status)
 
1972
        {
 
1973
          ret = get_cert_sign_status ();
 
1974
          if (ret)
 
1975
            usage |= GNUTLS_KEY_KEY_CERT_SIGN;
 
1976
 
 
1977
          ret = get_crl_sign_status ();
 
1978
          if (ret)
 
1979
            usage |= GNUTLS_KEY_CRL_SIGN;
 
1980
 
 
1981
          ret = get_code_sign_status ();
 
1982
          if (ret)
 
1983
            {
 
1984
              ret = gnutls_x509_crq_set_key_purpose_oid
 
1985
                (crq, GNUTLS_KP_CODE_SIGNING, 0);
 
1986
              if (ret < 0)
 
1987
                error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
1988
            }
 
1989
 
 
1990
          ret = get_ocsp_sign_status ();
 
1991
          if (ret)
 
1992
            {
 
1993
              ret = gnutls_x509_crq_set_key_purpose_oid
 
1994
                (crq, GNUTLS_KP_OCSP_SIGNING, 0);
 
1995
              if (ret < 0)
 
1996
                error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
1997
            }
 
1998
 
 
1999
          ret = get_time_stamp_status ();
 
2000
          if (ret)
 
2001
            {
 
2002
              ret = gnutls_x509_crq_set_key_purpose_oid
 
2003
                (crq, GNUTLS_KP_TIME_STAMPING, 0);
 
2004
              if (ret < 0)
 
2005
                error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
2006
            }
 
2007
 
 
2008
          ret = get_ipsec_ike_status ();
 
2009
          if (ret)
 
2010
            {
 
2011
              ret = gnutls_x509_crq_set_key_purpose_oid
 
2012
                (crq, GNUTLS_KP_IPSEC_IKE, 0);
 
2013
              if (ret < 0)
 
2014
                error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
2015
            }
 
2016
        }
 
2017
 
 
2018
      ret = gnutls_x509_crq_set_key_usage (crq, usage);
 
2019
      if (ret < 0)
 
2020
        error (EXIT_FAILURE, 0, "key_usage: %s", gnutls_strerror (ret));
 
2021
 
 
2022
      ret = get_tls_client_status ();
 
2023
      if (ret != 0)
 
2024
        {
 
2025
          ret = gnutls_x509_crq_set_key_purpose_oid
 
2026
            (crq, GNUTLS_KP_TLS_WWW_CLIENT, 0);
 
2027
          if (ret < 0)
 
2028
            error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
2029
        }
 
2030
 
 
2031
      ret = get_tls_server_status ();
 
2032
      if (ret != 0)
 
2033
        {
 
2034
          ret = gnutls_x509_crq_set_key_purpose_oid
 
2035
            (crq, GNUTLS_KP_TLS_WWW_SERVER, 0);
 
2036
          if (ret < 0)
 
2037
            error (EXIT_FAILURE, 0, "key_kp: %s", gnutls_strerror (ret));
 
2038
        }
1977
2039
    }
1978
2040
 
1979
2041
  ret = gnutls_x509_crq_set_key (crq, key);
1994
2056
static void print_verification_res (gnutls_x509_crt_t crt,
1995
2057
                                    gnutls_x509_crt_t issuer,
1996
2058
                                    gnutls_x509_crl_t * crl_list,
1997
 
                                    int crl_list_size);
 
2059
                                    int crl_list_size, unsigned int flags);
1998
2060
 
1999
2061
#define CERT_SEP "-----BEGIN CERT"
2000
2062
#define CRL_SEP "-----BEGIN X509 CRL"
2003
2065
{
2004
2066
  const char *ptr;
2005
2067
  int ret, i;
2006
 
  char name[256];
2007
 
  char issuer_name[256];
 
2068
  char name[512];
 
2069
  char issuer_name[512];
2008
2070
  size_t name_size;
2009
2071
  size_t issuer_name_size;
2010
2072
  gnutls_datum_t tmp;
2138
2200
          fprintf (outfile, "\tVerification output: ");
2139
2201
          print_verification_res (x509_cert_list[i - 2],
2140
2202
                                  x509_cert_list[i - 1], x509_crl_list,
2141
 
                                  x509_ncrls);
 
2203
                                  x509_ncrls,
 
2204
                                  GNUTLS_VERIFY_DO_NOT_ALLOW_SAME);
2142
2205
          fprintf (outfile, ".\n\n");
2143
2206
 
2144
2207
        }
2184
2247
  fprintf (outfile, "\tVerification output: ");
2185
2248
  print_verification_res (x509_cert_list[x509_ncerts - 1],
2186
2249
                          x509_cert_list[x509_ncerts - 1], x509_crl_list,
2187
 
                          x509_ncrls);
 
2250
                          /* we add GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT since it is
 
2251
                           * self signed. */
 
2252
                          x509_ncrls,
 
2253
                          GNUTLS_VERIFY_DO_NOT_ALLOW_SAME |
 
2254
                          GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
2188
2255
 
2189
2256
  fprintf (outfile, ".\n\n");
2190
2257
 
2196
2263
                                       &x509_cert_list[x509_ncerts - 1], 1,
2197
2264
                                       x509_crl_list,
2198
2265
                                       x509_ncrls,
2199
 
                                       GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT,
 
2266
                                       GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT |
 
2267
                                       GNUTLS_VERIFY_DO_NOT_ALLOW_SAME,
2200
2268
                                       &verify_status);
2201
2269
    if (ret < 0)
2202
2270
      error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify: %s",
2246
2314
static void
2247
2315
print_verification_res (gnutls_x509_crt_t crt,
2248
2316
                        gnutls_x509_crt_t issuer,
2249
 
                        gnutls_x509_crl_t * crl_list, int crl_list_size)
 
2317
                        gnutls_x509_crl_t * crl_list, int crl_list_size,
 
2318
                        unsigned int flags)
2250
2319
{
2251
2320
  unsigned int output;
2252
2321
  int comma = 0;
2253
2322
  int ret;
2254
 
  time_t now = time (0);
2255
2323
 
2256
 
  ret = gnutls_x509_crt_verify (crt, &issuer, 1, 0, &output);
 
2324
  ret = gnutls_x509_crt_verify (crt, &issuer, 1, flags, &output);
2257
2325
  if (ret < 0)
2258
 
    error (EXIT_FAILURE, 0, "verification error: %s",
2259
 
           gnutls_strerror (ret));
 
2326
    error (EXIT_FAILURE, 0, "verification error: %s", gnutls_strerror (ret));
2260
2327
 
2261
2328
  if (output & GNUTLS_CERT_INVALID)
2262
2329
    {
2285
2352
      comma = 1;
2286
2353
    }
2287
2354
 
2288
 
  /* Check expiration dates.
2289
 
   */
2290
 
 
2291
 
  if (gnutls_x509_crt_get_activation_time (crt) > now)
 
2355
  if (output & GNUTLS_CERT_NOT_ACTIVATED)
2292
2356
    {
2293
2357
      if (comma)
2294
2358
        fprintf (outfile, ", ");
2295
 
      comma = 1;
2296
2359
      fprintf (outfile, "Not activated");
 
2360
      comma = 1;
2297
2361
    }
2298
2362
 
2299
 
  if (gnutls_x509_crt_get_expiration_time (crt) < now)
 
2363
  if (output & GNUTLS_CERT_EXPIRED)
2300
2364
    {
2301
2365
      if (comma)
2302
2366
        fprintf (outfile, ", ");
2303
 
      comma = 1;
2304
2367
      fprintf (outfile, "Expired");
 
2368
      comma = 1;
2305
2369
    }
2306
2370
 
2307
2371
  ret = gnutls_x509_crt_check_revocation (crt, crl_list, crl_list_size);
2425
2489
  fprintf (outfile, "\n");
2426
2490
}
2427
2491
 
 
2492
 
2428
2493
void
2429
2494
generate_pkcs8 (void)
2430
2495
{
2446
2511
  if (info.export)
2447
2512
    flags = GNUTLS_PKCS_USE_PKCS12_RC2_40;
2448
2513
  else
2449
 
    flags = GNUTLS_PKCS_USE_PKCS12_3DES;
 
2514
    flags = cipher_to_flags (info.pkcs_cipher);
2450
2515
 
2451
2516
  if (password == NULL || password[0] == 0)
2452
2517
    {
2539
2604
      if (info.export)
2540
2605
        flags = GNUTLS_PKCS_USE_PKCS12_RC2_40;
2541
2606
      else
2542
 
        flags = GNUTLS_PKCS8_USE_PKCS12_3DES;
 
2607
        flags = cipher_to_flags (info.pkcs_cipher);
2543
2608
 
2544
2609
      result = gnutls_pkcs12_bag_encrypt (bag, pass, flags);
2545
2610
      if (result < 0)
2561
2626
      if (info.export)
2562
2627
        flags = GNUTLS_PKCS_USE_PKCS12_RC2_40;
2563
2628
      else
2564
 
        flags = GNUTLS_PKCS_USE_PKCS12_3DES;
 
2629
        flags = cipher_to_flags (info.pkcs_cipher);
2565
2630
 
2566
2631
      size = sizeof (buffer);
2567
2632
      result =
2633
2698
      return "Encrypted";
2634
2699
    case GNUTLS_BAG_CRL:
2635
2700
      return "CRL";
 
2701
    case GNUTLS_BAG_SECRET:
 
2702
      return "Secret";
2636
2703
    default:
2637
2704
      return "Unknown";
2638
2705
    }
2743
2810
  if (result < 0)
2744
2811
    error (0, 0, "verify_mac: %s", gnutls_strerror (result));
2745
2812
 
2746
 
  indx = 0;
2747
 
 
2748
2813
  for (indx = 0;; indx++)
2749
2814
    {
2750
2815
      result = gnutls_pkcs12_bag_init (&bag);