Ejemplo n.º 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)
Ejemplo n.º 2
0
 def testPemConversion(self):
     privateKey = PrivateKey()
     publicKey1 = privateKey.publicKey()
     pem = publicKey1.toPem()
     publicKey2 = PublicKey.fromPem(pem)
     self.assertEqual(publicKey1.point.x, publicKey2.point.x)
     self.assertEqual(publicKey1.point.y, publicKey2.point.y)
     self.assertEqual(publicKey1.curve, publicKey2.curve)
Ejemplo n.º 3
0
    def generate_wallet_address(public_key):
        """
        Generates a wallet's address from public key
        :param public_key:
        :return:
        """
        address = (hashlib.sha256(
            PublicKey.fromPem(public_key).toDer().encode()).hexdigest())[0:8]

        return address
Ejemplo n.º 4
0
    def convert_public_key_to_ecdsa(self, public_key):
        """
        Convert the public key string to a ECPublicKey.

        :param public_key: verification key under Mail Settings
        :type public_key string
        :return: public key using the ECDSA algorithm
        :rtype PublicKey
        """
        return PublicKey.fromPem(public_key)
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
 def valid_signature(self, transaction):
     """
     Validates the transaction signature : was the transaction really created by the sender ?
     :param transaction: <dict>
     :return: <bool>
     """
     transaction_copy = transaction.copy() # les dictionnaires sont passés par référence
     signature = transaction_copy.pop("signature")
     ecdsa_signature = ellipticcurve.signature.Signature.fromBase64(signature)
     key = transaction_copy['sender']
     ecdsa_key = PublicKey.fromPem(key)
     try:
         return Ecdsa.verify(self.hash(transaction_copy), ecdsa_signature, ecdsa_key)
     except:
         return False
Ejemplo n.º 7
0
def ppk_get_back_object(public_key=None, private_key=None):
    if config.DIGITAL_SIGNATURE_ALGO == 'ECDSA':
        if private_key:
            private_key = PrivateKey.fromPem(private_key)
        if public_key:
            public_key = PublicKey.fromPem(public_key)
    elif config.DIGITAL_SIGNATURE_ALGO == 'SCHNORR':
        if private_key:
            private_key = hex_to_bytes(private_key)
        if public_key:
            public_key = hex_to_bytes(public_key)
    else:
        log_error(
            "[security.ppk_keygen.ppk_get_back_object] Unknown keygen algo defined"
        )

    return public_key, private_key
Ejemplo n.º 8
0
 def get_public_key(self):
     return PublicKey.fromPem(self.public_key)
Ejemplo n.º 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))
Ejemplo n.º 10
0
def verify_Signature(message, sign64, str1):
    signature = Signature.fromBase64(sign64)
    publicKey = PublicKey.fromPem(str1)
    return (Ecdsa.verify(message, signature, publicKey))
Ejemplo n.º 11
0
 def deserialize_public_key(public_key):
     """
     Deserializes public key
     """
     return PublicKey.fromPem(public_key)
from json import dumps

from ellipticcurve.ecdsa import Ecdsa
from ellipticcurve.privateKey import PrivateKey
from ellipticcurve.ecdsa import Ecdsa
from ellipticcurve.signature import Signature
from ellipticcurve.publicKey import PublicKey
from ellipticcurve.utils.file import File
from sendgrid.helpers.eventwebhook import EventWebhook
import requests

publicKeyPem = File.read("publicKey.pem")
publicKey = PublicKey.fromPem(publicKeyPem)

privateKeyPem = File.read("privateKey.pem")
privateKey = PrivateKey.fromPem(privateKeyPem)


def send_mock_webhook(payload, timestamp):
    message = timestamp + payload
    signature = Ecdsa.sign(message, privateKey)
    base64_signature = signature.toBase64()
    # print("Verified:", Ecdsa.verify(message, signature, publicKey))
    url = 'https://cryptic-caverns-35958.herokuapp.com/mock_webhook'
    headers = {
        'x-twilio-email-event-webhook-timestamp': timestamp,
        'x-twilio-email-event-webhook-signature': base64_signature
    }
    data = payload.encode('utf-8')

    response = requests.post(url, headers=headers, data=data)