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

Add check for transHashSHA2 when verifying a transaction #145

Open
mintplugins opened this issue Feb 15, 2019 · 0 comments
Open

Add check for transHashSHA2 when verifying a transaction #145

mintplugins opened this issue Feb 15, 2019 · 0 comments

Comments

@mintplugins
Copy link

mintplugins commented Feb 15, 2019

The transHashSHA2 should be checked here in order to confirm there wasn't a man-in-the-middle attack:

https://github.com/AuthorizeNet/sample-code-php/blob/master/PaymentTransactions/charge-credit-card.php#L97

Something like this:

$authorize_hash = $tresponse->getTransHashSha2();
$string = '^' . \SampleCodeConstants::MERCHANT_LOGIN_ID . '^' . $tresponse->getTransId(). '^' . $amount . '^';
$key = hex2bin( \SampleCodeConstants::MERCHANT_SIGNATURE_KEY );
$my_hash = strtoupper( hash_hmac( 'sha512', $string, $key ) );

if( hash_equals ( $authorize_hash, $my_hash ) ) {
	
	echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n";
	echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n";
	echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n";
	echo " Auth Code: " . $tresponse->getAuthCode() . "\n";
	echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n";
	
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant