From 331b242a9c9d7d6cc42d59d1127274ea2163b8a8 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Tue, 28 Jun 2022 21:07:39 +0200 Subject: [PATCH] cmd/age: add scrypt testscript --- cmd/age/age.go | 3 +++ cmd/age/age_test.go | 4 ++++ cmd/age/testdata/scrypt.txt | 42 +++++++++++++++++++++++++++++++++++++ go.mod | 10 ++++++--- go.sum | 6 ++++-- 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 cmd/age/testdata/scrypt.txt diff --git a/cmd/age/age.go b/cmd/age/age.go index d53558e..cd46eea 100644 --- a/cmd/age/age.go +++ b/cmd/age/age.go @@ -360,9 +360,12 @@ func encryptPass(in io.Reader, out io.Writer, armor bool) { if err != nil { errorf("%v", err) } + testOnlyConfigureScryptIdentity(r) encrypt([]age.Recipient{r}, in, out, armor) } +var testOnlyConfigureScryptIdentity = func(*age.ScryptRecipient) {} + func encrypt(recipients []age.Recipient, in io.Reader, out io.Writer, withArmor bool) { if withArmor { a := armor.NewWriter(out) diff --git a/cmd/age/age_test.go b/cmd/age/age_test.go index 3c3527b..f1fcebe 100644 --- a/cmd/age/age_test.go +++ b/cmd/age/age_test.go @@ -8,6 +8,7 @@ import ( "os" "testing" + "filippo.io/age" "github.com/rogpeppe/go-internal/testscript" ) @@ -20,6 +21,9 @@ func TestMain(m *testing.M) { exitCode = recover().(int) } }() + testOnlyConfigureScryptIdentity = func(r *age.ScryptRecipient) { + r.SetWorkFactor(10) + } main() return 0 }, diff --git a/cmd/age/testdata/scrypt.txt b/cmd/age/testdata/scrypt.txt new file mode 100644 index 0000000..cb7c545 --- /dev/null +++ b/cmd/age/testdata/scrypt.txt @@ -0,0 +1,42 @@ +[windows] skip # no pty support + +# Encrypt with a provided passphrase. +pty terminal +age -p -o test.age +! stderr . +! stdout . + +# Decrypt with a provided passphrase. +pty terminal +age -d test.age +! stderr . +! stdout . + +# Decrypt with the wrong passphrase. +pty wrong +! age -d test.age +stderr 'incorrect passphrase' + +# Fail when -i is present. +pty terminal +! age -d -i key.txt test.age +stderr 'file is passphrase-encrypted but identities were specified' + +# Fail when passphrases don't match. +pty wrong +! age -p -o fail.age +stderr 'passphrases didn''t match' +! exists fail.age + +-- terminal -- +password +password +-- wrong -- +PASSWORD +password +-- input -- +test +-- key.txt -- +# created: 2021-02-02T13:09:43+01:00 +# public key: age1xmwwc06ly3ee5rytxm9mflaz2u56jjj36s0mypdrwsvlul66mv4q47ryef +AGE-SECRET-KEY-1EGTZVFFV20835NWYV6270LXYVK2VKNX2MMDKWYKLMGR48UAWX40Q2P2LM0 diff --git a/go.mod b/go.mod index 4d01f6a..e3498e8 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,16 @@ go 1.17 require ( filippo.io/edwards25519 v1.0.0-rc.1 - github.com/rogpeppe/go-internal v1.8.1 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 golang.org/x/sys v0.0.0-20210903071746-97244b99971b golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b ) -require github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect +// Test dependencies. +require ( + github.com/creack/pty v1.1.18 // indirect + github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect + github.com/rogpeppe/go-internal v1.8.1 +) -replace github.com/rogpeppe/go-internal v1.8.1 => github.com/FiloSottile/go-internal v1.8.2-0.20220621104300-7a6402ba46b3 // https://github.com/rogpeppe/go-internal/pull/160 +replace github.com/rogpeppe/go-internal => github.com/FiloSottile/go-internal v1.8.2-0.20220703103932-d3b1faae2802 diff --git a/go.sum b/go.sum index 9b905de..2b26ecc 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,9 @@ filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= -github.com/FiloSottile/go-internal v1.8.2-0.20220621104300-7a6402ba46b3 h1:GbSKIczszYD/5OPHiW+iH6GrQRcpfQ5gS0XrWIZ+V6Q= -github.com/FiloSottile/go-internal v1.8.2-0.20220621104300-7a6402ba46b3/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/FiloSottile/go-internal v1.8.2-0.20220703103932-d3b1faae2802 h1:nbboufyYTmxa9hcjNjUkBoKS6xBXXF0umj85jGKRiV0= +github.com/FiloSottile/go-internal v1.8.2-0.20220703103932-d3b1faae2802/go.mod h1:dNbK7mWDMlmf5ttOAJJg+a4CyamnqDRrw+Uja1sBETc= +github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=