Skip to content

Commit

Permalink
more name changes to make keys uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Dec 15, 2023
1 parent 9d741b0 commit 6c4dcc4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
52 changes: 26 additions & 26 deletions internal/openpgputil/openpgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@ import (
)

var (
testKey = testutil.PGPKeys["key1"]
extraTestKey = testutil.PGPKeys["key2"]
key1 = testutil.PGPKeys["key1"]
key2 = testutil.PGPKeys["key2"]
)

type archiveKeyTest struct {
summary string
armored string
armor string
relerror string
pubKey *packet.PublicKey
}

var archiveKeyTests = []archiveKeyTest{{
summary: "Armored data with one public key",
armored: testKey.PubKeyArmored,
pubKey: testKey.PubKey,
armor: key1.PubKeyArmor,
pubKey: key1.PubKey,
}, {
summary: "Armored data with two public keys",
armored: twoPubKeysArmored,
armor: twoPubKeysArmor,
relerror: "armored data contains more than one public key",
}, {
summary: "Armored data with no public key",
armored: armoredDataWithNoKeys,
armor: armoredDataWithNoKeys,
relerror: "armored data contains no public key",
}, {
summary: "Armored data with private key",
armored: testKey.PrivKeyArmored,
armor: key1.PrivKeyArmor,
relerror: "armored data contains private key",
}, {
summary: "Invalid armored data",
armored: `
armor: `
Roses are red
Violets are blue
`,
Expand All @@ -48,15 +48,15 @@ var archiveKeyTests = []archiveKeyTest{{
relerror: "cannot decode armored data",
}, {
summary: "Armored data: bad packets",
armored: invalidArmoredKey,
armor: invalidPubKeyArmor,
relerror: "openpgp: .*",
}}

func (s *S) TestDecodeArchivePubKey(c *C) {
for _, test := range archiveKeyTests {
c.Logf("Summary: %s", test.summary)

pubKey, err := openpgputil.DecodePubKey([]byte(test.armored))
pubKey, err := openpgputil.DecodePubKey([]byte(test.armor))
if test.relerror != "" {
c.Assert(err, ErrorMatches, test.relerror)
continue
Expand All @@ -77,38 +77,38 @@ type verifyClearSignTest struct {
var verifyClearSignTests = []verifyClearSignTest{{
summary: "Good data with proper sign",
clearData: clearSignedData,
pubKeys: []*packet.PublicKey{testKey.PubKey},
pubKeys: []*packet.PublicKey{key1.PubKey},
}, {
summary: "Good data with multiple signatures",
clearData: clearSignedWithMultipleSigns,
pubKeys: []*packet.PublicKey{testKey.PubKey, extraTestKey.PubKey},
pubKeys: []*packet.PublicKey{key1.PubKey, key2.PubKey},
}, {
summary: "Multiple signatures: verify at least one signature",
clearData: clearSignedWithMultipleSigns,
pubKeys: []*packet.PublicKey{testKey.PubKey},
pubKeys: []*packet.PublicKey{key1.PubKey},
}, {
summary: "Multiple signatures: no valid public keys",
clearData: clearSignedWithMultipleSigns,
relerror: "cannot verify any signatures",
}, {
summary: "Invalid data: improper hash",
clearData: invalidSignedData,
pubKeys: []*packet.PublicKey{testKey.PubKey},
clearData: invalidClearSignedData,
pubKeys: []*packet.PublicKey{key1.PubKey},
relerror: "openpgp: .*invalid signature: hash tag doesn't match.*",
}, {
summary: "Invalid data: bad packets",
clearData: invalidSignedDataBadPackets,
pubKeys: []*packet.PublicKey{testKey.PubKey},
clearData: invalidClearSignedDataBadPackets,
pubKeys: []*packet.PublicKey{key1.PubKey},
relerror: "cannot parse armored data: openpgp: .*",
}, {
summary: "Invalid data: malformed clearsign text",
clearData: "foo\n",
pubKeys: []*packet.PublicKey{testKey.PubKey},
pubKeys: []*packet.PublicKey{key1.PubKey},
relerror: "cannot decode clearsign text",
}, {
summary: "Wrong public key to verify with",
clearData: clearSignedData,
pubKeys: []*packet.PublicKey{extraTestKey.PubKey},
pubKeys: []*packet.PublicKey{key2.PubKey},
relerror: "openpgp: .*invalid signature:.*verification failure",
}}

Expand All @@ -129,10 +129,10 @@ func (s *S) TestVerifySignature(c *C) {
}
}

// twoPubKeysArmored contains two public keys:
// twoPubKeysArmor contains two public keys:
// - 854BAF1AA9D76600 ("foo-bar <foo@bar>")
// - 871920D1991BC93C ("Ubuntu Archive Automatic Signing Key (2018) <[email protected]>")
const twoPubKeysArmored = `
const twoPubKeysArmor = `
-----BEGIN PGP ARMORED FILE-----
mQENBGVs8P4BCADPh/fNnw2AI1JCYf+3p4jkcFQPLVsUkoTZk8OXjCxy+UP9Jd2m
Expand Down Expand Up @@ -202,7 +202,7 @@ cgcXWByCFx3J1hM=

// This should be an invalid clearsign data. Obtained by changing
// "foo" to "bar" in clearSignedData defined above.
const invalidSignedData = `
const invalidClearSignedData = `
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Expand All @@ -222,7 +222,7 @@ VvD4PlSNTcSmpZTICEmLmb3DLlXezQ0Rgfwy6Q6X0kt9xztIJsNo5sgRxQUlpVl3

// This should be an invalid clearsign data with invalid packets.
// Obtained by removing some lines from clearSignedData above.
const invalidSignedDataBadPackets = `
const invalidClearSignedDataBadPackets = `
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Expand Down Expand Up @@ -257,8 +257,8 @@ yVadRjJlRcYSHceghZt38RvEIzW+bXq3v2KivrjoHF58tVJcLQlM5a0mjw==
-----END PGP ARMORED FILE-----
`

// invalidArmoredKey contains bad packets.
const invalidArmoredKey = `
// invalidPubKeyArmor contains bad packets.
const invalidPubKeyArmor = `
-----BEGIN PGP PUBLIC KEY BLOCK-----
mI0EZXAwcgEEAMBQ4Qx6xam1k1hyjPrKQfCnGRBBm2+Lw9DHQcz0lreH51iZEVkS
Expand Down
14 changes: 7 additions & 7 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var setupTests = []setupTest{{
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
Expand Down Expand Up @@ -783,7 +783,7 @@ var setupTests = []setupTest{{
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
Expand Down Expand Up @@ -833,7 +833,7 @@ var setupTests = []setupTest{{
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
madeUpKey6: whatever
`,
"slices/mydir/mypkg.yaml": `
Expand Down Expand Up @@ -895,10 +895,10 @@ var setupTests = []setupTest{{
public-keys:
extra-key:
id: ` + extraTestKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(extraTestKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(extraTestKey.PubKeyArmor, "\t\t\t\t\t\t") + `
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
Expand Down Expand Up @@ -1007,7 +1007,7 @@ var setupTests = []setupTest{{
public-keys:
extra-key:
id: ` + extraTestKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
Expand All @@ -1026,7 +1026,7 @@ var defaultChiselYaml = `
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`

func (s *S) TestParseRelease(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions internal/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ var slicerTests = []slicerTest{{
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/base-files.yaml": `
package: base-files
Expand Down Expand Up @@ -537,7 +537,7 @@ var defaultChiselYaml = `
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmored, "\t\t\t\t\t\t") + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`

type testArchive struct {
Expand Down
34 changes: 17 additions & 17 deletions internal/testutil/pgpkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@ import (
)

type PGPKeyData struct {
ID string
PubKeyArmored string
PrivKeyArmored string
PubKey *packet.PublicKey
PrivKey *packet.PrivateKey
ID string
PubKeyArmor string
PrivKeyArmor string
PubKey *packet.PublicKey
PrivKey *packet.PrivateKey
}

var PGPKeys = map[string]*PGPKeyData{
"keyUbuntu2018": {
ID: "871920D1991BC93C",
PubKeyArmored: pubKeyUbuntu2018Armor,
ID: "871920D1991BC93C",
PubKeyArmor: pubKeyUbuntu2018Armor,
},
"key1": {
ID: "854BAF1AA9D76600",
PubKeyArmored: pubKey1Armor,
PrivKeyArmored: privKey1Armor,
ID: "854BAF1AA9D76600",
PubKeyArmor: pubKey1Armor,
PrivKeyArmor: privKey1Armor,
},
"key2": {
ID: "9568570379BF1F43",
PubKeyArmored: pubKey2Armor,
PrivKeyArmored: privKey2Armor,
ID: "9568570379BF1F43",
PubKeyArmor: pubKey2Armor,
PrivKeyArmor: privKey2Armor,
},
}

func init() {
for name, key := range PGPKeys {
if key.PubKeyArmored != "" {
pubKeys, privKeys, err := openpgputil.DecodeKeys([]byte(key.PubKeyArmored))
if key.PubKeyArmor != "" {
pubKeys, privKeys, err := openpgputil.DecodeKeys([]byte(key.PubKeyArmor))
if err != nil || len(privKeys) > 0 || len(pubKeys) != 1 || pubKeys[0].KeyIdString() != key.ID {
log.Panicf("invalid public key armored data: %s", name)
}
key.PubKey = pubKeys[0]
}
if key.PrivKeyArmored != "" {
pubKeys, privKeys, err := openpgputil.DecodeKeys([]byte(key.PrivKeyArmored))
if key.PrivKeyArmor != "" {
pubKeys, privKeys, err := openpgputil.DecodeKeys([]byte(key.PrivKeyArmor))
if err != nil || len(pubKeys) > 0 || len(privKeys) != 1 || privKeys[0].KeyIdString() != key.ID {
log.Panicf("invalid private key armored data: %s", name)
}
Expand Down

0 comments on commit 6c4dcc4

Please sign in to comment.