mirror of
https://github.com/moparisthebest/curl
synced 2024-11-16 06:25:03 -05:00
Extended my embedded-zero-in-cert-name fix based on a comment from Scott
Cantor. My previous attempt was half-baked and didn't cover the normal CN case.
This commit is contained in:
parent
47a9660ec1
commit
0b66efac9c
21
lib/ssluse.c
21
lib/ssluse.c
@ -1154,6 +1154,7 @@ static CURLcode verifyhost(struct connectdata *conn,
|
|||||||
|
|
||||||
unsigned char *nulstr = (unsigned char *)"";
|
unsigned char *nulstr = (unsigned char *)"";
|
||||||
unsigned char *peer_CN = nulstr;
|
unsigned char *peer_CN = nulstr;
|
||||||
|
size_t peer_len = 0;
|
||||||
|
|
||||||
X509_NAME *name = X509_get_subject_name(server_cert) ;
|
X509_NAME *name = X509_get_subject_name(server_cert) ;
|
||||||
if(name)
|
if(name)
|
||||||
@ -1172,19 +1173,23 @@ static CURLcode verifyhost(struct connectdata *conn,
|
|||||||
string manually to avoid the problem. This code can be made
|
string manually to avoid the problem. This code can be made
|
||||||
conditional in the future when OpenSSL has been fixed. Work-around
|
conditional in the future when OpenSSL has been fixed. Work-around
|
||||||
brought by Alexis S. L. Carvalho. */
|
brought by Alexis S. L. Carvalho. */
|
||||||
if(tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {
|
if(tmp) {
|
||||||
j = ASN1_STRING_length(tmp);
|
/* get the length off the ASN1 to avoid problems with embedded zeroes
|
||||||
if(j >= 0) {
|
*/
|
||||||
peer_CN = OPENSSL_malloc(j+1);
|
peer_len = ASN1_STRING_length(tmp);
|
||||||
|
if(ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {
|
||||||
|
if(peer_len) {
|
||||||
|
peer_CN = OPENSSL_malloc(peer_len+1);
|
||||||
if(peer_CN) {
|
if(peer_CN) {
|
||||||
memcpy(peer_CN, ASN1_STRING_data(tmp), j);
|
memcpy(peer_CN, ASN1_STRING_data(tmp), peer_len);
|
||||||
peer_CN[j] = '\0';
|
peer_CN[peer_len] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* not a UTF8 name */
|
else /* not a UTF8 name */
|
||||||
j = ASN1_STRING_to_UTF8(&peer_CN, tmp);
|
j = ASN1_STRING_to_UTF8(&peer_CN, tmp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(peer_CN == nulstr)
|
if(peer_CN == nulstr)
|
||||||
peer_CN = NULL;
|
peer_CN = NULL;
|
||||||
@ -1192,7 +1197,7 @@ static CURLcode verifyhost(struct connectdata *conn,
|
|||||||
else {
|
else {
|
||||||
/* convert peer_CN from UTF8 */
|
/* convert peer_CN from UTF8 */
|
||||||
size_t rc;
|
size_t rc;
|
||||||
rc = Curl_convert_from_utf8(data, peer_CN, strlen(peer_CN));
|
rc = Curl_convert_from_utf8(data, peer_CN, peer_len);
|
||||||
/* Curl_convert_from_utf8 calls failf if unsuccessful */
|
/* Curl_convert_from_utf8 calls failf if unsuccessful */
|
||||||
if(rc != CURLE_OK) {
|
if(rc != CURLE_OK) {
|
||||||
OPENSSL_free(peer_CN);
|
OPENSSL_free(peer_CN);
|
||||||
@ -1206,7 +1211,7 @@ static CURLcode verifyhost(struct connectdata *conn,
|
|||||||
"SSL: unable to obtain common name from peer certificate");
|
"SSL: unable to obtain common name from peer certificate");
|
||||||
return CURLE_PEER_FAILED_VERIFICATION;
|
return CURLE_PEER_FAILED_VERIFICATION;
|
||||||
}
|
}
|
||||||
else if(!cert_hostcheck((const char *)peer_CN, strlen((char *)peer_CN),
|
else if(!cert_hostcheck((const char *)peer_CN, peer_len,
|
||||||
conn->host.name)) {
|
conn->host.name)) {
|
||||||
if(data->set.ssl.verifyhost > 1) {
|
if(data->set.ssl.verifyhost > 1) {
|
||||||
failf(data, "SSL: certificate subject name '%s' does not match "
|
failf(data, "SSL: certificate subject name '%s' does not match "
|
||||||
|
Loading…
Reference in New Issue
Block a user