コード例 #1
0
def _verify_signature(content, signature, user=None, refresh=False):
    signature = Signature.fromBase64(signature)
    public_key = cache.get("starkbank-public-key")
    if public_key is None or refresh:
        pem = _get_public_key_pem(user)
        public_key = PublicKey.fromPem(pem)
        cache["starkbank-public-key"] = public_key
    return Ecdsa.verify(message=content, signature=signature, publicKey=public_key)
コード例 #2
0
ファイル: testSignature.py プロジェクト: vsgobbi/ecdsa-python
    def testDerConversion(self):
        privateKey = PrivateKey()
        message = "This is a text message"

        signature1 = Ecdsa.sign(message, privateKey)

        der = signature1.toDer()
        signature2 = Signature.fromDer(fromLatin(der))

        self.assertEqual(signature1.r, signature2.r)
        self.assertEqual(signature1.s, signature2.s)
コード例 #3
0
ファイル: testSignature.py プロジェクト: vsgobbi/ecdsa-python
    def testBase64Conversion(self):
        privateKey = PrivateKey()
        message = "This is a text message"

        signature1 = Ecdsa.sign(message, privateKey)

        base64 = signature1.toBase64()

        signature2 = Signature.fromBase64(base64)

        self.assertEqual(signature1.r, signature2.r)
        self.assertEqual(signature1.s, signature2.s)
コード例 #4
0
    def testDerConversion(self):
        privateKey = PrivateKey()
        message = "This is a text message"

        signature1 = Ecdsa.sign(message, privateKey)

        der = signature1.toDer(withRecoveryId=True)
        signature2 = Signature.fromDer(toBytes(der), recoveryByte=True)

        self.assertEqual(signature1.r, signature2.r)
        self.assertEqual(signature1.s, signature2.s)
        self.assertEqual(signature1.recid, signature2.recid)
コード例 #5
0
    def testBase64Conversion(self):
        privateKey = PrivateKey()
        message = "This is a text message"

        signature1 = Ecdsa.sign(message, privateKey)

        base64 = signature1.toBase64(withRecoveryId=True)

        signature2 = Signature.fromBase64(base64, recoveryByte=True)

        self.assertEqual(signature1.r, signature2.r)
        self.assertEqual(signature1.s, signature2.s)
        self.assertEqual(signature1.recid, signature2.recid)
コード例 #6
0
def verify(dictionary_msg, signature, sender_public_key):
    
    vk, _ = ppk_get_back_object(public_key=sender_public_key)
    if config.DIGITAL_SIGNATURE_ALGO == 'ECDSA':
        h = str(dictionary_msg)
        check = Ecdsa.verify(h, Signature.fromPem(signature), vk) # True
        # log_info("[security.digital_signature.verify] ECDSA Verify result: {}".format(check))
        return check
    elif config.DIGITAL_SIGNATURE_ALGO == 'SCHNORR': 
        h = dict_to_hash(dictionary_msg)
        check = schnorr_verify(h, vk, signature)
        # log_info("[security.digital_signature.verify] Schnorr Verify result: {}".format(check))
        return check
    else:
        log_error("[security.digital_signature.verify] Unknown DSA in config -- cannot verify signature!")
コード例 #7
0
ファイル: testOpenSSL.py プロジェクト: 5l1v3r1/ecdsa-python
    def testVerifySignature(self):
        # openssl ec -in privateKey.pem -pubout -out publicKey.pem

        publicKeyPem = File.read("./publicKey.pem")

        # openssl dgst -sha256 -sign privateKey.pem -out signature.binary message.txt
        signatureDer = File.read("./signatureDer.txt", "rb")

        message = File.read("./message.txt")

        publicKey = PublicKey.fromPem(publicKeyPem)

        signature = Signature.fromDer(string=signatureDer)

        self.assertTrue(Ecdsa.verify(message=message, signature=signature, publicKey=publicKey))
コード例 #8
0
    def verify_signature(self, payload, signature, timestamp, public_key=None):
        """
        Verify signed event webhook requests.

        :param payload: event payload in the request body
        :type payload: string
        :param signature: value obtained from the 'X-Twilio-Email-Event-Webhook-Signature' header
        :type signature: string
        :param timestamp: value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header
        :type timestamp: string
        :param public_key: elliptic curve public key
        :type public_key: PublicKey
        :return: true or false if signature is valid
        """
        timestamped_payload = timestamp + payload
        decoded_signature = Signature.fromBase64(signature)

        key = public_key or self.public_key
        return Ecdsa.verify(timestamped_payload, decoded_signature, key)
コード例 #9
0
def verify_Signature(message, signature_input, publicKey_input):
    publicKey_input = '-----BEGIN PUBLIC KEY-----\n' + publicKey_input + '\n-----END PUBLIC KEY-----\n'
    signature = Signature.fromBase64(signature_input)
    publicKey = PublicKey.fromPem(publicKey_input)
    return (Ecdsa.verify(message, signature, publicKey))
コード例 #10
0
def verify_Signature(message, sign64, str1):
    signature = Signature.fromBase64(sign64)
    publicKey = PublicKey.fromPem(str1)
    return (Ecdsa.verify(message, signature, publicKey))
コード例 #11
0
def verify_Signature(message, sign64, publicKey_input):
    signature = Signature.fromBase64(sign64)
    a = publicKey_input.split(".")
    pt = Point(int(a[0]), int(a[1]), int(a[2]))
    publicKey = PublicKey(point = pt, curve = secp256k1)
    return (Ecdsa.verify(message, signature, publicKey))