20
20
FILE_LICENCE ( GPL2_OR_LATER );
21
21
22
22
#include <stdlib.h>
23
+ #include <stdio.h>
23
24
#include <string.h>
24
25
#include <errno.h>
25
26
#include <assert.h>
@@ -533,6 +534,7 @@ static int x509_parse_subject_alt_name ( struct x509_certificate *cert,
533
534
struct asn1_cursor cursor ;
534
535
struct asn1_cursor string_cursor ;
535
536
int rc ;
537
+ unsigned int type ;
536
538
537
539
INIT_LIST_HEAD ( & subject_alt_name -> names );
538
540
@@ -548,7 +550,9 @@ static int x509_parse_subject_alt_name ( struct x509_certificate *cert,
548
550
/* Mark extension as present */
549
551
subject_alt_name -> present = 1 ;
550
552
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 ) {
552
556
char * name = zalloc ( string_cursor .len + 1 );
553
557
memcpy ( name , string_cursor .data , string_cursor .len );
554
558
if ( strlen ( name ) != string_cursor .len ) {
@@ -560,6 +564,19 @@ static int x509_parse_subject_alt_name ( struct x509_certificate *cert,
560
564
struct x509_san_link * link = zalloc ( sizeof ( struct x509_san_link ) );
561
565
link -> name = name ;
562
566
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
+ }
563
580
}
564
581
asn1_skip_any ( & cursor );
565
582
}
0 commit comments