Skip to content

Commit 574bc8c

Browse files
committed
pgp: don't shorten key fingerprints
If shortening fingerprints, the trailing '!' from subkey fingerprints is removed, and the wrong key is selected later on, potentially resulting in just-created secrets not being decryptable. Fixes #1365 Signed-off-by: tilpner <git@tilpner.com>
1 parent 0da6be8 commit 574bc8c

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

pgp/keysource.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ func (key *MasterKey) encryptWithOpenPGP(dataKey []byte) error {
321321
// PGP key that belongs to Fingerprint. It sets EncryptedDataKey, or returns
322322
// an error.
323323
func (key *MasterKey) encryptWithGnuPG(dataKey []byte) error {
324-
fingerprint := shortenFingerprint(key.Fingerprint)
325-
326324
args := []string{
327325
"--no-default-recipient",
328326
"--yes",
@@ -331,7 +329,7 @@ func (key *MasterKey) encryptWithGnuPG(dataKey []byte) error {
331329
"-r",
332330
key.Fingerprint,
333331
"--trusted-key",
334-
fingerprint,
332+
key.Fingerprint,
335333
"--no-encrypt-to",
336334
}
337335
stdout, stderr, err := gpgExec(key.gnuPGHomeDir, args, bytes.NewReader(dataKey))
@@ -629,13 +627,3 @@ func gnuPGHome(customPath string) string {
629627
}
630628
return dir
631629
}
632-
633-
// shortenFingerprint returns the short ID of the given fingerprint.
634-
// This is mostly used for compatibility reasons, as older versions of GnuPG
635-
// do not always like long IDs.
636-
func shortenFingerprint(fingerprint string) string {
637-
if offset := len(fingerprint) - 16; offset > 0 {
638-
fingerprint = fingerprint[offset:]
639-
}
640-
return fingerprint
641-
}

pgp/keysource_test.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,16 @@ func TestMasterKey_Decrypt(t *testing.T) {
338338
})
339339
assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))
340340

341-
fingerprint := shortenFingerprint(mockFingerprint)
342-
343341
data := []byte("this data is absolutely top secret")
344342
stdout, stderr, err := gpgExec(gnuPGHome.String(), []string{
345343
"--no-default-recipient",
346344
"--yes",
347345
"--encrypt",
348346
"-a",
349347
"-r",
350-
fingerprint,
348+
mockFingerprint,
351349
"--trusted-key",
352-
fingerprint,
350+
mockFingerprint,
353351
"--no-encrypt-to",
354352
}, bytes.NewReader(data))
355353
assert.Nil(t, err)
@@ -421,18 +419,16 @@ func TestMasterKey_decryptWithOpenPGP(t *testing.T) {
421419
})
422420
assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))
423421

424-
fingerprint := shortenFingerprint(mockFingerprint)
425-
426422
data := []byte("this data is absolutely top secret")
427423
stdout, stderr, err := gpgExec(gnuPGHome.String(), []string{
428424
"--no-default-recipient",
429425
"--yes",
430426
"--encrypt",
431427
"-a",
432428
"-r",
433-
fingerprint,
429+
mockFingerprint,
434430
"--trusted-key",
435-
fingerprint,
431+
mockFingerprint,
436432
"--no-encrypt-to",
437433
}, bytes.NewReader(data))
438434
assert.Nil(t, err)
@@ -470,18 +466,16 @@ func TestMasterKey_decryptWithGnuPG(t *testing.T) {
470466
})
471467
assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))
472468

473-
fingerprint := shortenFingerprint(mockFingerprint)
474-
475469
data := []byte("this data is absolutely top secret")
476470
stdout, stderr, err := gpgExec(gnuPGHome.String(), []string{
477471
"--no-default-recipient",
478472
"--yes",
479473
"--encrypt",
480474
"-a",
481475
"-r",
482-
fingerprint,
476+
mockFingerprint,
483477
"--trusted-key",
484-
fingerprint,
478+
mockFingerprint,
485479
"--no-encrypt-to",
486480
}, bytes.NewReader(data))
487481
assert.Nil(t, err)
@@ -696,13 +690,6 @@ func Test_gnuPGHome(t *testing.T) {
696690
assert.Equal(t, customP, gnuPGHome(customP))
697691
}
698692

699-
func Test_shortenFingerprint(t *testing.T) {
700-
shortId := shortenFingerprint(mockFingerprint)
701-
assert.Equal(t, "9732075EA221A7EA", shortId)
702-
703-
assert.Equal(t, shortId, shortenFingerprint(shortId))
704-
}
705-
706693
// TODO(hidde): previous tests kept around for now.
707694

708695
func TestPGP(t *testing.T) {

0 commit comments

Comments
 (0)