Skip to content

Commit f7f5466

Browse files
aviauFiloSottile
authored andcommitted
openpgp: test subkeys with sub-optimal signature packet ordering
Test for RFC4880 5.2.3.3: > An implementation that encounters multiple self-signatures on the > same object may resolve the ambiguity in any way it sees fit, but it > is RECOMMENDED that priority be given to the most recent self- > signature. Note: Some GPG implementation will reorder the packets for you when exporting keys. This makes it complicated to generate a key for this test. Should someone have to create a similar key again, look into gpgsplit, gpg --dearmor, and gpg --enarmor. These keys exist in the wild too. Change-Id: I5d46054ebbc95407d644e4e462d777aab290794c Reviewed-on: https://go-review.googlesource.com/138215 Run-TryBot: Filippo Valsorda <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent 0259c3f commit f7f5466

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

openpgp/keys_test.go

+78
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,51 @@ func TestSubkeyRevocation(t *testing.T) {
254254
}
255255
}
256256

257+
func TestKeyWithSubKeyAndBadSelfSigOrder(t *testing.T) {
258+
// This key was altered so that the self signatures following the
259+
// subkey are in a sub-optimal order.
260+
//
261+
// Note: Should someone have to create a similar key again, look into
262+
// gpgsplit, gpg --dearmor, and gpg --enarmor.
263+
//
264+
// The packet ordering is the following:
265+
// PUBKEY UID UIDSELFSIG SUBKEY SELFSIG1 SELFSIG2
266+
//
267+
// Where:
268+
// SELFSIG1 expires on 2018-06-14 and was created first
269+
// SELFSIG2 does not expire and was created after SELFSIG1
270+
//
271+
// Test for RFC 4880 5.2.3.3:
272+
// > An implementation that encounters multiple self-signatures on the
273+
// > same object may resolve the ambiguity in any way it sees fit, but it
274+
// > is RECOMMENDED that priority be given to the most recent self-
275+
// > signature.
276+
//
277+
// This means that we should keep SELFSIG2.
278+
279+
keys, err := ReadArmoredKeyRing(bytes.NewBufferString(keyWithSubKeyAndBadSelfSigOrder))
280+
if err != nil {
281+
t.Fatal(err)
282+
}
283+
284+
if len(keys) != 1 {
285+
t.Fatal("Failed to read key with a sub key and a bad selfsig packet order")
286+
}
287+
288+
key := keys[0]
289+
290+
if numKeys, expected := len(key.Subkeys), 1; numKeys != expected {
291+
t.Fatalf("Read %d subkeys, expected %d", numKeys, expected)
292+
}
293+
294+
subKey := key.Subkeys[0]
295+
296+
if lifetime := subKey.Sig.KeyLifetimeSecs; lifetime != nil {
297+
t.Errorf("The signature has a key lifetime (%d), but it should be nil", *lifetime)
298+
}
299+
300+
}
301+
257302
func TestKeyUsage(t *testing.T) {
258303
kring, err := ReadKeyRing(readerFromHex(subkeyUsageHex))
259304
if err != nil {
@@ -613,3 +658,36 @@ mvDgHfuogmgNJRjOMznvahbF+wpTXmB7LS0SK412gJzl1fFIpK4bgnhu0TwxNsO1
613658
Xt6B9h1YpeLoJwjwsvbi98UTRs0jXwoY
614659
=3fWu
615660
-----END PGP PUBLIC KEY BLOCK-----`
661+
662+
const keyWithSubKeyAndBadSelfSigOrder = `-----BEGIN PGP PUBLIC KEY BLOCK-----
663+
664+
mI0EWyLLDQEEAOqIOpJ/ha1OYAGduu9tS3rBz5vyjbNgJO4sFveEM0mgsHQ0X9/L
665+
plonW+d0gRoO1dhJ8QICjDAc6+cna1DE3tEb5m6JtQ30teLZuqrR398Cf6w7NNVz
666+
r3lrlmnH9JaKRuXl7tZciwyovneBfZVCdtsRZjaLI1uMQCz/BToiYe3DABEBAAG0
667+
I0dvbGFuZyBHb3BoZXIgPG5vLXJlcGx5QGdvbGFuZy5jb20+iM4EEwEKADgWIQRZ
668+
sixZOfQcZdW0wUqmgmdsv1O9xgUCWyLLDQIbAwULCQgHAwUVCgkICwUWAgMBAAIe
669+
AQIXgAAKCRCmgmdsv1O9xql2A/4pix98NxjhdsXtazA9agpAKeADf9tG4Za27Gj+
670+
3DCww/E4iP2X35jZimSm/30QRB6j08uGCqd9vXkkJxtOt63y/IpVOtWX6vMWSTUm
671+
k8xKkaYMP0/IzKNJ1qC/qYEUYpwERBKg9Z+k99E2Ql4kRHdxXUH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2y/U73GRl0EAJokkXmy4zKDHWWi
688+
wvK9gi2gQgRkVnu2AiONxJb5vjeLhM/07BRmH6K1o+w3fOeEQp4FjXj1eQ5fPSM6
689+
Hhwx2CTl9SDnPSBMiKXsEFRkmwQ2AAsQZLmQZvKBkLZYeBiwf+IY621eYDhZfo+G
690+
1dh1WoUCyREZsJQg2YoIpWIcvw+a
691+
=bNRo
692+
-----END PGP PUBLIC KEY BLOCK-----
693+
`

0 commit comments

Comments
 (0)