SOAP-Clean

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

Changes
MANIFEST
Makefile.PL
README
bin/wsdl-client.pl
crypto-files/CAcert.pem
crypto-files/CAkey.pem
crypto-files/KEY.pem
crypto-files/dsig.tmpl
crypto-files/enc.tmpl
crypto-files/private.pem
crypto-files/private2.pem
crypto-files/public.pem
crypto-files/public2.pem
doc/cgi-env.txt
doc/descr.txt
examples/a.xml
examples/soap-client.pl
examples/soap-client.sh

crypto-files/ChangeLog  view on Meta::CPAN

2002-11-12  Paul Stodghill  <stodghil@quimby-xp>

	* CAcert.pem, CAkey.pem, KEY.pem, dsig.tmpl, enc.tmpl, private.pem, private2.pem, public.pem, public2.pem:
	"Original version". Taken from ../

crypto-files/dsig.tmpl  view on Meta::CPAN

       <wsse:Security
             xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext"
	      xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
         <ds:Signature>
            <ds:SignedInfo>
               <ds:CanonicalizationMethod
                   Algorithm=
                          "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
               <ds:SignatureMethod 
                        Algorithm=
                        "http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
               <ds:Reference URI="#MsgBody">
                  <ds:DigestMethod 
                          Algorithm=
                        "http://www.w3.org/2000/09/xmldsig#sha1"/>
                  <ds:DigestValue></ds:DigestValue>
               </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue></ds:SignatureValue>
            <ds:KeyInfo>
                <ds:X509Data>
	        </ds:X509Data>
            </ds:KeyInfo>
        </ds:Signature>
      </wsse:Security>

crypto-files/enc.tmpl  view on Meta::CPAN

<?xml version="1.0" encoding="UTF-8"?>
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" 
                    xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
  <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
  <ds:KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <xenc:EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
        <ds:DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      </xenc:EncryptionMethod>
      <ds:KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
      </ds:KeyInfo>
      <xenc:CipherData>
        <xenc:CipherValue>
        </xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedKey>
    <xenc:EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
        <ds:DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      </xenc:EncryptionMethod>
      <ds:KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
      </ds:KeyInfo>
      <xenc:CipherData>
        <xenc:CipherValue>
        </xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedKey>
  </ds:KeyInfo>
  <xenc:CipherData>
    <xenc:CipherValue>
    </xenc:CipherValue>

examples/soap-client.pl  view on Meta::CPAN

print "Setting up server\n";
print "--------------------------------------------------\n";

my $test = 
  new SOAP::Clean::Client(
			  'cgifile:./soap-server.cgi?wsdl'
#			  'cgifile:./soap-server2.cgi?wsdl'
			 )
   ->verbose(2)
#  ->enc_dec_params(1,"private.pem","public2.pem","enc.tmpl","xmlsec")
#  ->dsig_keys(0,"CAkey.pem","CAcert.pem","dsig.tmpl","xmlsec")
  ;

my $a = xml_from_string("<?xml version=\"1.0\"?>"
			."<a>123</a>");

my ($result,$out1,$out2);

########################################################################

print "--------------------------------------------------\n";

examples/soap-server.cgi  view on Meta::CPAN

#! /usr/bin/env perl

# This file is placed in the public domain.

use lib '..';

use SOAP::Clean::CGI;

new SOAP::Clean::CGI
#  ->enc_dec_params(1,"private2.pem","public.pem","enc.tmpl","xmlsec")
#  ->dsig_keys(0,"CAcert.pem","xmlsec")
  ->urn('cgifile:./soap-server.cgi')
  ->name('soap_server')
  ->full_name('SOAP::Clean Test Server')
  ->descr("./soap-server.sh -x[in file x:raw] -y[in y:string] -s[in sleep_for:int=5]"
	  ."    [in file w:xml]"
	  ."    [out file out1:raw] [out file out2:xml] > [out file result:int]")
  ->in_order(qw(sleep_for w x y))
  ->out_order(qw(result out1 out2))
  ->go();

examples/soap-server2.cgi  view on Meta::CPAN


# This file is placed in the public domain.

use lib '..';

use SOAP::Clean::Server;
use SOAP::Clean::CGI;

new SOAP::Clean::CGI
#  ->enc_dec_params(1,"private2.pem","public.pem","enc.tmpl","xmlsec")
#  ->dsig_keys(0,"CAcert.pem","xmlsec")
  ->urn('cgifile:./soap-server.cgi')
  ->name('soap_server')
  ->full_name('SOAP::Clean Test Server')
  ->params(
	   default(in(val('sleep_for','int')),5),
	   in(file('w','xml')),
	   in(file('x','raw')),
	   in(val('y','string')),
	   out(file('result','int')),
	   out(file('out1','raw')),

lib/SOAP/Clean/CGI.pm  view on Meta::CPAN

  # Read the request from STDIN
  my $request = xml_from_fh(\*STDIN);
  defined($request) || assert(0,"Can't parse request?!?");

  # Take a SOAP request. Parse it and extract the method name and
  # arguments. Call the appropriate function for the method. Package the
  # results into a SOAP response and return it.

  # Here we verify the digital signature if the server wants to check
  # digital signatures
  if (defined($self->{dsig})) { verify_envelope($self,$request); }

  #### DECRYPTION HERE #########
  if (defined($self->{enc})) { decrypt_body($self,$request); }

  my $envelope = xml_get_child($request,$SOAP_ENV,'Envelope');
  assert(defined($envelope));
  my $body = xml_get_child($envelope,$SOAP_ENV,'Body');
  assert(defined($body));

  # The body contains a single element which is the message.

lib/SOAP/Clean/CGI.pm  view on Meta::CPAN

  print header,
    start_html($server_name.": Results"),
      h1($server_name.": Results"), p;

  if (!param()) {
    print "No params? How did you manage that?", hr;
    print end_html;
    return 1;
  }

  # Throw an error if either dsig or enc was expected.
  if (defined($self->{dsig})) { 
    assert(0,"No digitial signatures for POST's");
  }
  if (defined($self->{enc})) { 
    assert(0,"No encryption for POST's");
  }

  # Determine the formal parameters based on the method name
  my @formal_params;
  if ( $method_name eq "Call" || $method_name eq "Spawn" ) {
    my %h = ();

lib/SOAP/Clean/ChangeLog  view on Meta::CPAN

	* Client.pm:
	Pretty much completely rewritten to handle WSDL.

	* Internal.pm:
	arg_encode: Function for encoding arguments.

	soaphttp:
	wsdl_http:
	wsdl_mime: new globals used in WSDL.pm

	dsig_keys:
	enc_dec_params: Moved from Client.pm and CGI.pm

	descr_file
	descr
	urn
	name
	full_name: Moved to CGI.pm

	_comm: Now takes a hash of extra headers.

	read_descr
	parse_descr: Moved to CGI.pm

	* CGI.pm: dsig_keys:
	enc_dec_params: Internal.pm

	descr_file:
	descr:
	urn:
	name:
	full_name: Moved from Internal.pm

	in_order:
	out_order: New functions to establish the argument and result order.

lib/SOAP/Clean/Client.pm  view on Meta::CPAN

  # specified
  if (defined($self->{enc})) {
    SOAP::Clean::Security::encrypt_body($d,
					$self->{privkeyenc},
					$self->{pubkeyenc},
					$self->{enctmpl},
					$self->{appl});
  }

  # Sign the envelope
  if (defined($self->{dsig})) { $self->_dsign_envelope($d); }

  # Send it the request envelope and receive the response envelope
  my $request_str = xml_to_string($d,1);
  my $response =
    $self->_comm($method_name,$location,$request_method,
		 { 'Content-Type' => "text/xml",
		   'SOAPAction' => $$operation{soapAction} },
		 $request_str);
  ($response->code == 200)
    || die("SOAP request failed. Response follows:\n".

lib/SOAP/Clean/Internal.pm  view on Meta::CPAN


########################################################################
# Global variable initialization
########################################################################

# initialize package globals, first exported ones

our $SOAP_ENC = "http://schemas.xmlsoap.org/soap/encoding/";
our $SOAP_ENV = "http://schemas.xmlsoap.org/soap/envelope/";
our $soaphttp = "http://schemas.xmlsoap.org/soap/http";
our $ds = "http://www.w3.org/2000/09/xmldsig#";
our $wsdl = "http://schemas.xmlsoap.org/wsdl/";
our $wsdl_http = "http://schemas.xmlsoap.org/wsdl/http/";
our $wsdl_mime = "http://schemas.xmlsoap.org/wsdl/mime/";
our $wsdl_soap = "http://schemas.xmlsoap.org/wsdl/soap/";
our $wsse = "http://schemas.xmlsoap.org/ws/2002/04/secext";
our $xenc = "http://www.w3.org/2001/04/xmlenc#";
our $xsd = "http://www.w3.org/2001/XMLSchema";
our $xsi = "http://www.w3.org/2001/XMLSchema-instance";


lib/SOAP/Clean/Internal.pm  view on Meta::CPAN

  my ($self) = @_;
  return ($self->{request_count},$self->{response_count});
}

sub verbose {
  my ($self,$verbose_level) = @_;
  $self->{verbose} = $verbose_level;
  return $self;
}

sub dsig_keys{
  my ($self,$dsigcl,$key_file,$cert_file,$tmpl_file,$appl) = @_;
  $self->{dsig} = $dsigcl;
  $self->{key} = $key_file;
  $self->{cert} = $cert_file;
  $self->{tmpl} = $tmpl_file;
  $self->{appl} = $appl;
  return $self;
}       

sub enc_dec_params{
  my ($self,$enccl,$privkey_file_enc,$pubkey_file_enc,$tmpl_file,$appl) = @_;
  $self->{enc} = $enccl;

lib/SOAP/Clean/Security.pm  view on Meta::CPAN

  @ISA         = qw(Exporter);
  @EXPORT      = qw(
		   );
};

########################################################################

#Digitally signing a document
sub digsign {
  my ($doc,$keyfile,$certfile,$sigapp) = @_;
  my $in_tmp = "/tmp/tmpdsig.tmpl";
  my $in_tmp2 = "/tmp/tmpdsig2.tmpl";
  open DOCIN, "> $in_tmp" || die("SOAP-ENV:Server - Error! Line ".__LINE__);
  print DOCIN "$doc";
  close DOCIN ||
        die("SOAP-ENV:Server - Error! Line ".__LINE__);
  system ("$sigapp sign --privkey $keyfile,$certfile $in_tmp > $in_tmp2");
  my $newdoc = docinsert($in_tmp2);
  return $newdoc;
}

########################################################################

#Verifying a signed document
sub digverify {
  my ($doc,$certfile,$sigapp) = @_;
  my $in_tmp = "/tmp/tmpdsigsrv.tmpl";
  my $in_tmp2 = "/tmp/dsiganswer.tmpl";
  open DOCIN, "> $in_tmp" || die("SOAP-ENV:Server - Error! Line ".__LINE__);
  print DOCIN "$doc";
  close DOCIN ||
        die("SOAP-ENV:Server - Error! Line ".__LINE__);
  system ("$sigapp verify --trusted $certfile $in_tmp > $in_tmp2");
  open ANS, "< $in_tmp2";

  my $newdoc = <ANS>;
  return $newdoc;

lib/SOAP/Clean/Security.pm  view on Meta::CPAN

  my $newdoc = docinsert($in_tmp2);
  return $newdoc;
}

########################################################################

sub verify_envelope {
  my ($server,$d) = @_;


  defined($server->{dsig}) ||
    die("Error! file \"".__FILE__."\", line ".__LINE__);

  my $verification = 
    digverify(xml_to_string($d),$server->{cert},$server->{appl});
  $verification eq "OK\n" ||
    die("Error, your signature is a fraud!");
}


########################################################################



( run in 2.220 seconds using v1.01-cache-2.11-cpan-71847e10f99 )