mirror of
https://github.com/openssl/openssl.git
synced 2024-12-27 06:21:43 +08:00
e077455e9e
Since OPENSSL_malloc() and friends report ERR_R_MALLOC_FAILURE, and at least handle the file name and line number they are called from, there's no need to report ERR_R_MALLOC_FAILURE where they are called directly, or when SSLfatal() and RLAYERfatal() is used, the reason `ERR_R_MALLOC_FAILURE` is changed to `ERR_R_CRYPTO_LIB`. There were a number of places where `ERR_R_MALLOC_FAILURE` was reported even though it was a function from a different sub-system that was called. Those places are changed to report ERR_R_{lib}_LIB, where {lib} is the name of that sub-system. Some of them are tricky to get right, as we have a lot of functions that belong in the ASN1 sub-system, and all the `sk_` calls or from the CRYPTO sub-system. Some extra adaptation was necessary where there were custom OPENSSL_malloc() wrappers, and some bugs are fixed alongside these changes. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> (Merged from https://github.com/openssl/openssl/pull/19301)
114 lines
2.8 KiB
C
114 lines
2.8 KiB
C
/*
|
|
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
|
*
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
* in the file LICENSE in the source distribution or at
|
|
* https://www.openssl.org/source/license.html
|
|
*/
|
|
|
|
#ifdef OPENSSL_NO_CT
|
|
# error "CT is disabled"
|
|
#endif
|
|
|
|
#include <openssl/ct.h>
|
|
#include <openssl/err.h>
|
|
#include "internal/time.h"
|
|
|
|
#include "ct_local.h"
|
|
|
|
/*
|
|
* Number of seconds in the future that an SCT timestamp can be, by default,
|
|
* without being considered invalid. This is added to time() when setting a
|
|
* default value for CT_POLICY_EVAL_CTX.epoch_time_in_ms.
|
|
* It can be overridden by calling CT_POLICY_EVAL_CTX_set_time().
|
|
*/
|
|
static const time_t SCT_CLOCK_DRIFT_TOLERANCE = 300;
|
|
|
|
CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new_ex(OSSL_LIB_CTX *libctx,
|
|
const char *propq)
|
|
{
|
|
CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));
|
|
OSSL_TIME now;
|
|
|
|
if (ctx == NULL)
|
|
return NULL;
|
|
|
|
ctx->libctx = libctx;
|
|
if (propq != NULL) {
|
|
ctx->propq = OPENSSL_strdup(propq);
|
|
if (ctx->propq == NULL) {
|
|
OPENSSL_free(ctx);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
now = ossl_time_add(ossl_time_now(),
|
|
ossl_seconds2time(SCT_CLOCK_DRIFT_TOLERANCE));
|
|
ctx->epoch_time_in_ms = ossl_time2ms(now);
|
|
|
|
return ctx;
|
|
}
|
|
|
|
CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)
|
|
{
|
|
return CT_POLICY_EVAL_CTX_new_ex(NULL, NULL);
|
|
}
|
|
|
|
void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx)
|
|
{
|
|
if (ctx == NULL)
|
|
return;
|
|
X509_free(ctx->cert);
|
|
X509_free(ctx->issuer);
|
|
OPENSSL_free(ctx->propq);
|
|
OPENSSL_free(ctx);
|
|
}
|
|
|
|
int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert)
|
|
{
|
|
if (!X509_up_ref(cert))
|
|
return 0;
|
|
ctx->cert = cert;
|
|
return 1;
|
|
}
|
|
|
|
int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer)
|
|
{
|
|
if (!X509_up_ref(issuer))
|
|
return 0;
|
|
ctx->issuer = issuer;
|
|
return 1;
|
|
}
|
|
|
|
void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,
|
|
CTLOG_STORE *log_store)
|
|
{
|
|
ctx->log_store = log_store;
|
|
}
|
|
|
|
void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)
|
|
{
|
|
ctx->epoch_time_in_ms = time_in_ms;
|
|
}
|
|
|
|
X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx)
|
|
{
|
|
return ctx->cert;
|
|
}
|
|
|
|
X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx)
|
|
{
|
|
return ctx->issuer;
|
|
}
|
|
|
|
const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx)
|
|
{
|
|
return ctx->log_store;
|
|
}
|
|
|
|
uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx)
|
|
{
|
|
return ctx->epoch_time_in_ms;
|
|
}
|