| 1 | package Plack::Middleware::ClientCert; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use parent qw(Plack::Middleware); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.100'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub client_cert | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
client_cert: called CC=11 SCAR=24.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 3 | my ($env) = @_; | |||||||||||||||||||||||||||
| 12 | 3 | my %cert = (); | |||||||||||||||||||||||||||
| 13 | 3 | my $prefix = 'client_'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | my $ssl_env = "SSL_CLIENT_S_DN"; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | my $dn = $env->{ CERT_SUBJECT } || $env->{ $ssl_env } || ''; | ||||||||||||||||||||||||||
|
Condition60%3/5
$env->{'CERT_SUBJECT'} || $env->{$ssl_env} || ''
$env->{"CERT_SUBJECT"} or $env->{$ssl_env}
MC/DC0%0/2
$env->{'CERT_SUBJECT'} || $env->{$ssl_env} || ''
$env->{"CERT_SUBJECT"}
$env->{$ssl_env}
Truth table66%2/3
A or B
A= $env->{"CERT_SUBJECT"}B= $env->{$ssl_env}
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | # If headers are passed in by a proxy, they are prefixed by HTTP_ | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | 3 | ▶ | if (!$dn && $env->{ "HTTP_$ssl_env" }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $dn and $$env{"HTTP_$ssl_env"}
MC/DC0%0/2
not $dn and $$env{"HTTP_$ssl_env"}
not $dn
$$env{"HTTP_$ssl_env"}
Truth table33%1/3
not(A) and B
A= not $dnB= $$env{"HTTP_$ssl_env"}
| |||||||||||||||||||||||||||||
| 23 | 0 | $ssl_env = "HTTP_$ssl_env"; | |||||||||||||||||||||||||||
| 24 | 0 | $dn = $env->{ $ssl_env }; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||
| 28 | # Apache on Linux does the parsing for us. The parts to the DN are | ||||||||||||||||||||||||||||
| 29 | # all in SSL_CLIENT_S_DN_xx | ||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||
| 31 | 3 | my @keys = grep s/^${ssl_env}_(.*)/$1/, (keys %{ $env }); | |||||||||||||||||||||||||||
| 32 | 3 | ▶ | if (@keys) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 33 | 1 | for my $key (@keys) { | |||||||||||||||||||||||||||
| 34 | 4 | $env->{ $prefix . lc( $key ) } = $env->{ "${ssl_env}_${key}" }; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||
| 38 | # The DN can be delimited by commas or slashes (/). Assume commas unless | ||||||||||||||||||||||||||||
| 39 | # the very first character is a slash. | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | elsif ($dn =~ /^\//) { | ||||||||||||||||||||||||||||
| 42 | # Iterate through the DN while there are still 'field=value' pairs | ||||||||||||||||||||||||||||
| 43 | 1 | ▶ | while ($dn =~ /=/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||
| 45 | # Match the leading slash, then the field name, equals sign, | ||||||||||||||||||||||||||||
| 46 | # and value. Finally, match the next slash seperator or the | ||||||||||||||||||||||||||||
| 47 | # end of the line. | ||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||
| 49 | 4 | $dn =~ s/^\/(.*?)=(.*?)(\/|$)/$3/; | |||||||||||||||||||||||||||
| 50 | 4 | $env->{ $prefix . lc( $1 ) } = $2; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | # Iterate through the DN while there are still 'field=value' pairs | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | while ($dn =~ /=/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||
| 57 | # The first match is the field. Then match 0 or 1 quotation mark(s). | ||||||||||||||||||||||||||||
| 58 | # The third match is the value. Match the closed quote (or nothing). | ||||||||||||||||||||||||||||
| 59 | # Finally, match the comma seperator and blank space, or the end | ||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||
| 61 | 4 | $dn =~ s/^(.*?)=(\"*)(.*?)\2(,\s*|$)//; | |||||||||||||||||||||||||||
| 62 | 4 | $env->{ $prefix . lc( $1 ) } = $3; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Add serial number if appropriate | ||||||||||||||||||||||||||||
| 67 | 3 | my $serial_key = $ssl_env; | |||||||||||||||||||||||||||
| 68 | 3 | $serial_key =~ s/S_DN/M_SERIAL/; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | $env->{ "${prefix}serial" } = $env->{ $serial_key } || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$env->{$serial_key} || ''
MC/DC0%0/1
$env->{$serial_key} || ''
$env->{$serial_key}
Truth table50%1/2
A
A= $env->{$serial_key}
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | return; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | } # End of client_cert() | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 3 | my($self, $env) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 3 | client_cert( $env ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 3 | return $self->app->($env); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | 1; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||