2222DS = ElementMaker (namespace = NS ['ds' ], nsmap = NSDefault )
2323
2424
25+ log = logging .getLogger ('xmlsec' )
26+
2527class Config (object ):
2628 """
2729 This class holds a set of configuration parameters (using pyconfig) for pyXMLSecurity:
@@ -92,7 +94,7 @@ def _signed_value(data, key_size, do_pad, hash_alg): # TODO Do proper asn1 CMS
9294
9395def _get_by_id (t , id_v ):
9496 for id_a in config .id_attributes :
95- logging .debug ("Looking for #%s using id attribute '%s'" % (id_v , id_a ))
97+ log .debug ("Looking for #%s using id attribute '%s'" % (id_v , id_a ))
9698 elts = t .xpath ("//*[@%s='%s']" % (id_a , id_v ))
9799 if elts is not None and len (elts ) > 0 :
98100 return elts [0 ]
@@ -176,21 +178,21 @@ def _process_references(t, sig, verify_mode=True, sig_path=".//{%s}Signature" %
176178 fd .write (obj )
177179
178180 hash_alg = _ref_digest (ref )
179- logging .debug ("using hash algorithm %s" % hash_alg )
181+ log .debug ("using hash algorithm %s" % hash_alg )
180182 digest = xmlsec .crypto ._digest (obj , hash_alg )
181- logging .debug ("computed %s digest %s for ref %s" % (hash_alg , digest , uri ))
183+ log .debug ("computed %s digest %s for ref %s" % (hash_alg , digest , uri ))
182184 dv = ref .find (".//{%s}DigestValue" % NS ['ds' ])
183185
184186 if verify_mode :
185- logging .debug ("found %s digest %s for ref %s" % (hash_alg , dv .text , uri ))
187+ log .debug ("found %s digest %s for ref %s" % (hash_alg , dv .text , uri ))
186188 computed_digest_binary = b64d (digest )
187189 digest_binary = b64d (dv .text )
188190 if digest_binary == computed_digest_binary : # no point in verifying signature if the digest doesn't match
189191 verified_objects [ref ] = obj_copy
190192 else :
191- logging .error ("not returning ref %s - digest mismatch" % uri )
193+ log .error ("not returning ref %s - digest mismatch" % uri )
192194 else : # signing - lets store the digest
193- logging .debug ("replacing digest in %s" % etree .tostring (dv ))
195+ log .debug ("replacing digest in %s" % etree .tostring (dv ))
194196 dv .text = digest
195197
196198
@@ -306,12 +308,12 @@ def _verify(t, keyspec, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=F
306308 if not sv :
307309 raise XMLSigException ("No SignatureValue" )
308310
309- logging .debug ("SignatureValue: {!s}" .format (sv ))
311+ log .debug ("SignatureValue: {!s}" .format (sv ))
310312 this_cert = xmlsec .crypto .from_keyspec (keyspec , signature_element = sig )
311- logging .debug ("key size: {!s} bits" .format (this_cert .keysize ))
313+ log .debug ("key size: {!s} bits" .format (this_cert .keysize ))
312314
313315 si = sig .find (".//{%s}SignedInfo" % NS ['ds' ])
314- logging .debug ("Found signedinfo {!s}" .format (etree .tostring (si )))
316+ log .debug ("Found signedinfo {!s}" .format (etree .tostring (si )))
315317 cm_alg = _cm_alg (si )
316318 try :
317319 sig_digest_alg = _sig_alg (si )
@@ -321,12 +323,12 @@ def _verify(t, keyspec, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=F
321323 refmap = _process_references (t , sig , verify_mode = True , sig_path = sig_path , drop_signature = drop_signature )
322324 for ref ,obj in refmap .items ():
323325
324- logging .debug ("transform %s on %s" % (cm_alg , etree .tostring (si )))
326+ log .debug ("transform %s on %s" % (cm_alg , etree .tostring (si )))
325327 sic = _transform (cm_alg , si )
326- logging .debug ("SignedInfo C14N: %s" % sic )
328+ log .debug ("SignedInfo C14N: %s" % sic )
327329 if this_cert .do_digest :
328330 digest = xmlsec .crypto ._digest (sic , sig_digest_alg )
329- logging .debug ("SignedInfo digest: %s" % digest )
331+ log .debug ("SignedInfo digest: %s" % digest )
330332 b_digest = b64d (digest )
331333 actual = _signed_value (b_digest , this_cert .keysize , True , sig_digest_alg )
332334 else :
@@ -336,7 +338,7 @@ def _verify(t, keyspec, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=F
336338 raise XMLSigException ("Failed to validate {!s} using sig digest {!s} and cm {!s}" .format (etree .tostring (sig ), sig_digest_alg , cm_alg ))
337339 validated .append (obj )
338340 except XMLSigException as ex :
339- logging .error (ex )
341+ log .error (ex )
340342
341343 if not validated :
342344 raise XMLSigException ("No valid ds:Signature elements found" )
@@ -437,7 +439,7 @@ def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path
437439 raise XMLSigException ("Public and private key sizes do not match ({!s}, {!s})" .format (
438440 public .keysize , private .keysize ))
439441 # This might be incorrect for PKCS#11 tokens if we have no public key
440- logging .debug ("Using {!s} bit key" .format (private .keysize ))
442+ log .debug ("Using {!s} bit key" .format (private .keysize ))
441443 sig_paths = t .findall (sig_path )
442444 templates = list (filter (_is_template , sig_paths ))
443445 if not templates :
@@ -451,22 +453,22 @@ def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path
451453 fd .write (etree_to_string (root_elt (t )))
452454
453455 for sig in templates :
454- logging .debug ("processing sig template: %s" % etree .tostring (sig ))
456+ log .debug ("processing sig template: %s" % etree .tostring (sig ))
455457 si = sig .find (".//{%s}SignedInfo" % NS ['ds' ])
456458 assert si is not None
457459 cm_alg = _cm_alg (si )
458460 sig_alg = _sig_alg (si )
459461
460462 _process_references (t , sig , verify_mode = False , sig_path = sig_path )
461463 # XXX create signature reference duplicates/overlaps process references unless a c14 is part of transforms
462- logging .debug ("transform %s on %s" % (cm_alg , etree .tostring (si )))
464+ log .debug ("transform %s on %s" % (cm_alg , etree .tostring (si )))
463465 sic = _transform (cm_alg , si )
464- logging .debug ("SignedInfo C14N: %s" % sic )
466+ log .debug ("SignedInfo C14N: %s" % sic )
465467
466468 # sign hash digest and insert it into the XML
467469 if private .do_digest :
468470 digest = xmlsec .crypto ._digest (sic , sig_alg )
469- logging .debug ("SignedInfo digest: %s" % digest )
471+ log .debug ("SignedInfo digest: %s" % digest )
470472 b_digest = b64d (digest )
471473 tbs = _signed_value (b_digest , private .keysize , private .do_padding , sig_alg )
472474 else :
@@ -476,7 +478,7 @@ def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path
476478 signature = b64e (signed )
477479 if isinstance (signature , six .binary_type ):
478480 signature = six .text_type (signature , 'utf-8' )
479- logging .debug ("SignatureValue: %s" % signature )
481+ log .debug ("SignatureValue: %s" % signature )
480482 sv = sig .find (".//{%s}SignatureValue" % NS ['ds' ])
481483 if sv is None :
482484 si .addnext (DS .SignatureValue (signature ))
0 commit comments