Skip to content

Commit 66a05e9

Browse files
committed
Merge branch 'openssl_1.1'
2 parents c999092 + 85fe324 commit 66a05e9

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

src/canl_mod_gridsite.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,16 +2336,22 @@ int GRST_get_session_id(SSL *ssl, char *session_id, size_t len)
23362336
{
23372337
int i;
23382338
SSL_SESSION *session;
2339+
unsigned int sess_len;
2340+
const unsigned char *sess_id;
23392341

2340-
if (((session = SSL_get_session(ssl)) == NULL) ||
2341-
(session->session_id_length == 0))
2342+
session = SSL_get_session(ssl);
2343+
if (session == NULL)
23422344
return GRST_RET_FAILED;
2343-
2344-
if (2 * session->session_id_length + 1 > len)
2345+
2346+
sess_id = SSL_SESSION_get_id(session, &sess_len);
2347+
if (sess_len == 0)
2348+
return GRST_RET_FAILED;
2349+
2350+
if (2 * sess_len + 1 > len)
23452351
return GRST_RET_FAILED;
23462352

2347-
for (i=0; i < (int) session->session_id_length; ++i)
2348-
sprintf(&(session_id[i*2]), "%02X", (unsigned char) session->session_id[i]);
2353+
for (i=0; i < sess_len; ++i)
2354+
sprintf(&(session_id[i*2]), "%02X", sess_id[i]);
23492355

23502356
session_id[i*2] = '\0';
23512357

@@ -2742,7 +2748,6 @@ static int mod_gridsite_perm_handler(request_rec *r)
27422748
if ((user == NULL) &&
27432749
(sslconn != NULL) &&
27442750
(sslconn->ssl != NULL) &&
2745-
(sslconn->ssl->session != NULL) &&
27462751
(r->connection->notes != NULL) &&
27472752
(apr_table_get(r->connection->notes, "GRST_save_ssl_creds") == NULL))
27482753
{
@@ -3973,7 +3978,7 @@ static int mod_gridsite_server_post_config(apr_pool_t *pPool,
39733978
#endif
39743979

39753980
/* Use default caNl callbacks to verify certificates*/
3976-
canl_ssl_ctx_set_clb(c_ctx, ctx, ctx->verify_mode,
3981+
canl_ssl_ctx_set_clb(c_ctx, ctx, SSL_CTX_get_verify_mode(ctx),
39773982
GRST_callback_SSLVerify_wrapper);
39783983

39793984
if (GRST_AP_LOGLEVEL(main_server) >= APLOG_DEBUG)

src/grst_asn1.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,8 @@ static int GRSTasn1Parse2(BIO *bp, unsigned char **pp, long length, int offset,
302302
{
303303
int ii;
304304

305-
opp=op;
306-
ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
307-
if (ii < 0)
305+
ii = (int)*p;
306+
if (ii < 0 || (int)len != 1)
308307
{
309308
if ((bp != NULL) &&
310309
(BIO_write(bp,"Bad boolean\n",12)))
@@ -338,7 +337,7 @@ static int GRSTasn1Parse2(BIO *bp, unsigned char **pp, long length, int offset,
338337
goto end;
339338
}
340339

341-
M_ASN1_OCTET_STRING_free(os);
340+
ASN1_OCTET_STRING_free(os);
342341
os=NULL;
343342
}
344343
}
@@ -377,7 +376,7 @@ static int GRSTasn1Parse2(BIO *bp, unsigned char **pp, long length, int offset,
377376
(BIO_write(bp,"BAD INTEGER",11) <= 0))
378377
goto end;
379378
}
380-
M_ASN1_INTEGER_free(bs);
379+
ASN1_INTEGER_free(bs);
381380
}
382381
else if (tag == V_ASN1_ENUMERATED)
383382
{
@@ -414,7 +413,7 @@ static int GRSTasn1Parse2(BIO *bp, unsigned char **pp, long length, int offset,
414413
(BIO_write(bp,"BAD ENUMERATED",11) <= 0))
415414
goto end;
416415
}
417-
M_ASN1_ENUMERATED_free(bs);
416+
ASN1_ENUMERATED_free(bs);
418417
}
419418
else if (len > 0 && dump)
420419
{
@@ -450,7 +449,7 @@ static int GRSTasn1Parse2(BIO *bp, unsigned char **pp, long length, int offset,
450449
ret=1;
451450
end:
452451
if (o != NULL) ASN1_OBJECT_free(o);
453-
if (os != NULL) M_ASN1_OCTET_STRING_free(os);
452+
if (os != NULL) ASN1_OCTET_STRING_free(os);
454453
*pp=p;
455454
return(ret);
456455
}

src/grst_canl_x509.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,17 @@ GRSTasn1FindField(const char *oid, char *coords,
206206
struct GRSTasn1TagList taglist[], int lasttag,
207207
int *result);
208208

209+
static void
210+
ssl_init_crypto(void)
211+
{
212+
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
213+
}
214+
209215
/* Safely initialize OpenSSL digests */
210216
static void GRSTx509SafeOpenSSLInitialization(void)
211217
{
212218
static pthread_once_t digests_once = PTHREAD_ONCE_INIT;
213-
(void) pthread_once(&digests_once, OpenSSL_add_all_digests);
219+
(void) pthread_once(&digests_once, ssl_init_crypto);
214220
}
215221

216222
/// Compare X509 Distinguished Name strings
@@ -341,26 +347,30 @@ static int GRSTx509VerifySig(time_t *time1_time, time_t *time2_time,
341347
{
342348
int ret;
343349
EVP_PKEY *prvkey;
344-
EVP_MD_CTX ctx;
350+
EVP_MD_CTX *ctx = NULL;
345351
time_t voms_service_time1, voms_service_time2;
346352

347353
prvkey = X509_extract_key(cert);
348354
if (prvkey == NULL) return GRST_RET_FAILED;
355+
356+
ctx = EVP_MD_CTX_new();
357+
if (ctx == NULL)
358+
return GRST_RET_FAILED;
349359

350360
GRSTx509SafeOpenSSLInitialization();
351361
#if OPENSSL_VERSION_NUMBER >= 0x0090701fL
352-
EVP_MD_CTX_init(&ctx);
353-
EVP_VerifyInit_ex(&ctx, md_type, NULL);
362+
EVP_MD_CTX_init(ctx);
363+
EVP_VerifyInit_ex(ctx, md_type, NULL);
354364
#else
355-
EVP_VerifyInit(&ctx, md_type);
365+
EVP_VerifyInit(ctx, md_type);
356366
#endif
357367

358-
EVP_VerifyUpdate(&ctx, txt, txt_len);
368+
EVP_VerifyUpdate(ctx, txt, txt_len);
359369

360-
ret = EVP_VerifyFinal(&ctx, sig, sig_len, prvkey);
370+
ret = EVP_VerifyFinal(ctx, sig, sig_len, prvkey);
361371

362372
#if OPENSSL_VERSION_NUMBER >= 0x0090701fL
363-
EVP_MD_CTX_cleanup(&ctx);
373+
EVP_MD_CTX_free(ctx);
364374
#endif
365375
EVP_PKEY_free(prvkey);
366376

@@ -375,7 +385,7 @@ static int GRSTx509VerifySig(time_t *time1_time, time_t *time2_time,
375385
GRSTasn1TimeToTimeT(ASN1_STRING_data(X509_get_notAfter(cert)),0);
376386
if (voms_service_time2 < *time2_time)
377387
*time2_time = voms_service_time2;
378-
388+
379389
return GRST_RET_OK ; /* verified */
380390
}
381391

@@ -2639,24 +2649,28 @@ char *GRSTx509MakeDelegationID(void)
26392649
int i, delegation_id_len;
26402650
char cred_name[14], *cred_value, *delegation_id;
26412651
const EVP_MD *m;
2642-
EVP_MD_CTX ctx;
2652+
EVP_MD_CTX *ctx = NULL;
26432653

26442654
GRSTx509SafeOpenSSLInitialization();
26452655

2656+
ctx = EVP_MD_CTX_new();
2657+
if (ctx == NULL)
2658+
return NULL;
2659+
26462660
m = EVP_sha1();
26472661
if (m == NULL) return NULL;
26482662

2649-
EVP_DigestInit(&ctx, m);
2663+
EVP_DigestInit(ctx, m);
26502664

26512665
for (i=0; i <= 999; ++i)
26522666
{
26532667
snprintf(cred_name, sizeof(cred_name), "GRST_CRED_%d", i);
26542668
if ((cred_value = getenv(cred_name)) == NULL) break;
26552669

2656-
EVP_DigestUpdate(&ctx, cred_value, strlen(cred_value));
2670+
EVP_DigestUpdate(ctx, cred_value, strlen(cred_value));
26572671
}
26582672

2659-
EVP_DigestFinal(&ctx, hash_delegation_id, &delegation_id_len);
2673+
EVP_DigestFinal(ctx, hash_delegation_id, &delegation_id_len);
26602674

26612675
delegation_id = malloc(17);
26622676

@@ -2665,6 +2679,8 @@ char *GRSTx509MakeDelegationID(void)
26652679

26662680
delegation_id[16] = '\0';
26672681

2682+
EVP_MD_CTX_free(ctx);
2683+
26682684
return delegation_id;
26692685
}
26702686

0 commit comments

Comments
 (0)