| 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 | 1 | $VERSION = '0.0.2'; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | my %params = { | |||||||||||||||||||||||||||
| 57 | crr => undef, | ||||||||||||||||||||||||||||
| 58 | parsedCRR => undef, | ||||||||||||||||||||||||||||
| 59 | signature => undef, | ||||||||||||||||||||||||||||
| 60 | body => undef, | ||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my $that = shift; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $class = ref($that) || $that; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $self = { | |||||||||||||||||||||||||||
| 68 | %params, | ||||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my $keys = { @_ }; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $self->{crr} = $keys->{DATA} || $_[0]; | ||||||||||||||||||||||||||
|
Condition0%0/3
$keys->{'DATA'} || $_[0]
MC/DC0%0/2
$keys->{'DATA'} || $_[0]
$keys->{'DATA'}
$_[0]
Truth table0%0/3
A || B
A= $keys->{'DATA'}B= $_[0]
| |||||||||||||||||||||||||||||
| 76 | 0 | $self->{parsedCRR} = $self->getParsed( $self->{crr} ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return if ( (not $self->{crr}) or (not $self->{parsedCRR}) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"crr"} and $self->{"parsedCRR"}
MC/DC0%0/2
$self->{"crr"} and $self->{"parsedCRR"}
$self->{"crr"}
$self->{"parsedCRR"}
Truth table0%0/3
A and B
A= $self->{"crr"}B= $self->{"parsedCRR"}
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | $self->{signature} = $self->{parsedCRR}->{SIGNATURE}; | |||||||||||||||||||||||||||
| 81 | 0 | $self->{body} = $self->{parsedCRR}->{BODY}; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | return $self; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub parseCRR { | ||||||||||||||||||||||||||
|
Subroutine
parseCRR: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 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 | ▶ | return if (not $crr); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my @lines = split ( /\n/, $crr ); | |||||||||||||||||||||||||||
| 104 | 0 | foreach $line ( @lines ) { | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | $isCRR = 1 if( $line =~ /$beginCRR/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $isCRR = 0 if( $line =~ /$endCRR/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $isSignature = 1 if( $line =~ /$beginSig/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $isSignature = 0 if( $line =~ /$endSig/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if( $isCRR ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 112 | 0 | $body .= "$line\n"; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($line =~ /Submitted on:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ( $date ) = | |||||||||||||||||||||||||||
| 116 | ( $line =~ /Submitted on:[\s]*(.*)/i ); | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($line =~ /DN:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ( $dn ) = ( $line =~ /DN:[\s]*(.*)/ ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($line =~ /Issued by:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ($issuer) = | |||||||||||||||||||||||||||
| 125 | ( $line=~ /Issued by:[\s]*(.*)/i ); | ||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($line =~ /Not After[\s]*:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | ($notAfter) = | |||||||||||||||||||||||||||
| 130 | ($line =~ /Not After:[\s]*(.*)/i ); | ||||||||||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($line =~ /Not Before:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | ($notBefore) = | |||||||||||||||||||||||||||
| 134 | ( $line=~ /Not Before:[\s]*(.*)/i ); | ||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($line =~ /Serial:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | ($serial) = | |||||||||||||||||||||||||||
| 139 | ( $line =~ /Serial:[\s]*([0-9A-F]+)/i); | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if( length( $serial ) % 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub getParsed { | ||||||||||||||||||||||||||
|
Subroutine
getParsed: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return if ( not $self->{parsedCRR} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | return $self->{parsedCRR}; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub getSignature { | ||||||||||||||||||||||||||
|
Subroutine
getSignature: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return if ( not $self->{signature} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | return $self->{signature}; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub getBody { | ||||||||||||||||||||||||||
|
Subroutine
getBody: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return if ( not $self->{body} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | return $self->{body}; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub getCRR { | ||||||||||||||||||||||||||
|
Subroutine
getCRR: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return if ( not $self->{crr} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | return $self->{crr}; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | 1; | |||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||