signxml icon indicating copy to clipboard operation
signxml copied to clipboard

_check_key_value_matches_cert_public_key overwrites public_key variable for ECDSA

Open msetina opened this issue 11 months ago • 1 comments

def _check_key_value_matches_cert_public_key(self, key_value, public_key, signature_alg: SignatureMethod):
        if signature_alg.name.startswith("ECDSA_") and isinstance(
            public_key.to_cryptography_key(), ec.EllipticCurvePublicKey
        ):
            ec_key_value = self._find(key_value, "dsig11:ECKeyValue")
            named_curve = self._find(ec_key_value, "dsig11:NamedCurve")
            public_key = self._find(ec_key_value, "dsig11:PublicKey")
            key_data = b64decode(public_key.text)[1:]
            x = bytes_to_long(key_data[: len(key_data) // 2])
            y = bytes_to_long(key_data[len(key_data) // 2 :])
            curve_class = self.known_ecdsa_curves[named_curve.get("URI")]

            pubk_curve = public_key.to_cryptography_key().public_numbers().curve
            pubk_x = public_key.to_cryptography_key().public_numbers().x
            pubk_y = public_key.to_cryptography_key().public_numbers().y

            return curve_class == pubk_curve and x == pubk_x and y == pubk_y

it overwrites public_key variable when getting "dsig11:PublicKey" from XML

msetina avatar Mar 16 '24 15:03 msetina