Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
oliwel committed Apr 26, 2021
2 parents 7c7372a + 76fca29 commit f8c12e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion META.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Crypt-X509
version: 0.52
version: 0.53
abstract: Parse a X.509 certificate
author:
- Mike Jackson, Alexander Jung, Duncan Segrest, Oliver Welter
Expand Down
54 changes: 53 additions & 1 deletion lib/Crypt/X509.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [qw()] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
#our @EXPORT = qw(error new not_before not_after serial);
our $VERSION = '0.52';
our $VERSION = '0.53';
my $parser = undef;
my $asn = undef;
my $error = undef;
Expand Down Expand Up @@ -766,6 +766,58 @@ sub SubjectAltName {
}
return undef;
}

=head2 DecodedSubjectAltNames
Returns a pointer to an array of strings containing all the alternative subject name
extensions.
Each such extension is represented as a decoded ASN.1 value, i.e. a pointer to a list
of pointers to objects, each object having a single key with the type of the alternative
name and a value specific to that type.
Example return value:
[
[
{
'directoryName' => {
'rdnSequence' => [
[
{
'value' => { 'utf8String' => 'example' },
'type' => '2.5.4.3'
}
]
]
}
},
{
'dNSName' => 'example.com'
}
]
]
=cut back

sub DecodedSubjectAltNames {
my $self = shift;
my @sans = ();
my $exts = $self->{'tbsCertificate'}->{'extensions'};
foreach my $ext ( @{$exts} ) {
if ( $ext->{'extnID'} eq '2.5.29.17' ) { #OID for subjectAltName
my $parsSubjAlt = _init('SubjectAltName');
my $altnames = $parsSubjAlt->decode( $ext->{'extnValue'} );
if ( $parsSubjAlt->error ) {
$self->{'_error'} = $parsSubjAlt->error;
return undef;
}
push @sans, $altnames;
}
}
return \@sans;
}

#########################################################################
# accessors - authorityCertIssuer
#########################################################################
Expand Down
7 changes: 6 additions & 1 deletion t/Crypt-X509.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Crypt-X509.t'
use Test::More tests => 68;
use Test::More tests => 70;
use Math::BigInt;
BEGIN { use_ok('Crypt::X509') }

Expand Down Expand Up @@ -39,6 +39,7 @@ is( $decoded2->sig_algorithm, "1.2.840.113549.1.1.5", "sig_algorithm" );
is( length( $decoded2->pubkey ), 140, "Pubkey length" );
is( length( $decoded2->signature ), 256, "Signature Length" );
is( join( ',', @{ $decoded2->SubjectAltName } ), "rfc822Name=alexander.jung\@allianz.de", 'SubjectAltName parsed' );
is_deeply( $decoded2->DecodedSubjectAltNames, [[{rfc822Name => '[email protected]'}]], 'DecodedSubjectAltName parsed' );

$cert = loadcert('t/aj2.cer');
$decoded3 = Crypt::X509->new( cert => $cert );
Expand Down Expand Up @@ -87,6 +88,10 @@ is( $mon + 1, 3, "generalTime month" );
is( $year + 1900, 2005, "generalTime year" );
is( join( ',', @{ $decoded->Issuer } ), 'C=DE,O=Deutsche Telekom AG,nameDistinguisher=1,CN=NKS CA 6:PN', 'Issuer for telesec' );
is( join( ',', @{ $decoded->Subject } ), 'C=DE,nameDistinguisher=2,CN=Schefe, Jan', 'Subject for telesec' );
is_deeply( $decoded->DecodedSubjectAltNames, [[
{otherName => {value => "0\x111\x0f0\x0d\x06\x03U\x04\x04\x14\x06Schefe", type => '0.2.262.1.10.3.0'}},
{otherName => {value => "0\x0e1\x0c0\x0a\x06\x03U\x04*\x14\x03Jan", type => '0.2.262.1.10.3.0'}}]],
'DecodedSubjectAltNames for telesec');

$cert = loadcert('t/dsacert.der');
$decoded = Crypt::X509->new( cert => $cert );
Expand Down

0 comments on commit f8c12e3

Please sign in to comment.