line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Net::SSLeay::OO::X509::Name; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1599
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Carp qw(croak confess); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'x509_name' => isa => 'Int', |
8
|
|
|
|
|
|
|
is => "ro", |
9
|
|
|
|
|
|
|
required => 1, |
10
|
|
|
|
|
|
|
; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %field_to_NID = qw( |
13
|
|
|
|
|
|
|
cn NID_commonName |
14
|
|
|
|
|
|
|
country NID_countryName |
15
|
|
|
|
|
|
|
locality NID_localityName |
16
|
|
|
|
|
|
|
state NID_stateOrProvinceName |
17
|
|
|
|
|
|
|
org NID_organizationName |
18
|
|
|
|
|
|
|
org_unit NID_organizationalUnitName |
19
|
|
|
|
|
|
|
subject_key NID_subject_key_identifier |
20
|
|
|
|
|
|
|
key_usage NID_key_usage |
21
|
|
|
|
|
|
|
serial NID_serialNumber |
22
|
|
|
|
|
|
|
name NID_name |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_text_by_NID { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
my $nid = shift; |
28
|
|
|
|
|
|
|
my $val = |
29
|
|
|
|
|
|
|
Net::SSLeay::X509_NAME_get_text_by_NID( $self->x509_name,$nid, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
&Net::SSLeay::OO::Error::die_if_ssl_error("get_text_by_nid($nid)"); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# work around a bug in X509_NAME_get_text_by_NID |
34
|
|
|
|
|
|
|
chop($val) if substr( $val, -1, 1 ) eq "\0"; |
35
|
|
|
|
|
|
|
$val; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Net::SSLeay::OO::Functions 'x509_name'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub AUTOLOAD { |
41
|
|
|
|
|
|
|
no strict 'refs'; |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
our $AUTOLOAD =~ m{::([^:]*)$}; |
44
|
|
|
|
|
|
|
my $field = $1; |
45
|
|
|
|
|
|
|
$self->{$field} ||= do { |
46
|
|
|
|
|
|
|
my $nid_name = $field_to_NID{$field} |
47
|
|
|
|
|
|
|
or croak "unknown method/field '$field'"; |
48
|
|
|
|
|
|
|
if ( !defined &{$nid_name} ) { |
49
|
|
|
|
|
|
|
eval { |
50
|
|
|
|
|
|
|
Net::SSLeay::OO::Constants->import($nid_name); |
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
or croak "unknown NID '$nid_name'?; $@"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
$self->get_text_by_NID(&$nid_name); |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Net::SSLeay::OO::X509::Name - methods to call on SSL certificate names |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $name = $cert->get_subject_name; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# for 'common' attributes |
72
|
|
|
|
|
|
|
print "Summary of cert: ".$name->oneline."\n"; |
73
|
|
|
|
|
|
|
print "Common name is ".$name->cn."\n"; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# others... |
76
|
|
|
|
|
|
|
use Net::SSLeay::OO::Constants qw(NID_pbe_WithSHA1And2_Key_TripleDES_CBC); |
77
|
|
|
|
|
|
|
my $val = $name->get_text_by_NID(NID_pbe_WithSHA1And2_Key_TripleDES_CBC); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This object represents the X509_NAME structure in OpenSSL. It has a |
82
|
|
|
|
|
|
|
bunch of fields such as "common name", etc. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Two methods are imported from the OpenSSL library; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=over |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item B<oneline> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns a string, such as: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
/C=NZ/ST=Wellington/O=Catalyst IT/OU=Security/CN=Test Client |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item B<get_text_by_NID(NID_xxx)> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Return a given field from the name. See F<openssl/objects.h> for the |
97
|
|
|
|
|
|
|
complete list. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=back |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Convenience methods have been added which return the following common |
102
|
|
|
|
|
|
|
fields: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
cn NID_commonName |
105
|
|
|
|
|
|
|
country NID_countryName |
106
|
|
|
|
|
|
|
locality NID_localityName |
107
|
|
|
|
|
|
|
state NID_stateOrProvinceName |
108
|
|
|
|
|
|
|
org NID_organizationName |
109
|
|
|
|
|
|
|
org_unit NID_organizationalUnitName |
110
|
|
|
|
|
|
|
subject_key NID_subject_key_identifier |
111
|
|
|
|
|
|
|
key_usage NID_key_usage |
112
|
|
|
|
|
|
|
serial NID_serialNumber |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Sam Vilain, L<samv@cpan.org> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Copyright (C) 2009 NZ Registry Services |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
123
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0 or later. You should |
124
|
|
|
|
|
|
|
have received a copy of the Artistic License the file COPYING.txt. If |
125
|
|
|
|
|
|
|
not, see <http://www.perlfoundation.org/artistic_license_2_0> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L<Net::SSLeay::OO>, L<Net::SSLeay::OO::X509> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Local Variables: |
134
|
|
|
|
|
|
|
# mode:cperl |
135
|
|
|
|
|
|
|
# indent-tabs-mode: t |
136
|
|
|
|
|
|
|
# cperl-continued-statement-offset: 8 |
137
|
|
|
|
|
|
|
# cperl-brace-offset: 0 |
138
|
|
|
|
|
|
|
# cperl-close-paren-offset: 0 |
139
|
|
|
|
|
|
|
# cperl-continued-brace-offset: 0 |
140
|
|
|
|
|
|
|
# cperl-continued-statement-offset: 8 |
141
|
|
|
|
|
|
|
# cperl-extra-newline-before-brace: nil |
142
|
|
|
|
|
|
|
# cperl-indent-level: 8 |
143
|
|
|
|
|
|
|
# cperl-indent-parens-as-block: t |
144
|
|
|
|
|
|
|
# cperl-indent-wrt-brace: nil |
145
|
|
|
|
|
|
|
# cperl-label-offset: -8 |
146
|
|
|
|
|
|
|
# cperl-merge-trailing-else: t |
147
|
|
|
|
|
|
|
# End: |
148
|
|
|
|
|
|
|
# vim: filetype=perl:noexpandtab:ts=3:sw=3 |
149
|
|
|
|
|
|
|
|