Skip to content

Commit 885ceab

Browse files
committed
stir_shaken: use a new bio for chain
avoid using the same cbio, as it needs to be rewind to be read again in wolfssl; openssl handles this properly though
1 parent b2e3270 commit 885ceab

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

modules/stir_shaken/stir_shaken.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ static X509_INFO *ss_sk_X509_INFO_shift(STACK_OF(X509_INFO) *sk)
10831083

10841084
static int load_cert(X509 **cert, STACK_OF(X509) **certchain, str *cert_buf)
10851085
{
1086-
BIO *cbio;
1086+
BIO *cbio, *chainbio;
10871087
STACK_OF(X509) *stack;
10881088
STACK_OF(X509_INFO) *sk;
10891089
X509_INFO *xi;
@@ -1115,12 +1115,23 @@ static int load_cert(X509 **cert, STACK_OF(X509) **certchain, str *cert_buf)
11151115
SS_UNLOCK;
11161116
return -1;
11171117
}
1118+
chainbio = BIO_new_mem_buf((void*)cert_buf->s,cert_buf->len);
1119+
if (!chainbio) {
1120+
LM_ERR("error reading certificate stack\n");
1121+
X509_free(*cert);
1122+
*cert = NULL;
1123+
BIO_free(cbio);
1124+
sk_X509_free(stack);
1125+
SS_UNLOCK;
1126+
return -1;
1127+
}
11181128

1119-
sk = PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL);
1129+
sk = PEM_X509_INFO_read_bio(chainbio, NULL, NULL, NULL);
11201130
if (!sk) {
11211131
LM_ERR("error reading certificate stack\n");
11221132
X509_free(*cert);
11231133
*cert = NULL;
1134+
BIO_free(chainbio);
11241135
BIO_free(cbio);
11251136
sk_X509_free(stack);
11261137
SS_UNLOCK;
@@ -1141,6 +1152,7 @@ static int load_cert(X509 **cert, STACK_OF(X509) **certchain, str *cert_buf)
11411152
else
11421153
*certchain = stack;
11431154

1155+
BIO_free(chainbio);
11441156
BIO_free(cbio);
11451157
sk_X509_INFO_free(sk);
11461158
} else {

0 commit comments

Comments
 (0)