XML-Compile-WSS-Signature
view release on metacpan or search on metacpan
Improvements:
- tests: move template generation from t/31keyinfo.t into t/02templs.t
- support key-info type X509Data
- too many to mention! Close to full rework.
version 1.09:
Fixes:
- receive messages without PrefixList [Karen Etheridge]
- token and private_key configuration is optional: report errors
lazy.
Improvements:
- use ::Cache::addPrefixes()
version 1.08: Fri Jan 18 13:37:45 CET 2013
Changes:
- elementsToSign() -> takeElementsToSign()
lib/XML/Compile/WSS/Sign.pod view on Meta::CPAN
XML::Compile::WSS::Sign is extended by
XML::Compile::WSS::Sign::HMAC
XML::Compile::WSS::Sign::RSA
=head1 SYNOPSIS
# either
use XML::Compile::WSS::Util qw/DSIG_RSA_SHA1/;
my $sign = XML::Compile::WSS::Sign->new
( sign_method => DSIG_RSA_SHA1
, private_key => $key
, ...
);
# or
use XML::Compile::WSS::Sign::RSA;
my $sign = XML::Compile::WSS::Sign::RSA->new
( hashing => 'SHA1'
, private_key => $key
, ...
);
=head1 DESCRIPTION
=head2 Supported signers
=over 4
=item * RSA
lib/XML/Compile/WSS/Sign/RSA.pm view on Meta::CPAN
use Crypt::OpenSSL::RSA ();
use File::Slurp qw/read_file/;
use Scalar::Util qw/blessed/;
sub init($)
{ my ($self, $args) = @_;
$self->SUPER::init($args);
$self->privateKey
( $args->{private_key}
, hashing => $args->{hashing}
, padding => $args->{padding}
);
$self->publicKey
( $args->{public_key}
, hashing => $args->{hashing}
, padding => $args->{padding}
);
$self;
lib/XML/Compile/WSS/Sign/RSA.pm view on Meta::CPAN
my ($key, $rsa) = $self->toPrivateSHA($priv);
$self->{XCWSR_privrsa} = $self->_setRSAflags($key, $rsa, @_);
$self->{XCWSR_privkey} = $key;
$key;
}
sub toPrivateSHA($)
{ my ($self, $priv) = @_;
return ($priv->get_private_key_string, $priv)
if blessed $priv && $priv->isa('Crypt::OpenSSL::RSA');
error __x"unsupported private key object `{object}'", object=>$priv
if ref $priv =~ m/Crypt/;
return ($priv, Crypt::OpenSSL::RSA->new_private_key($priv))
if index($priv, "\n") >= 0;
my $key = read_file $priv;
my $rsa = eval { Crypt::OpenSSL::RSA->new_private_key($key) };
if($@)
{ error __x"cannot read private RSA key from {file}: {err}"
, file => $priv, err => $@;
}
($key, $rsa);
}
sub privateKeyRSA() {shift->{XCWSR_privrsa}}
lib/XML/Compile/WSS/Sign/RSA.pm view on Meta::CPAN
sub publicKeyRSA() {shift->{XCWSR_pubrsa}}
#-----------------
# Do we need next 4? Probably not
sub sign(@)
{ my ($self, $text) = @_;
my $priv = $self->privateKeyRSA
or error "signing rsa requires the private_key";
$priv->sign($text);
}
sub encrypt(@)
{ my ($self, $text) = @_;
my $pub = $self->publicKeyRSA
or error "encrypting rsa requires the public_key";
$pub->encrypt($text);
}
sub decrypt(@)
{ my ($self, $text) = @_;
my $priv = $self->privateKeyRSA
or error "decrypting rsa requires the private_key";
$priv->decrypt($text);
}
#XXX Unused? See checker()
sub check($$)
{ my ($self, $text, $signature) = @_;
my $rsa = $self->publicKeyRSA
or error "checking signature with rsa requires the public_key";
$rsa->verify($text, $signature);
}
### above functions probably not needed.
sub builder()
{ my ($self) = @_;
my $priv = $self->privateKeyRSA
or error "signing rsa requires the private_key";
sub { $priv->sign($_[0]) };
}
sub checker()
{ my ($self) = @_;
my $pub = $self->publicKeyRSA
or error "checking signature with rsa requires the public_key";
sub { # ($text, $signature)
lib/XML/Compile/WSS/Sign/RSA.pod view on Meta::CPAN
=item XML::Compile::WSS::Sign::RSA-E<gt>B<fromConfig>(HASH|PAIRS)
Inherited, see L<XML::Compile::WSS::Sign/"Constructors">
=item XML::Compile::WSS::Sign::RSA-E<gt>B<new>(%options)
-Option --Defined in --Default
hashing <undef>
padding <undef>
private_key undef
public_key <from private key>
sign_method XML::Compile::WSS::Sign DSIG_RSA_SHA1
=over 2
=item hashing => 'SHA1'|'MD5'|...
=item padding => 'NO'|'PKCS1'|...
=item private_key => OBJECT|STRING|FILENAME
Required if you want to use this object to sign. See L<privateKey()|XML::Compile::WSS::Sign::RSA/"Attributes">
=item public_key => OBJECT|STRING|FILENAME
Required if you want to use this object to L<check()|XML::Compile::WSS::Sign::RSA/"Handlers">. See L<publicKey()|XML::Compile::WSS::Sign::RSA/"Attributes">
Usually, you need either the public or the private key, not both. However,
when you specify a private key, you can ask for the public key as well: it
is included.
lib/XML/Compile/WSS/Sign/RSA.pod view on Meta::CPAN
=back
=head2 Attributes
Extends L<"Attributes" in XML::Compile::WSS::Sign|XML::Compile::WSS::Sign/"Attributes">.
=over 4
=item $obj-E<gt>B<privateKey>( [$key, %options] )
The private key must be set with L<new(private_key)|XML::Compile::WSS::Sign::RSA/"Constructors"> or this method before
you can sign. This method will return the text of the key.
=over 4
=item * an Crypt::OpenSSL::RSA object
=item * PEM formatted key, as accepted by Crypt::OpenSSL::RSA method C<new_private_key()>
=item * a filename which contains such bytes.
=back
-Option --Default
hashing <undef>
padding <undef>
=over 2
lib/XML/Compile/WSS/Signature.pm view on Meta::CPAN
sub init($)
{ my ($self, $args) = @_;
my $wss_v = $args->{wss_version} ||= '1.1';
$self->SUPER::init($args);
my $signer = delete $args->{signer} || {};
blessed $signer || ref $signer
or $signer = +{ sign_method => $signer }; # pre 2.00
$signer->{private_key} ||= delete $args->{private_key}; # pre 2.00
$self->{XCWS_signer} =
XML::Compile::WSS::Sign->fromConfig(%$signer, wss => $self);
my $si = delete $args->{signed_info} || {};
$si->{$_} ||= delete $args->{$_}
for qw/digest_method cannon_method prefix_list/; # pre 2.00
$self->{XCWS_siginfo} =
XML::Compile::WSS::SignedInfo->fromConfig(%$si, wss => $self);
t/20signature.t view on Meta::CPAN
my $wss = XML::Compile::SOAP::WSS->new;
my $wsdl = XML::Compile::WSDL11->new($wsdlfn);
my $token = XML::Compile::WSS::SecToken::X509v3->fromFile($certfn);
isa_ok($token, 'XML::Compile::WSS::SecToken::X509v3');
my $sig = $wss->signature
( digest_method => DSIGM_SHA384
, signer => DSIGM_RSA_SHA384
, canon_method => C14N_EXC_NO_COMM # default
, private_key => $privkeyfn
, token => $token
);
$wsdl->compileCalls(transport_hook => \&fake_server);
my ($out, $trace) = $wsdl->call($anyop, One => 1, Two => 2, Three => 3);
#warn "******* CALL END";
#warn Dumper $out;
$trace->printErrors;
#$trace->printResponse;
#my ($out2, $trace2) = $wsdl->call($anyop, One => 1, Two => 2, Three => 3);
t/31keyinfo.t view on Meta::CPAN
my $schema = XML::Compile::Cache->new;
ok(defined $schema);
my $wss = XML::Compile::WSS::Signature->new
( version => '1.1'
, schema => $schema
, token => 'dummy'
, sign_types => []
, sign_put => []
, private_key => $privkey_fn
);
isa_ok($wss, 'XML::Compile::WSS');
isa_ok($wss, 'XML::Compile::WSS::Signature');
### top-level KeyInfo readers and writers
use_ok('XML::Compile::WSS::KeyInfo');
my $ki = XML::Compile::WSS::KeyInfo->new;
isa_ok($ki, 'XML::Compile::WSS::KeyInfo');
( run in 0.274 second using v1.01-cache-2.11-cpan-4d50c553e7e )