2 * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
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
10 #include "internal/cryptlib.h"
11 #include <openssl/objects.h>
12 #include <openssl/ts.h>
17 TS_VERIFY_CTX *TS_VERIFY_CTX_new(void)
19 TS_VERIFY_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
22 TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE);
26 void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx)
28 OPENSSL_assert(ctx != NULL);
29 memset(ctx, 0, sizeof(*ctx));
32 void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx)
37 TS_VERIFY_CTX_cleanup(ctx);
41 int TS_VERIFY_CTX_add_flags(TS_VERIFY_CTX *ctx, int f)
47 int TS_VERIFY_CTX_set_flags(TS_VERIFY_CTX *ctx, int f)
53 BIO *TS_VERIFY_CTX_set_data(TS_VERIFY_CTX *ctx, BIO *b)
59 X509_STORE *TS_VERIFY_CTX_set_store(TS_VERIFY_CTX *ctx, X509_STORE *s)
65 STACK_OF(X509) *TS_VERIFY_CTX_set_certs(TS_VERIFY_CTX *ctx,
66 STACK_OF(X509) *certs)
72 unsigned char *TS_VERIFY_CTX_set_imprint(TS_VERIFY_CTX *ctx,
73 unsigned char *hexstr, long len)
75 ctx->imprint = hexstr;
76 ctx->imprint_len = len;
80 void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx)
85 X509_STORE_free(ctx->store);
86 sk_X509_pop_free(ctx->certs, X509_free);
88 ASN1_OBJECT_free(ctx->policy);
90 X509_ALGOR_free(ctx->md_alg);
91 OPENSSL_free(ctx->imprint);
93 BIO_free_all(ctx->data);
95 ASN1_INTEGER_free(ctx->nonce);
97 GENERAL_NAME_free(ctx->tsa_name);
99 TS_VERIFY_CTX_init(ctx);
102 TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx)
104 TS_VERIFY_CTX *ret = ctx;
106 TS_MSG_IMPRINT *imprint;
108 ASN1_OCTET_STRING *msg;
109 const ASN1_INTEGER *nonce;
111 OPENSSL_assert(req != NULL);
113 TS_VERIFY_CTX_cleanup(ret);
114 else if ((ret = TS_VERIFY_CTX_new()) == NULL)
117 ret->flags = TS_VFY_ALL_IMPRINT & ~(TS_VFY_TSA_NAME | TS_VFY_SIGNATURE);
119 if ((policy = req->policy_id) != NULL) {
120 if ((ret->policy = OBJ_dup(policy)) == NULL)
123 ret->flags &= ~TS_VFY_POLICY;
125 imprint = req->msg_imprint;
126 md_alg = imprint->hash_algo;
127 if ((ret->md_alg = X509_ALGOR_dup(md_alg)) == NULL)
129 msg = imprint->hashed_msg;
130 ret->imprint_len = ASN1_STRING_length(msg);
131 if ((ret->imprint = OPENSSL_malloc(ret->imprint_len)) == NULL)
133 memcpy(ret->imprint, ASN1_STRING_get0_data(msg), ret->imprint_len);
135 if ((nonce = req->nonce) != NULL) {
136 if ((ret->nonce = ASN1_INTEGER_dup(nonce)) == NULL)
139 ret->flags &= ~TS_VFY_NONCE;
144 TS_VERIFY_CTX_cleanup(ctx);
146 TS_VERIFY_CTX_free(ret);