Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1 | /* |
Matt Caswell | fecb3aa | 2022-05-03 11:52:38 +0100 | [diff] [blame] | 2 | * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved. |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 3 | * |
Richard Levitte | dffa752 | 2018-12-06 13:00:26 +0100 | [diff] [blame] | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Richard Levitte | f385263 | 2016-03-18 20:06:29 +0100 | [diff] [blame] | 10 | #include <openssl/opensslconf.h> |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | #include "apps.h" |
| 15 | #include "progs.h" |
| 16 | #include <openssl/bio.h> |
| 17 | #include <openssl/err.h> |
| 18 | #include <openssl/pem.h> |
| 19 | #include <openssl/rand.h> |
| 20 | #include <openssl/ts.h> |
| 21 | #include <openssl/bn.h> |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 22 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 23 | /* Request nonce length, in bits (must be a multiple of 8). */ |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 24 | #define NONCE_LENGTH 64 |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 25 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 26 | /* Name of config entry that defines the OID file. */ |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 27 | #define ENV_OID_FILE "oid_file" |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 28 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 29 | /* Is |EXACTLY_ONE| of three pointers set? */ |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 30 | #define EXACTLY_ONE(a, b, c) \ |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 31 | (( a && !b && !c) || \ |
| 32 | ( b && !a && !c) || \ |
| 33 | ( c && !a && !b)) |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 34 | |
| 35 | static ASN1_OBJECT *txt2obj(const char *oid); |
| 36 | static CONF *load_config_file(const char *configfile); |
| 37 | |
| 38 | /* Query related functions. */ |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 39 | static int query_command(const char *data, const char *digest, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 40 | const EVP_MD *md, const char *policy, int no_nonce, |
| 41 | int cert, const char *in, const char *out, int text); |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 42 | static TS_REQ *create_query(BIO *data_bio, const char *digest, const EVP_MD *md, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 43 | const char *policy, int no_nonce, int cert); |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 44 | static int create_digest(BIO *input, const char *digest, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 45 | const EVP_MD *md, unsigned char **md_value); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 46 | static ASN1_INTEGER *create_nonce(int bits); |
| 47 | |
| 48 | /* Reply related functions. */ |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 49 | static int reply_command(CONF *conf, const char *section, const char *engine, |
| 50 | const char *queryfile, const char *passin, const char *inkey, |
| 51 | const EVP_MD *md, const char *signer, const char *chain, |
| 52 | const char *policy, const char *in, int token_in, |
| 53 | const char *out, int token_out, int text); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 54 | static TS_RESP *read_PKCS7(BIO *in_bio); |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 55 | static TS_RESP *create_response(CONF *conf, const char *section, const char *engine, |
| 56 | const char *queryfile, const char *passin, |
| 57 | const char *inkey, const EVP_MD *md, const char *signer, |
| 58 | const char *chain, const char *policy); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 59 | static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 60 | static ASN1_INTEGER *next_serial(const char *serialfile); |
| 61 | static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial); |
| 62 | |
| 63 | /* Verify related functions. */ |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 64 | static int verify_command(const char *data, const char *digest, const char *queryfile, |
| 65 | const char *in, int token_in, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 66 | const char *CApath, const char *CAfile, |
| 67 | const char *CAstore, |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 68 | char *untrusted, X509_VERIFY_PARAM *vpm); |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 69 | static TS_VERIFY_CTX *create_verify_ctx(const char *data, const char *digest, |
| 70 | const char *queryfile, |
| 71 | const char *CApath, const char *CAfile, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 72 | const char *CAstore, |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 73 | char *untrusted, |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 74 | X509_VERIFY_PARAM *vpm); |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 75 | static X509_STORE *create_cert_store(const char *CApath, const char *CAfile, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 76 | const char *CAstore, X509_VERIFY_PARAM *vpm); |
Rich Salz | 6d23cf9 | 2015-01-12 17:29:26 -0500 | [diff] [blame] | 77 | static int verify_cb(int ok, X509_STORE_CTX *ctx); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 78 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 79 | typedef enum OPTION_choice { |
Dr. David von Oheimb | b0f9601 | 2021-05-01 15:29:00 +0200 | [diff] [blame] | 80 | OPT_COMMON, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 81 | OPT_ENGINE, OPT_CONFIG, OPT_SECTION, OPT_QUERY, OPT_DATA, |
Rich Salz | 3ee1eac | 2017-07-05 10:58:48 -0400 | [diff] [blame] | 82 | OPT_DIGEST, OPT_TSPOLICY, OPT_NO_NONCE, OPT_CERT, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 83 | OPT_IN, OPT_TOKEN_IN, OPT_OUT, OPT_TOKEN_OUT, OPT_TEXT, |
| 84 | OPT_REPLY, OPT_QUERYFILE, OPT_PASSIN, OPT_INKEY, OPT_SIGNER, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 85 | OPT_CHAIN, OPT_VERIFY, OPT_CAPATH, OPT_CAFILE, OPT_CASTORE, OPT_UNTRUSTED, |
Pauli | 6bd4e3f | 2020-02-25 14:29:30 +1000 | [diff] [blame] | 86 | OPT_MD, OPT_V_ENUM, OPT_R_ENUM, OPT_PROV_ENUM |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 87 | } OPTION_CHOICE; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 88 | |
FdaSilvaYY | 44c83eb | 2016-03-13 14:07:50 +0100 | [diff] [blame] | 89 | const OPTIONS ts_options[] = { |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 90 | OPT_SECTION("General"), |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 91 | {"help", OPT_HELP, '-', "Display this summary"}, |
| 92 | {"config", OPT_CONFIG, '<', "Configuration file"}, |
| 93 | {"section", OPT_SECTION, 's', "Section to use within config file"}, |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 94 | #ifndef OPENSSL_NO_ENGINE |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 95 | {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 96 | #endif |
Rich Salz | 48b5352 | 2017-05-20 21:44:31 -0400 | [diff] [blame] | 97 | {"inkey", OPT_INKEY, 's', "File with private key for reply"}, |
FdaSilvaYY | 12d56b2 | 2016-07-31 19:02:50 +0200 | [diff] [blame] | 98 | {"signer", OPT_SIGNER, 's', "Signer certificate file"}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 99 | {"chain", OPT_CHAIN, '<', "File with signer CA chain"}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 100 | {"CAfile", OPT_CAFILE, '<', "File with trusted CA certs"}, |
Dr. David von Oheimb | 2b264ae | 2020-03-06 21:46:33 +0100 | [diff] [blame] | 101 | {"CApath", OPT_CAPATH, '/', "Path to trusted CA files"}, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 102 | {"CAstore", OPT_CASTORE, ':', "URI to trusted CA store"}, |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 103 | {"untrusted", OPT_UNTRUSTED, '<', "Extra untrusted certs"}, |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 104 | {"token_in", OPT_TOKEN_IN, '-', "Input is a PKCS#7 file"}, |
| 105 | {"token_out", OPT_TOKEN_OUT, '-', "Output is a PKCS#7 file"}, |
| 106 | {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, |
Rich Salz | 9c3bcfa | 2015-05-15 13:50:38 -0400 | [diff] [blame] | 107 | {"", OPT_MD, '-', "Any supported digest"}, |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 108 | |
| 109 | OPT_SECTION("Query"), |
| 110 | {"query", OPT_QUERY, '-', "Generate a TS query"}, |
| 111 | {"data", OPT_DATA, '<', "File to hash"}, |
| 112 | {"digest", OPT_DIGEST, 's', "Digest (as a hex string)"}, |
| 113 | {"queryfile", OPT_QUERYFILE, '<', "File containing a TS query"}, |
| 114 | {"cert", OPT_CERT, '-', "Put cert request into query"}, |
| 115 | {"in", OPT_IN, '<', "Input file"}, |
| 116 | |
| 117 | OPT_SECTION("Verify"), |
| 118 | {"verify", OPT_VERIFY, '-', "Verify a TS response"}, |
| 119 | {"reply", OPT_REPLY, '-', "Generate a TS reply"}, |
| 120 | {"tspolicy", OPT_TSPOLICY, 's', "Policy OID to use"}, |
| 121 | {"no_nonce", OPT_NO_NONCE, '-', "Do not include a nonce"}, |
| 122 | {"out", OPT_OUT, '>', "Output file"}, |
| 123 | {"text", OPT_TEXT, '-', "Output text (not DER)"}, |
| 124 | |
| 125 | OPT_R_OPTIONS, |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 126 | OPT_V_OPTIONS, |
Pauli | 6bd4e3f | 2020-02-25 14:29:30 +1000 | [diff] [blame] | 127 | OPT_PROV_OPTIONS, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 128 | {NULL} |
| 129 | }; |
| 130 | |
| 131 | /* |
klemens | 6025001 | 2016-08-05 19:56:58 +0200 | [diff] [blame] | 132 | * This command is so complex, special help is needed. |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 133 | */ |
| 134 | static char* opt_helplist[] = { |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 135 | "", |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 136 | "Typical uses:", |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 137 | " openssl ts -query [-rand file...] [-config file] [-data file]", |
| 138 | " [-digest hexstring] [-tspolicy oid] [-no_nonce] [-cert]", |
| 139 | " [-in file] [-out file] [-text]", |
| 140 | "", |
| 141 | " openssl ts -reply [-config file] [-section tsa_section]", |
| 142 | " [-queryfile file] [-passin password]", |
| 143 | " [-signer tsa_cert.pem] [-inkey private_key.pem]", |
| 144 | " [-chain certs_file.pem] [-tspolicy oid]", |
| 145 | " [-in file] [-token_in] [-out file] [-token_out]", |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 146 | #ifndef OPENSSL_NO_ENGINE |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 147 | " [-text] [-engine id]", |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 148 | #else |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 149 | " [-text]", |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 150 | #endif |
Rich Salz | 5388f98 | 2019-11-08 06:08:30 +1000 | [diff] [blame] | 151 | "", |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 152 | " openssl ts -verify -CApath dir -CAfile root-cert.pem -CAstore uri", |
| 153 | " -untrusted extra-certs.pem [-data file] [-digest hexstring]", |
| 154 | " [-queryfile request.tsq] -in response.tsr [-token_in] ...", |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 155 | NULL, |
| 156 | }; |
| 157 | |
| 158 | int ts_main(int argc, char **argv) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 159 | { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 160 | CONF *conf = NULL; |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 161 | const char *CAfile = NULL, *prog; |
| 162 | char *untrusted = NULL; |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 163 | const char *configfile = default_config_file, *engine = NULL; |
Rich Salz | d0190e1 | 2021-02-08 14:03:35 -0500 | [diff] [blame] | 164 | const char *section = NULL, *digestname = NULL; |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 165 | char **helpp; |
| 166 | char *password = NULL; |
Rich Salz | 3ee1eac | 2017-07-05 10:58:48 -0400 | [diff] [blame] | 167 | char *data = NULL, *digest = NULL, *policy = NULL; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 168 | char *in = NULL, *out = NULL, *queryfile = NULL, *passin = NULL; |
| 169 | char *inkey = NULL, *signer = NULL, *chain = NULL, *CApath = NULL; |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 170 | char *CAstore = NULL; |
Rich Salz | 606a417 | 2021-02-17 16:15:27 -0500 | [diff] [blame] | 171 | EVP_MD *md = NULL; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 172 | OPTION_CHOICE o, mode = OPT_ERR; |
| 173 | int ret = 1, no_nonce = 0, cert = 0, text = 0; |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 174 | int vpmtouched = 0; |
| 175 | X509_VERIFY_PARAM *vpm = NULL; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 176 | /* Input is ContentInfo instead of TimeStampResp. */ |
| 177 | int token_in = 0; |
| 178 | /* Output is ContentInfo instead of TimeStampResp. */ |
| 179 | int token_out = 0; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 180 | |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 181 | if ((vpm = X509_VERIFY_PARAM_new()) == NULL) |
| 182 | goto end; |
| 183 | |
Dr. David von Oheimb | 2c27244 | 2021-08-24 12:03:12 +0200 | [diff] [blame] | 184 | opt_set_unknown_name("digest"); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 185 | prog = opt_init(argc, argv, ts_options); |
| 186 | while ((o = opt_next()) != OPT_EOF) { |
| 187 | switch (o) { |
| 188 | case OPT_EOF: |
| 189 | case OPT_ERR: |
| 190 | opthelp: |
| 191 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); |
| 192 | goto end; |
| 193 | case OPT_HELP: |
| 194 | opt_help(ts_options); |
| 195 | for (helpp = opt_helplist; *helpp; ++helpp) |
| 196 | BIO_printf(bio_err, "%s\n", *helpp); |
| 197 | ret = 0; |
| 198 | goto end; |
| 199 | case OPT_CONFIG: |
| 200 | configfile = opt_arg(); |
| 201 | break; |
| 202 | case OPT_SECTION: |
| 203 | section = opt_arg(); |
| 204 | break; |
| 205 | case OPT_QUERY: |
| 206 | case OPT_REPLY: |
| 207 | case OPT_VERIFY: |
Dr. David von Oheimb | d9f0735 | 2021-08-27 15:33:18 +0200 | [diff] [blame] | 208 | if (mode != OPT_ERR) { |
| 209 | BIO_printf(bio_err, "%s: Must give only one of -query, -reply, or -verify\n", prog); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 210 | goto opthelp; |
Dr. David von Oheimb | d9f0735 | 2021-08-27 15:33:18 +0200 | [diff] [blame] | 211 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 212 | mode = o; |
| 213 | break; |
| 214 | case OPT_DATA: |
| 215 | data = opt_arg(); |
| 216 | break; |
| 217 | case OPT_DIGEST: |
| 218 | digest = opt_arg(); |
| 219 | break; |
Rich Salz | 3ee1eac | 2017-07-05 10:58:48 -0400 | [diff] [blame] | 220 | case OPT_R_CASES: |
| 221 | if (!opt_rand(o)) |
| 222 | goto end; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 223 | break; |
Pauli | 6bd4e3f | 2020-02-25 14:29:30 +1000 | [diff] [blame] | 224 | case OPT_PROV_CASES: |
| 225 | if (!opt_provider(o)) |
| 226 | goto end; |
| 227 | break; |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 228 | case OPT_TSPOLICY: |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 229 | policy = opt_arg(); |
| 230 | break; |
| 231 | case OPT_NO_NONCE: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 232 | no_nonce = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 233 | break; |
| 234 | case OPT_CERT: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 235 | cert = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 236 | break; |
| 237 | case OPT_IN: |
| 238 | in = opt_arg(); |
| 239 | break; |
| 240 | case OPT_TOKEN_IN: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 241 | token_in = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 242 | break; |
| 243 | case OPT_OUT: |
| 244 | out = opt_arg(); |
| 245 | break; |
| 246 | case OPT_TOKEN_OUT: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 247 | token_out = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 248 | break; |
| 249 | case OPT_TEXT: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 250 | text = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 251 | break; |
| 252 | case OPT_QUERYFILE: |
| 253 | queryfile = opt_arg(); |
| 254 | break; |
| 255 | case OPT_PASSIN: |
| 256 | passin = opt_arg(); |
| 257 | break; |
| 258 | case OPT_INKEY: |
| 259 | inkey = opt_arg(); |
| 260 | break; |
| 261 | case OPT_SIGNER: |
| 262 | signer = opt_arg(); |
| 263 | break; |
| 264 | case OPT_CHAIN: |
| 265 | chain = opt_arg(); |
| 266 | break; |
| 267 | case OPT_CAPATH: |
| 268 | CApath = opt_arg(); |
| 269 | break; |
| 270 | case OPT_CAFILE: |
| 271 | CAfile = opt_arg(); |
| 272 | break; |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 273 | case OPT_CASTORE: |
| 274 | CAstore = opt_arg(); |
| 275 | break; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 276 | case OPT_UNTRUSTED: |
| 277 | untrusted = opt_arg(); |
| 278 | break; |
| 279 | case OPT_ENGINE: |
| 280 | engine = opt_arg(); |
| 281 | break; |
| 282 | case OPT_MD: |
Rich Salz | d0190e1 | 2021-02-08 14:03:35 -0500 | [diff] [blame] | 283 | digestname = opt_unknown(); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 284 | break; |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 285 | case OPT_V_CASES: |
| 286 | if (!opt_verify(o, vpm)) |
| 287 | goto end; |
| 288 | vpmtouched++; |
| 289 | break; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 290 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 291 | } |
Rich Salz | 021410e | 2020-11-28 16:12:58 -0500 | [diff] [blame] | 292 | |
| 293 | /* No extra arguments. */ |
Dr. David von Oheimb | d9f0735 | 2021-08-27 15:33:18 +0200 | [diff] [blame] | 294 | if (!opt_check_rest_arg(NULL)) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 295 | goto opthelp; |
Dr. David von Oheimb | d9f0735 | 2021-08-27 15:33:18 +0200 | [diff] [blame] | 296 | if (mode == OPT_ERR) { |
| 297 | BIO_printf(bio_err, "%s: Must give one of -query, -reply, or -verify\n", prog); |
| 298 | goto opthelp; |
| 299 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 300 | |
Dr. David von Oheimb | 3ad6030 | 2021-04-03 12:53:51 +0200 | [diff] [blame] | 301 | if (!app_RAND_load()) |
| 302 | goto end; |
| 303 | |
Dr. David von Oheimb | d9f0735 | 2021-08-27 15:33:18 +0200 | [diff] [blame] | 304 | if (!opt_md(digestname, &md)) |
| 305 | goto opthelp; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 306 | if (mode == OPT_REPLY && passin && |
| 307 | !app_passwd(passin, NULL, &password, NULL)) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 308 | BIO_printf(bio_err, "Error getting password.\n"); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 309 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 310 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 311 | |
kinichiro | dd0139f | 2019-12-11 21:12:53 +0900 | [diff] [blame] | 312 | if ((conf = load_config_file(configfile)) == NULL) |
| 313 | goto end; |
Dr. Stephen Henson | c821def | 2016-05-15 18:43:03 +0100 | [diff] [blame] | 314 | if (configfile != default_config_file && !app_load_modules(conf)) |
Richard Levitte | 296f54e | 2015-05-29 08:07:10 +0200 | [diff] [blame] | 315 | goto end; |
| 316 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 317 | /* Check parameter consistency and execute the appropriate function. */ |
Rich Salz | f3b3d7f | 2016-08-30 13:31:18 -0400 | [diff] [blame] | 318 | if (mode == OPT_QUERY) { |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 319 | if (vpmtouched) |
| 320 | goto opthelp; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 321 | if ((data != NULL) && (digest != NULL)) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 322 | goto opthelp; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 323 | ret = !query_command(data, digest, md, policy, no_nonce, cert, |
| 324 | in, out, text); |
Rich Salz | f3b3d7f | 2016-08-30 13:31:18 -0400 | [diff] [blame] | 325 | } else if (mode == OPT_REPLY) { |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 326 | if (vpmtouched) |
| 327 | goto opthelp; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 328 | if ((in != NULL) && (queryfile != NULL)) |
| 329 | goto opthelp; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 330 | if (in == NULL) { |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 331 | if ((conf == NULL) || (token_in != 0)) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 332 | goto opthelp; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 333 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 334 | ret = !reply_command(conf, section, engine, queryfile, |
Dr. Stephen Henson | e20b472 | 2015-09-11 16:58:57 +0100 | [diff] [blame] | 335 | password, inkey, md, signer, chain, policy, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 336 | in, token_in, out, token_out, text); |
Rich Salz | f3b3d7f | 2016-08-30 13:31:18 -0400 | [diff] [blame] | 337 | |
| 338 | } else if (mode == OPT_VERIFY) { |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 339 | if ((in == NULL) || !EXACTLY_ONE(queryfile, data, digest)) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 340 | goto opthelp; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 341 | ret = !verify_command(data, digest, queryfile, in, token_in, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 342 | CApath, CAfile, CAstore, untrusted, |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 343 | vpmtouched ? vpm : NULL); |
Rich Salz | f3b3d7f | 2016-08-30 13:31:18 -0400 | [diff] [blame] | 344 | } else { |
| 345 | goto opthelp; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 348 | end: |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 349 | X509_VERIFY_PARAM_free(vpm); |
Rich Salz | 606a417 | 2021-02-17 16:15:27 -0500 | [diff] [blame] | 350 | EVP_MD_free(md); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 351 | NCONF_free(conf); |
| 352 | OPENSSL_free(password); |
KaoruToda | 26a7d93 | 2017-10-17 23:04:09 +0900 | [diff] [blame] | 353 | return ret; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 354 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 355 | |
| 356 | /* |
| 357 | * Configuration file-related function definitions. |
| 358 | */ |
| 359 | |
| 360 | static ASN1_OBJECT *txt2obj(const char *oid) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 361 | { |
| 362 | ASN1_OBJECT *oid_obj = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 363 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 364 | if ((oid_obj = OBJ_txt2obj(oid, 0)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 365 | BIO_printf(bio_err, "cannot convert %s to OID\n", oid); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 366 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 367 | return oid_obj; |
| 368 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 369 | |
| 370 | static CONF *load_config_file(const char *configfile) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 371 | { |
Rich Salz | cc01d21 | 2015-05-28 13:52:55 -0400 | [diff] [blame] | 372 | CONF *conf = app_load_config(configfile); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 373 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 374 | if (conf != NULL) { |
| 375 | const char *p; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 376 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 377 | BIO_printf(bio_err, "Using configuration from %s\n", configfile); |
| 378 | p = NCONF_get_string(conf, NULL, ENV_OID_FILE); |
| 379 | if (p != NULL) { |
| 380 | BIO *oid_bio = BIO_new_file(p, "r"); |
| 381 | if (!oid_bio) |
| 382 | ERR_print_errors(bio_err); |
| 383 | else { |
| 384 | OBJ_create_objects(oid_bio); |
| 385 | BIO_free_all(oid_bio); |
| 386 | } |
| 387 | } else |
| 388 | ERR_clear_error(); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 389 | if (!add_oid_section(conf)) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 390 | ERR_print_errors(bio_err); |
| 391 | } |
| 392 | return conf; |
| 393 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 394 | |
| 395 | /* |
| 396 | * Query-related method definitions. |
| 397 | */ |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 398 | static int query_command(const char *data, const char *digest, const EVP_MD *md, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 399 | const char *policy, int no_nonce, |
| 400 | int cert, const char *in, const char *out, int text) |
| 401 | { |
| 402 | int ret = 0; |
| 403 | TS_REQ *query = NULL; |
| 404 | BIO *in_bio = NULL; |
| 405 | BIO *data_bio = NULL; |
| 406 | BIO *out_bio = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 407 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 408 | /* Build query object. */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 409 | if (in != NULL) { |
Richard Levitte | bdd58d9 | 2015-09-04 12:49:06 +0200 | [diff] [blame] | 410 | if ((in_bio = bio_open_default(in, 'r', FORMAT_ASN1)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 411 | goto end; |
| 412 | query = d2i_TS_REQ_bio(in_bio, NULL); |
| 413 | } else { |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 414 | if (digest == NULL |
Richard Levitte | bdd58d9 | 2015-09-04 12:49:06 +0200 | [diff] [blame] | 415 | && (data_bio = bio_open_default(data, 'r', FORMAT_ASN1)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 416 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 417 | query = create_query(data_bio, digest, md, policy, no_nonce, cert); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 418 | } |
| 419 | if (query == NULL) |
| 420 | goto end; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 421 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 422 | if (text) { |
Richard Levitte | bdd58d9 | 2015-09-04 12:49:06 +0200 | [diff] [blame] | 423 | if ((out_bio = bio_open_default(out, 'w', FORMAT_TEXT)) == NULL) |
| 424 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 425 | if (!TS_REQ_print_bio(out_bio, query)) |
| 426 | goto end; |
| 427 | } else { |
Richard Levitte | bdd58d9 | 2015-09-04 12:49:06 +0200 | [diff] [blame] | 428 | if ((out_bio = bio_open_default(out, 'w', FORMAT_ASN1)) == NULL) |
| 429 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 430 | if (!i2d_TS_REQ_bio(out_bio, query)) |
| 431 | goto end; |
| 432 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 433 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 434 | ret = 1; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 435 | |
| 436 | end: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 437 | ERR_print_errors(bio_err); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 438 | BIO_free_all(in_bio); |
| 439 | BIO_free_all(data_bio); |
| 440 | BIO_free_all(out_bio); |
| 441 | TS_REQ_free(query); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 442 | return ret; |
| 443 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 444 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 445 | static TS_REQ *create_query(BIO *data_bio, const char *digest, const EVP_MD *md, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 446 | const char *policy, int no_nonce, int cert) |
| 447 | { |
| 448 | int ret = 0; |
| 449 | TS_REQ *ts_req = NULL; |
| 450 | int len; |
| 451 | TS_MSG_IMPRINT *msg_imprint = NULL; |
| 452 | X509_ALGOR *algo = NULL; |
| 453 | unsigned char *data = NULL; |
| 454 | ASN1_OBJECT *policy_obj = NULL; |
| 455 | ASN1_INTEGER *nonce_asn1 = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 456 | |
Tomas Mraz | a6dfa18 | 2018-12-14 12:10:58 +0100 | [diff] [blame] | 457 | if (md == NULL && (md = EVP_get_digestbyname("sha256")) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 458 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 459 | if ((ts_req = TS_REQ_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 460 | goto err; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 461 | if (!TS_REQ_set_version(ts_req, 1)) |
| 462 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 463 | if ((msg_imprint = TS_MSG_IMPRINT_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 464 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 465 | if ((algo = X509_ALGOR_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 466 | goto err; |
Tomas Mraz | ed576ac | 2021-05-21 16:58:08 +0200 | [diff] [blame] | 467 | if ((algo->algorithm = OBJ_nid2obj(EVP_MD_get_type(md))) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 468 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 469 | if ((algo->parameter = ASN1_TYPE_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 470 | goto err; |
| 471 | algo->parameter->type = V_ASN1_NULL; |
| 472 | if (!TS_MSG_IMPRINT_set_algo(msg_imprint, algo)) |
| 473 | goto err; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 474 | if ((len = create_digest(data_bio, digest, md, &data)) == 0) |
| 475 | goto err; |
| 476 | if (!TS_MSG_IMPRINT_set_msg(msg_imprint, data, len)) |
| 477 | goto err; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 478 | if (!TS_REQ_set_msg_imprint(ts_req, msg_imprint)) |
| 479 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 480 | if (policy && (policy_obj = txt2obj(policy)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 481 | goto err; |
| 482 | if (policy_obj && !TS_REQ_set_policy_id(ts_req, policy_obj)) |
| 483 | goto err; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 484 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 485 | /* Setting nonce if requested. */ |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 486 | if (!no_nonce && (nonce_asn1 = create_nonce(NONCE_LENGTH)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 487 | goto err; |
| 488 | if (nonce_asn1 && !TS_REQ_set_nonce(ts_req, nonce_asn1)) |
| 489 | goto err; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 490 | if (!TS_REQ_set_cert_req(ts_req, cert)) |
| 491 | goto err; |
| 492 | |
| 493 | ret = 1; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 494 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 495 | if (!ret) { |
| 496 | TS_REQ_free(ts_req); |
| 497 | ts_req = NULL; |
| 498 | BIO_printf(bio_err, "could not create query\n"); |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 499 | ERR_print_errors(bio_err); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 500 | } |
| 501 | TS_MSG_IMPRINT_free(msg_imprint); |
| 502 | X509_ALGOR_free(algo); |
| 503 | OPENSSL_free(data); |
| 504 | ASN1_OBJECT_free(policy_obj); |
| 505 | ASN1_INTEGER_free(nonce_asn1); |
| 506 | return ts_req; |
| 507 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 508 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 509 | static int create_digest(BIO *input, const char *digest, const EVP_MD *md, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 510 | unsigned char **md_value) |
| 511 | { |
| 512 | int md_value_len; |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 513 | int rv = 0; |
| 514 | EVP_MD_CTX *md_ctx = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 515 | |
Tomas Mraz | ed576ac | 2021-05-21 16:58:08 +0200 | [diff] [blame] | 516 | md_value_len = EVP_MD_get_size(md); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 517 | if (md_value_len < 0) |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 518 | return 0; |
| 519 | |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 520 | if (input != NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 521 | unsigned char buffer[4096]; |
| 522 | int length; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 523 | |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 524 | md_ctx = EVP_MD_CTX_new(); |
Richard Levitte | 6e59a89 | 2015-11-27 14:02:12 +0100 | [diff] [blame] | 525 | if (md_ctx == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 526 | return 0; |
Richard Levitte | 6e59a89 | 2015-11-27 14:02:12 +0100 | [diff] [blame] | 527 | *md_value = app_malloc(md_value_len, "digest buffer"); |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 528 | if (!EVP_DigestInit(md_ctx, md)) |
| 529 | goto err; |
Richard Levitte | 6e59a89 | 2015-11-27 14:02:12 +0100 | [diff] [blame] | 530 | while ((length = BIO_read(input, buffer, sizeof(buffer))) > 0) { |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 531 | if (!EVP_DigestUpdate(md_ctx, buffer, length)) |
| 532 | goto err; |
Richard Levitte | 6e59a89 | 2015-11-27 14:02:12 +0100 | [diff] [blame] | 533 | } |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 534 | if (!EVP_DigestFinal(md_ctx, *md_value, NULL)) |
| 535 | goto err; |
Tomas Mraz | ed576ac | 2021-05-21 16:58:08 +0200 | [diff] [blame] | 536 | md_value_len = EVP_MD_get_size(md); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 537 | } else { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 538 | long digest_len; |
Rich Salz | 12a765a | 2019-09-16 15:28:57 -0400 | [diff] [blame] | 539 | |
Rich Salz | 14f051a | 2016-04-13 15:58:28 -0400 | [diff] [blame] | 540 | *md_value = OPENSSL_hexstr2buf(digest, &digest_len); |
Rich Salz | 12a765a | 2019-09-16 15:28:57 -0400 | [diff] [blame] | 541 | if (*md_value == NULL || md_value_len != digest_len) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 542 | OPENSSL_free(*md_value); |
| 543 | *md_value = NULL; |
| 544 | BIO_printf(bio_err, "bad digest, %d bytes " |
| 545 | "must be specified\n", md_value_len); |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 546 | return 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 547 | } |
| 548 | } |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 549 | rv = md_value_len; |
| 550 | err: |
| 551 | EVP_MD_CTX_free(md_ctx); |
| 552 | return rv; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 553 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 554 | |
| 555 | static ASN1_INTEGER *create_nonce(int bits) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 556 | { |
| 557 | unsigned char buf[20]; |
| 558 | ASN1_INTEGER *nonce = NULL; |
| 559 | int len = (bits - 1) / 8 + 1; |
| 560 | int i; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 561 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 562 | if (len > (int)sizeof(buf)) |
| 563 | goto err; |
| 564 | if (RAND_bytes(buf, len) <= 0) |
| 565 | goto err; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 566 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 567 | /* Find the first non-zero byte and creating ASN1_INTEGER object. */ |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 568 | for (i = 0; i < len && !buf[i]; ++i) |
| 569 | continue; |
| 570 | if ((nonce = ASN1_INTEGER_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 571 | goto err; |
| 572 | OPENSSL_free(nonce->data); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 573 | nonce->length = len - i; |
Rich Salz | 68dc682 | 2015-04-30 17:48:31 -0400 | [diff] [blame] | 574 | nonce->data = app_malloc(nonce->length + 1, "nonce buffer"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 575 | memcpy(nonce->data, buf + i, nonce->length); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 576 | return nonce; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 577 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 578 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 579 | BIO_printf(bio_err, "could not create nonce\n"); |
| 580 | ASN1_INTEGER_free(nonce); |
| 581 | return NULL; |
| 582 | } |
| 583 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 584 | /* |
| 585 | * Reply-related method definitions. |
| 586 | */ |
| 587 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 588 | static int reply_command(CONF *conf, const char *section, const char *engine, |
| 589 | const char *queryfile, const char *passin, const char *inkey, |
| 590 | const EVP_MD *md, const char *signer, const char *chain, |
| 591 | const char *policy, const char *in, int token_in, |
| 592 | const char *out, int token_out, int text) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 593 | { |
| 594 | int ret = 0; |
| 595 | TS_RESP *response = NULL; |
| 596 | BIO *in_bio = NULL; |
| 597 | BIO *query_bio = NULL; |
| 598 | BIO *inkey_bio = NULL; |
| 599 | BIO *signer_bio = NULL; |
| 600 | BIO *out_bio = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 601 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 602 | if (in != NULL) { |
| 603 | if ((in_bio = BIO_new_file(in, "rb")) == NULL) |
| 604 | goto end; |
| 605 | if (token_in) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 606 | response = read_PKCS7(in_bio); |
| 607 | } else { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 608 | response = d2i_TS_RESP_bio(in_bio, NULL); |
| 609 | } |
| 610 | } else { |
| 611 | response = create_response(conf, section, engine, queryfile, |
Dr. Stephen Henson | e20b472 | 2015-09-11 16:58:57 +0100 | [diff] [blame] | 612 | passin, inkey, md, signer, chain, policy); |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 613 | if (response != NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 614 | BIO_printf(bio_err, "Response has been generated.\n"); |
| 615 | else |
| 616 | BIO_printf(bio_err, "Response is not generated.\n"); |
| 617 | } |
| 618 | if (response == NULL) |
| 619 | goto end; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 620 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 621 | /* Write response. */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 622 | if (text) { |
Richard Levitte | bdd58d9 | 2015-09-04 12:49:06 +0200 | [diff] [blame] | 623 | if ((out_bio = bio_open_default(out, 'w', FORMAT_TEXT)) == NULL) |
| 624 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 625 | if (token_out) { |
| 626 | TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response); |
| 627 | if (!TS_TST_INFO_print_bio(out_bio, tst_info)) |
| 628 | goto end; |
| 629 | } else { |
| 630 | if (!TS_RESP_print_bio(out_bio, response)) |
| 631 | goto end; |
| 632 | } |
| 633 | } else { |
Richard Levitte | bdd58d9 | 2015-09-04 12:49:06 +0200 | [diff] [blame] | 634 | if ((out_bio = bio_open_default(out, 'w', FORMAT_ASN1)) == NULL) |
| 635 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 636 | if (token_out) { |
| 637 | PKCS7 *token = TS_RESP_get_token(response); |
| 638 | if (!i2d_PKCS7_bio(out_bio, token)) |
| 639 | goto end; |
| 640 | } else { |
| 641 | if (!i2d_TS_RESP_bio(out_bio, response)) |
| 642 | goto end; |
| 643 | } |
| 644 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 645 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 646 | ret = 1; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 647 | |
| 648 | end: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 649 | ERR_print_errors(bio_err); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 650 | BIO_free_all(in_bio); |
| 651 | BIO_free_all(query_bio); |
| 652 | BIO_free_all(inkey_bio); |
| 653 | BIO_free_all(signer_bio); |
| 654 | BIO_free_all(out_bio); |
| 655 | TS_RESP_free(response); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 656 | return ret; |
| 657 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 658 | |
| 659 | /* Reads a PKCS7 token and adds default 'granted' status info to it. */ |
| 660 | static TS_RESP *read_PKCS7(BIO *in_bio) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 661 | { |
| 662 | int ret = 0; |
| 663 | PKCS7 *token = NULL; |
| 664 | TS_TST_INFO *tst_info = NULL; |
| 665 | TS_RESP *resp = NULL; |
| 666 | TS_STATUS_INFO *si = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 667 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 668 | if ((token = d2i_PKCS7_bio(in_bio, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 669 | goto end; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 670 | if ((tst_info = PKCS7_to_TS_TST_INFO(token)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 671 | goto end; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 672 | if ((resp = TS_RESP_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 673 | goto end; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 674 | if ((si = TS_STATUS_INFO_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 675 | goto end; |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 676 | if (!TS_STATUS_INFO_set_status(si, TS_STATUS_GRANTED)) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 677 | goto end; |
| 678 | if (!TS_RESP_set_status_info(resp, si)) |
| 679 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 680 | TS_RESP_set_tst_info(resp, token, tst_info); |
| 681 | token = NULL; /* Ownership is lost. */ |
| 682 | tst_info = NULL; /* Ownership is lost. */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 683 | ret = 1; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 684 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 685 | end: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 686 | PKCS7_free(token); |
| 687 | TS_TST_INFO_free(tst_info); |
| 688 | if (!ret) { |
| 689 | TS_RESP_free(resp); |
| 690 | resp = NULL; |
| 691 | } |
| 692 | TS_STATUS_INFO_free(si); |
| 693 | return resp; |
| 694 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 695 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 696 | static TS_RESP *create_response(CONF *conf, const char *section, const char *engine, |
| 697 | const char *queryfile, const char *passin, |
| 698 | const char *inkey, const EVP_MD *md, const char *signer, |
| 699 | const char *chain, const char *policy) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 700 | { |
| 701 | int ret = 0; |
| 702 | TS_RESP *response = NULL; |
| 703 | BIO *query_bio = NULL; |
| 704 | TS_RESP_CTX *resp_ctx = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 705 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 706 | if ((query_bio = BIO_new_file(queryfile, "rb")) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 707 | goto end; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 708 | if ((section = TS_CONF_get_tsa_section(conf, section)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 709 | goto end; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 710 | if ((resp_ctx = TS_RESP_CTX_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 711 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 712 | if (!TS_CONF_set_serial(conf, section, serial_cb, resp_ctx)) |
| 713 | goto end; |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 714 | #ifndef OPENSSL_NO_ENGINE |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 715 | if (!TS_CONF_set_crypto_device(conf, section, engine)) |
| 716 | goto end; |
Rich Salz | 1ae56f2 | 2020-03-04 16:52:22 -0500 | [diff] [blame] | 717 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 718 | if (!TS_CONF_set_signer_cert(conf, section, signer, resp_ctx)) |
| 719 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 720 | if (!TS_CONF_set_certs(conf, section, chain, resp_ctx)) |
| 721 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 722 | if (!TS_CONF_set_signer_key(conf, section, inkey, passin, resp_ctx)) |
| 723 | goto end; |
Dr. Stephen Henson | e20b472 | 2015-09-11 16:58:57 +0100 | [diff] [blame] | 724 | |
| 725 | if (md) { |
| 726 | if (!TS_RESP_CTX_set_signer_digest(resp_ctx, md)) |
| 727 | goto end; |
| 728 | } else if (!TS_CONF_set_signer_digest(conf, section, NULL, resp_ctx)) { |
| 729 | goto end; |
| 730 | } |
| 731 | |
Marek Klein | f0ef20b | 2016-03-01 16:32:10 +0000 | [diff] [blame] | 732 | if (!TS_CONF_set_ess_cert_id_digest(conf, section, resp_ctx)) |
| 733 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 734 | if (!TS_CONF_set_def_policy(conf, section, policy, resp_ctx)) |
| 735 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 736 | if (!TS_CONF_set_policies(conf, section, resp_ctx)) |
| 737 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 738 | if (!TS_CONF_set_digests(conf, section, resp_ctx)) |
| 739 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 740 | if (!TS_CONF_set_accuracy(conf, section, resp_ctx)) |
| 741 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 742 | if (!TS_CONF_set_clock_precision_digits(conf, section, resp_ctx)) |
| 743 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 744 | if (!TS_CONF_set_ordering(conf, section, resp_ctx)) |
| 745 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 746 | if (!TS_CONF_set_tsa_name(conf, section, resp_ctx)) |
| 747 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 748 | if (!TS_CONF_set_ess_cert_id_chain(conf, section, resp_ctx)) |
| 749 | goto end; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 750 | if ((response = TS_RESP_create_response(resp_ctx, query_bio)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 751 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 752 | ret = 1; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 753 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 754 | end: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 755 | if (!ret) { |
| 756 | TS_RESP_free(response); |
| 757 | response = NULL; |
| 758 | } |
| 759 | TS_RESP_CTX_free(resp_ctx); |
| 760 | BIO_free_all(query_bio); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 761 | return response; |
| 762 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 763 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 764 | static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data) |
| 765 | { |
| 766 | const char *serial_file = (const char *)data; |
| 767 | ASN1_INTEGER *serial = next_serial(serial_file); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 768 | |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 769 | if (serial == NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 770 | TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION, |
| 771 | "Error during serial number " |
| 772 | "generation."); |
| 773 | TS_RESP_CTX_add_failure_info(ctx, TS_INFO_ADD_INFO_NOT_AVAILABLE); |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 774 | } else { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 775 | save_ts_serial(serial_file, serial); |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 776 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 777 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 778 | return serial; |
| 779 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 780 | |
| 781 | static ASN1_INTEGER *next_serial(const char *serialfile) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 782 | { |
| 783 | int ret = 0; |
| 784 | BIO *in = NULL; |
| 785 | ASN1_INTEGER *serial = NULL; |
| 786 | BIGNUM *bn = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 787 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 788 | if ((serial = ASN1_INTEGER_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 789 | goto err; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 790 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 791 | if ((in = BIO_new_file(serialfile, "r")) == NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 792 | ERR_clear_error(); |
| 793 | BIO_printf(bio_err, "Warning: could not open file %s for " |
| 794 | "reading, using serial number: 1\n", serialfile); |
| 795 | if (!ASN1_INTEGER_set(serial, 1)) |
| 796 | goto err; |
| 797 | } else { |
| 798 | char buf[1024]; |
| 799 | if (!a2i_ASN1_INTEGER(in, serial, buf, sizeof(buf))) { |
| 800 | BIO_printf(bio_err, "unable to load number from %s\n", |
| 801 | serialfile); |
| 802 | goto err; |
| 803 | } |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 804 | if ((bn = ASN1_INTEGER_to_BN(serial, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 805 | goto err; |
| 806 | ASN1_INTEGER_free(serial); |
| 807 | serial = NULL; |
| 808 | if (!BN_add_word(bn, 1)) |
| 809 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 810 | if ((serial = BN_to_ASN1_INTEGER(bn, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 811 | goto err; |
| 812 | } |
| 813 | ret = 1; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 814 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 815 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 816 | if (!ret) { |
| 817 | ASN1_INTEGER_free(serial); |
| 818 | serial = NULL; |
| 819 | } |
| 820 | BIO_free_all(in); |
| 821 | BN_free(bn); |
| 822 | return serial; |
| 823 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 824 | |
| 825 | static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 826 | { |
| 827 | int ret = 0; |
| 828 | BIO *out = NULL; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 829 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 830 | if ((out = BIO_new_file(serialfile, "w")) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 831 | goto err; |
| 832 | if (i2a_ASN1_INTEGER(out, serial) <= 0) |
| 833 | goto err; |
| 834 | if (BIO_puts(out, "\n") <= 0) |
| 835 | goto err; |
| 836 | ret = 1; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 837 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 838 | if (!ret) |
| 839 | BIO_printf(bio_err, "could not save serial number to %s\n", |
| 840 | serialfile); |
| 841 | BIO_free_all(out); |
| 842 | return ret; |
| 843 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 844 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 845 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 846 | /* |
| 847 | * Verify-related method definitions. |
| 848 | */ |
| 849 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 850 | static int verify_command(const char *data, const char *digest, const char *queryfile, |
| 851 | const char *in, int token_in, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 852 | const char *CApath, const char *CAfile, |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 853 | const char *CAstore, char *untrusted, |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 854 | X509_VERIFY_PARAM *vpm) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 855 | { |
| 856 | BIO *in_bio = NULL; |
| 857 | PKCS7 *token = NULL; |
| 858 | TS_RESP *response = NULL; |
| 859 | TS_VERIFY_CTX *verify_ctx = NULL; |
| 860 | int ret = 0; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 861 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 862 | if ((in_bio = BIO_new_file(in, "rb")) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 863 | goto end; |
| 864 | if (token_in) { |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 865 | if ((token = d2i_PKCS7_bio(in_bio, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 866 | goto end; |
| 867 | } else { |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 868 | if ((response = d2i_TS_RESP_bio(in_bio, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 869 | goto end; |
| 870 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 871 | |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 872 | if ((verify_ctx = create_verify_ctx(data, digest, queryfile, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 873 | CApath, CAfile, CAstore, untrusted, |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 874 | vpm)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 875 | goto end; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 876 | |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 877 | ret = token_in |
| 878 | ? TS_RESP_verify_token(verify_ctx, token) |
| 879 | : TS_RESP_verify_response(verify_ctx, response); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 880 | |
| 881 | end: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 882 | printf("Verification: "); |
| 883 | if (ret) |
| 884 | printf("OK\n"); |
| 885 | else { |
| 886 | printf("FAILED\n"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 887 | ERR_print_errors(bio_err); |
| 888 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 889 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 890 | BIO_free_all(in_bio); |
| 891 | PKCS7_free(token); |
| 892 | TS_RESP_free(response); |
| 893 | TS_VERIFY_CTX_free(verify_ctx); |
| 894 | return ret; |
| 895 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 896 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 897 | static TS_VERIFY_CTX *create_verify_ctx(const char *data, const char *digest, |
| 898 | const char *queryfile, |
| 899 | const char *CApath, const char *CAfile, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 900 | const char *CAstore, |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 901 | char *untrusted, |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 902 | X509_VERIFY_PARAM *vpm) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 903 | { |
| 904 | TS_VERIFY_CTX *ctx = NULL; |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 905 | STACK_OF(X509) *certs; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 906 | BIO *input = NULL; |
| 907 | TS_REQ *request = NULL; |
| 908 | int ret = 0; |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 909 | int f = 0; |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 910 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 911 | if (data != NULL || digest != NULL) { |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 912 | if ((ctx = TS_VERIFY_CTX_new()) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 913 | goto err; |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 914 | f = TS_VFY_VERSION | TS_VFY_SIGNER; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 915 | if (data != NULL) { |
Yuchi | e067097 | 2017-02-05 19:33:47 -0500 | [diff] [blame] | 916 | BIO *out = NULL; |
| 917 | |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 918 | f |= TS_VFY_DATA; |
Yuchi | e067097 | 2017-02-05 19:33:47 -0500 | [diff] [blame] | 919 | if ((out = BIO_new_file(data, "rb")) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 920 | goto err; |
Yuchi | e067097 | 2017-02-05 19:33:47 -0500 | [diff] [blame] | 921 | if (TS_VERIFY_CTX_set_data(ctx, out) == NULL) { |
| 922 | BIO_free_all(out); |
| 923 | goto err; |
| 924 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 925 | } else if (digest != NULL) { |
| 926 | long imprint_len; |
Rich Salz | 14f051a | 2016-04-13 15:58:28 -0400 | [diff] [blame] | 927 | unsigned char *hexstr = OPENSSL_hexstr2buf(digest, &imprint_len); |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 928 | f |= TS_VFY_IMPRINT; |
| 929 | if (TS_VERIFY_CTX_set_imprint(ctx, hexstr, imprint_len) == NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 930 | BIO_printf(bio_err, "invalid digest string\n"); |
| 931 | goto err; |
| 932 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 933 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 934 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 935 | } else if (queryfile != NULL) { |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 936 | if ((input = BIO_new_file(queryfile, "rb")) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 937 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 938 | if ((request = d2i_TS_REQ_bio(input, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 939 | goto err; |
Rich Salz | 75ebbd9 | 2015-05-06 13:43:59 -0400 | [diff] [blame] | 940 | if ((ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL)) == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 941 | goto err; |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 942 | } else { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 943 | return NULL; |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 944 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 945 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 946 | /* Add the signature verification flag and arguments. */ |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 947 | TS_VERIFY_CTX_add_flags(ctx, f | TS_VFY_SIGNATURE); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 948 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 949 | /* Initialising the X509_STORE object. */ |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 950 | if (TS_VERIFY_CTX_set_store(ctx, |
| 951 | create_cert_store(CApath, CAfile, CAstore, vpm)) |
Rich Salz | ca4a494 | 2015-06-10 14:07:40 -0400 | [diff] [blame] | 952 | == NULL) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 953 | goto err; |
| 954 | |
Dr. David von Oheimb | f62846b | 2021-03-10 17:27:13 +0100 | [diff] [blame] | 955 | /* Loading any extra untrusted certificates. */ |
| 956 | if (untrusted != NULL) { |
| 957 | certs = load_certs_multifile(untrusted, NULL, "extra untrusted certs", |
| 958 | vpm); |
| 959 | if (certs == NULL || TS_VERIFY_CTX_set_certs(ctx, certs) == NULL) |
| 960 | goto err; |
| 961 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 962 | ret = 1; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 963 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 964 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 965 | if (!ret) { |
| 966 | TS_VERIFY_CTX_free(ctx); |
| 967 | ctx = NULL; |
| 968 | } |
| 969 | BIO_free_all(input); |
| 970 | TS_REQ_free(request); |
| 971 | return ctx; |
| 972 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 973 | |
FdaSilvaYY | cc69629 | 2016-08-04 23:52:22 +0200 | [diff] [blame] | 974 | static X509_STORE *create_cert_store(const char *CApath, const char *CAfile, |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 975 | const char *CAstore, X509_VERIFY_PARAM *vpm) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 976 | { |
| 977 | X509_STORE *cert_ctx = NULL; |
| 978 | X509_LOOKUP *lookup = NULL; |
Dr. Matthias St. Pierre | b425001 | 2020-10-15 12:55:50 +0300 | [diff] [blame] | 979 | OSSL_LIB_CTX *libctx = app_get0_libctx(); |
Shane Lontis | 6725682 | 2020-07-24 22:53:27 +1000 | [diff] [blame] | 980 | const char *propq = app_get0_propq(); |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 981 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 982 | cert_ctx = X509_STORE_new(); |
Zhou Qingyang | 3f07596 | 2022-04-07 00:48:09 +0800 | [diff] [blame] | 983 | if (cert_ctx == NULL) { |
| 984 | BIO_printf(bio_err, "memory allocation failure\n"); |
| 985 | return NULL; |
| 986 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 987 | X509_STORE_set_verify_cb(cert_ctx, verify_cb); |
Matt Caswell | 96487cd | 2015-10-30 11:18:04 +0000 | [diff] [blame] | 988 | if (CApath != NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 989 | lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir()); |
| 990 | if (lookup == NULL) { |
| 991 | BIO_printf(bio_err, "memory allocation failure\n"); |
| 992 | goto err; |
| 993 | } |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 994 | if (!X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM)) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 995 | BIO_printf(bio_err, "Error loading directory %s\n", CApath); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 996 | goto err; |
| 997 | } |
| 998 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 999 | |
Matt Caswell | 96487cd | 2015-10-30 11:18:04 +0000 | [diff] [blame] | 1000 | if (CAfile != NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1001 | lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file()); |
| 1002 | if (lookup == NULL) { |
| 1003 | BIO_printf(bio_err, "memory allocation failure\n"); |
| 1004 | goto err; |
| 1005 | } |
Matt Caswell | d8652be | 2020-09-24 10:42:23 +0100 | [diff] [blame] | 1006 | if (!X509_LOOKUP_load_file_ex(lookup, CAfile, X509_FILETYPE_PEM, libctx, |
| 1007 | propq)) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1008 | BIO_printf(bio_err, "Error loading file %s\n", CAfile); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1009 | goto err; |
| 1010 | } |
| 1011 | } |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 1012 | |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 1013 | if (CAstore != NULL) { |
| 1014 | lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_store()); |
| 1015 | if (lookup == NULL) { |
| 1016 | BIO_printf(bio_err, "memory allocation failure\n"); |
| 1017 | goto err; |
| 1018 | } |
Matt Caswell | d8652be | 2020-09-24 10:42:23 +0100 | [diff] [blame] | 1019 | if (!X509_LOOKUP_load_store_ex(lookup, CAstore, libctx, propq)) { |
Richard Levitte | fd3397f | 2019-03-07 15:26:34 +0100 | [diff] [blame] | 1020 | BIO_printf(bio_err, "Error loading store URI %s\n", CAstore); |
| 1021 | goto err; |
| 1022 | } |
| 1023 | } |
| 1024 | |
FdaSilvaYY | 6b4a77f | 2016-06-28 22:51:51 +0200 | [diff] [blame] | 1025 | if (vpm != NULL) |
fbroda | 08538fc | 2016-03-15 10:08:49 +0100 | [diff] [blame] | 1026 | X509_STORE_set1_param(cert_ctx, vpm); |
| 1027 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1028 | return cert_ctx; |
Rich Salz | 18cd23d | 2015-05-07 23:41:07 -0400 | [diff] [blame] | 1029 | |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 1030 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1031 | X509_STORE_free(cert_ctx); |
| 1032 | return NULL; |
| 1033 | } |
Ulf Möller | c7235be | 2006-02-12 23:11:56 +0000 | [diff] [blame] | 1034 | |
Rich Salz | 6d23cf9 | 2015-01-12 17:29:26 -0500 | [diff] [blame] | 1035 | static int verify_cb(int ok, X509_STORE_CTX *ctx) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1036 | { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1037 | return ok; |
| 1038 | } |