1package Firefox::Marionette::Certificate; 2 3use strict; 4use warnings; 5 6our $VERSION = '1.10'; 7 8sub _NUMBER_OF_MICROSECOND_DIGITS { return -6 } 9 10sub new { 11 my ( $class, $parameters ) = @_; 12 13 my $self = bless { %{$parameters} }, $class; 14 return $self; 15} 16 17sub issuer_name { 18 my ($self) = @_; 19 return $self->{issuerName}; 20} 21 22sub common_name { 23 my ($self) = @_; 24 return $self->{commonName}; 25} 26 27sub is_any_cert { 28 my ($self) = @_; 29 return $self->{ANY_CERT} & $self->{certType}; 30} 31 32sub email_address { 33 my ($self) = @_; 34 return $self->{emailAddress} eq '(no email address)' 35 ? undef 36 : $self->{emailAddress}; 37} 38 39sub sha256_subject_public_key_info_digest { 40 my ($self) = @_; 41 return $self->{sha256SubjectPublicKeyInfoDigest}; 42} 43 44sub issuer_organization { 45 my ($self) = @_; 46 return $self->{issuerOrganization}; 47} 48 49sub db_key { 50 my ($self) = @_; 51 return $self->{dbKey}; 52} 53 54sub is_unknown_cert { 55 my ($self) = @_; 56 return $self->{UNKNOWN_CERT} & $self->{certType}; 57} 58 59sub is_built_in_root { 60 my ($self) = @_; 61 return $self->{isBuiltInRoot}; 62} 63 64sub token_name { 65 my ($self) = @_; 66 return $self->{tokenName}; 67} 68 69sub sha256_fingerprint { 70 my ($self) = @_; 71 return $self->{sha256Fingerprint}; 72} 73 74sub is_server_cert { 75 my ($self) = @_; 76 return $self->{SERVER_CERT} & $self->{certType}; 77} 78 79sub is_user_cert { 80 my ($self) = @_; 81 return $self->{USER_CERT} & $self->{certType}; 82} 83 84sub subject_name { 85 my ($self) = @_; 86 return $self->{subjectName}; 87} 88 89sub key_usages { 90 my ($self) = @_; 91 return $self->{keyUsages}; 92} 93 94sub is_ca_cert { 95 my ($self) = @_; 96 return $self->{CA_CERT} & $self->{certType}; 97} 98 99sub issuer_organization_unit { 100 my ($self) = @_; 101 return $self->{issuerOrganizationUnit}; 102} 103 104sub _convert_time_to_seconds { 105 my ( $self, $microseconds ) = @_; 106 my $seconds = substr $microseconds, 0, _NUMBER_OF_MICROSECOND_DIGITS(); 107 return $seconds + 0; 108} 109 110sub not_valid_after { 111 my ($self) = @_; 112 return $self->_convert_time_to_seconds( $self->{validity}->{notAfter} ); 113} 114 115sub not_valid_before { 116 my ($self) = @_; 117 return $self->_convert_time_to_seconds( $self->{validity}->{notBefore} ); 118} 119 120sub serial_number { 121 my ($self) = @_; 122 return $self->{serialNumber}; 123} 124 125sub is_email_cert { 126 my ($self) = @_; 127 return $self->{EMAIL_CERT} & $self->{certType}; 128} 129 130sub issuer_common_name { 131 my ($self) = @_; 132 return $self->{issuerCommonName}; 133} 134 135sub organization { 136 my ($self) = @_; 137 return $self->{organization}; 138} 139 140sub nickname { 141 my ($self) = @_; 142 return $self->{nickname}; 143} 144 145sub sha1_fingerprint { 146 my ($self) = @_; 147 return $self->{sha1Fingerprint}; 148} 149 150sub display_name { 151 my ($self) = @_; 152 return $self->{displayName}; 153} 154 155sub organizational_unit { 156 my ($self) = @_; 157 return $self->{organizationalUnit}; 158} 159 1601; # Magic true value required at end of module 161__END__ 162 163=head1 NAME 164 165Firefox::Marionette::Certificate - Represents a x509 Certificate from Firefox 166 167=head1 VERSION 168 169Version 1.10 170 171=head1 SYNOPSIS 172 173 use Firefox::Marionette(); 174 use v5.10; 175 176 my $firefox = Firefox::Marionette->new(); 177 foreach my $certificate (sort { $a->display_name() cmp $b->display_name() } $firefox->certificates()) { 178 ... 179 } 180 181=head1 DESCRIPTION 182 183This module handles the implementation of a x509 Certificate from Firefox 184 185=head1 SUBROUTINES/METHODS 186 187=head2 common_name 188 189returns the common name from the certificate. This can contain the domain name (or wildcard) attached to the certificate or a Certificate Authority name, such as 'VeriSign Class 3 Public Primary Certification Authority - G4' 190 191=head2 db_key 192 193returns a unique value for the certificate, such as 'AAAAAAAAAAAAAAAQAAAAzS+A/iOMDiIPSGcSKJGHrLMwgcoxCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEfMB0GA1UECxMWVmVyaVNpZ24gVHJ1c3QgTmV0d29yazE6MDgGA1UECxMxKGMpIDIwMDcgVmVyaVNpZ24sIEluYy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25seTFFMEMGA1UEAxM8VmVyaVNpZ24gQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEc0' 194 195=head2 display_name 196 197returns the display name field, such as 'VeriSign Class 3 Public Primary Certification Authority - G4' 198 199=head2 email_address 200 201returns the emailAddress field if supplied, otherwise it will return undef. 202 203=head2 is_any_cert 204 205returns a boolean value to determine if the certificate is a certificate. I would regard it as quite surprising to get a certificate that returned false. 206 207=head2 is_built_in_root 208 209returns a boolean value to determine if the certificate is a built in root certificate. 210 211=head2 is_ca_cert 212 213returns a boolean value to determine if the certificate is a certificate authority certificate 214 215=head2 is_email_cert 216 217returns a boolean value to determine if the certificate is an email certificate. 218 219=head2 is_server_cert 220 221returns a boolean value to determine if the certificate is a server certificate. 222 223=head2 is_unknown_cert 224 225returns a boolean value to determine if the certificate type is unknown. 226 227=head2 is_user_cert 228 229returns a boolean value to determine if the certificate is a user certificate. 230 231=head2 issuer_common_name 232 233returns the L<issuer common name|https://datatracker.ietf.org/doc/html/rfc5280#section-5.1.2.3> from the certificate, such as 'VeriSign Class 3 Public Primary Certification Authority - G4' 234 235=head2 issuer_name 236 237returns the L<issuer name|https://datatracker.ietf.org/doc/html/rfc5280#section-5.1.2.3> from the certificate, such as 'CN=VeriSign Class 3 Public Primary Certification Authority - G4,OU="(c) 2007 VeriSign, Inc. - For authorized use only",OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US' 238 239=head2 issuer_organization 240 241returns the L<issuer organisation|https://datatracker.ietf.org/doc/html/rfc5280#section-5.1.2.3> from the certificate, such as 'VeriSign, Inc.' 242 243=head2 issuer_organization_unit 244 245returns the L<issuer organization unit|https://datatracker.ietf.org/doc/html/rfc5280#section-5.1.2.3> from the certificate, such as 'VeriSign Trust Network' 246 247=head2 key_usages 248 249returns a string describing the intended usages of the certificate, such as 'Certificate Signer' 250 251=head2 new 252 253This method is intended for use exclusively by the L<Firefox::Marionette|Firefox::Marionette> module. You should not need to call this method from your code. 254 255=head2 nickname 256 257returns the nickname field, such as 'Builtin Object Token:VeriSign Class 3 Public Primary Certification Authority - G4' 258 259=head2 not_valid_after 260 261returns the L<not valid after|https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.5> time in seconds since the UNIX epoch. 262 263=head2 not_valid_before 264 265returns the L<not valid before|https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.5> time in seconds since the UNIX epoch. 266 267=head2 organization 268 269returns the organization field, such as 'VeriSign, Inc.' 270 271=head2 organizational_unit 272 273returns the organization unit field, such as 'VeriSign Trust Network' 274 275=head2 serial_number 276 277returns the L<serial number|https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.2> of the certificate, such as '2F:80:FE:23:8C:0E:22:0F:48:67:12:28:91:87:AC:B3' 278 279=head2 sha1_fingerprint 280 281returns the sha1Fingerprint field, such as '22:D5:D8:DF:8F:02:31:D1:8D:F7:9D:B7:CF:8A:2D:64:C9:3F:6C:3A' 282 283=head2 sha256_fingerprint 284 285returns the sha256Fingerprint field, such as '69:DD:D7:EA:90:BB:57:C9:3E:13:5D:C8:5E:A6:FC:D5:48:0B:60:32:39:BD:C4:54:FC:75:8B:2A:26:CF:7F:79' 286 287=head2 sha256_subject_public_key_info_digest 288 289returns the base64 encoded sha256 digest of the L<subject public key info|https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.7> field, such as 'UZJDjsNp1+4M5x9cbbdflB779y5YRBcV6Z6rBMLIrO4=' 290 291=head2 subject_name 292 293returns the name from the L<subject|https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.6> field, such as 'CN=VeriSign Class 3 Public Primary Certification Authority - G4,OU="(c) 2007 VeriSign, Inc. - For authorized use only",OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US' 294 295=head2 token_name 296 297returns a string describing the type of certificate, such as 'Builtin Object Token' 298 299=head1 DIAGNOSTICS 300 301None. 302 303=head1 CONFIGURATION AND ENVIRONMENT 304 305Firefox::Marionette::Certificate requires no configuration files or environment variables. 306 307=head1 DEPENDENCIES 308 309None. 310 311=head1 INCOMPATIBILITIES 312 313None reported. 314 315=head1 BUGS AND LIMITATIONS 316 317No bugs have been reported. 318 319Please report any bugs or feature requests to 320C<bug-firefox-marionette@rt.cpan.org>, or through the web interface at 321L<http://rt.cpan.org>. 322 323=head1 AUTHOR 324 325David Dick C<< <ddick@cpan.org> >> 326 327=head1 LICENSE AND COPYRIGHT 328 329Copyright (c) 2021, David Dick C<< <ddick@cpan.org> >>. All rights reserved. 330 331This module is free software; you can redistribute it and/or 332modify it under the same terms as Perl itself. See L<perlartistic/perlartistic>. 333 334=head1 DISCLAIMER OF WARRANTY 335 336BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 337FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 338OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 339PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 340EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 341WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 342ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH 343YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL 344NECESSARY SERVICING, REPAIR, OR CORRECTION. 345 346IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 347WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 348REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE 349LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, 350OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE 351THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 352RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 353FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 354SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 355SUCH DAMAGES. 356