mirror of
https://github.com/nginx/nginx.git
synced 2026-11-20 07:02:58 +00:00
OCSP: removed padding of serial in cache keys
Right-padding the serials makes it impossible to distinguish between n, n * 256 and so on. This has no practical impact, as small, predictable serial numbers have been discouraged for the last two decades. While the change has a potential of introducing memory fragmentation, current allocations stay within a single slab bucket on all supported architectures. Reported by Gyejin Lee, QED Audit.
This commit is contained in:
parent
45ae79aa6a
commit
d56c3fb5dc
1 changed files with 10 additions and 11 deletions
|
|
@ -2668,13 +2668,20 @@ ngx_ssl_ocsp_create_key(ngx_ssl_ocsp_ctx_t *ctx)
|
|||
ASN1_INTEGER *serial;
|
||||
const X509_NAME *name;
|
||||
|
||||
p = ngx_pnalloc(ctx->pool, 60);
|
||||
serial = X509_get_serialNumber(ctx->cert);
|
||||
length = ASN1_STRING_length(serial);
|
||||
|
||||
if (length > 20) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
p = ngx_pnalloc(ctx->pool, 40 + length);
|
||||
if (p == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ctx->key.data = p;
|
||||
ctx->key.len = 60;
|
||||
ctx->key.len = 40 + length;
|
||||
|
||||
name = X509_get_subject_name(ctx->issuer);
|
||||
if (X509_NAME_digest(name, EVP_sha1(), p, NULL) == 0) {
|
||||
|
|
@ -2689,15 +2696,7 @@ ngx_ssl_ocsp_create_key(ngx_ssl_ocsp_ctx_t *ctx)
|
|||
|
||||
p += 20;
|
||||
|
||||
serial = X509_get_serialNumber(ctx->cert);
|
||||
length = ASN1_STRING_length(serial);
|
||||
|
||||
if (length > 20) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
p = ngx_cpymem(p, ASN1_STRING_get0_data(serial), length);
|
||||
ngx_memzero(p, 20 - length);
|
||||
ngx_memcpy(p, ASN1_STRING_get0_data(serial), length);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ctx->log, 0,
|
||||
"ssl ocsp key %xV", &ctx->key);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue