Debian Codegraph @

age/README.md

raw symbols SCIP
1 # age test vectors
2
3 This directory contains a large set of test vectors for the age file encryption
4 format, as well as a framework to easily generate them.
5
6 The test suite can be applied to any age implementation, regardless of the language
7 it's implemented in, and the level of abstraction of its interface.
8 For the simplest, most universal integration, the implementation can just attempt
9 to decrypt the test files, check the operation only succeeds if `expect` is
10 `success`, and compare the decrypted payload. Test vectors involving
11 unimplemented features (such as passphrase encryption or armoring) can be ignored.
12
13 These vectors can't be used to test the encryption direction end-to-end (because
14 there is no strict specification for how to [reproducibly inject randomness](
15 https://words.filippo.io/dispatches/avoid-the-randomness-from-the-sky/)
16 in the process), however, they can be used to test that parsing and encoding
17 operations round-trip in various edge cases. Specifically, `armored` vectors can
18 be used to test round-trips of armor decode/encode (accounting for CRLF/LF and
19 trailing and leading spaces tolerance), any vector that's not a `header failure`
20 can be used to test round-trips of header decode/encode, and any `success` vector
21 can be used to test round-trips of STREAM decrypt/encrypt (with the help of the
22 `file key`).
23
24 For an example of how to use this test suite, check [the reference Go
25 implementation](https://github.com/FiloSottile/age/blob/980763a/testkit_test.go).
26
27 ## Accessing the test vectors
28
29 If testing a Go program, you can import the `c2sp.org/CCTV/age` module and use
30 the embedded filesystem.
31
32 If using npm, you can install the `cctv-age` package and use the module exports.
33
34 Otherwise, you can use `git-subtree` to include a copy of the vectors in your
35 project. The license allows this without attribution.
36
37 ```
38 git fetch https://github.com/C2SP/CCTV
39 TEMPDIR=$(mktemp -d)
40 git worktree add $TEMPDIR FETCH_HEAD
41 SPLIT=$(cd $TEMPDIR && git subtree split -P age/testdata --annotate 'testkit: ')
42 git worktree remove $TEMPDIR
43 git subtree add -P testkit $SPLIT
44 ```
45
46 To update the vectors, repeat the process with `git subtree merge` instead of
47 `git subtree add`.
48
49 ## Test file format
50
51 Each file in the `testdata` folder is a separate test vector, meant to be
52 processed independently. Each vector is meant to test only one failure (or
53 success) scenario.
54
55 The file is in two parts: first a textual header, then an empty line, and then
56 an age encrypted file, possibly compressed. The textual header is a series of
57 key-value pairs, separated by a colon and a space, each on their own line.
58
59 The following header keys are defined. Files with unknown keys should be
60 ignored.
61
62 - `expect`
63
64 This key defines what the result of decrypting the file should be.
65 Distinguishing between different types of failure can be important to avoid
66 masking what should be a lower-level error (for example, a parsing error) with
67 a higher-level error (for example, incorrect HMAC because the incorrectly
68 parsed file was re-encoded before calculating the HMAC). However, they might
69 not map effectively to your API, in which case you should consider aliasing
70 indistinguishable cases. It can take the following values.
71
72 * `success`
73
74 The file should decrypt correctly all the way to EOF, and the payload should
75 match the expected hash (see below).
76
77 * `no match`
78
79 The header should parse successfully, but none of the recipient stanzas can
80 be unwrapped.
81
82 * `HMAC failure`
83
84 The header should parse successfully, and a file key can be unwrapped, but
85 the header HMAC should not match.
86
87 * `header failure`
88
89 The header should fail to parse successfully.
90
91 * `payload failure`
92
93 The header should parse successfully, and a file key can be unwrapped, but
94 the STREAM-encrypted payload doesn't decrypt successfully all the way to
95 EOF. **Whatever payload decrypted successfully before encountering the error
96 must be checked against the payload hash (see below).**
97
98 * `armor failure`
99
100 The ASCII armor should fail to parse successfully.
101
102 - `compressed`
103
104 This key will be `gzip` if the age encrypted file is compressed with gzip.
105 Note that encrypted files usually don't compress well, but large test files in
106 this collection are generated from plaintexts selected to make the ciphertext
107 compressible. **Some of these files can be several megabytes once decompressed.**
108
109 - `payload`
110
111 This is a hex-encoded SHA-256 hash of the payload. **All** the plaintext that
112 would have been released to the application by the API must match this hash,
113 even if the decryption eventually fails.
114
115 - `identity`
116
117 This is a Bech32 encoded X25519 identity that should be used to unwrap
118 recipient stanzas. This key can appear multiple times.
119
120 - `passphrase`
121
122 This is a passphrase that should be used to unwrap `scrypt` recipient stanzas.
123 This key can appear multiple times.
124
125 - `armored`
126
127 This key will be `yes` if the file is supposed to be encoded in the optional
128 ASCII armor.
129
130 - `file key`
131
132 This is the hex-encoded file key, to aid debugging. This can be ignored.
133
134 - `comment`
135
136 This is a textual comment that explains the vector. This can be ignored.
137
138 ## The testkit framework
139
140 Every test vector in `testdata` is generated by a corresponding file in
141 `internal/tests`, using the framework in `internal/testkit`.
142
143 To generate the files, run
144
145 ```
146 go generate ./...
147 ```
148
149 ## License
150
151 The vectors in the `testdata` folder and the files in this top-level directory
152 are available under the terms of the
153 [Zero-Clause BSD](https://opensource.org/licenses/0BSD) (reproduced below),
154 [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/), or
155 [Unlicense](https://unlicense.org/) license, to your choice.
156
157 Copyright (c) 2022 The age Authors
158
159 Permission to use, copy, modify, and/or distribute this software for any purpose
160 with or without fee is hereby granted.
161
162 **The software is provided "as is" and the author disclaims all warranties with
163 regard to this software including all implied warranties of merchantability and
164 fitness. In no event shall the author be liable for any special, direct,
165 indirect, or consequential damages or any damages whatsoever resulting from loss
166 of use, data or profits, whether in an action of contract, negligence or other
167 tortious action, arising out of or in connection with the use or performance of
168 this software.**