File Coverage

blib/lib/OpenCA/CRR.pm
Criterion Covered Total %
statement 0 61 0.0
branch 0 38 0.0
condition 0 9 0.0
subroutine 0 6 0.0
pod 3 6 50.0
total 3 120 2.5


line stmt bran cond sub pod time code
1             ## OpenCA::CRR
2             ##
3             ## Copyright (C) 1998-1999 Massimiliano Pala (madwolf@openca.org)
4             ## All rights reserved.
5             ##
6             ## This library is free for commercial and non-commercial use as long as
7             ## the following conditions are aheared to. The following conditions
8             ## apply to all code found in this distribution, be it the RC4, RSA,
9             ## lhash, DES, etc., code; not just the SSL code. The documentation
10             ## included with this distribution is covered by the same copyright terms
11             ##
12             ## Copyright remains Massimiliano Pala's, and as such any Copyright notices
13             ## in the code are not to be removed.
14             ## If this package is used in a product, Massimiliano Pala should be given
15             ## attribution as the author of the parts of the library used.
16             ## This can be in the form of a textual message at program startup or
17             ## in documentation (online or textual) provided with the package.
18             ##
19             ## Redistribution and use in source and binary forms, with or without
20             ## modification, are permitted provided that the following conditions
21             ## are met:
22             ## 1. Redistributions of source code must retain the copyright
23             ## notice, this list of conditions and the following disclaimer.
24             ## 2. Redistributions in binary form must reproduce the above copyright
25             ## notice, this list of conditions and the following disclaimer in the
26             ## documentation and/or other materials provided with the distribution.
27             ## 3. All advertising materials mentioning features or use of this software
28             ## must display the following acknowledgement:
29             ## "This product includes OpenCA software written by Massimiliano Pala
30             ## (madwolf@openca.org) and the OpenCA Group (www.openca.org)"
31             ## 4. If you include any Windows specific code (or a derivative thereof) from
32             ## some directory (application code) you must include an acknowledgement:
33             ## "This product includes OpenCA software (www.openca.org)"
34             ##
35             ## THIS SOFTWARE IS PROVIDED BY OPENCA DEVELOPERS ``AS IS'' AND
36             ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37             ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38             ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
39             ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40             ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41             ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42             ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43             ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44             ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45             ## SUCH DAMAGE.
46             ##
47             ## The licence and distribution terms for any publically available version or
48             ## derivative of this code cannot be changed. i.e. this code cannot simply be
49             ## copied and put under another distribution licence
50             ## [including the GNU Public Licence.]
51             ##
52             package OpenCA::CRR;
53              
54             $VERSION = '0.0.2';
55              
56             my %params = {
57             crr => undef,
58             parsedCRR => undef,
59             signature => undef,
60             body => undef,
61             };
62              
63             sub new {
64 0     0 1   my $that = shift;
65 0   0       my $class = ref($that) || $that;
66            
67 0           my $self = {
68             %params,
69             };
70              
71 0           bless $self, $class;
72              
73 0           my $keys = { @_ };
74              
75 0   0       $self->{crr} = $keys->{DATA} || $_[0];
76 0           $self->{parsedCRR} = $self->getParsed( $self->{crr} );
77              
78 0 0 0       return if ( (not $self->{crr}) or (not $self->{parsedCRR}) );
79              
80 0           $self->{signature} = $self->{parsedCRR}->{SIGNATURE};
81 0           $self->{body} = $self->{parsedCRR}->{BODY};
82              
83 0           return $self;
84             }
85             sub parseCRR {
86 0     0 0   my $self = shift;
87 0           my @keys = @_;
88              
89 0           my $crr = $keys[0];
90 0           my $beginCRR = "-----BEGIN CRR-----";
91 0           my $endCRR = "-----END CRR-----";
92 0           my $beginSig = "-----BEGIN PKCS7-----";
93 0           my $endSig = "-----END PKCS7-----";
94              
95 0           my $line, $dn, $serial, $notBefore, $notAfter, $issuer;
96 0           my $signature = "";
97 0           my $body = "";
98 0           my $isSignature = 0;
99 0           my $isCRR = 0;
100              
101 0 0         return if (not $crr);
102              
103 0           my @lines = split ( /\n/, $crr );
104 0           foreach $line ( @lines ) {
105 0 0         $isCRR = 1 if( $line =~ /$beginCRR/ );
106 0 0         $isCRR = 0 if( $line =~ /$endCRR/ );
107              
108 0 0         $isSignature = 1 if( $line =~ /$beginSig/ );
109 0 0         $isSignature = 0 if( $line =~ /$endSig/ );
110              
111 0 0         if( $isCRR ) {
    0          
112 0           $body .= "$line\n";
113              
114 0 0         if ($line =~ /Submitted on:/) {
115 0           ( $date ) =
116             ( $line =~ /Submitted on:[\s]*(.*)/i );
117             }
118              
119 0 0         if ($line =~ /DN:/) {
120 0           ( $dn ) = ( $line =~ /DN:[\s]*(.*)/ );
121             }
122              
123 0 0         if ($line =~ /Issued by:/) {
124 0           ($issuer) =
125             ( $line=~ /Issued by:[\s]*(.*)/i );
126             };
127              
128 0 0         if ($line =~ /Not After[\s]*:/) {
129 0           ($notAfter) =
130             ($line =~ /Not After:[\s]*(.*)/i );
131             };
132 0 0         if ($line =~ /Not Before:/) {
133 0           ($notBefore) =
134             ( $line=~ /Not Before:[\s]*(.*)/i );
135             };
136              
137 0 0         if ($line =~ /Serial:/) {
138 0           ($serial) =
139             ( $line =~ /Serial:[\s]*([0-9A-F]+)/i);
140              
141 0 0         if( length( $serial ) % 2 ) {
142 0           $serial = "0" . $serial;
143             }
144             }
145              
146             } elsif ( $isSignature ) {
147 0           $signature .= "$line\n";
148             }
149             }
150              
151 0           my $ret = {
152             SUBMIT_DATE => $date,
153             BODY => $body,
154             SIGNATURE => $signature,
155             CERTIFICATE_DN => $dn,
156             CERTIFICATE_NOT_BEFORE => $notbefore,
157             CERTIFICATE_NOT_AFTER => $notafter,
158             CERTIFICATE_SERIAL => $serial,
159             CERTIFICATE_ISSUER => $issuer,
160             };
161              
162 0           return $ret;
163             }
164              
165             sub getParsed {
166 0     0 1   my $self = shift;
167              
168 0 0         return if ( not $self->{parsedCRR} );
169 0           return $self->{parsedCRR};
170             }
171              
172             sub getSignature {
173 0     0 1   my $self = shift;
174              
175 0 0         return if ( not $self->{signature} );
176 0           return $self->{signature};
177             }
178              
179             sub getBody {
180 0     0 0   my $self = shift;
181              
182 0 0         return if ( not $self->{body} );
183 0           return $self->{body};
184             }
185              
186             sub getCRR {
187 0     0 0   my $self = shift;
188              
189 0 0         return if ( not $self->{crr} );
190 0           return $self->{crr};
191             }
192              
193              
194             1;
195             __END__