Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgp: don't shorten key fingerprints #1522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions pgp/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ func (key *MasterKey) encryptWithOpenPGP(dataKey []byte) error {
// PGP key that belongs to Fingerprint. It sets EncryptedDataKey, or returns
// an error.
func (key *MasterKey) encryptWithGnuPG(dataKey []byte) error {
fingerprint := shortenFingerprint(key.Fingerprint)

args := []string{
"--no-default-recipient",
"--yes",
Expand All @@ -331,7 +329,7 @@ func (key *MasterKey) encryptWithGnuPG(dataKey []byte) error {
"-r",
key.Fingerprint,
"--trusted-key",
fingerprint,
key.Fingerprint,
"--no-encrypt-to",
}
stdout, stderr, err := gpgExec(key.gnuPGHomeDir, args, bytes.NewReader(dataKey))
Expand Down Expand Up @@ -629,13 +627,3 @@ func gnuPGHome(customPath string) string {
}
return dir
}

// shortenFingerprint returns the short ID of the given fingerprint.
// This is mostly used for compatibility reasons, as older versions of GnuPG
// do not always like long IDs.
func shortenFingerprint(fingerprint string) string {
if offset := len(fingerprint) - 16; offset > 0 {
fingerprint = fingerprint[offset:]
}
return fingerprint
}
25 changes: 6 additions & 19 deletions pgp/keysource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,16 @@ func TestMasterKey_Decrypt(t *testing.T) {
})
assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))

fingerprint := shortenFingerprint(mockFingerprint)

data := []byte("this data is absolutely top secret")
stdout, stderr, err := gpgExec(gnuPGHome.String(), []string{
"--no-default-recipient",
"--yes",
"--encrypt",
"-a",
"-r",
fingerprint,
mockFingerprint,
"--trusted-key",
fingerprint,
mockFingerprint,
"--no-encrypt-to",
}, bytes.NewReader(data))
assert.Nil(t, err)
Expand Down Expand Up @@ -421,18 +419,16 @@ func TestMasterKey_decryptWithOpenPGP(t *testing.T) {
})
assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))

fingerprint := shortenFingerprint(mockFingerprint)

data := []byte("this data is absolutely top secret")
stdout, stderr, err := gpgExec(gnuPGHome.String(), []string{
"--no-default-recipient",
"--yes",
"--encrypt",
"-a",
"-r",
fingerprint,
mockFingerprint,
"--trusted-key",
fingerprint,
mockFingerprint,
"--no-encrypt-to",
}, bytes.NewReader(data))
assert.Nil(t, err)
Expand Down Expand Up @@ -470,18 +466,16 @@ func TestMasterKey_decryptWithGnuPG(t *testing.T) {
})
assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))

fingerprint := shortenFingerprint(mockFingerprint)

data := []byte("this data is absolutely top secret")
stdout, stderr, err := gpgExec(gnuPGHome.String(), []string{
"--no-default-recipient",
"--yes",
"--encrypt",
"-a",
"-r",
fingerprint,
mockFingerprint,
"--trusted-key",
fingerprint,
mockFingerprint,
"--no-encrypt-to",
}, bytes.NewReader(data))
assert.Nil(t, err)
Expand Down Expand Up @@ -696,13 +690,6 @@ func Test_gnuPGHome(t *testing.T) {
assert.Equal(t, customP, gnuPGHome(customP))
}

func Test_shortenFingerprint(t *testing.T) {
shortId := shortenFingerprint(mockFingerprint)
assert.Equal(t, "9732075EA221A7EA", shortId)

assert.Equal(t, shortId, shortenFingerprint(shortId))
}

// TODO(hidde): previous tests kept around for now.

func TestPGP(t *testing.T) {
Expand Down
Loading