@@ -107,8 +107,10 @@ sub _assert_encryption_digest {
107107 state $ENC_DIGEST = {
108108 ' http://www.w3.org/2000/09/xmldsig#sha1' => ' SHA1' ,
109109 ' http://www.w3.org/2001/04/xmlenc#sha256' => ' SHA256' ,
110+ ' http://www.w3.org/2001/04/xmldsig-more#sha224' => ' SHA224' ,
111+ ' http://www.w3.org/2001/04/xmldsig-more#sha384' => ' SHA384' ,
112+ ' http://www.w3.org/2001/04/xmlenc#sha512' => ' SHA512' ,
110113 };
111-
112114 die " Unsupported encryption digest algo $algo " unless $ENC_DIGEST -> { $algo };
113115 return $ENC_DIGEST -> { $algo };
114116}
@@ -196,6 +198,37 @@ Used in encryption. Optional. Default method: mgf1sha1
196198
197199=back
198200
201+ =item B<oaep_params >
202+
203+ Specify the OAEPparams value to use as part of the mask generation function (MGF).
204+ It is optional but can be specified for rsa-oaep and rsa-oaep-mgf1p EncryptionMethods.
205+
206+ It is base64 encoded and stored in the XML as OAEPparams.
207+
208+ If specified you MAY specify the oaep_label_hash that should be used. You should note
209+ that not all implementations support an oaep_label_hash that differs from that of the
210+ MGF specified in the xenc11:MGF element or the default MGF1 with SHA1.
211+
212+ The oaep_label_hash is stored in the DigestMethod child element of the EncryptionMethod.
213+
214+ =item B<oaep_label_hash >
215+
216+ Specify the Hash Algorithm to use for the rsa-oaep label as specified by oaep_params.
217+
218+ The default is sha1. Supported algorithms are:
219+
220+ =over
221+
222+ =item * L<sha1|http://www.w3.org/2000/09/xmldsig#sha1>
223+
224+ =item * L<sha224|http://www.w3.org/2001/04/xmldsig-more#sha224>
225+
226+ =item * L<sha256|http://www.w3.org/2001/04/xmlenc#sha256>
227+
228+ =item * L<sha384|http://www.w3.org/2001/04/xmldsig-more#sha384>
229+
230+ =item * L<sha512|http://www.w3.org/2001/04/xmlenc#sha512>
231+
199232=back
200233
201234=cut
@@ -225,8 +258,12 @@ sub new {
225258 my $key_method = exists ($params -> {' key_transport' }) ? $params -> {' key_transport' } : ' rsa-oaep-mgf1p ' ;
226259 $self -> {' key_transport' } = $self -> _setKeyEncryptionMethod($key_method );
227260
228- my $oaep_mgf_alg = exists ($params -> {' oaep_mgf_alg' }) ? $params -> {' oaep_mgf_alg' } : ' http://www.w3.org/2009/xmlenc11#mgf1sha1' ;
229- $self -> {' oaep_mgf_alg' } = $self -> _setOAEPAlgorithm($oaep_mgf_alg );
261+ if (exists $params -> {' oaep_mgf_alg' }) {
262+ $self -> {' oaep_mgf_alg' } = $self -> _setOAEPAlgorithm($params -> {' oaep_mgf_alg' });
263+ }
264+ if (exists $params -> {' oaep_label_hash' } ) {
265+ $self -> {' oaep_label_hash' } = $self -> _setOAEPDigest($params -> {' oaep_label_hash' });
266+ }
230267
231268 $self -> {' oaep_params' } = exists ($params -> {' oaep_params' }) ? $params -> {' oaep_params' } : ' ' ;
232269
@@ -576,6 +613,36 @@ sub _getOAEPAlgorithm {
576613 return $OAEPAlgorithm -> {$method } // ' SHA1' ;
577614}
578615
616+ sub _setOAEPDigest {
617+ my $self = shift ;
618+ my $method = shift ;
619+
620+ state $OAEPDigest = {
621+ ' sha1' => ' http://www.w3.org/2000/09/xmldsig#sha1' ,
622+ ' sha224' => ' http://www.w3.org/2001/04/xmldsig-more#sha224' ,
623+ ' sha256' => ' http://www.w3.org/2001/04/xmlenc#sha256' ,
624+ ' sha384' => ' http://www.w3.org/2001/04/xmldsig-more#sha384' ,
625+ ' sha512' => ' http://www.w3.org/2001/04/xmlenc#sha512' ,
626+ };
627+
628+ return $OAEPDigest -> {$method } // $OAEPDigest -> {' sha256' };
629+ }
630+
631+ sub _getParamsAlgorithm {
632+ my $self = shift ;
633+ my $method = shift ;
634+
635+ state $ParamsAlgorithm = {
636+ ' http://www.w3.org/2000/09/xmldsig#sha1' => ' SHA1' ,
637+ ' http://www.w3.org/2001/04/xmldsig-more#sha224' => ' SHA224' ,
638+ ' http://www.w3.org/2001/04/xmlenc#sha256' => ' SHA256' ,
639+ ' http://www.w3.org/2001/04/xmldsig-more#sha384' => ' SHA384' ,
640+ ' http://www.w3.org/2001/04/xmlenc#sha512' => ' SHA512' ,
641+ };
642+
643+ return $ParamsAlgorithm -> {$method } // $ParamsAlgorithm -> {' http://www.w3.org/2000/09/xmldsig#sha1' };
644+ }
645+
579646sub _setKeyEncryptionMethod {
580647 my $self = shift ;
581648 my $method = shift ;
@@ -681,23 +748,45 @@ sub _decrypt_key {
681748 if ($algo eq ' http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' ) {
682749 return _decrypt(
683750 sub {
684- $self -> {key_obj }-> decrypt(
685- $key , ' oaep' ,
686- $digest_name // ' SHA1' ,
687- $oaep // ' '
688- );
751+ if ($CryptX::VERSION le 0.077) {
752+ # print "Caller: _decrypt_key rsa-oaep-mgf1p\n";
753+ $self -> {key_obj }-> decrypt(
754+ $key , ' oaep' ,
755+ # $self->_getOAEPAlgorithm($mgf),
756+ $digest_name // ' SHA1' ,
757+ $oaep // ' ' ,
758+ );
759+ } else {
760+ # print "Caller: _decrypt_key rsa-oaep-mgf1p\n";
761+ # print "digest_name: ", $digest_name, "\n";
762+ $self -> {key_obj }-> decrypt(
763+ $key , ' oaep' ,
764+ $mgf // ' SHA1' ,
765+ $oaep // ' ' ,
766+ $digest_name // ' SHA1' ,
767+ );
768+ }
689769 }
690770 );
691771 }
692772
693773 if ($algo eq ' http://www.w3.org/2009/xmlenc11#rsa-oaep' ) {
694774 return _decrypt(
695775 sub {
696- $self -> {key_obj }-> decrypt(
697- $key , ' oaep' ,
698- $self -> _getOAEPAlgorithm($mgf ),
699- $oaep // ' ' ,
700- );
776+ if ($CryptX::VERSION le 0.077) {
777+ $self -> {key_obj }-> decrypt(
778+ $key , ' oaep' ,
779+ $self -> _getOAEPAlgorithm($mgf ),
780+ $oaep // ' ' ,
781+ );
782+ } else {
783+ $self -> {key_obj }-> decrypt(
784+ $key , ' oaep' ,
785+ $self -> _getOAEPAlgorithm($mgf ),
786+ $oaep // ' ' ,
787+ $digest_name // ' ' ,
788+ );
789+ }
701790 }
702791 );
703792 }
@@ -716,10 +805,35 @@ sub _EncryptKey {
716805 ${$key} = $rsa_pub -> encrypt(${$key} , ' v1.5' );
717806 }
718807 elsif ($keymethod eq ' http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' ) {
719- ${$key} = $rsa_pub -> encrypt(${$key} , ' oaep' , ' SHA1' , $self -> {oaep_params });
808+ if ($CryptX::VERSION le 0.077) {
809+ ${$key} = $rsa_pub -> encrypt(${$key} , ' oaep' , ' SHA1' , $self -> {oaep_params });
810+ } else {
811+ my $oaep_label_hash = (defined $self -> {oaep_label_hash } && $self -> {oaep_label_hash } ne ' ' ) ?
812+ $self -> _getParamsAlgorithm($self -> {oaep_label_hash }) : ' SHA1' ;
813+ my $mgf_hash = defined $self -> {oaep_mgf_alg } ?
814+ $self -> _getOAEPAlgorithm($self -> {oaep_mgf_alg }) : undef ;
815+ # print "Y_mgf_hash: ", $mgf_hash, "\n";
816+ # print "Xoaep_label_hash: ", $oaep_label_hash, "\n";
817+ # print "Xoaep_params: ", $self->{oaep_params}, "\n";
818+ ${$key} = $rsa_pub -> encrypt(${$key} , ' oaep' , ' SHA1' , $self -> {oaep_params }, $oaep_label_hash );
819+ # print "Got Here\n";
820+ }
720821 }
721822 elsif ($keymethod eq ' http://www.w3.org/2009/xmlenc11#rsa-oaep' ) {
722- ${$key} = $rsa_pub -> encrypt(${$key} , ' oaep' , $self -> _getOAEPAlgorithm($self -> {oaep_mgf_alg }), $self -> {oaep_params });
823+ # FIXME
824+ my $mgf_hash = defined $self -> {oaep_mgf_alg } ?
825+ $self -> _getOAEPAlgorithm($self -> {oaep_mgf_alg }) : undef ;
826+ my $oaep_label_hash = (defined $self -> {oaep_label_hash } && $self -> {oaep_label_hash } ne ' ' ) ?
827+ $self -> _getParamsAlgorithm($self -> {oaep_label_hash }) : $mgf_hash ;
828+ # print "Y_mgf_hash: ", $mgf_hash, "\n";
829+ # print "Y_oaep_label_hash: ", $self->{oaep_label_hash}, "\n";
830+ # print "Y_oaep_label_hash: ", $oaep_label_hash, "\n";
831+ # print "Y_oaep_params: ", $self->{oaep_params}, "\n";
832+ if ($CryptX::VERSION le 0.077) {
833+ ${$key} = $rsa_pub -> encrypt(${$key} , ' oaep' , $mgf_hash , $self -> {oaep_params });
834+ } else {
835+ ${$key} = $rsa_pub -> encrypt(${$key} , ' oaep' , $mgf_hash , $self -> {oaep_params }, $oaep_label_hash );
836+ }
723837 } else {
724838 die " Unsupported algorithm for key encyption $keymethod }" ;
725839 }
@@ -1030,6 +1144,20 @@ sub _create_encrypted_data_xml {
10301144 }
10311145 );
10321146
1147+ if ($self -> {key_transport } eq ' http://www.w3.org/2009/xmlenc11#rsa-oaep' ||
1148+ $self -> {key_transport } eq ' http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' &&
1149+ $self -> {oaep_label_hash }) {
1150+ my $digestmethod = $self -> _create_node(
1151+ $doc ,
1152+ $dsigns ,
1153+ $kencmethod ,
1154+ ' dsig:DigestMethod' ,
1155+ {
1156+ Algorithm => $self -> {oaep_label_hash },
1157+ }
1158+ );
1159+ };
1160+
10331161 if ($self -> {' oaep_params' } ne ' ' ) {
10341162 my $oaep_params = $self -> _create_node(
10351163 $doc ,
@@ -1039,7 +1167,8 @@ sub _create_encrypted_data_xml {
10391167 );
10401168 };
10411169
1042- if ($self -> {key_transport } eq ' http://www.w3.org/2009/xmlenc11#rsa-oaep' ) {
1170+ if ($self -> {key_transport } eq ' http://www.w3.org/2009/xmlenc11#rsa-oaep' &&
1171+ $self -> {oaep_mgf_alg }) {
10431172 my $oaepmethod = $self -> _create_node(
10441173 $doc ,
10451174 $xenc11ns ,
0 commit comments