|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include "internal/cryptlib.h"
|
|
Packit Service |
084de1 |
#include <openssl/objects.h>
|
|
Packit Service |
084de1 |
#include <openssl/ts.h>
|
|
Packit Service |
084de1 |
#include "ts_local.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX *TS_VERIFY_CTX_new(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (ctx == NULL)
|
|
Packit Service |
084de1 |
TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE);
|
|
Packit Service |
084de1 |
return ctx;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
OPENSSL_assert(ctx != NULL);
|
|
Packit Service |
084de1 |
memset(ctx, 0, sizeof(*ctx));
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
if (!ctx)
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX_cleanup(ctx);
|
|
Packit Service |
084de1 |
OPENSSL_free(ctx);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int TS_VERIFY_CTX_add_flags(TS_VERIFY_CTX *ctx, int f)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->flags |= f;
|
|
Packit Service |
084de1 |
return ctx->flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int TS_VERIFY_CTX_set_flags(TS_VERIFY_CTX *ctx, int f)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->flags = f;
|
|
Packit Service |
084de1 |
return ctx->flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
BIO *TS_VERIFY_CTX_set_data(TS_VERIFY_CTX *ctx, BIO *b)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->data = b;
|
|
Packit Service |
084de1 |
return ctx->data;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
X509_STORE *TS_VERIFY_CTX_set_store(TS_VERIFY_CTX *ctx, X509_STORE *s)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->store = s;
|
|
Packit Service |
084de1 |
return ctx->store;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
STACK_OF(X509) *TS_VERIFY_CTS_set_certs(TS_VERIFY_CTX *ctx,
|
|
Packit Service |
084de1 |
STACK_OF(X509) *certs)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->certs = certs;
|
|
Packit Service |
084de1 |
return ctx->certs;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
unsigned char *TS_VERIFY_CTX_set_imprint(TS_VERIFY_CTX *ctx,
|
|
Packit Service |
084de1 |
unsigned char *hexstr, long len)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ctx->imprint = hexstr;
|
|
Packit Service |
084de1 |
ctx->imprint_len = len;
|
|
Packit Service |
084de1 |
return ctx->imprint;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
if (!ctx)
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
X509_STORE_free(ctx->store);
|
|
Packit Service |
084de1 |
sk_X509_pop_free(ctx->certs, X509_free);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ASN1_OBJECT_free(ctx->policy);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
X509_ALGOR_free(ctx->md_alg);
|
|
Packit Service |
084de1 |
OPENSSL_free(ctx->imprint);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
BIO_free_all(ctx->data);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ASN1_INTEGER_free(ctx->nonce);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
GENERAL_NAME_free(ctx->tsa_name);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX_init(ctx);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX *ret = ctx;
|
|
Packit Service |
084de1 |
ASN1_OBJECT *policy;
|
|
Packit Service |
084de1 |
TS_MSG_IMPRINT *imprint;
|
|
Packit Service |
084de1 |
X509_ALGOR *md_alg;
|
|
Packit Service |
084de1 |
ASN1_OCTET_STRING *msg;
|
|
Packit Service |
084de1 |
const ASN1_INTEGER *nonce;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
OPENSSL_assert(req != NULL);
|
|
Packit Service |
084de1 |
if (ret)
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX_cleanup(ret);
|
|
Packit Service |
084de1 |
else if ((ret = TS_VERIFY_CTX_new()) == NULL)
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ret->flags = TS_VFY_ALL_IMPRINT & ~(TS_VFY_TSA_NAME | TS_VFY_SIGNATURE);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if ((policy = req->policy_id) != NULL) {
|
|
Packit Service |
084de1 |
if ((ret->policy = OBJ_dup(policy)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
} else
|
|
Packit Service |
084de1 |
ret->flags &= ~TS_VFY_POLICY;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
imprint = req->msg_imprint;
|
|
Packit Service |
084de1 |
md_alg = imprint->hash_algo;
|
|
Packit Service |
084de1 |
if ((ret->md_alg = X509_ALGOR_dup(md_alg)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
msg = imprint->hashed_msg;
|
|
Packit Service |
084de1 |
ret->imprint_len = ASN1_STRING_length(msg);
|
|
Packit Service |
084de1 |
if ((ret->imprint = OPENSSL_malloc(ret->imprint_len)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
memcpy(ret->imprint, ASN1_STRING_get0_data(msg), ret->imprint_len);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if ((nonce = req->nonce) != NULL) {
|
|
Packit Service |
084de1 |
if ((ret->nonce = ASN1_INTEGER_dup(nonce)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
} else
|
|
Packit Service |
084de1 |
ret->flags &= ~TS_VFY_NONCE;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return ret;
|
|
Packit Service |
084de1 |
err:
|
|
Packit Service |
084de1 |
if (ctx)
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX_cleanup(ctx);
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
TS_VERIFY_CTX_free(ret);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|