Skip to content

Commit e4a9069

Browse files
author
Jarrod Johnson
committedMar 19, 2014
Add iPaddress support for subjectAltName
subjectaltname only understood DNS entries. Amend it to support IPv4 iPAddress.
1 parent fea8166 commit e4a9069

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
 

‎src/crypto/x509.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
FILE_LICENCE ( GPL2_OR_LATER );
2121

2222
#include <stdlib.h>
23+
#include <stdio.h>
2324
#include <string.h>
2425
#include <errno.h>
2526
#include <assert.h>
@@ -533,6 +534,7 @@ static int x509_parse_subject_alt_name ( struct x509_certificate *cert,
533534
struct asn1_cursor cursor;
534535
struct asn1_cursor string_cursor;
535536
int rc;
537+
unsigned int type;
536538

537539
INIT_LIST_HEAD ( &subject_alt_name->names );
538540

@@ -548,7 +550,9 @@ static int x509_parse_subject_alt_name ( struct x509_certificate *cert,
548550
/* Mark extension as present */
549551
subject_alt_name->present = 1;
550552
memcpy ( &string_cursor, &cursor, sizeof ( string_cursor ) );
551-
if ( ( rc = asn1_enter ( &string_cursor, ASN1_IMPLICIT_TAG ( 2 ) ) ) == 0 ) {
553+
type = asn1_type( &string_cursor );
554+
rc = asn1_enter_any ( &string_cursor );
555+
if ( type == 0x82) {
552556
char* name = zalloc ( string_cursor.len + 1 );
553557
memcpy ( name, string_cursor.data, string_cursor.len );
554558
if ( strlen ( name ) != string_cursor.len ) {
@@ -560,6 +564,19 @@ static int x509_parse_subject_alt_name ( struct x509_certificate *cert,
560564
struct x509_san_link* link = zalloc ( sizeof ( struct x509_san_link ) );
561565
link->name = name;
562566
list_add ( &link->list, &subject_alt_name->names );
567+
} else if ( type == 0x87 ) {
568+
if ( string_cursor.len == 4 ) { // TODO: IPv6
569+
char* name = zalloc ( 16 ); // max ipv4 string length
570+
snprintf( name, 16, "%d.%d.%d.%d",
571+
((unsigned char*)string_cursor.data)[0],
572+
((unsigned char*)string_cursor.data)[1],
573+
((unsigned char*)string_cursor.data)[2],
574+
((unsigned char*)string_cursor.data)[3] );
575+
//DBGC ( cert, "X509 %p subjectAltName %s\n", cert, name );
576+
struct x509_san_link* link = zalloc ( sizeof ( struct x509_san_link ) );
577+
link->name = name;
578+
list_add ( &link->list, &subject_alt_name->names );
579+
}
563580
}
564581
asn1_skip_any ( &cursor );
565582
}

0 commit comments

Comments
 (0)