line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2013-2015 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
5
|
|
|
5
|
|
167105
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
152
|
|
6
|
5
|
|
|
5
|
|
23
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
166
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Net::Domain::SMD::Schema; |
9
|
5
|
|
|
5
|
|
25
|
use vars '$VERSION'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
330
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.18'; |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
24
|
use base 'Exporter'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
613
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/SMD10_NS MARK10_NS/; |
15
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
16
|
|
|
|
|
|
|
( ns10 => [ qw/SMD10_NS MARK10_NS/ ] |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
5
|
|
727
|
use Log::Report 'net-domain-smd'; |
|
5
|
|
|
|
|
110212
|
|
|
5
|
|
|
|
|
35
|
|
20
|
5
|
|
|
5
|
|
4440
|
use XML::Compile::Cache (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use XML::Compile::WSS::Signature (); |
22
|
|
|
|
|
|
|
use XML::Compile::WSS::Util qw(DSIG_NS DSIGM_RSA_SHA256); |
23
|
|
|
|
|
|
|
use Net::Domain::SMD::File (); |
24
|
|
|
|
|
|
|
use File::Basename qw(dirname); |
25
|
|
|
|
|
|
|
use Scalar::Util qw(blessed); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use constant |
28
|
|
|
|
|
|
|
{ SMD10_NS => 'urn:ietf:params:xml:ns:signedMark-1.0' |
29
|
|
|
|
|
|
|
, MARK10_NS => 'urn:ietf:params:xml:ns:mark-1.0' |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %prefixes = |
33
|
|
|
|
|
|
|
( ds => DSIG_NS # do not take this prefix from these schemas |
34
|
|
|
|
|
|
|
, smd => SMD10_NS |
35
|
|
|
|
|
|
|
, mark => MARK10_NS |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new($%) { my ($class, %args) = @_; (bless {}, $class)->init(\%args) } |
40
|
|
|
|
|
|
|
sub init($) |
41
|
|
|
|
|
|
|
{ my ($self, $args) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $xsddir = (dirname __FILE__) . '/xsd'; |
44
|
|
|
|
|
|
|
my @xsds = |
45
|
|
|
|
|
|
|
( "$xsddir/mark-1.0.xsd" |
46
|
|
|
|
|
|
|
, "$xsddir/mark-1.0-bugs.xsd" |
47
|
|
|
|
|
|
|
, "$xsddir/signedMark-1.0.xsd" |
48
|
|
|
|
|
|
|
, "$xsddir/signedMark-1.0-bugs.xsd" |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $schemas = $self->{NDSS_schemas} |
52
|
|
|
|
|
|
|
= XML::Compile::Cache->new(\@xsds, prefixes => \%prefixes); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# do not prefix 'mark', because the accesses it all the time. |
55
|
|
|
|
|
|
|
$schemas->addKeyRewrite('PREFIXED(smd)'); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $cert = $args->{tmv_certificate}; |
58
|
|
|
|
|
|
|
if(defined $cert) |
59
|
|
|
|
|
|
|
{ blessed $cert && $cert->isa('Crypt::OpenSSL::X509') |
60
|
|
|
|
|
|
|
or error __x"incorrect tmv_certificate parameter, expect {pkg}" |
61
|
|
|
|
|
|
|
, pkg => 'Crypt::OpenSSL::X509'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $prepare = $cert ? 'ALL' : 'READER'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my @w_opts; |
67
|
|
|
|
|
|
|
if($cert) |
68
|
|
|
|
|
|
|
{ push @w_opts |
69
|
|
|
|
|
|
|
, token => $cert |
70
|
|
|
|
|
|
|
, private_key => undef #XXX Work in progress |
71
|
|
|
|
|
|
|
, publish_token => 'X509DATA' |
72
|
|
|
|
|
|
|
, sign_info => |
73
|
|
|
|
|
|
|
{ sign_method => DSIGM_RSA_SHA256 |
74
|
|
|
|
|
|
|
# , private_key => $tmv_key |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $sig = XML::Compile::WSS::Signature->new |
79
|
|
|
|
|
|
|
( schema => $schemas |
80
|
|
|
|
|
|
|
, prepare => $prepare |
81
|
|
|
|
|
|
|
, sign_types => [ 'smd:signedMarkType', 'ds:KeyInfoType' ] |
82
|
|
|
|
|
|
|
, sign_put => 'smd:signedMarkType' # enveloped-signature |
83
|
|
|
|
|
|
|
, @w_opts |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$schemas->addHook |
87
|
|
|
|
|
|
|
( action => 'READER', type => 'xsd:dateTime' |
88
|
|
|
|
|
|
|
, after => sub { Net::Domain::SMD->date2time($_[1]) } |
89
|
|
|
|
|
|
|
) if $args->{auto_datetime}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$self; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#------------------------- |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub schemas() {shift->{NDSS_schemas}} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#------------------------- |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub from($%) |
103
|
|
|
|
|
|
|
{ my ($self, $xml, %args) = @_; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return ($self->read($xml, %args), $xml) |
106
|
|
|
|
|
|
|
if $xml !~ m/\n/ && -f $xml; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $source; |
109
|
|
|
|
|
|
|
unless(blessed $xml && $xml->isa('XML::LibXML::Node')) |
110
|
|
|
|
|
|
|
{ $xml = XML::LibXML->load_xml(string => $xml); |
111
|
|
|
|
|
|
|
$source = 'string'; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if($xml->isa('XML::LibXML::Document')) |
115
|
|
|
|
|
|
|
{ $xml = $xml->documentElement; |
116
|
|
|
|
|
|
|
$source ||= 'document'; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $smd = Net::Domain::SMD->fromNode($xml, schemas => $self->schemas); |
120
|
|
|
|
|
|
|
$source ||= 'element'; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
($smd, $source); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub read($) |
127
|
|
|
|
|
|
|
{ my ($self, $fn) = @_; |
128
|
|
|
|
|
|
|
Net::Domain::SMD::File->fromFile($fn, schemas => $self->schemas); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub createSignedMark($$$) |
133
|
|
|
|
|
|
|
{ my ($self, $doc, $data, $args) = @_; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$data->{ds_Signature} = {}; # trigger inclusion of signature |
136
|
|
|
|
|
|
|
$self->schemas->writer('smd:signedMark')->($doc, $data); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |