Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change signature verification hash algorithm from SHA1 to SHA256 #21

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pywisetransfer/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def verify_signature(payload, signature, environment="sandbox"):
)
public_key = load_pem_public_key(key_data, backend=default_backend())
try:
public_key.verify(signature, payload, padding.PKCS1v15(), hashes.SHA1())
public_key.verify(signature, payload, padding.PKCS1v15(), hashes.SHA256())
return True
except InvalidSignature:
return False
8 changes: 4 additions & 4 deletions test/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

@pytest.fixture
def valid_payload():
return b'{"data":{"resource":{"id":0,"profile_id":0,"type":"balance-account"},"amount":0.01,"currency":"EUR","post_transaction_balance_amount":0.01,"occurred_at":"2020-03-02T14:30:03Z","transaction_type":"credit"},"subscription_id":"00000000-0000-0000-0000-000000000000","event_type":"balances#credit","schema_version":"2.0.0","sent_at":"2020-03-02T14:30:03Z"}'
return b'{"data":{"resource":{"id":0,"profile_id":0,"account_id":0,"type":"transfer"},"current_state":"processing","previous_state":"incoming_payment_waiting","occurred_at":"2022-02-23T19:22:53Z"},"subscription_id":"00000000-0000-0000-0000-000000000000","event_type":"transfers#state-change","schema_version":"2.0.0","sent_at":"2022-02-23T19:22:53Z"}'


@pytest.fixture
def corrupt_payload():
return b'{"data":{"resource":{"id":0,"profile_id":0,"type":"balance-account"},"amount":0.02,"currency":"EUR","post_transaction_balance_amount":0.01,"occurred_at":"2020-03-02T14:30:03Z","transaction_type":"credit"},"subscription_id":"00000000-0000-0000-0000-000000000000","event_type":"balances#credit","schema_version":"2.0.0","sent_at":"2020-03-02T14:30:03Z"}'
return b'{"data":{"resource":{"id":0,"profile_id":0,"account_id":0,"type":"transfer"},"current_state":"processing","previous_state":"incoming_payment_waiting","occurred_at":"2022-02-23T19:22:53Z"},"subscription_id":"00000000-0000-0008-8000-000000000000","event_type":"transfers#state-change","schema_version":"2.0.0","sent_at":"2022-02-23T19:22:53Z"}'


@pytest.fixture
def valid_signature():
return "eZsnoryOFBa9lNT2rR0cLU18P84M1SQP7p+tru5f+5KJHnx8yL6nM3jHbSs03ah3Eh/nOsLCD4FjSi7nsQD1p3wboxAuOA7lyXEI4nxTPcYyxeAG9M4pT2eyDDl4kG/npbV7QuWpFoWDhtDoz33OvJS0Sy7tU1v0WigeuxJxHoV44/g9+ERF4I13Jl6vF0CMk9o/911Sc4z0NgRgZFR2MTRpKJHXLm8OsRXWJeZy86XgOvNSj52DB2WugtPfE4kYIt65d/Hod3XlWgJknx5O/IYKjaPl17+rXxkn/loWsy/DITy9y443D1hOLA/ohgGH4tTsljizGTykdFJxoD4CNA=="
return "EMRety5CM0VqStb6bIeB2DeQwdAO5Nm06ZSSGT0/8qW4+cbYDaPwFa5bL1Ylkn/E/JqKhZNtydeT0x+z+nkKCqlFx3Mt/K/WCSD9t+stoZa/Viv8GY8gVzt20A//2+mg0lqCdob5KFCBGHa7GRAwpO4WR5i5reBo17xubq6uVCB8/4hEUVDEstX1m32TU1OES1pFwWECCE/uFPoVJ+5h9BFqnVLSh2XnJde+9aHZ1N+nPBljZWCi9Z+iPpr1MFtHJdjGMPol8+i0VGzi02nhiHUNghmK4uIajB3rledPDZ0MgkQ3wfzJuzHcKGrb0iUMwAsOUNyEJT3b0/g4J7Ka+Q=="


@pytest.fixture
def corrupt_signature():
return "eZsnoryOFBa9lNT2rR0cLU18P84M1SQP7p+tru6f+5KJHnx8yL6nM3jHbSs03ah3Eh/nOsLCD4FjSi7nsQD1p3wboxAuOA7lyXEI4nxTPcYyxeAG9M4pT2eyDDl4kG/npbV7QuWpFoWDhtDoz33OvJS0Sy7tU1v0WigeuxJxHoV44/g9+ERF4I13Jl6vF0CMk9o/911Sc4z0NgRgZFR2MTRpKJHXLm8OsRXWJeZy86XgOvNSj52DB2WugtPfE4kYIt65d/Hod3XlWgJknx5O/IYKjaPl17+rXxkn/loWsy/DITy9y443D1hOLA/ohgGH4tTsljizGTykdFJxoD4CNA=="
return "EMRety5CM0VqStb6bIeB2DeQwdAO5Nm06ZSSGT0/8qW4+cbYDaPwFa5bL1Ylkn/E/JqKhZNtydeT1x+z+nkKCqlFx3Mt/K/WCSD9t+stoZa/Viv8GY8gVzt20A//2+mg0lqCdob5KFCBGHa7GRAwpO4WR5i5reBo17xubq6uVCB8/4hEUVDEstX1m32TU1OES1pFwWECCE/uFPoVJ+5h9BFqnVLSh2XnJde+9aHZ1N+nPBljZWCi9Z+iPpr1MFtHJdjGMPol8+i0VGzi02nhiHUNghmK4uIajB3rledPDZ0MgkQ3wfzJuzHcKGrb0iUMwAsOUNyEJT3b0/g4J7Ka+Q=="


def test_correct_signature(valid_payload, valid_signature):
Expand Down