Example #1
0
    def _post_decode_hook(self):
        if self.asn1["parameters"] is None:
            raise InvalidInputException(
                "ECC private key does not contain curve OID. Cannot proceed.")
        if self.asn1["publicKey"] is None:
            raise InvalidInputException(
                "ECC private key does not contain public key. Cannot proceed.")

        curve_oid = OID.from_asn1(self.asn1["parameters"])
        self._curve = CurveDB().instantiate(oid=curve_oid)

        self._d = int.from_bytes(self.asn1["privateKey"], byteorder="big")
        (self._x, self._y) = ECCTools.decode_enc_pubkey(
            ASN1Tools.bitstring2bytes(self.asn1["publicKey"]))
Example #2
0
    def _post_decode_hook(self):
        alg_oid = OID.from_asn1(self.asn1["algorithm"]["algorithm"])
        self._pk_alg = PublicKeyAlgorithms.lookup("oid", alg_oid)
        if self._pk_alg is None:
            self._key_decoding_error = "Unable to determine public key algorithm for OID %s." % (
                alg_oid)
            return

        if self._pk_alg not in self._HANDLERS_BY_PK_ALG:
            self._key_decoding_error = "Unable to determine public key handler for public key algorithm %s." % (
                self._pk_alg.name)
            return

        handler_class = self._HANDLERS_BY_PK_ALG[self._pk_alg]
        key_data = ASN1Tools.bitstring2bytes(self.asn1["subjectPublicKey"])
        self._key = handler_class.from_subject_pubkey_info(
            self._pk_alg, self.asn1["algorithm"]["parameters"], key_data)
        self._key_decoding_error = None
Example #3
0
 def signature(self):
     signature = ASN1Tools.bitstring2bytes(self.asn1["signatureValue"])
     return signature
Example #4
0
 def keyid(self, hashfnc="sha1"):
     hashval = hashlib.new(hashfnc)
     inner_key = ASN1Tools.bitstring2bytes(self.asn1["subjectPublicKey"])
     hashval.update(inner_key)
     return hashval.digest()