Skip to content

Commit 04f0ab9

Browse files
committed
OpenSSL-1.1 support
1 parent 5150993 commit 04f0ab9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

ngx_rtmp_handshake.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,37 @@ static ngx_int_t
104104
ngx_rtmp_make_digest(ngx_str_t *key, ngx_buf_t *src,
105105
u_char *skip, u_char *dst, ngx_log_t *log)
106106
{
107-
static HMAC_CTX hmac;
108-
static unsigned hmac_initialized;
107+
static HMAC_CTX *hmac;
109108
unsigned int len;
110109

111-
if (!hmac_initialized) {
112-
HMAC_CTX_init(&hmac);
113-
hmac_initialized = 1;
110+
if (hmac == NULL) {
111+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
112+
static HMAC_CTX shmac;
113+
hmac = &shmac;
114+
HMAC_CTX_init(hmac);
115+
#else
116+
hmac = HMAC_CTX_new();
117+
if (hmac == NULL) {
118+
return NGX_ERROR;
119+
}
120+
#endif
114121
}
115122

116-
HMAC_Init_ex(&hmac, key->data, key->len, EVP_sha256(), NULL);
123+
HMAC_Init_ex(hmac, key->data, key->len, EVP_sha256(), NULL);
117124

118125
if (skip && src->pos <= skip && skip <= src->last) {
119126
if (skip != src->pos) {
120-
HMAC_Update(&hmac, src->pos, skip - src->pos);
127+
HMAC_Update(hmac, src->pos, skip - src->pos);
121128
}
122129
if (src->last != skip + NGX_RTMP_HANDSHAKE_KEYLEN) {
123-
HMAC_Update(&hmac, skip + NGX_RTMP_HANDSHAKE_KEYLEN,
130+
HMAC_Update(hmac, skip + NGX_RTMP_HANDSHAKE_KEYLEN,
124131
src->last - skip - NGX_RTMP_HANDSHAKE_KEYLEN);
125132
}
126133
} else {
127-
HMAC_Update(&hmac, src->pos, src->last - src->pos);
134+
HMAC_Update(hmac, src->pos, src->last - src->pos);
128135
}
129136

130-
HMAC_Final(&hmac, dst, &len);
137+
HMAC_Final(hmac, dst, &len);
131138

132139
return NGX_OK;
133140
}

0 commit comments

Comments
 (0)