Skip to content

support openssl v3 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions src/ngx_http_aws_auth_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,9 @@ static ngx_uint_t argument_number[] = {
static void
ngx_http_aws_auth_sha256_hex(ngx_str_t *message, u_char *digest)
{
u_char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
u_char hash[SHA256_DIGEST_LENGTH];

SHA256_Init(&sha256);
SHA256_Update(&sha256, message->data, message->len);
SHA256_Final(hash, &sha256);
SHA256(message->data, message->len, hash);

ngx_hex_dump(digest, hash, sizeof(hash));
}
Expand All @@ -204,31 +201,15 @@ static ngx_int_t
ngx_http_aws_auth_hmac_sha256(ngx_http_request_t *r, ngx_str_t *key,
ngx_str_t *message, ngx_str_t *dest)
{
unsigned hash_len;
#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
HMAC_CTX hmac_buf;
#endif
HMAC_CTX *hmac;

#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
hmac = HMAC_CTX_new();
if (hmac == NULL) {
unsigned hash_len;

if (HMAC(EVP_sha256(), key->data, key->len, message->data, message->len,
dest->data, &hash_len) == NULL)
{
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"ngx_http_aws_auth_hmac_sha256: HMAC_CTX_new failed");
"ngx_http_aws_auth_hmac_sha256: HMAC failed");
return NGX_ERROR;
}
#else
hmac = &hmac_buf;
HMAC_CTX_init(hmac);
#endif
HMAC_Init_ex(hmac, key->data, key->len, EVP_sha256(), NULL);
HMAC_Update(hmac, message->data, message->len);
HMAC_Final(hmac, dest->data, &hash_len);
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
HMAC_CTX_free(hmac);
#else
HMAC_CTX_cleanup(hmac);
#endif

dest->len = hash_len;

Expand Down