Exemple #1
0
def parse(content, signature, user=None):
    """# Create single notification Event from a content string
    Create a single Event object received from event listening at subscribed user endpoint.
    If the provided digital signature does not check out with the StarkBank public key, a
    starkbank.exception.InvalidSignatureException will be raised.
    ## Parameters (required):
    - content [string]: response content from request received at user endpoint (not parsed)
    - signature [string]: base-64 digital signature received at response header "Digital-Signature"
    ## Parameters (optional):
    - user [Organization/Project object, default None]: Organization or Project object. Not necessary if starkbank.user was set before function call
    ## Return:
    - Parsed Event object
    """
    event = from_api_json(_resource, loads(content)["event"])

    try:
        signature = Signature.fromBase64(signature)
    except:
        raise InvalidSignatureError("The provided signature is not valid")

    public_key = _get_public_key(user=user)
    if _is_valid(content=content, signature=signature, public_key=public_key):
        return event

    public_key = _get_public_key(user=user, refresh=True)
    if _is_valid(content=content, signature=signature, public_key=public_key):
        return event

    raise InvalidSignatureError(
        "The provided signature and content do not match the Stark Bank public key"
    )
Exemple #2
0
    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)
    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.recoveryId, signature2.recoveryId)
Exemple #4
0
    def testMany(self):
        for _ in range(1000):
            privateKey1 = PrivateKey()
            publicKey1 = privateKey1.publicKey()

            privateKeyPem = privateKey1.toPem()
            publicKeyPem = publicKey1.toPem()

            privateKey2 = PrivateKey.fromPem(privateKeyPem)
            publicKey2 = PublicKey.fromPem(publicKeyPem)

            message = "test"

            signatureBase64 = Ecdsa.sign(message=message,
                                         privateKey=privateKey2).toBase64()
            signature = Signature.fromBase64(signatureBase64)

            self.assertTrue(
                Ecdsa.verify(message=message,
                             signature=signature,
                             publicKey=publicKey2))
Exemple #5
0
def TestOneInput(input_bytes):
    fdp = atheris.FuzzedDataProvider(input_bytes)

    privateKey1 = PrivateKey()
    publicKey1 = privateKey1.publicKey()

    privateKeyPem = privateKey1.toPem()
    publicKeyPem = publicKey1.toPem()

    privateKey2 = PrivateKey.fromPem(privateKeyPem)
    publicKey2 = PublicKey.fromPem(publicKeyPem)

    message = fdp.ConsumeUnicode(sys.maxsize)

    signatureBase64 = Ecdsa.sign(message=message,
                                 privateKey=privateKey2).toBase64()

    signature = Signature.fromBase64(signatureBase64)
    assert (Ecdsa.verify(message=message,
                         signature=signature,
                         publicKey=publicKey2))