-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- modify Signature decodding based on how Lace is codding it - for signature verification construct the Signed payload based on the Signature headers - fix the skipped verification of the signature when the returned values is Right False - add complete signature tests refs: [PLT-5598](https://input-output.atlassian.net/browse/PLT-5598)
- Loading branch information
1 parent
de1b18d
commit 795be41
Showing
7 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} | ||
{-# OPTIONS_GHC -Wno-missing-signatures #-} | ||
{-# OPTIONS_GHC -Wno-unused-record-wildcards #-} | ||
|
||
module SignatureSpec (spec) where | ||
import Test.Hspec | ||
import IOHK.Certification.SignatureVerification | ||
import Data.Aeson | ||
import Plutus.Certification.API | ||
import Text.RawString.QQ(r) | ||
|
||
(Just laceObject) = decode @LoginBody [r|{ | ||
"address": "addr_test1qr9g2tnvpgc264tvnjkcpqfeulvmuu2k26enq25yszwl5yw6gvppa4mz9sayrvfklds5dqq44nl36xkng33kz738g0hqj0adak", | ||
"key": "a5010102583900ca852e6c0a30ad556c9cad808139e7d9be715656b3302a84809dfa11da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743ee03272006215820d3be7240cd3f131316a2489c609ff4d7a75732834bd120f34618afc66a236f16", | ||
"signature": "845882a3012704583900ca852e6c0a30ad556c9cad808139e7d9be715656b3302a84809dfa11da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743ee6761646472657373583900ca852e6c0a30ad556c9cad808139e7d9be715656b3302a84809dfa11da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743eea166686173686564f458d45369676e2074686973206d65737361676520696620796f752061726520746865206f776e6572206f662074686520616464725f74657374317172396732746e7670676332363474766e6a6b6370716665756c766d7575326b3236656e71323579737a776c357977366776707061346d7a397361797276666b6c64733564717134346e6c3336786b6e6733336b7a373338673068716a306164616b20616464726573732e200a2054696d657374616d703a203c3c313639333935383634313e3e200a204578706972793a203630207365636f6e64735840511b7f3b847ad1e5b8ffac44ff4af5f5cbf1f4dda3d4d179dbc5c9ce1626aaca0118795fa41bdd0a4440473a609bfe47f6b4c23bd34b0a9bf8b7a56c6e120009" | ||
}|] | ||
|
||
(Just numyObject) = decode @LoginBody [r|{ | ||
"address": "addr_test1qr9g2tnvpgc264tvnjkcpqfeulvmuu2k26enq25yszwl5yw6gvppa4mz9sayrvfklds5dqq44nl36xkng33kz738g0hqj0adak", | ||
"key": "a4010103272006215820d3be7240cd3f131316a2489c609ff4d7a75732834bd120f34618afc66a236f16", | ||
"signature": "845846a201276761646472657373583900ca852e6c0a30ad556c9cad808139e7d9be715656b3302a84809dfa11da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743eea166686173686564f458d45369676e2074686973206d65737361676520696620796f752061726520746865206f776e6572206f662074686520616464725f74657374317172396732746e7670676332363474766e6a6b6370716665756c766d7575326b3236656e71323579737a776c357977366776707061346d7a397361797276666b6c64733564717134346e6c3336786b6e6733336b7a373338673068716a306164616b20616464726573732e200a2054696d657374616d703a203c3c313639333935373436313e3e200a204578706972793a203630207365636f6e64735840a2559f6b3aaed7dd920c8d647c118758fcf7d958279d0291271bfe77150c8cc3faac5367879236abbb325bd6361f06f5d59e8178feed8406ba3f67140abae504" | ||
}|] | ||
|
||
(Just yoroiObject) = decode @LoginBody [r|{ | ||
"address": "stake_test1urdyxqs76a3zcwjpkym0kc2xsq26elcartf5gcmp0gn58ms32qx04", | ||
"key": "a4010103272006215820a1904e3efe35ad81a349f7d973943e3e340558ae9966b704f0ac6bddb4cc8c49", | ||
"signature": "84582aa201276761646472657373581de0da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743eea166686173686564f458d45369676e2074686973206d65737361676520696620796f752061726520746865206f776e6572206f662074686520616464725f74657374317172303278346a726d7271756d36307765773672356638347671396c677a7a7437667634766a393271756c6d767737366776707061346d7a397361797276666b6c64733564717134346e6c3336786b6e6733336b7a37333867306871713836616b7220616464726573732e200a2054696d657374616d703a203c3c313639343038303837383e3e200a204578706972793a203630207365636f6e6473584094b50f5393283596c7c2d85a1d6f6d8a31be87b79c31ffcb4185191a070ce2374d6b1900d0632b78a419dbc9937f97716d14750f9881b2d1d44df5ffbac75508" | ||
}|] | ||
|
||
(Just wrongAddressObject) = decode @LoginBody [r|{ | ||
"address": "addr_test1qr9g2tnvpgc264tvnjkcpqfeulvmuu2k26enq25yszwl5yw6gvppa4mz9sayrvfklds5dqq44nl36xkng33kz738g0hqj0adak", | ||
"key": "a4010103272006215820a1904e3efe35ad81a349f7d973943e3e340558ae9966b704f0ac6bddb4cc8c49", | ||
"signature": "84582aa201276761646472657373581de0da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743eea166686173686564f458d45369676e2074686973206d65737361676520696620796f752061726520746865206f776e6572206f662074686520616464725f74657374317172303278346a726d7271756d36307765773672356638347671396c677a7a7437667634766a393271756c6d767737366776707061346d7a397361797276666b6c64733564717134346e6c3336786b6e6733336b7a37333867306871713836616b7220616464726573732e200a2054696d657374616d703a203c3c313639343038303837383e3e200a204578706972793a203630207365636f6e6473584094b50f5393283596c7c2d85a1d6f6d8a31be87b79c31ffcb4185191a070ce2374d6b1900d0632b78a419dbc9937f97716d14750f9881b2d1d44df5ffbac75508" | ||
}|] | ||
|
||
(Just wrongPublicKey) = decode @LoginBody [r|{ | ||
"address": "stake_test1urdyxqs76a3zcwjpkym0kc2xsq26elcartf5gcmp0gn58ms32qx04", | ||
"key": "a5010102583900ca852e6c0a30ad556c9cad808139e7d9be715656b3302a84809dfa11da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743ee03272006215820d3be7240cd3f131316a2489c609ff4d7a75732834bd120f34618afc66a236f16", | ||
"signature": "84582aa201276761646472657373581de0da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743eea166686173686564f458d45369676e2074686973206d65737361676520696620796f752061726520746865206f776e6572206f662074686520616464725f74657374317172303278346a726d7271756d36307765773672356638347671396c677a7a7437667634766a393271756c6d767737366776707061346d7a397361797276666b6c64733564717134346e6c3336786b6e6733336b7a37333867306871713836616b7220616464726573732e200a2054696d657374616d703a203c3c313639343038303837383e3e200a204578706972793a203630207365636f6e6473584094b50f5393283596c7c2d85a1d6f6d8a31be87b79c31ffcb4185191a070ce2374d6b1900d0632b78a419dbc9937f97716d14750f9881b2d1d44df5ffbac75508" | ||
|
||
}|] | ||
|
||
(Just malformedPublicKey) = decode @LoginBody [r|{ | ||
"address": "stake_test1urdyxqs76a3zcwjpkym0kc2xsq26elcartf5gcmp0gn58ms32qx04", | ||
"key": "A6010102583900CA852E6C0A30AD556C9CAD808139E7D9BE715656B3302A84809DFA11DA43021ED7622C3A41B136FB61468015ACFF1D1AD34463617A2743EE032720060405215820D3BE7240CD3F131316A2489C609FF4D7A75732834BD120F34618AFC66A236F16", | ||
"signature": "84582aa201276761646472657373581de0da43021ed7622c3a41b136fb61468015acff1d1ad34463617a2743eea166686173686564f458d45369676e2074686973206d65737361676520696620796f752061726520746865206f776e6572206f662074686520616464725f74657374317172303278346a726d7271756d36307765773672356638347671396c677a7a7437667634766a393271756c6d767737366776707061346d7a397361797276666b6c64733564717134346e6c3336786b6e6733336b7a37333867306871713836616b7220616464726573732e200a2054696d657374616d703a203c3c313639343038303837383e3e200a204578706972793a203630207365636f6e6473584094b50f5393283596c7c2d85a1d6f6d8a31be87b79c31ffcb4185191a070ce2374d6b1900d0632b78a419dbc9937f97716d14750f9881b2d1d44df5ffbac75508" | ||
}|] | ||
|
||
(Just wrongSignature) = decode @LoginBody [r|{ | ||
"address": "stake_test1urdyxqs76a3zcwjpkym0kc2xsq26elcartf5gcmp0gn58ms32qx04", | ||
"key": "a4010103272006215820a1904e3efe35ad81a349f7d973943e3e340558ae9966b704f0ac6bddb4cc8c49", | ||
"signature": "84582AA201276761646472657373581DE0DA43021ED7622C3A41B136FB61468015ACFF1D1AD34463617A2743EEA166686173686564F458D45369676E2074686973206D65737361676520696620796F752061726520746865206F776E6572206F662074686520616464725F74657374317172396732746E7670676332363474766E6A6B6370716665756C766D7575326B3236656E71323579737A776C357977366776707061346D7A397361797276666B6C64733564717134346E6C3336786B6E6733336B7A373338673068716A306164616B20616464726573732E200A2054696D657374616D703A203C3C313639333935373436313E3E200A204578706972793A203630207365636F6E64735840A2559F6B3AAED7DD920C8D647C118758FCF7D958279D0291271BFE77150C8CC3FAAC5367879236ABBB325BD6361F06F5D59E8178FEED8406BA3F67140ABAE504" | ||
}|] | ||
spec :: SpecWith () | ||
spec = | ||
describe "Signature verification" $ do | ||
|
||
it "successfully validates Lace signature" $ do | ||
let LoginBody{..} = laceObject | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) `shouldBe` Right True | ||
|
||
it "successfully validates Numy signature" $ do | ||
let LoginBody{..} = numyObject | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) `shouldBe` Right True | ||
|
||
it "successfully validates Yoroi signature" $ do | ||
let LoginBody{..} = yoroiObject | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) `shouldBe` Right True | ||
|
||
it "fails to validate signature with wrong address" $ do | ||
let LoginBody{..} = wrongAddressObject | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) | ||
`shouldBe` Left "Hash address verification failed" | ||
|
||
it "fails to validate signature with wrong public key" $ do | ||
let LoginBody{..} = wrongPublicKey | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) | ||
`shouldBe` Left "Hash address verification failed" | ||
|
||
it "fails to validate signature with malformed public key" $ do | ||
let LoginBody{..} = malformedPublicKey | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) | ||
`shouldBe` Left | ||
"unfoldPublicKey: \"DeserialiseFailure 1 \\\"decodePublicKeyWithAlgorithm: expected map of 4 or 5 elements, got 6\\\"\"" | ||
|
||
it "fails to validate signature with wrong signature" $ do | ||
let LoginBody{..} = wrongSignature | ||
verifyCIP30Signature key signature Nothing (Just $ Bech32Address address) | ||
`shouldBe` Right False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import Test.Hspec | ||
import qualified ProfileWalletSpec as ProfileWallet | ||
import qualified SignatureSpec as Signature | ||
|
||
main :: IO () | ||
main = hspec ProfileWallet.spec | ||
main = hspec $ do | ||
ProfileWallet.spec | ||
Signature.spec |