diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-08-14 15:46:20 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-08-14 17:26:26 +0200 |
commit | b6c3b0cbea62e3f9e12fe61713a64a3d48cf7961 (patch) | |
tree | 513291af98a1bc1efc87bbc48ba243427f2c4489 /openpgp/tests | |
parent | 7ac4372f981304856e179262eb9c6e8903a7dafb (diff) |
openpgp: Make armor parsing more robust.
- ASCII Armor, designed to protect OpenPGP data in transit, has been
a source of problems if the armor structure is damaged. For
example, copying data manually from one program to another might
introduce or drop newlines.
- This change introduces a heuristic that simply tries to detect the
base64-encoded OpenPGP data. This way, if the framing is in any
way damaged, or even stripped, we can still recover the message.
- Fixes #40.
Diffstat (limited to 'openpgp/tests')
46 files changed, 130 insertions, 0 deletions
diff --git a/openpgp/tests/data/armor/README b/openpgp/tests/data/armor/README new file mode 100644 index 00000000..4f28345a --- /dev/null +++ b/openpgp/tests/data/armor/README @@ -0,0 +1,16 @@ +This directory contains test vectors for the armor module. + +# literal-$n.* + +These files are generated using: + + (cd ../../../.. && cargo build -p openpgp --example wrap-literal) + for n in 0 1 2 3 47 48 49 50 51 + do + dd if=/dev/urandom bs=1 count=$n \ + | ../../../../target/debug/examples/wrap-literal > literal-$n.asc + sq dearmor -o literal-$n.bin literal-$n.asc + grep -v - literal-$n.asc > literal-$n-no-header-with-chksum.asc + grep -v - literal-$n.asc | head -n -1 > literal-$n-no-header.asc + tr "\n" " " <literal-$n.asc > literal-$n-no-newlines.asc + done diff --git a/openpgp/tests/data/armor/literal-0-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-0-no-header-with-chksum.asc new file mode 100644 index 00000000..d700041d --- /dev/null +++ b/openpgp/tests/data/armor/literal-0-no-header-with-chksum.asc @@ -0,0 +1,3 @@ + +ywZiAAAAAAA= +=JgGx diff --git a/openpgp/tests/data/armor/literal-0-no-header.asc b/openpgp/tests/data/armor/literal-0-no-header.asc new file mode 100644 index 00000000..69cfa72e --- /dev/null +++ b/openpgp/tests/data/armor/literal-0-no-header.asc @@ -0,0 +1,2 @@ + +ywZiAAAAAAA= diff --git a/openpgp/tests/data/armor/literal-0-no-newlines.asc b/openpgp/tests/data/armor/literal-0-no-newlines.asc new file mode 100644 index 00000000..ad64567e --- /dev/null +++ b/openpgp/tests/data/armor/literal-0-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- ywZiAAAAAAA= =JgGx -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-0.asc b/openpgp/tests/data/armor/literal-0.asc new file mode 100644 index 00000000..c2ff554d --- /dev/null +++ b/openpgp/tests/data/armor/literal-0.asc @@ -0,0 +1,5 @@ +-----BEGIN PGP MESSAGE----- + +ywZiAAAAAAA= +=JgGx +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-0.bin b/openpgp/tests/data/armor/literal-0.bin Binary files differnew file mode 100644 index 00000000..209897e5 --- /dev/null +++ b/openpgp/tests/data/armor/literal-0.bin diff --git a/openpgp/tests/data/armor/literal-1-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-1-no-header-with-chksum.asc new file mode 100644 index 00000000..4d204ab1 --- /dev/null +++ b/openpgp/tests/data/armor/literal-1-no-header-with-chksum.asc @@ -0,0 +1,3 @@ + +ywdiAAAAAAAG +=+GtG diff --git a/openpgp/tests/data/armor/literal-1-no-header.asc b/openpgp/tests/data/armor/literal-1-no-header.asc new file mode 100644 index 00000000..e7170783 --- /dev/null +++ b/openpgp/tests/data/armor/literal-1-no-header.asc @@ -0,0 +1,2 @@ + +ywdiAAAAAAAG diff --git a/openpgp/tests/data/armor/literal-1-no-newlines.asc b/openpgp/tests/data/armor/literal-1-no-newlines.asc new file mode 100644 index 00000000..6b0d3838 --- /dev/null +++ b/openpgp/tests/data/armor/literal-1-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- ywdiAAAAAAAG =+GtG -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-1.asc b/openpgp/tests/data/armor/literal-1.asc new file mode 100644 index 00000000..1407f7be --- /dev/null +++ b/openpgp/tests/data/armor/literal-1.asc @@ -0,0 +1,5 @@ +-----BEGIN PGP MESSAGE----- + +ywdiAAAAAAAG +=+GtG +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-1.bin b/openpgp/tests/data/armor/literal-1.bin Binary files differnew file mode 100644 index 00000000..6ed6090f --- /dev/null +++ b/openpgp/tests/data/armor/literal-1.bin diff --git a/openpgp/tests/data/armor/literal-2-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-2-no-header-with-chksum.asc new file mode 100644 index 00000000..9b7328f2 --- /dev/null +++ b/openpgp/tests/data/armor/literal-2-no-header-with-chksum.asc @@ -0,0 +1,3 @@ + +ywhiAAAAAACbFA== +=wkzG diff --git a/openpgp/tests/data/armor/literal-2-no-header.asc b/openpgp/tests/data/armor/literal-2-no-header.asc new file mode 100644 index 00000000..d738360f --- /dev/null +++ b/openpgp/tests/data/armor/literal-2-no-header.asc @@ -0,0 +1,2 @@ + +ywhiAAAAAACbFA== diff --git a/openpgp/tests/data/armor/literal-2-no-newlines.asc b/openpgp/tests/data/armor/literal-2-no-newlines.asc new file mode 100644 index 00000000..b61e03a5 --- /dev/null +++ b/openpgp/tests/data/armor/literal-2-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- ywhiAAAAAACbFA== =wkzG -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-2.asc b/openpgp/tests/data/armor/literal-2.asc new file mode 100644 index 00000000..98748b4e --- /dev/null +++ b/openpgp/tests/data/armor/literal-2.asc @@ -0,0 +1,5 @@ +-----BEGIN PGP MESSAGE----- + +ywhiAAAAAACbFA== +=wkzG +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-2.bin b/openpgp/tests/data/armor/literal-2.bin Binary files differnew file mode 100644 index 00000000..84698131 --- /dev/null +++ b/openpgp/tests/data/armor/literal-2.bin diff --git a/openpgp/tests/data/armor/literal-3-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-3-no-header-with-chksum.asc new file mode 100644 index 00000000..a5dd886e --- /dev/null +++ b/openpgp/tests/data/armor/literal-3-no-header-with-chksum.asc @@ -0,0 +1,3 @@ + +ywliAAAAAACC7XQ= +=EBpN diff --git a/openpgp/tests/data/armor/literal-3-no-header.asc b/openpgp/tests/data/armor/literal-3-no-header.asc new file mode 100644 index 00000000..e39c21d2 --- /dev/null +++ b/openpgp/tests/data/armor/literal-3-no-header.asc @@ -0,0 +1,2 @@ + +ywliAAAAAACC7XQ= diff --git a/openpgp/tests/data/armor/literal-3-no-newlines.asc b/openpgp/tests/data/armor/literal-3-no-newlines.asc new file mode 100644 index 00000000..8608aa6b --- /dev/null +++ b/openpgp/tests/data/armor/literal-3-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- ywliAAAAAACC7XQ= =EBpN -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-3.asc b/openpgp/tests/data/armor/literal-3.asc new file mode 100644 index 00000000..f2dd6678 --- /dev/null +++ b/openpgp/tests/data/armor/literal-3.asc @@ -0,0 +1,5 @@ +-----BEGIN PGP MESSAGE----- + +ywliAAAAAACC7XQ= +=EBpN +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-3.bin b/openpgp/tests/data/armor/literal-3.bin Binary files differnew file mode 100644 index 00000000..0d2c43f6 --- /dev/null +++ b/openpgp/tests/data/armor/literal-3.bin diff --git a/openpgp/tests/data/armor/literal-47-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-47-no-header-with-chksum.asc new file mode 100644 index 00000000..d0ffb8d2 --- /dev/null +++ b/openpgp/tests/data/armor/literal-47-no-header-with-chksum.asc @@ -0,0 +1,4 @@ + +yzViAAAAAAAu+RbYYqLiPxrbAE2b5G/9FLK/59YiRxzH2rVW60Uor4I9dPLill2d +kS2Upbc15A== +=jgHY diff --git a/openpgp/tests/data/armor/literal-47-no-header.asc b/openpgp/tests/data/armor/literal-47-no-header.asc new file mode 100644 index 00000000..62064acb --- /dev/null +++ b/openpgp/tests/data/armor/literal-47-no-header.asc @@ -0,0 +1,3 @@ + +yzViAAAAAAAu+RbYYqLiPxrbAE2b5G/9FLK/59YiRxzH2rVW60Uor4I9dPLill2d +kS2Upbc15A== diff --git a/openpgp/tests/data/armor/literal-47-no-newlines.asc b/openpgp/tests/data/armor/literal-47-no-newlines.asc new file mode 100644 index 00000000..60246a13 --- /dev/null +++ b/openpgp/tests/data/armor/literal-47-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- yzViAAAAAAAu+RbYYqLiPxrbAE2b5G/9FLK/59YiRxzH2rVW60Uor4I9dPLill2d kS2Upbc15A== =jgHY -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-47.asc b/openpgp/tests/data/armor/literal-47.asc new file mode 100644 index 00000000..de7c88a9 --- /dev/null +++ b/openpgp/tests/data/armor/literal-47.asc @@ -0,0 +1,6 @@ +-----BEGIN PGP MESSAGE----- + +yzViAAAAAAAu+RbYYqLiPxrbAE2b5G/9FLK/59YiRxzH2rVW60Uor4I9dPLill2d +kS2Upbc15A== +=jgHY +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-47.bin b/openpgp/tests/data/armor/literal-47.bin Binary files differnew file mode 100644 index 00000000..369dbfeb --- /dev/null +++ b/openpgp/tests/data/armor/literal-47.bin diff --git a/openpgp/tests/data/armor/literal-48-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-48-no-header-with-chksum.asc new file mode 100644 index 00000000..b545cc03 --- /dev/null +++ b/openpgp/tests/data/armor/literal-48-no-header-with-chksum.asc @@ -0,0 +1,4 @@ + +yzZiAAAAAAAB+RqN/31/ZIrDdjPkr0f0tmBIyR6up5Dbhqbqbc0bcSNq6sTGByhT +KBToa+1N4BM= +=py+D diff --git a/openpgp/tests/data/armor/literal-48-no-header.asc b/openpgp/tests/data/armor/literal-48-no-header.asc new file mode 100644 index 00000000..3e4e96b8 --- /dev/null +++ b/openpgp/tests/data/armor/literal-48-no-header.asc @@ -0,0 +1,3 @@ + +yzZiAAAAAAAB+RqN/31/ZIrDdjPkr0f0tmBIyR6up5Dbhqbqbc0bcSNq6sTGByhT +KBToa+1N4BM= diff --git a/openpgp/tests/data/armor/literal-48-no-newlines.asc b/openpgp/tests/data/armor/literal-48-no-newlines.asc new file mode 100644 index 00000000..99f4aad9 --- /dev/null +++ b/openpgp/tests/data/armor/literal-48-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- yzZiAAAAAAAB+RqN/31/ZIrDdjPkr0f0tmBIyR6up5Dbhqbqbc0bcSNq6sTGByhT KBToa+1N4BM= =py+D -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-48.asc b/openpgp/tests/data/armor/literal-48.asc new file mode 100644 index 00000000..d69b48ee --- /dev/null +++ b/openpgp/tests/data/armor/literal-48.asc @@ -0,0 +1,6 @@ +-----BEGIN PGP MESSAGE----- + +yzZiAAAAAAAB+RqN/31/ZIrDdjPkr0f0tmBIyR6up5Dbhqbqbc0bcSNq6sTGByhT +KBToa+1N4BM= +=py+D +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-48.bin b/openpgp/tests/data/armor/literal-48.bin Binary files differnew file mode 100644 index 00000000..d23d4ae7 --- /dev/null +++ b/openpgp/tests/data/armor/literal-48.bin diff --git a/openpgp/tests/data/armor/literal-49-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-49-no-header-with-chksum.asc new file mode 100644 index 00000000..0d9bab32 --- /dev/null +++ b/openpgp/tests/data/armor/literal-49-no-header-with-chksum.asc @@ -0,0 +1,4 @@ + +yzdiAAAAAAA13Wsm+LgnhFS3W4A1wbcLJVaznjMZjj5EXAQPG2c99zr6XiJ1KisS +kJFNlVbsWkvL +=PrpW diff --git a/openpgp/tests/data/armor/literal-49-no-header.asc b/openpgp/tests/data/armor/literal-49-no-header.asc new file mode 100644 index 00000000..996d1bad --- /dev/null +++ b/openpgp/tests/data/armor/literal-49-no-header.asc @@ -0,0 +1,3 @@ + +yzdiAAAAAAA13Wsm+LgnhFS3W4A1wbcLJVaznjMZjj5EXAQPG2c99zr6XiJ1KisS +kJFNlVbsWkvL diff --git a/openpgp/tests/data/armor/literal-49-no-newlines.asc b/openpgp/tests/data/armor/literal-49-no-newlines.asc new file mode 100644 index 00000000..f10a7810 --- /dev/null +++ b/openpgp/tests/data/armor/literal-49-no-newlines.asc @@ -0,0 +1 @@ +-----BEGIN PGP MESSAGE----- yzdiAAAAAAA13Wsm+LgnhFS3W4A1wbcLJVaznjMZjj5EXAQPG2c99zr6XiJ1KisS kJFNlVbsWkvL =PrpW -----END PGP MESSAGE-----
\ No newline at end of file diff --git a/openpgp/tests/data/armor/literal-49.asc b/openpgp/tests/data/armor/literal-49.asc new file mode 100644 index 00000000..00230d7b --- /dev/null +++ b/openpgp/tests/data/armor/literal-49.asc @@ -0,0 +1,6 @@ +-----BEGIN PGP MESSAGE----- + +yzdiAAAAAAA13Wsm+LgnhFS3W4A1wbcLJVaznjMZjj5EXAQPG2c99zr6XiJ1KisS +kJFNlVbsWkvL +=PrpW +-----END PGP MESSAGE----- diff --git a/openpgp/tests/data/armor/literal-49.bin b/openpgp/tests/data/armor/literal-49.bin Binary files differnew file mode 100644 index 00000000..6842b92c --- /dev/null +++ b/openpgp/tests/data/armor/literal-49.bin diff --git a/openpgp/tests/data/armor/literal-50-no-header-with-chksum.asc b/openpgp/tests/data/armor/literal-50-no-header-with-chksum.asc new file mode 100644 index 00000000..4439bd3c --- /dev/null +++ b/openpgp/tests/data/armor/literal-50-no-header-with-chksum.asc @@ -0,0 +1,4 @@ + +yzhiAAAAAAA0SHlL3w6uPWhW1tZyUCn6sfzWbCmepdvPGK8QoxGrMpjfAYDIf2RX +2DstnrFcBeR3ow== +=SZ+v |