Skip to content

Commit

Permalink
Merge branch 'release/0.55'
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Hardin committed Jan 9, 2023
2 parents 3e5b4c5 + e838024 commit 93f6253
Show file tree
Hide file tree
Showing 5 changed files with 133 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.54';
version: '0.55';
abstract: Parse a X.509 certificate
author:
- Mike Jackson, Alexander Jung, Duncan Segrest, Oliver Welter
Expand Down
2 changes: 2 additions & 0 deletions build.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Note: Replace '0.10' in the examples below with the current version.

* Upload tarball to https://pause.perl.org

cpan-upload Crypt-X509-$modver.tar.gz

# If the build env is not already set up, run the following:

curl -L http://install.perlbrew.pl | bash
Expand Down
28 changes: 26 additions & 2 deletions 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.54';
our $VERSION = '0.55';
my $parser = undef;
my $asn = undef;
my $error = undef;
Expand Down Expand Up @@ -39,6 +39,7 @@ our %oid2attr = (
"2.5.4.11" => "OU",
"1.2.840.113549.1.9.1" => "emailAddress",
'1.2.840.113549.1.9.2' => 'unstructuredName',
'1.2.840.113549.1.9.8' => 'unstructuredAddress',
"0.9.2342.19200300.100.1.1" => "UID",
"0.9.2342.19200300.100.1.25" => "DC",
"0.2.262.1.10.7.20" => "nameDistinguisher",
Expand Down Expand Up @@ -394,6 +395,7 @@ from the OID-Numbers, unknown numbers are output verbatim.
print "DN for this Certificate is:".join(',',@{$decoded->Subject})."\n";
=cut back

sub Subject {
my $self = shift;
my ( $i, $type );
Expand All @@ -414,6 +416,15 @@ sub Subject {
return $subjdn;
}

=head2 SubjectRaw
Returns the RDNs as list of hashes, values are stringified but OIDs are
not translated.
If a component contains a SET, the component will become an array of hashes
on the second level.
=cut

sub SubjectRaw {

Expand All @@ -434,6 +445,19 @@ sub SubjectRaw {
return \@subject;
}

=head2 SubjectSequence
Returns the subject as returned from the ASN1 parser.
=cut

sub SubjectSequence {

my $self = shift;
return $self->{'tbsCertificate'}->{'subject'}->{'rdnSequence'};

}

sub _subject_part {
my $self = shift;
my $oid = shift;
Expand Down Expand Up @@ -1204,7 +1228,7 @@ sub SubjectDirectoryAttributes {
for my $type ( @{$subject_dir_attrs} ) {
for my $value ( @{ $type->{'values'} } ) {
for my $key ( keys %{$value} ) {
push @{$attributes}, $type->{'type'} . " = " . $value->{$key} . " ($key)";
push @{$attributes}, $type->{'type'} . " = " . $value->{$key} . " ($key)";
}
}
}
Expand Down
File renamed without changes.
104 changes: 104 additions & 0 deletions t/04_complex_rdn.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/perl

use strict;
use warnings;

use MIME::Base64;
use Test::More 0.94;

plan tests => 2;
use Crypt::X509;

my $data = decode_base64("
MIIEDTCCAvWgAwIBAgIUWNbTsN1cmdX0Ew4DlbirvCGPTywwDQYJKoZIhvcNAQEL
BQAwgZUxCzAJBgNVBAYTAkRFMRAwDgYDVQQKDAdPcGVuUEtJMRYwFAYDVQQLDA1C
cmFuY2grT2ZmaWNlMQswCQYDVQQLDAJJVDEpMA8GA1UEAwwISm9obiBEb2UwFgYK
CZImiZPyLGQBAQwIam9obi5kb2UxJDAiBgkqhkiG9w0BCQEWFWpvaG4uZG9lQG9w
ZW54cGtpLm9yZzAeFw0yMzAxMDkwNzQyMDVaFw0yMzAyMDgwNzQyMDVaMIGVMQsw
CQYDVQQGEwJERTEQMA4GA1UECgwHT3BlblBLSTEWMBQGA1UECwwNQnJhbmNoK09m
ZmljZTELMAkGA1UECwwCSVQxKTAPBgNVBAMMCEpvaG4gRG9lMBYGCgmSJomT8ixk
AQEMCGpvaG4uZG9lMSQwIgYJKoZIhvcNAQkBFhVqb2huLmRvZUBvcGVueHBraS5v
cmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDoQIN+eRw9zUN23DS0
k5FNxYy0JgkP78nV6FQ+AaKrb8ablKnCu9DFfTAStCUPZWh12Ta2ubwqUQPlWxva
GYMzAA+4Rqrgw1ksyLoFLUfyKKZk6ShiprUnHgB5iOdPpEgIXq7NHAfosW7VAXyR
NTQeFywDAgrlF0iVnjqL38eaIttzuxJs3os1uBST9L0ygpbaNUTfE9P0KT6c3LM4
eM29Z8jaUh3QvOJt0ybpnAWCcojikDhmfWFeAKLviokWp5FEuAtPxAr5KN+rE3W8
nC0a0f4gmNKbuf4vdVRiPhpWfUNvJgemxTClfB4IAL/MjOMsIEZkVIgWcjx74f2Y
4nMTAgMBAAGjUzBRMB0GA1UdDgQWBBTKOocoryob5WCO+9mGTbxNunL++DAfBgNV
HSMEGDAWgBTKOocoryob5WCO+9mGTbxNunL++DAPBgNVHRMBAf8EBTADAQH/MA0G
CSqGSIb3DQEBCwUAA4IBAQDD60DX+YzWLRkZJ+KgOoGTBSg+ghiepIV6GgTOk3q9
DOyXG5mE0e+FkMorqhnOFbjCkykSmPdOGBWzQAUTdMpOXh2e2MfvL7Dzqd8BLGjj
hz+NwfUZco/Ts9b1m5I2XDc9sEmREVaDF1s37qzR58idwzjKsqIAWjprnY1qTz3n
4WYqC5m89JUtaBwuJSPJ9ydrT4B45rWH52VqNkPhtRPBjGIzyP0QZcujA+4m33/0
IxpQGDLMDyZj5gfn8V/jxPiEH471BtjV7j3zPH6XZjexjUdH158rcfB2OYjj6zQL
9UlbEjCYgJe8zGRfS2WSMMV98CQ0B0rkj9woT1D+HqMv");

my $x509 = Crypt::X509->new(cert => $data );

is_deeply(scalar $x509->Subject(), [
'C=DE',
'O=OpenPKI',
'OU=Branch+Office',
'OU=IT',
'CN=John Doe',
'UID=john.doe',
'[email protected]'
]);

my $cert_subject = $x509->SubjectSequence();
is_deeply($cert_subject,[
[
{
'type' => '2.5.4.6',
'value' => {
'printableString' => 'DE'
}
}
],
[
{
'value' => {
'utf8String' => 'OpenPKI'
},
'type' => '2.5.4.10'
}
],
[
{
'value' => {
'utf8String' => 'Branch+Office'
},
'type' => '2.5.4.11'
}
],
[
{
'value' => {
'utf8String' => 'IT'
},
'type' => '2.5.4.11'
}
],
[
{
'value' => {
'utf8String' => 'John Doe'
},
'type' => '2.5.4.3'
},
{
'type' => '0.9.2342.19200300.100.1.1',
'value' => {
'utf8String' => 'john.doe'
}
}
],
[
{
'type' => '1.2.840.113549.1.9.1',
'value' => {
'ia5String' => '[email protected]'
}
}
]
]);

0 comments on commit 93f6253

Please sign in to comment.