From 4980788afc3173298829c5e861a6b25f4b278950 Mon Sep 17 00:00:00 2001 From: Sun Knudsen Date: Sun, 18 Apr 2021 10:06:04 -0400 Subject: [PATCH] Refactored unit tests --- .../qr-backup.sh | 2 +- .../qr-backup.sh.sig | 26 +- .../qr-restore.sh | 2 + .../qr-restore.sh.sig | 26 +- how-to-create-encrypted-paper-backup/test.exp | 45 +++ how-to-create-encrypted-paper-backup/test.sh | 6 +- .../tests/bip39.exp | 134 ++------- .../tests/clone.exp | 99 +++++++ .../convert-default-to-shamir-2-of-3.exp | 129 ++++++++ .../convert-shamir-2-of-3-to-default.exp | 93 ++++++ .../tests/default.exp | 219 +++++++------- .../tests/duplicate.exp | 69 +++++ .../tests/electrum.exp | 51 +--- .../tests/helpers/backup.exp | 63 ++++ .../tests/helpers/restore.exp | 27 ++ .../tests/helpers/shamir-2-of-3-backup.exp | 99 +++++++ .../tests/helpers/shamir-2-of-3-restore.exp | 31 ++ .../tests/shamir-2-of-3.exp | 25 ++ .../tests/shamir.exp | 219 ++------------ .../tests/shamir2of3.exp | 280 ------------------ 20 files changed, 876 insertions(+), 769 deletions(-) create mode 100644 how-to-create-encrypted-paper-backup/test.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/clone.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/convert-default-to-shamir-2-of-3.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/convert-shamir-2-of-3-to-default.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/duplicate.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/helpers/backup.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/helpers/restore.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-backup.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-restore.exp create mode 100644 how-to-create-encrypted-paper-backup/tests/shamir-2-of-3.exp delete mode 100644 how-to-create-encrypted-paper-backup/tests/shamir2of3.exp diff --git a/how-to-create-encrypted-paper-backup/qr-backup.sh b/how-to-create-encrypted-paper-backup/qr-backup.sh index 94c0030..6cabc60 100755 --- a/how-to-create-encrypted-paper-backup/qr-backup.sh +++ b/how-to-create-encrypted-paper-backup/qr-backup.sh @@ -156,7 +156,7 @@ read_passphrase () { printf "$bold%s$normal\n" "Please type passphrase and press enter (again)" read -rs data_confirmation if [ ! "$data" = "$data_confirmation" ]; then - printf "$red%s$normal\n" "Passphrases do not match" + printf "$bold$red%s$normal\n" "Passphrases do not match" return 1 fi diff --git a/how-to-create-encrypted-paper-backup/qr-backup.sh.sig b/how-to-create-encrypted-paper-backup/qr-backup.sh.sig index 2fe8a7f..267aad3 100644 --- a/how-to-create-encrypted-paper-backup/qr-backup.sh.sig +++ b/how-to-create-encrypted-paper-backup/qr-backup.sh.sig @@ -1,16 +1,16 @@ -----BEGIN PGP SIGNATURE----- -iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB7OOAACgkQH6dnhiu9 -EwXjPg//VtWqugIVSPKBE2HBTKr4Pp9EDBSuLy1nI/Dq89vxU74BjXovDFN02iLv -J7t7vgQ1gk4zfisMdPi199GrgKOVE6Ke1xxHbRWIdWRTBF+7hcNzEm7YCd+HfrMq -S1dEMbN+2xxDm9NJJ506d9BPS5GicOY+0yu1BAOonKioIgrBwPCcAhjA6Miws8+/ -E0XIhNErSwqVOPQcRlRLhhIWIT6iMZgMOLPUpTHna7KfOlmfCcbNzlxHxBPO8OV7 -4LruoGqDRQAk5h6pXKf95WVaDioUe4SHDvdq0tLjDNqMBZ0Fur9PBCzDcHc3KDaq -XwWKldxIWvjTGLD7I2Jz7Y6/vnANoibQpJ20yXTS1KTZiVqRJbZI76NHz+Tm6ZJ1 -hVMjl+ZUAHrDnCIFxBdirJh62pBPRFvvC/FmbluNUuUQXPNs5E+62LDlkzMwN4XI -fmhiFj5karjsIk7TYAXyeOb8dQQXTohfsY0YTUBSAt09Pb0L3Dq4kSVm79gEXaem -5WIy4UawC3yj2lA4EaqyVUrA7oldMM7AIUfIo1niKNMPnrjaP9VdHJQR0g4QSMms -VnTxcrJPT7t4BkEgvjc43vTEAkVtGqZv32nmT8aLAhy3GERH//ZDqFe3wvqw0VGM -hI+lXgTwywALCna9cqOmWD/cktmq/riG0aB9SQGPluqI80elaO4= -=CTqJ +iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB8uqsACgkQH6dnhiu9 +EwXNpRAApaR7KeapzT01v6WgfDD1/BNCTjGDR2A6dq2eY0VCi6T1GsPudzWtaeni +h4LJTgkJ0nmMH+hM9acPdPYi+9JnhOM/RGmaMOO7dcFio5abp8+IVERXytrYgH6k +jtx+GE8lEpxLSl2yTNvq/jep9Vmcpwp0w2MWIx7Ra6ahmwqHqvdwLIMPx1/+UclX +Eb8vzsi/WOwncE8nyahDgY5yCAwbqziVcAnPtg4ACLMBlX7hhw0XBub5aiQFpr7r +LZaDd6j6O77povtOT3SKJ/6xYZxwzMgZ2MTZpTr/X8rAoXSwQ3N+IqBcHRntzYVJ +jVE0fInqw56V5KJFtaZdnbK9H0VVQ86pvpU2Rry3S04k1CiNzwfgtv0iZ55hKPJA +Rn1s0SQBQ4GHalJAqNhCoub4FoDmPcM/qTtjuwg8wIL20dHLdzRL9JacENKmg3yn +jdLEn/MxCaTHiWHzTocjO5Gpkvffu1hSYmjbHGVU/fK9HWKmXBNzSJn1/gI48SBv +Q5cjJfxFA96cHPeuFkWgCO+RyVj9YMG6hF58D6PGK+3XwnSy9aDTRRbTSGZAMG3c +gyAfZfrtuhUk/+fPtxOrIIt4N/m092JVV35ROxoPLzHR7eQGEW52wuUTDV1cTC+8 +3sIFNeL+L7Q9RIiA7q+f66LE+uDQfZzD/I98Xbl+5CcuvHWm+Qs= +=7QwI -----END PGP SIGNATURE----- diff --git a/how-to-create-encrypted-paper-backup/qr-restore.sh b/how-to-create-encrypted-paper-backup/qr-restore.sh index 3669a23..1a8717c 100755 --- a/how-to-create-encrypted-paper-backup/qr-restore.sh +++ b/how-to-create-encrypted-paper-backup/qr-restore.sh @@ -3,6 +3,8 @@ set -e set -o pipefail +shamir_secret_sharing=false + share_threshold=3 positional=() diff --git a/how-to-create-encrypted-paper-backup/qr-restore.sh.sig b/how-to-create-encrypted-paper-backup/qr-restore.sh.sig index 6fb14a5..a3eabb0 100644 --- a/how-to-create-encrypted-paper-backup/qr-restore.sh.sig +++ b/how-to-create-encrypted-paper-backup/qr-restore.sh.sig @@ -1,16 +1,16 @@ -----BEGIN PGP SIGNATURE----- -iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB7OOYACgkQH6dnhiu9 -EwUy3w//ckQVIouZjTiNam7DBoyGUXw+lfXKKnkR0HEbLeUld0KvDh8fON1IB4GM -0eRIpkkbmW8Dp4uAnVxtcQKeEHTZfja7g04hD7AO0JjD7b1drtFjxny8Ue74lR4Q -kfIIcB4WEj7nAfEFffgHbihnt1R27shXFcbvWH11DkChXT0tpFZhN2QYqDzK+8t+ -Ru4Xz+zQ6YDRv40YV4NRMJG8ju9xvfecPLRDK0aO0W/N7HNZMiMYP+ZqgpLlx+11 -ru550caSKg8VlwywkjoKx84kmBCdhuc90BNgjOsLoL71naRo2f6N+PelUcWzF+VB -9J0yVrOq8el6oCfPxT9lnn3BcaVjMrQWHfTM4AllRYEpeU/MqdnknhnxCGlH/u3I -fov9kA/shgeAwQ266KTX+l+mPADE4uV0UWCT9vfXOUM9gkPzW040t1pwCqBqhJNP -Rwy9ppF4yIMgDZTokpt/s2JMhAHKYCqJRZKaQx0sf+eSO8Ye+SeyfrXYT79JiCT5 -TYNBEClTLfPJIBx6g2HTxJoO/oKQr0J/usNXzqdN1y5Rzq9IVeyVOxw03VqLu7dW -eLfJm5sNUQZtwu8fwqzc3/gtsHchFXmd5700i35rCT/DxUdpEKTDtH/qlp3kqUez -5iJmmhsMKXL2AYXYroTAWo/FnPlALJ1+mE/8eWwYjDFjItUjGE8= -=9ATO +iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB8tvUACgkQH6dnhiu9 +EwWnhQ//QqY56NLvkUreXU7mEcqvUhxE3HwJdX519QqmMC5+qgLGP1V0BoKqaUYo +JlJ5qPiK8y3P6ZYHoX4oajm5LlVoGh5MG+R0xJtnKN0leTa220guzh3/DEKoYJ/1 +wNFT+R3eGqZIS9ulZrRxKJPaxb+QfbpNVmwMymnwgS+4v0M6uN7L8d9GVws+8DMK +owPuT7gC3IpTVR+/Qo++Oesldo3xGWVny7/a+bZ+vCV0OpQ/ybZ139Mava4KrKg7 +FIFmHcLrSLGu9ud537aMOvtltHAulcpQ/WQND2GAwt9xuVlD0wb924DkmSMEqmL3 +sn7GMl3icKW2lUR7a4O6kSR+gBGz+6nW9l2XkQjjXrjJsuWcL23x4kAKCvl2TxZF +qLGgl7jwrdiaPxdUp45wSgInLORDujXatMRd1otaq34R0L5aH98/RhktiqKI2Mq/ +9XsW1+k2bWL6tizcL5iv9lqYIoZpfbAO2OcrTfMlG9I2Lcc/UQ9WQAWxMrdCMYCp +3RAjkt1miGH77+F3tWRF+MQ+i43F5/C9rty2/3wOYjDei41KQuehDKQ3g4fATkOs +AbaP+EEcwwGw0tnQ/lWnJ7dBBtdT2sRnwqKQJ7LMVHcPLqM9m9Pfxlk7GHecp8xi +QJ7LUUmSE4hp3xspxxaTLVsTJcBXQeIooiDnDP5T4fSh8ByBodw= +=Ljp9 -----END PGP SIGNATURE----- diff --git a/how-to-create-encrypted-paper-backup/test.exp b/how-to-create-encrypted-paper-backup/test.exp new file mode 100644 index 0000000..cb5e469 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/test.exp @@ -0,0 +1,45 @@ +#!/usr/bin/expect + +# exp_internal 1 +# log_file -noappend ~/expect.log + +set timeout 30 + +set bold [exec tput bold] +set red [exec tput setaf 1] +set green [exec tput setaf 2] +set normal [exec tput sgr0] + +proc test_label {value} { + upvar bold bold + upvar normal normal + puts "Running ${bold}${value}${normal}…" +} +proc test_send {value} { + sleep 0.1 + send "$value" +} +proc test_failed {} { + upvar bold bold + upvar red red + upvar normal normal + sleep 0.1 + puts "${bold}${red}Failed${normal}" + exit 1 +} +proc test_ok {{force_close false}} { + upvar bold bold + upvar green green + upvar normal normal + sleep 0.1 + puts "${bold}${green}OK${normal}" + if {$force_close} { + close + } +} + +expect_before { + default { + test_failed + } +} diff --git a/how-to-create-encrypted-paper-backup/test.sh b/how-to-create-encrypted-paper-backup/test.sh index b61f1de..676add6 100755 --- a/how-to-create-encrypted-paper-backup/test.sh +++ b/how-to-create-encrypted-paper-backup/test.sh @@ -17,4 +17,8 @@ expect ./tests/bip39.exp expect ./tests/electrum.exp expect ./tests/default.exp expect ./tests/shamir.exp -expect ./tests/shamir2of3.exp +expect ./tests/shamir-2-of-3.exp +expect ./tests/clone.exp +expect ./tests/convert-default-to-shamir-2-of-3.exp +expect ./tests/convert-shamir-2-of-3-to-default.exp +expect ./tests/duplicate.exp diff --git a/how-to-create-encrypted-paper-backup/tests/bip39.exp b/how-to-create-encrypted-paper-backup/tests/bip39.exp index df7c5ef..5521ef2 100644 --- a/how-to-create-encrypted-paper-backup/tests/bip39.exp +++ b/how-to-create-encrypted-paper-backup/tests/bip39.exp @@ -1,190 +1,104 @@ #!/usr/bin/expect -# exp_internal 1 -# log_file -noappend ~/expect.log - -set timeout 30 - -proc bold {} { - return [exec tput bold] -} -proc red {} { - return [exec tput setaf 1] -} -proc green {} { - return [exec tput setaf 2] -} -proc normal {} { - return [exec tput sgr0] -} +source ./test.exp set bip39_mnemonic "online pipe enough dutch decorate want moment scheme rigid enlist blast boat purse sick chalk shop brush all return betray jacket salon abandon retire" set electrum_mnemonic "month pet slice know amused leave now vague palm guess cattle element cross truly auto put among craft repeat van sample nephew sad family" -set failed "[bold][red]Failed[normal]" -set ok "[bold][green]OK[normal]" -puts "[bold]Should create BIP39 mnemonic[normal]" +test_label "Should create BIP39 mnemonic" spawn qr-backup.sh --create-bip39-mnemonic expect { - default { - puts $failed - exit 1 - } -re {Format USB flash drive \(y or n\)\?} { - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } -re {Creating BIP39 mnemonic…} } expect { - default { - puts $failed - exit 1 - } - -re {(([a-z]+ ?){24})} { - exit 0 + -re {([a-z]+ ?){24}} { + test_ok true } } -puts "[bold]Should validate valid BIP39 mnemonic[normal]" +test_label "Should validate valid BIP39 mnemonic" spawn qr-backup.sh --validate-bip39-mnemonic expect { - default { - puts $failed - exit 1 - } -re {Format USB flash drive \(y or n\)\?} { - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } -re {Please type secret and press enter, then ctrl\+d} { - sleep 0.1 - send "$bip39_mnemonic\r" - sleep 0.1 - send "\x04" + test_send "$bip39_mnemonic\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } - -re {Please type bip39_mnemonic and press enter, then ctrl\+d \(again\)} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" + -re {Please type secret and press enter, then ctrl\+d \(again\)} { + test_send "$bip39_mnemonic\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter} { - puts $ok - exit 0 + test_ok true } } -puts "[bold]Should fail to validate invalid BIP39 mnemonic[normal]" +test_label "Should fail to validate invalid BIP39 mnemonic" spawn qr-backup.sh --validate-bip39-mnemonic expect { - default { - puts $failed - exit 1 - } -re {Format USB flash drive \(y or n\)\?} { - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } -re {Please type secret and press enter, then ctrl\+d} { - sleep 0.1 - send "$electrum_mnemonic\r" - sleep 0.1 - send "\x04" + test_send "$electrum_mnemonic\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } - -re {Please type electrum_mnemonic and press enter, then ctrl\+d \(again\)} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" + -re {Please type secret and press enter, then ctrl\+d \(again\)} { + test_send "$electrum_mnemonic\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } -re {Invalid BIP39 mnemonic} { - puts $ok - exit 0 + test_ok true } } - -interact diff --git a/how-to-create-encrypted-paper-backup/tests/clone.exp b/how-to-create-encrypted-paper-backup/tests/clone.exp new file mode 100644 index 0000000..484e960 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/clone.exp @@ -0,0 +1,99 @@ +#!/usr/bin/expect + +source ./test.exp + +set secret "foo\nbar" +set passphrase "asdasd" + +test_label "Should clone backup" + +source ./tests/helpers/backup.exp + +spawn qr-clone.sh --qr-restore-options "--images $short_hash.jpg" + +expect { + -re {Restoring…} +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show secret \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +expect { + -re {Backing up…} +} + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Please type passphrase and press enter \(again\)} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show passphrase \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set new_short_hash $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +if { "$new_short_hash" == "$short_hash" } { + test_failed +} + +set short_hash "$new_short_hash" + +source ./tests/helpers/restore.exp + +regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret +regsub -all {\r} $restored_secret {} restored_secret + +if { "$restored_secret" != "$secret" } { + test_failed +} else { + test_ok +} diff --git a/how-to-create-encrypted-paper-backup/tests/convert-default-to-shamir-2-of-3.exp b/how-to-create-encrypted-paper-backup/tests/convert-default-to-shamir-2-of-3.exp new file mode 100644 index 0000000..06d2d17 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/convert-default-to-shamir-2-of-3.exp @@ -0,0 +1,129 @@ +#!/usr/bin/expect + +source ./test.exp + +set secret "foo\nbar" +set passphrase "asdasd" + +test_label "Should convert default backup to 2-of-3 Shamir Secret Sharing" + +source ./tests/helpers/backup.exp + +spawn qr-clone.sh --qr-restore-options "--images $short_hash.jpg" --qr-backup-options "--shamir-secret-sharing --number-of-shares 3 --share-threshold 2" + +expect { + -re {Restoring…} +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show secret \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +expect { + -re {Backing up…} +} + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Please type passphrase and press enter \(again\)} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show passphrase \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Encrypting secret share 1 of 3…} +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash_1 $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Encrypting secret share 2 of 3…} +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash_2 $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Encrypting secret share 3 of 3…} +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash_3 $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +source ./tests/helpers/shamir-2-of-3-restore.exp + +regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret +regsub -all {\r} $restored_secret {} restored_secret + +if { "$restored_secret" != "$secret" } { + test_failed +} else { + test_ok +} diff --git a/how-to-create-encrypted-paper-backup/tests/convert-shamir-2-of-3-to-default.exp b/how-to-create-encrypted-paper-backup/tests/convert-shamir-2-of-3-to-default.exp new file mode 100644 index 0000000..3e186b7 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/convert-shamir-2-of-3-to-default.exp @@ -0,0 +1,93 @@ +#!/usr/bin/expect + +source ./test.exp + +set secret "foo\nbar" +set passphrase "asdasd" + +test_label "Should convert 2-of-3 Shamir Secret Sharing backup to default" + +source ./tests/helpers/shamir-2-of-3-backup.exp + +spawn qr-clone.sh --qr-restore-options "--images \"$short_hash_1.jpg,$short_hash_2.jpg\" --shamir-secret-sharing --share-threshold 2" + +expect { + -re {Restoring…} +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show secret \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +expect { + -re {Backing up…} +} + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Please type passphrase and press enter \(again\)} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show passphrase \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +source ./tests/helpers/restore.exp + +regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret +regsub -all {\r} $restored_secret {} restored_secret + +if { "$restored_secret" != "$secret" } { + test_failed +} else { + test_ok +} diff --git a/how-to-create-encrypted-paper-backup/tests/default.exp b/how-to-create-encrypted-paper-backup/tests/default.exp index 2a8fc81..5b92d38 100644 --- a/how-to-create-encrypted-paper-backup/tests/default.exp +++ b/how-to-create-encrypted-paper-backup/tests/default.exp @@ -1,200 +1,191 @@ #!/usr/bin/expect -# exp_internal 1 -# log_file -noappend ~/expect.log - -set timeout 30 - -proc bold {} { - return [exec tput bold] -} -proc red {} { - return [exec tput setaf 1] -} -proc green {} { - return [exec tput setaf 2] -} -proc normal {} { - return [exec tput sgr0] -} +source ./test.exp set secret "foo\nbar" set passphrase "asdasd" -set failed "[bold][red]Failed[normal]" -set ok "[bold][green]OK[normal]" -puts "[bold]Should backup secret[normal]" +test_label "Should fails to backup secret using secrets that do not match" spawn qr-backup.sh expect { - default { - puts $failed - exit 1 - } -re {Format USB flash drive \(y or n\)\?} { - sleep 0.1 - send "y\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - sleep 0.1 - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 + -re {Please type secret and press enter, then ctrl\+d} { + test_send "$secret\r" + test_send "\x04" } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d \(again\)} { + test_send "foo\r" + test_send "\x04" + } +} + +expect { + -re {Secrets do not match} { + test_ok + } +} + +test_label "Should fails to backup secret using passphrases that do not match" + +spawn qr-backup.sh + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d} { + test_send "$secret\r" + test_send "\x04" + } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d \(again\)} { + test_send "$secret\r" + test_send "\x04" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Please type passphrase and press enter \(again\)} { + test_send "foo\r" + } +} + +expect { + -re {Passphrases do not match} { + test_ok + } +} + +test_label "Should format USB flash drive and backup secret showing passphrase" + +spawn qr-backup.sh + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "y\r" + } +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { -re {mkfs\.fat 4\.1 \(2017-01-24\)} } expect { - default { - puts $failed - exit 1 - } -re {Please type secret and press enter, then ctrl\+d} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" + test_send "$secret\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } -re {Please type secret and press enter, then ctrl\+d \(again\)} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" + test_send "$secret\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter} { - sleep 0.1 - send "$passphrase\r" + test_send "$passphrase\r" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter \(again\)} { - sleep 0.1 - send "$passphrase\r" + test_send "$passphrase\r" } } expect { - default { - puts $failed - exit 1 - } -re {Show passphrase \(y or n\)\?} { - sleep 0.1 - send "y\r" + test_send "y\r" } } expect { - default { - puts $failed - exit 1 - } $passphrase } expect { - default { - puts $failed - exit 1 - } -re {SHA512 short hash: .+?([a-f0-9]{8})} { set short_hash $expect_out(1,string) } } expect { - default { - puts $failed - exit 1 - } -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 + -re {Done} { + test_ok } - -re {Done} } -puts "[bold]Should restore secret[normal]" +test_label "Should restore secret" spawn qr-restore.sh --images $short_hash.jpg expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - sleep 0.1 - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter} { - sleep 0.1 - send "$passphrase\r" + test_send "$passphrase\r" } } expect { - default { - puts $failed - exit 1 - } -re {Show secret \(y or n\)\?} { - sleep 0.1 - send "y\r" + test_send "y\r" } } expect { - default { - puts $failed - exit 1 - } -re {Secret:\r\n((.|\r\n)+?)\r\nDone} { set restored_secret $expect_out(1,string) } @@ -204,11 +195,7 @@ regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret regsub -all {\r} $restored_secret {} restored_secret if { "$restored_secret" != "$secret" } { - puts $failed - exit 1 + test_failed } else { - puts $ok - exit 0 + test_ok } - -interact diff --git a/how-to-create-encrypted-paper-backup/tests/duplicate.exp b/how-to-create-encrypted-paper-backup/tests/duplicate.exp new file mode 100644 index 0000000..70a1471 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/duplicate.exp @@ -0,0 +1,69 @@ +#!/usr/bin/expect + +source ./test.exp + +set secret "foo\nbar" +set passphrase "asdasd" + +test_label "Should duplicate backup" + +source ./tests/helpers/backup.exp + +spawn qr-clone.sh --duplicate --qr-restore-options "--images $short_hash.jpg" + +expect { + -re {Restoring…} +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Done} +} + +expect { + -re {Backing up…} +} + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set new_short_hash $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} + +if { "$new_short_hash" != "$short_hash" } { + test_failed +} + +set short_hash "$new_short_hash" + +source ./tests/helpers/restore.exp + +regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret +regsub -all {\r} $restored_secret {} restored_secret + +if { "$restored_secret" != "$secret" } { + test_failed +} else { + test_ok +} diff --git a/how-to-create-encrypted-paper-backup/tests/electrum.exp b/how-to-create-encrypted-paper-backup/tests/electrum.exp index c104da5..5ac7645 100644 --- a/how-to-create-encrypted-paper-backup/tests/electrum.exp +++ b/how-to-create-encrypted-paper-backup/tests/electrum.exp @@ -1,68 +1,29 @@ #!/usr/bin/expect -# exp_internal 1 -# log_file -noappend ~/expect.log +source ./test.exp -set timeout 30 - -proc bold {} { - return [exec tput bold] -} -proc red {} { - return [exec tput setaf 1] -} -proc green {} { - return [exec tput setaf 2] -} -proc normal {} { - return [exec tput sgr0] -} - -set passphrase "asdasd" -set failed "[bold][red]Failed[normal]" -set ok "[bold][green]OK[normal]" - -puts "[bold]Should create Electrum mnemonic[normal]" +test_label "Should create Electrum mnemonic" spawn qr-backup.sh --create-electrum-mnemonic expect { - default { - puts $failed - exit 1 - } -re {Format USB flash drive \(y or n\)\?} { - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } -re {Creating Electrum mnemonic…} } expect { - default { - puts $failed - exit 1 - } - -re {(([a-z]+ ?){24})} { - puts $ok - exit 0 + -re {([a-z]+ ?){24}} { + test_ok true } } - -interact diff --git a/how-to-create-encrypted-paper-backup/tests/helpers/backup.exp b/how-to-create-encrypted-paper-backup/tests/helpers/backup.exp new file mode 100644 index 0000000..24de3ea --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/helpers/backup.exp @@ -0,0 +1,63 @@ +#!/usr/bin/expect + +spawn qr-backup.sh + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d} { + test_send "$secret\r" + test_send "\x04" + } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d \(again\)} { + test_send "$secret\r" + test_send "\x04" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Please type passphrase and press enter \(again\)} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show passphrase \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} diff --git a/how-to-create-encrypted-paper-backup/tests/helpers/restore.exp b/how-to-create-encrypted-paper-backup/tests/helpers/restore.exp new file mode 100644 index 0000000..7d4e1f6 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/helpers/restore.exp @@ -0,0 +1,27 @@ +#!/usr/bin/expect + +spawn qr-restore.sh --images $short_hash.jpg + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show secret \(y or n\)\?} { + test_send "y\r" + } +} + +expect { + -re {Secret:\r\n((.|\r\n)+?)\r\nDone} { + set restored_secret $expect_out(1,string) + } +} diff --git a/how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-backup.exp b/how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-backup.exp new file mode 100644 index 0000000..71f17f0 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-backup.exp @@ -0,0 +1,99 @@ +#!/usr/bin/expect + +spawn qr-backup.sh --shamir-secret-sharing --number-of-shares 3 --share-threshold 2 + +expect { + -re {Format USB flash drive \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d} { + test_send "$secret\r" + test_send "\x04" + } +} + +expect { + -re {Please type secret and press enter, then ctrl\+d \(again\)} { + test_send "$secret\r" + test_send "\x04" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Please type passphrase and press enter \(again\)} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show passphrase \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Encrypting secret share 1 of 3…} +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash_1 $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Encrypting secret share 2 of 3…} +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash_2 $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Encrypting secret share 3 of 3…} +} + +expect { + -re {SHA512 short hash: .+?([a-f0-9]{8})} { + set short_hash_3 $expect_out(1,string) + } +} + +expect { + -re {Show SHA512 hash as QR code \(y or n\)\?} { + test_send "n\r" + } +} + +expect { + -re {Done} +} diff --git a/how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-restore.exp b/how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-restore.exp new file mode 100644 index 0000000..9f953a5 --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/helpers/shamir-2-of-3-restore.exp @@ -0,0 +1,31 @@ +#!/usr/bin/expect + +spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg" --shamir-secret-sharing --share-threshold 2 + +expect { + -re {\[sudo\] password for pi:} { + test_send "$env(password)\r" + } +} + +expect { + -re {Please type passphrase and press enter} { + test_send "$passphrase\r" + } +} + +expect { + -re {Show secret \(y or n\)\?} { + test_send "y\r" + } +} + +expect { + -re {Secret:\r\n((.|\r\n)+?)\r\nDone} { + set restored_secret $expect_out(1,string) + } +} + +expect { + -re {Done} +} diff --git a/how-to-create-encrypted-paper-backup/tests/shamir-2-of-3.exp b/how-to-create-encrypted-paper-backup/tests/shamir-2-of-3.exp new file mode 100644 index 0000000..9a3f7ee --- /dev/null +++ b/how-to-create-encrypted-paper-backup/tests/shamir-2-of-3.exp @@ -0,0 +1,25 @@ +#!/usr/bin/expect + +source ./test.exp + +set passphrase "asdasd" +set secret "foo\nbar" + +test_label "Should backup secret using 2-of-3 Shamir Secret Sharing" + +source ./tests/helpers/shamir-2-of-3-backup.exp + +test_ok + +test_label "Should restore secret using 2-of-3 Shamir Secret Sharing" + +source ./tests/helpers/shamir-2-of-3-restore.exp + +regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret +regsub -all {\r} $restored_secret {} restored_secret + +if { "$restored_secret" != "$secret" } { + test_failed +} else { + test_ok +} diff --git a/how-to-create-encrypted-paper-backup/tests/shamir.exp b/how-to-create-encrypted-paper-backup/tests/shamir.exp index ae2105b..7044dae 100644 --- a/how-to-create-encrypted-paper-backup/tests/shamir.exp +++ b/how-to-create-encrypted-paper-backup/tests/shamir.exp @@ -1,324 +1,167 @@ #!/usr/bin/expect -# exp_internal 1 -# log_file -noappend ~/expect.log - -set timeout 30 - -proc bold {} { - return [exec tput bold] -} -proc red {} { - return [exec tput setaf 1] -} -proc green {} { - return [exec tput setaf 2] -} -proc normal {} { - return [exec tput sgr0] -} +source ./test.exp set passphrase "asdasd" set secret "foo\nbar" -set failed "[bold][red]Failed[normal]" -set ok "[bold][green]OK[normal]" -puts "[bold]Should backup secret using Shamir Secret Sharing[normal]" +test_label "Should backup secret using Shamir Secret Sharing" spawn qr-backup.sh --shamir-secret-sharing expect { - default { - puts $failed - exit 1 - } -re {Format USB flash drive \(y or n\)\?} { - sleep 0.1 - send "y\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - sleep 0.1 - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } - -re {mkfs\.fat 4\.1 \(2017-01-24\)} -} - -expect { - default { - puts $failed - exit 1 - } -re {Please type secret and press enter, then ctrl\+d} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" + test_send "$secret\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } -re {Please type secret and press enter, then ctrl\+d \(again\)} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" + test_send "$secret\r" + test_send "\x04" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter} { - sleep 0.1 - send "$passphrase\r" + test_send "$passphrase\r" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter \(again\)} { - sleep 0.1 - send "$passphrase\r" + test_send "$passphrase\r" } } expect { - default { - puts $failed - exit 1 - } -re {Show passphrase \(y or n\)\?} { - sleep 0.1 - send "y\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } - $passphrase + -re {Encrypting secret share 1 of 5…} } expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 1 of 5…} -} - -expect { - default { - puts $failed - exit 1 - } -re {SHA512 short hash: .+?([a-f0-9]{8})} { set short_hash_1 $expect_out(1,string) } } expect { - default { - puts $failed - exit 1 - } -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 2 of 5…} + -re {Encrypting secret share 2 of 5…} } expect { - default { - puts $failed - exit 1 - } -re {SHA512 short hash: .+?([a-f0-9]{8})} { set short_hash_2 $expect_out(1,string) } } expect { - default { - puts $failed - exit 1 - } -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 3 of 5…} + -re {Encrypting secret share 3 of 5…} } expect { - default { - puts $failed - exit 1 - } -re {SHA512 short hash: .+?([a-f0-9]{8})} { set short_hash_3 $expect_out(1,string) } } expect { - default { - puts $failed - exit 1 - } -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 4 of 5…} + -re {Encrypting secret share 4 of 5…} } expect { - default { - puts $failed - exit 1 - } -re {SHA512 short hash: .+?([a-f0-9]{8})} { set short_hash_4 $expect_out(1,string) } } expect { - default { - puts $failed - exit 1 - } -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 5 of 5…} + -re {Encrypting secret share 5 of 5…} } expect { - default { - puts $failed - exit 1 - } -re {SHA512 short hash: .+?([a-f0-9]{8})} { set short_hash_5 $expect_out(1,string) } } expect { - default { - puts $failed - exit 1 - } -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" + test_send "n\r" } } expect { - default { - puts $failed - exit 1 + -re {Done} { + test_ok } - -re {Done} } -puts "[bold]Should restore secret using Shamir Secret Sharing[normal]" +test_label "Should restore secret using Shamir Secret Sharing" spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg,$short_hash_5.jpg" --shamir-secret-sharing expect { - default { - puts $failed - exit 1 - } -re {\[sudo\] password for pi:} { - sleep 0.1 - send "$env(password)\r" + test_send "$env(password)\r" } } expect { - default { - puts $failed - exit 1 - } -re {Please type passphrase and press enter} { - sleep 0.1 - send "$passphrase\r" + test_send "$passphrase\r" } } expect { - default { - puts $failed - exit 1 - } -re {Show secret \(y or n\)\?} { - sleep 0.1 - send "y\r" + test_send "y\r" } } expect { - default { - puts $failed - exit 1 - } -re {Secret:\r\n((.|\r\n)+?)\r\nDone} { set restored_secret $expect_out(1,string) } @@ -328,11 +171,7 @@ regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret regsub -all {\r} $restored_secret {} restored_secret if { "$restored_secret" != "$secret" } { - puts $failed - exit 1 + test_failed } else { - puts $ok - exit 0 + test_ok } - -interact diff --git a/how-to-create-encrypted-paper-backup/tests/shamir2of3.exp b/how-to-create-encrypted-paper-backup/tests/shamir2of3.exp deleted file mode 100644 index 73d9409..0000000 --- a/how-to-create-encrypted-paper-backup/tests/shamir2of3.exp +++ /dev/null @@ -1,280 +0,0 @@ -#!/usr/bin/expect - -# exp_internal 1 -# log_file -noappend ~/expect.log - -set timeout 30 - -proc bold {} { - return [exec tput bold] -} -proc red {} { - return [exec tput setaf 1] -} -proc green {} { - return [exec tput setaf 2] -} -proc normal {} { - return [exec tput sgr0] -} - -set passphrase "asdasd" -set secret "foo\nbar" -set failed "[bold][red]Failed[normal]" -set ok "[bold][green]OK[normal]" - -puts "[bold]Should backup secret using 2 of 3 Shamir Secret Sharing[normal]" - -spawn qr-backup.sh --shamir-secret-sharing --number-of-shares 3 --share-threshold 2 - -expect { - default { - puts $failed - exit 1 - } - -re {Format USB flash drive \(y or n\)\?} { - sleep 0.1 - send "y\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {\[sudo\] password for pi:} { - sleep 0.1 - send "$env(password)\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {mkfs\.fat 4\.1 \(2017-01-24\)} -} - -expect { - default { - puts $failed - exit 1 - } - -re {Please type secret and press enter, then ctrl\+d} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Please type secret and press enter, then ctrl\+d \(again\)} { - sleep 0.1 - send "$secret\r" - sleep 0.1 - send "\x04" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Please type passphrase and press enter} { - sleep 0.1 - send "$passphrase\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Please type passphrase and press enter \(again\)} { - sleep 0.1 - send "$passphrase\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Show passphrase \(y or n\)\?} { - sleep 0.1 - send "y\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - $passphrase -} - -expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 1 of 3…} -} - -expect { - default { - puts $failed - exit 1 - } - -re {SHA512 short hash: .+?([a-f0-9]{8})} { - set short_hash_1 $expect_out(1,string) - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 2 of 3…} -} - -expect { - default { - puts $failed - exit 1 - } - -re {SHA512 short hash: .+?([a-f0-9]{8})} { - set short_hash_2 $expect_out(1,string) - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - {Encrypting secret share 3 of 3…} -} - -expect { - default { - puts $failed - exit 1 - } - -re {SHA512 short hash: .+?([a-f0-9]{8})} { - set short_hash_3 $expect_out(1,string) - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Show SHA512 hash as QR code \(y or n\)\?} { - sleep 0.1 - send "n\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Done} -} - -puts "[bold]Should restore secret using 2 of 3 Shamir Secret Sharing[normal]" - -spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg" --shamir-secret-sharing --share-threshold 2 - -expect { - default { - puts $failed - exit 1 - } - -re {\[sudo\] password for pi:} { - sleep 0.1 - send "$env(password)\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Please type passphrase and press enter} { - sleep 0.1 - send "$passphrase\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Show secret \(y or n\)\?} { - sleep 0.1 - send "y\r" - } -} - -expect { - default { - puts $failed - exit 1 - } - -re {Secret:\r\n((.|\r\n)+?)\r\nDone} { - set restored_secret $expect_out(1,string) - } -} - -regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret -regsub -all {\r} $restored_secret {} restored_secret - -if { "$restored_secret" != "$secret" } { - puts $failed - exit 1 -} else { - puts $ok - exit 0 -} - -interact