@@ -363,15 +363,13 @@ def sign(self, data, key=None, passphrase=None, cert=None, reference_uri=None, k
363
363
364
364
hash_alg = self ._get_signature_digest_method_by_tag (self .sign_alg )
365
365
if self .sign_alg .startswith ("dsa-" ):
366
- signer = key .signer ( signature_algorithm = hash_alg )
366
+ signature = key .sign ( signed_info_c14n , algorithm = hash_alg )
367
367
elif self .sign_alg .startswith ("ecdsa-" ):
368
- signer = key .signer ( signature_algorithm = ec .ECDSA (algorithm = hash_alg ))
368
+ signature = key .sign ( signed_info_c14n , signature_algorithm = ec .ECDSA (algorithm = hash_alg ))
369
369
elif self .sign_alg .startswith ("rsa-" ):
370
- signer = key .signer ( padding = PKCS1v15 (), algorithm = hash_alg )
370
+ signature = key .sign ( signed_info_c14n , padding = PKCS1v15 (), algorithm = hash_alg )
371
371
else :
372
372
raise NotImplementedError ()
373
- signer .update (signed_info_c14n )
374
- signature = signer .finalize ()
375
373
if self .sign_alg .startswith ("dsa-" ):
376
374
# Note: The output of the DSA signer is a DER-encoded ASN.1 sequence of two DER integers.
377
375
from asn1crypto .algos import DSASignature
@@ -534,7 +532,9 @@ def _verify_signature_with_pubkey(self, signed_info_c14n, raw_signature, key_val
534
532
y = bytes_to_long (key_data [len (key_data )// 2 :])
535
533
curve_class = self .known_ecdsa_curves [named_curve .get ("URI" )]
536
534
key = ec .EllipticCurvePublicNumbers (x = x , y = y , curve = curve_class ()).public_key (backend = default_backend ())
537
- verifier = key .verifier (raw_signature , ec .ECDSA (self ._get_signature_digest_method (signature_alg )))
535
+ key .verify (raw_signature ,
536
+ data = signed_info_c14n ,
537
+ signature_algorithm = ec .ECDSA (self ._get_signature_digest_method (signature_alg )))
538
538
elif "dsa-" in signature_alg :
539
539
dsa_key_value = self ._find (key_value , "DSAKeyValue" )
540
540
p = self ._get_long (dsa_key_value , "P" )
@@ -545,20 +545,21 @@ def _verify_signature_with_pubkey(self, signed_info_c14n, raw_signature, key_val
545
545
key = pn .public_key (backend = default_backend ())
546
546
from asn1crypto .algos import DSASignature
547
547
sig_as_der_seq = DSASignature .from_p1363 (raw_signature ).dump ()
548
- verifier = key .verifier (sig_as_der_seq , self ._get_signature_digest_method (signature_alg ))
548
+ key .verify (sig_as_der_seq ,
549
+ data = signed_info_c14n ,
550
+ algorithm = self ._get_signature_digest_method (signature_alg ))
549
551
elif "rsa-" in signature_alg :
550
552
rsa_key_value = self ._find (key_value , "RSAKeyValue" )
551
553
modulus = self ._get_long (rsa_key_value , "Modulus" )
552
554
exponent = self ._get_long (rsa_key_value , "Exponent" )
553
555
key = rsa .RSAPublicNumbers (e = exponent , n = modulus ).public_key (backend = default_backend ())
554
- verifier = key .verifier (raw_signature , padding = PKCS1v15 (),
555
- algorithm = self ._get_signature_digest_method (signature_alg ))
556
+ key .verify (raw_signature ,
557
+ data = signed_info_c14n ,
558
+ padding = PKCS1v15 (),
559
+ algorithm = self ._get_signature_digest_method (signature_alg ))
556
560
else :
557
561
raise NotImplementedError ()
558
562
559
- verifier .update (signed_info_c14n )
560
- verifier .verify ()
561
-
562
563
def _get_inclusive_ns_prefixes (self , transform_node ):
563
564
inclusive_namespaces = transform_node .find ("./ec:InclusiveNamespaces[@PrefixList]" , namespaces = namespaces )
564
565
if inclusive_namespaces is None :
0 commit comments