From a787511e011bba264f37f66fc0cb598a071b41f9 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 15 Jun 2022 18:54:09 +0200 Subject: [PATCH] testdata: add a few more testkit vectors --- cmd/age/testdata/fail_bad_hmac.age | Bin 230 -> 0 bytes .../testdata/fail_large_filekey_x25519.age | Bin 225 -> 0 bytes cmd/age/testdata/good_empty_payload.age | Bin 200 -> 0 bytes .../testdata/good_empty_recipient_body.age | Bin 236 -> 0 bytes internal/testkit/testkit.go | 45 ++++++++++-------- testdata/bad_hmac.go | 21 ++++++++ testdata/bad_hmac.test | 9 ++++ testdata/empty_payload.go | 18 +++++++ testdata/empty_payload.test | 10 ++++ testdata/long_file_key.go | 21 ++++++++ testdata/long_file_key.test | 10 ++++ testdata/no_match.go | 21 ++++++++ testdata/no_match.test | 9 ++++ testdata/stanza_empty_body.go | 20 ++++++++ testdata/stanza_empty_body.test | 12 +++++ testdata/stanza_empty_last_line.go | 24 ++++++++++ testdata/stanza_empty_last_line.test | 13 +++++ testdata/stanza_missing_body.go | 22 +++++++++ testdata/stanza_missing_body.test | 11 +++++ testdata/stanza_missing_final_line.go | 26 ++++++++++ testdata/stanza_missing_final_line.test | 12 +++++ testdata/stanza_multiple_short_lines.go | 27 +++++++++++ testdata/stanza_multiple_short_lines.test | 13 +++++ testdata/x25519.test | 1 + testkit_test.go | 18 ++++++- 25 files changed, 342 insertions(+), 21 deletions(-) delete mode 100644 cmd/age/testdata/fail_bad_hmac.age delete mode 100644 cmd/age/testdata/fail_large_filekey_x25519.age delete mode 100644 cmd/age/testdata/good_empty_payload.age delete mode 100644 cmd/age/testdata/good_empty_recipient_body.age create mode 100644 testdata/bad_hmac.go create mode 100644 testdata/bad_hmac.test create mode 100644 testdata/empty_payload.go create mode 100644 testdata/empty_payload.test create mode 100644 testdata/long_file_key.go create mode 100644 testdata/long_file_key.test create mode 100644 testdata/no_match.go create mode 100644 testdata/no_match.test create mode 100644 testdata/stanza_empty_body.go create mode 100644 testdata/stanza_empty_body.test create mode 100644 testdata/stanza_empty_last_line.go create mode 100644 testdata/stanza_empty_last_line.test create mode 100644 testdata/stanza_missing_body.go create mode 100644 testdata/stanza_missing_body.test create mode 100644 testdata/stanza_missing_final_line.go create mode 100644 testdata/stanza_missing_final_line.test create mode 100644 testdata/stanza_multiple_short_lines.go create mode 100644 testdata/stanza_multiple_short_lines.test diff --git a/cmd/age/testdata/fail_bad_hmac.age b/cmd/age/testdata/fail_bad_hmac.age deleted file mode 100644 index b524055d1287656a22a1cbfe910d378b866181d7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 230 zcmYdHPt{G$OD?J`D9Oyv)5|YP*Do{V(zR2FFfuhYv{cA6^YV{0E-mv-aVmAKOo~hj zDKK_*b}RM|aE;V=G|usgG|VvwEHmfQSnKUUXIf diff --git a/cmd/age/testdata/fail_large_filekey_x25519.age b/cmd/age/testdata/fail_large_filekey_x25519.age deleted file mode 100644 index e72482862f6f5f355954175719ab3a3f92f580ae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 225 zcmV<703QEgXJsvAZewzJaCB*JZZ2C-L3Cwp zRy9;tG;>FHc~C@9O-W`_XE;`6IC5e{SadXWLw9a&OJhxOGD|jLZ*h1E3N0-yAa+$~ zOjR&dIYeVPS!iNQc{EdaOLcKDX;X1=YC=~>Zb)WYM=LoiPc(Kk3c$JbXYlf}fM^x8 bSCRPXQ%U;UX0OJEM2+=PJJ3=UXzGb~4YN~a diff --git a/cmd/age/testdata/good_empty_payload.age b/cmd/age/testdata/good_empty_payload.age deleted file mode 100644 index 93e5611fcf71667da5f1bfbefbcfdd4032afa742..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 200 zcmYdHPt{G$OD?J`D9Oyv)5|YP*Do{V(zR2FFfuhYv{dj4$}je;GD<89PtFK1Dh&29 zD|a&sH7~7lG0S!-^@?ywiYoIn^!0bo&FAti@C>Xd$WC%{@hB|N_A2)9$qcD9N-+(J z3@R@$Dy%9CEpkjXNObYf%jVM6)m6wZ3d>3=OsdMY2sIA2%*%2tHZ{&S32@6aEcZ6H zO!Ev3G)WK2GR`#j4CUf(IiLPfXkRbS6(NK6iCg)O`LQli&-(o>F~5;-r`od+011Uf AQvd(} diff --git a/cmd/age/testdata/good_empty_recipient_body.age b/cmd/age/testdata/good_empty_recipient_body.age deleted file mode 100644 index d101cf62f2bad68ef65701dc37ae096ab2ef31b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 236 zcmYdHPt{G$OD?J`D9Oyv)5|YP*Do{V(zR2FFfuhYv{XpU3Cc@#DbDcBFfq<6uXHih zPRl3_aWM@EN)67lut+m1EjG!hiVCQ#3gs$rPbu~DHuVk7$SbY#tq3 zUg~KYT%770lg>h*Yq(zF^dnn$?@b? j>+IH0oA-vlir4+OPq?OCKW&oAa*u1_O=b4w7E$2 X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +hjabGXwSLQ9c3S6Lw2i+S2Tu2fiwQHHslbBN6B41FLE +--- UGnodA32FkH3AOl9BHP6biSZTkNvu8B99I++7JpqZGk +[. #wυ=aYkz66ڦRL \ No newline at end of file diff --git a/testdata/empty_payload.go b/testdata/empty_payload.go new file mode 100644 index 0000000..82b4e93 --- /dev/null +++ b/testdata/empty_payload.go @@ -0,0 +1,18 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import "filippo.io/age/internal/testkit" + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519(testkit.TestX25519Recipient) + f.HMAC() + f.Payload("") + f.Generate() +} diff --git a/testdata/empty_payload.test b/testdata/empty_payload.test new file mode 100644 index 0000000..6ec1c83 --- /dev/null +++ b/testdata/empty_payload.test @@ -0,0 +1,10 @@ +expect: success +payload: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +EmECAEcKN+n/Vs9SbWiV+Hu0r+E8R77DdWYyd83nw7U +--- Vn+54jqiiUCE+WZcEVY3f1sqHjlu/z1LCQ/T7Xm7qI0 +bΑ3'NhL.O>RA0ޫC6U \ No newline at end of file diff --git a/testdata/long_file_key.go b/testdata/long_file_key.go new file mode 100644 index 0000000..df59334 --- /dev/null +++ b/testdata/long_file_key.go @@ -0,0 +1,21 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import "filippo.io/age/internal/testkit" + +func main() { + f := testkit.NewTestFile() + f.FileKey([]byte("A LONGER YELLOW SUBMARINE")) + f.VersionLine("v1") + f.X25519(testkit.TestX25519Identity) + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Comment("the file key must be checked to be 16 bytes before decrypting it") + f.Generate() +} diff --git a/testdata/long_file_key.test b/testdata/long_file_key.test new file mode 100644 index 0000000..30dc440 --- /dev/null +++ b/testdata/long_file_key.test @@ -0,0 +1,10 @@ +expect: header failure +file key: 41204c4f4e4745522059454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1EGTZVFFV20835NWYV6270LXYVK2VKNX2MMDKWYKLMGR48UAWX40Q2P2LM0 +comment: the file key must be checked to be 16 bytes before decrypting it + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +nlObGn0CSA4pxiaG3W6nLlaFFuHmqW+bFC6sJmbsJ9yFesgSok1K0AI +--- C49Jo3+j4I6jWB2tldSs1jVAXbv0mOTAnwdT+5vOiBg +bΑ3'NhLc( tǏP)x1 \ No newline at end of file diff --git a/testdata/no_match.go b/testdata/no_match.go new file mode 100644 index 0000000..af27c51 --- /dev/null +++ b/testdata/no_match.go @@ -0,0 +1,21 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import "filippo.io/age/internal/testkit" + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + identity := f.Rand(32) + f.X25519RecordIdentity(identity) + f.X25519NoRecordIdentity(testkit.TestX25519Recipient) + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Generate() +} diff --git a/testdata/no_match.test b/testdata/no_match.test new file mode 100644 index 0000000..c146be3 --- /dev/null +++ b/testdata/no_match.test @@ -0,0 +1,9 @@ +expect: header failure +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-143WN7DCXU4G8R5AXQSSYD9AEPYDNT3HXSLWSPK36CDU6E8M59SSSAGZ3KG + +age-encryption.org/v1 +-> X25519 ajtqAvDEkVNr2B7zUOtq2mAQXDSBlNrVAuM/dKb5sT4 +HUKtz0R2j5Bl2ER7HhAZrURikCFpiIjNa0KjHcjbAGU +--- rrpTlvKEKrK3EqhoOPJeP1KE8O1d2arrRez77mwekRc +roW= 1$!ox-yG^^ \ No newline at end of file diff --git a/testdata/stanza_empty_body.go b/testdata/stanza_empty_body.go new file mode 100644 index 0000000..d5eb52d --- /dev/null +++ b/testdata/stanza_empty_body.go @@ -0,0 +1,20 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import "filippo.io/age/internal/testkit" + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519(testkit.TestX25519Recipient) + f.ArgsLine("empty") + f.Body([]byte("")) + f.HMAC() + f.Payload("age") + f.Generate() +} diff --git a/testdata/stanza_empty_body.test b/testdata/stanza_empty_body.test new file mode 100644 index 0000000..cf8ec9b --- /dev/null +++ b/testdata/stanza_empty_body.test @@ -0,0 +1,12 @@ +expect: success +payload: 013f54400c82da08037759ada907a8b864e97de81c088a182062c4b5622fd2ab +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +EmECAEcKN+n/Vs9SbWiV+Hu0r+E8R77DdWYyd83nw7U +-> empty + +--- 697zSC9pa/ZLNIaXGtuwcUobmxv+Dpx48Hv0papk5c0 +bΑ3'NhLL[R,1f \ No newline at end of file diff --git a/testdata/stanza_empty_last_line.go b/testdata/stanza_empty_last_line.go new file mode 100644 index 0000000..519be1e --- /dev/null +++ b/testdata/stanza_empty_last_line.go @@ -0,0 +1,24 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "bytes" + + "filippo.io/age/internal/testkit" +) + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519(testkit.TestX25519Recipient) + f.ArgsLine("stanza") + f.Body(bytes.Repeat([]byte("A"), 48)) + f.HMAC() + f.Payload("age") + f.Generate() +} diff --git a/testdata/stanza_empty_last_line.test b/testdata/stanza_empty_last_line.test new file mode 100644 index 0000000..285f0d8 --- /dev/null +++ b/testdata/stanza_empty_last_line.test @@ -0,0 +1,13 @@ +expect: success +payload: 013f54400c82da08037759ada907a8b864e97de81c088a182062c4b5622fd2ab +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +EmECAEcKN+n/Vs9SbWiV+Hu0r+E8R77DdWYyd83nw7U +-> stanza +QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB + +--- +3PC416gxa7Mk7WxpX0kb6DVfSuCun0niGre+G4bZhE +bΑ3'NhLL[R,1f \ No newline at end of file diff --git a/testdata/stanza_missing_body.go b/testdata/stanza_missing_body.go new file mode 100644 index 0000000..649b5b6 --- /dev/null +++ b/testdata/stanza_missing_body.go @@ -0,0 +1,22 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import "filippo.io/age/internal/testkit" + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519(testkit.TestX25519Recipient) + f.ArgsLine("empty") + // Missing body. + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Comment("every stanza must end with a short body line, even if empty") + f.Generate() +} diff --git a/testdata/stanza_missing_body.test b/testdata/stanza_missing_body.test new file mode 100644 index 0000000..4c184c7 --- /dev/null +++ b/testdata/stanza_missing_body.test @@ -0,0 +1,11 @@ +expect: header failure +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 +comment: every stanza must end with a short body line, even if empty + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +EmECAEcKN+n/Vs9SbWiV+Hu0r+E8R77DdWYyd83nw7U +-> empty +--- CDgFIIJ1wE4CpW6zG+LVZ6/G/RCNTH6ZUVGp2NbeIkU +bΑ3'NhLL[R,1f \ No newline at end of file diff --git a/testdata/stanza_missing_final_line.go b/testdata/stanza_missing_final_line.go new file mode 100644 index 0000000..5b5b6b5 --- /dev/null +++ b/testdata/stanza_missing_final_line.go @@ -0,0 +1,26 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "strings" + + "filippo.io/age/internal/testkit" +) + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519(testkit.TestX25519Recipient) + f.ArgsLine("stanza") + f.TextLine(strings.Repeat("A", 64)) + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Comment("every stanza must end with a short body line") + f.Generate() +} diff --git a/testdata/stanza_missing_final_line.test b/testdata/stanza_missing_final_line.test new file mode 100644 index 0000000..58774f4 --- /dev/null +++ b/testdata/stanza_missing_final_line.test @@ -0,0 +1,12 @@ +expect: header failure +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 +comment: every stanza must end with a short body line + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +EmECAEcKN+n/Vs9SbWiV+Hu0r+E8R77DdWYyd83nw7U +-> stanza +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +--- GRjUy1ShNhFoV3cQikdtUZqDeDEZSrbtNXUgDtDbwC8 +bΑ3'NhLL[R,1f \ No newline at end of file diff --git a/testdata/stanza_multiple_short_lines.go b/testdata/stanza_multiple_short_lines.go new file mode 100644 index 0000000..045f78f --- /dev/null +++ b/testdata/stanza_multiple_short_lines.go @@ -0,0 +1,27 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "strings" + + "filippo.io/age/internal/testkit" +) + +func main() { + f := testkit.NewTestFile() + f.VersionLine("v1") + f.X25519(testkit.TestX25519Recipient) + f.ArgsLine("stanza") + f.TextLine(strings.Repeat("A", 32)) + f.TextLine(strings.Repeat("A", 32)) + f.HMAC() + f.Payload("age") + f.ExpectHeaderFailure() + f.Comment("a short body line ends the stanza") + f.Generate() +} diff --git a/testdata/stanza_multiple_short_lines.test b/testdata/stanza_multiple_short_lines.test new file mode 100644 index 0000000..e191764 --- /dev/null +++ b/testdata/stanza_multiple_short_lines.test @@ -0,0 +1,13 @@ +expect: header failure +file key: 59454c4c4f57205355424d4152494e45 +identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 +comment: a short body line ends the stanza + +age-encryption.org/v1 +-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc +EmECAEcKN+n/Vs9SbWiV+Hu0r+E8R77DdWYyd83nw7U +-> stanza +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +--- ct87HSIMoTC4nUsQva+8AeKc2bK2q8b9sPjRhjuf1us +bΑ3'NhLL[R,1f \ No newline at end of file diff --git a/testdata/x25519.test b/testdata/x25519.test index d0444b4..c7bb509 100644 --- a/testdata/x25519.test +++ b/testdata/x25519.test @@ -1,5 +1,6 @@ expect: success payload: 013f54400c82da08037759ada907a8b864e97de81c088a182062c4b5622fd2ab +file key: 59454c4c4f57205355424d4152494e45 identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6 age-encryption.org/v1 diff --git a/testkit_test.go b/testkit_test.go index 01fdda9..cfc1233 100644 --- a/testkit_test.go +++ b/testkit_test.go @@ -9,7 +9,6 @@ import ( "crypto/sha256" "encoding/hex" "flag" - "fmt" "io" "log" "os" @@ -27,15 +26,26 @@ func TestMain(m *testing.M) { genFlag := flag.Bool("generate", false, "regenerate test files") flag.Parse() if *genFlag { + log.SetFlags(0) + tests, err := filepath.Glob("testdata/*.test") + if err != nil { + log.Fatal(err) + } + for _, test := range tests { + os.Remove(test) + } generators, err := filepath.Glob("testdata/*.go") if err != nil { log.Fatal(err) } for _, generator := range generators { vector := strings.TrimSuffix(generator, ".go") + ".test" - fmt.Fprintf(os.Stderr, "%s -> %s\n", generator, vector) + log.Printf("%s -> %s\n", generator, vector) out, err := exec.Command("go", "run", generator).Output() if err != nil { + if err, ok := err.(*exec.ExitError); ok { + log.Fatalf("%s", err.Stderr) + } log.Fatal(err) } os.WriteFile(vector, out, 0664) @@ -104,6 +114,8 @@ func testVector(t *testing.T, test []byte) { t.Fatal(err) } identities = append(identities, i) + case "file key": + // Ignored. case "comment": t.Log(value) default: @@ -114,6 +126,7 @@ func testVector(t *testing.T, test []byte) { r, err := age.Decrypt(bytes.NewReader(test), identities...) if err != nil { if expectHeaderFailure { + t.Log(err) return } t.Fatal("unexpected header error:", err) @@ -123,6 +136,7 @@ func testVector(t *testing.T, test []byte) { out, err := io.ReadAll(r) if err != nil { if expectPayloadFailure { + t.Log(err) return } t.Fatal("unexpected payload error:", err)