1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

s/GPG/PGP

This commit is contained in:
Adrian Utrilla
2017-09-12 09:00:12 -07:00
parent 7d6597b60c
commit cdbac51221
6 changed files with 67 additions and 67 deletions

View File

@@ -12,8 +12,8 @@ func KeyFromMasterKey(mk keys.MasterKey) Key {
switch mk := mk.(type) {
case *pgp.MasterKey:
return Key{
KeyType: &Key_GpgKey{
GpgKey: &GpgKey{
KeyType: &Key_PgpKey{
PgpKey: &PgpKey{
Fingerprint: mk.Fingerprint,
},
},

View File

@@ -9,7 +9,7 @@ It is generated from these files:
It has these top-level messages:
Key
GpgKey
PgpKey
KmsKey
EncryptRequest
EncryptResponse
@@ -41,7 +41,7 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Key struct {
// Types that are valid to be assigned to KeyType:
// *Key_KmsKey
// *Key_GpgKey
// *Key_PgpKey
KeyType isKey_KeyType `protobuf_oneof:"key_type"`
}
@@ -57,12 +57,12 @@ type isKey_KeyType interface {
type Key_KmsKey struct {
KmsKey *KmsKey `protobuf:"bytes,1,opt,name=kms_key,json=kmsKey,oneof"`
}
type Key_GpgKey struct {
GpgKey *GpgKey `protobuf:"bytes,2,opt,name=gpg_key,json=gpgKey,oneof"`
type Key_PgpKey struct {
PgpKey *PgpKey `protobuf:"bytes,2,opt,name=pgp_key,json=pgpKey,oneof"`
}
func (*Key_KmsKey) isKey_KeyType() {}
func (*Key_GpgKey) isKey_KeyType() {}
func (*Key_PgpKey) isKey_KeyType() {}
func (m *Key) GetKeyType() isKey_KeyType {
if m != nil {
@@ -78,9 +78,9 @@ func (m *Key) GetKmsKey() *KmsKey {
return nil
}
func (m *Key) GetGpgKey() *GpgKey {
if x, ok := m.GetKeyType().(*Key_GpgKey); ok {
return x.GpgKey
func (m *Key) GetPgpKey() *PgpKey {
if x, ok := m.GetKeyType().(*Key_PgpKey); ok {
return x.PgpKey
}
return nil
}
@@ -89,7 +89,7 @@ func (m *Key) GetGpgKey() *GpgKey {
func (*Key) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _Key_OneofMarshaler, _Key_OneofUnmarshaler, _Key_OneofSizer, []interface{}{
(*Key_KmsKey)(nil),
(*Key_GpgKey)(nil),
(*Key_PgpKey)(nil),
}
}
@@ -102,9 +102,9 @@ func _Key_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
if err := b.EncodeMessage(x.KmsKey); err != nil {
return err
}
case *Key_GpgKey:
case *Key_PgpKey:
b.EncodeVarint(2<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.GpgKey); err != nil {
if err := b.EncodeMessage(x.PgpKey); err != nil {
return err
}
case nil:
@@ -125,13 +125,13 @@ func _Key_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (b
err := b.DecodeMessage(msg)
m.KeyType = &Key_KmsKey{msg}
return true, err
case 2: // key_type.gpg_key
case 2: // key_type.pgp_key
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(GpgKey)
msg := new(PgpKey)
err := b.DecodeMessage(msg)
m.KeyType = &Key_GpgKey{msg}
m.KeyType = &Key_PgpKey{msg}
return true, err
default:
return false, nil
@@ -147,8 +147,8 @@ func _Key_OneofSizer(msg proto.Message) (n int) {
n += proto.SizeVarint(1<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *Key_GpgKey:
s := proto.Size(x.GpgKey)
case *Key_PgpKey:
s := proto.Size(x.PgpKey)
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
@@ -159,16 +159,16 @@ func _Key_OneofSizer(msg proto.Message) (n int) {
return n
}
type GpgKey struct {
type PgpKey struct {
Fingerprint string `protobuf:"bytes,1,opt,name=fingerprint" json:"fingerprint,omitempty"`
}
func (m *GpgKey) Reset() { *m = GpgKey{} }
func (m *GpgKey) String() string { return proto.CompactTextString(m) }
func (*GpgKey) ProtoMessage() {}
func (*GpgKey) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *PgpKey) Reset() { *m = PgpKey{} }
func (m *PgpKey) String() string { return proto.CompactTextString(m) }
func (*PgpKey) ProtoMessage() {}
func (*PgpKey) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *GpgKey) GetFingerprint() string {
func (m *PgpKey) GetFingerprint() string {
if m != nil {
return m.Fingerprint
}
@@ -289,7 +289,7 @@ func (m *DecryptResponse) GetPlaintext() []byte {
func init() {
proto.RegisterType((*Key)(nil), "Key")
proto.RegisterType((*GpgKey)(nil), "GpgKey")
proto.RegisterType((*PgpKey)(nil), "PgpKey")
proto.RegisterType((*KmsKey)(nil), "KmsKey")
proto.RegisterType((*EncryptRequest)(nil), "EncryptRequest")
proto.RegisterType((*EncryptResponse)(nil), "EncryptResponse")
@@ -405,28 +405,28 @@ var _KeyService_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("keyservice.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 361 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4d, 0x4f, 0xab, 0x40,
0x14, 0x2d, 0xa5, 0x8f, 0x3e, 0x2e, 0x4d, 0x21, 0x93, 0xe6, 0xa5, 0x69, 0x5e, 0x4c, 0x33, 0xab,
0xc6, 0xc5, 0x18, 0x71, 0x63, 0xba, 0x54, 0xab, 0x4d, 0xd8, 0xe1, 0xca, 0x55, 0x53, 0xc9, 0x15,
0x09, 0x14, 0xc6, 0x61, 0xda, 0x38, 0x7f, 0xc5, 0x5f, 0x6b, 0x18, 0xe8, 0x07, 0x75, 0xe3, 0xee,
0xcc, 0x99, 0x73, 0xcf, 0x39, 0x77, 0x32, 0xe0, 0xa5, 0xa8, 0x4a, 0x14, 0xbb, 0x24, 0x42, 0xc6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x06, 0xf7, 0xe0, 0x53, 0xf2, 0x22, 0x2f, 0x91,
0x5c, 0x00, 0x44, 0x09, 0x7f, 0x47, 0xa1, 0x27, 0x0c, 0x3d, 0x71, 0xc2, 0xd0, 0x25, 0x0c, 0x1f,
0xf0, 0x57, 0xd1, 0x6d, 0xa7, 0xee, 0x0f, 0xa7, 0x2b, 0x70, 0x0f, 0x4e, 0x4d, 0x78, 0xab, 0xad,
0x71, 0xd6, 0xd6, 0xcf, 0x00, 0x02, 0x54, 0xcf, 0xf5, 0x6f, 0xa9, 0xde, 0xbb, 0xe9, 0x4e, 0x5c,
0xd6, 0x7e, 0x8d, 0x89, 0xc7, 0xce, 0xd6, 0xa2, 0x9d, 0x4a, 0xdf, 0xc4, 0x11, 0x97, 0xb5, 0x57,
0x98, 0x78, 0xec, 0xac, 0x09, 0xed, 0xbc, 0x5a, 0xfa, 0x3b, 0xde, 0x7c, 0x07, 0x00, 0x00, 0xff,
0xff, 0xa3, 0x20, 0x0a, 0xea, 0xa2, 0x02, 0x00, 0x00,
// 359 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4d, 0x4b, 0xc3, 0x40,
0x14, 0x6c, 0x9a, 0x9a, 0x9a, 0x97, 0xd2, 0x84, 0xa5, 0x48, 0x29, 0x22, 0x65, 0x4f, 0xc5, 0xc3,
0x8a, 0xf1, 0x22, 0x3d, 0xaa, 0x95, 0x42, 0x2e, 0x12, 0x4f, 0x9e, 0x4a, 0x0d, 0xcf, 0x1a, 0x92,
0x26, 0xeb, 0x66, 0x5b, 0xdc, 0xbf, 0xe2, 0xaf, 0x95, 0x6c, 0xd2, 0x8f, 0xd4, 0x8b, 0xb7, 0xd9,
0xd9, 0x79, 0x33, 0xf3, 0x96, 0x05, 0x2f, 0x41, 0x55, 0xa0, 0xd8, 0xc6, 0x11, 0x32, 0x2e, 0x72,
0x99, 0xd3, 0x37, 0x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 0x90, 0x5c, 0x01,
0x44, 0x31, 0xff, 0x44, 0xa1, 0x27, 0x0c, 0x3d, 0x71, 0xc4, 0xd0, 0x39, 0xf4, 0x9f, 0xf0, 0x5f,
0xd1, 0x4d, 0xa7, 0xf6, 0x1f, 0xa7, 0x1b, 0x70, 0xf7, 0x4e, 0x75, 0x78, 0xa3, 0xad, 0x71, 0xd2,
0xd6, 0x4f, 0x01, 0x02, 0x54, 0xaf, 0xd5, 0x6f, 0x29, 0xdf, 0xbb, 0xee, 0x4e, 0x5c, 0xd6, 0x7c,
0x8d, 0x91, 0xc7, 0x4e, 0xd6, 0xa2, 0xad, 0x52, 0x5f, 0xc7, 0x11, 0x97, 0x35, 0x57, 0x18, 0x79,
0xec, 0xa4, 0x09, 0x6d, 0xbd, 0x5b, 0xfa, 0x3b, 0xde, 0xfd, 0x06, 0x00, 0x00, 0xff, 0xff, 0x9f,
0x63, 0x38, 0x1d, 0xa2, 0x02, 0x00, 0x00,
}

View File

@@ -3,11 +3,11 @@ syntax = "proto3";
message Key {
oneof key_type {
KmsKey kms_key = 1;
GpgKey gpg_key = 2;
PgpKey pgp_key = 2;
}
}
message GpgKey {
message PgpKey {
string fingerprint = 1;
}

View File

@@ -10,7 +10,7 @@ import (
type Server struct{}
func (ks *Server) encryptWithPgp(key *GpgKey, plaintext []byte) ([]byte, error) {
func (ks *Server) encryptWithPgp(key *PgpKey, plaintext []byte) ([]byte, error) {
pgpKey := pgp.NewMasterKeyFromFingerprint(key.Fingerprint)
err := pgpKey.Encrypt(plaintext)
if err != nil {
@@ -36,7 +36,7 @@ func (ks *Server) encryptWithKms(key *KmsKey, plaintext []byte) ([]byte, error)
return []byte(kmsKey.EncryptedKey), nil
}
func (ks *Server) decryptWithPgp(key *GpgKey, ciphertext []byte) ([]byte, error) {
func (ks *Server) decryptWithPgp(key *PgpKey, ciphertext []byte) ([]byte, error) {
pgpKey := pgp.NewMasterKeyFromFingerprint(key.Fingerprint)
pgpKey.EncryptedKey = string(ciphertext)
plaintext, err := pgpKey.Decrypt()
@@ -62,8 +62,8 @@ func (ks Server) Encrypt(ctx context.Context,
req *EncryptRequest) (*EncryptResponse, error) {
key := *req.Key
switch k := key.KeyType.(type) {
case *Key_GpgKey:
ciphertext, err := ks.encryptWithPgp(k.GpgKey, req.Plaintext)
case *Key_PgpKey:
ciphertext, err := ks.encryptWithPgp(k.PgpKey, req.Plaintext)
if err != nil {
return nil, err
}
@@ -89,8 +89,8 @@ func (ks Server) Decrypt(ctx context.Context,
req *DecryptRequest) (*DecryptResponse, error) {
key := *req.Key
switch k := key.KeyType.(type) {
case *Key_GpgKey:
plaintext, err := ks.decryptWithPgp(k.GpgKey, req.Ciphertext)
case *Key_PgpKey:
plaintext, err := ks.decryptWithPgp(k.PgpKey, req.Ciphertext)
if err != nil {
return nil, err
}

View File

@@ -110,19 +110,19 @@ func (key *MasterKey) encryptWithCryptoOpenPGP(dataKey []byte) error {
// Encrypt encrypts the data key with the PGP key with the same fingerprint as the MasterKey. It looks for PGP public keys in $PGPHOME/pubring.gpg.
func (key *MasterKey) Encrypt(dataKey []byte) error {
log.Printf("Attempting encryption of GPG MasterKey with fingerprint %s", key.Fingerprint)
log.Printf("Attempting encryption of PGP MasterKey with fingerprint %s", key.Fingerprint)
openpgpErr := key.encryptWithCryptoOpenPGP(dataKey)
if openpgpErr == nil {
log.Printf("Encryption of GPG MasterKey with fingerprint %s succeeded", key.Fingerprint)
log.Printf("Encryption of PGP MasterKey with fingerprint %s succeeded", key.Fingerprint)
return nil
}
log.Print("Encryption with golang's openpgp package failed, falling back to the GPG binary")
binaryErr := key.encryptWithGPGBinary(dataKey)
if binaryErr == nil {
log.Printf("Encryption of GPG MasterKey with fingerprint %s succeeded", key.Fingerprint)
log.Printf("Encryption of PGP MasterKey with fingerprint %s succeeded", key.Fingerprint)
return nil
}
log.Printf("Encryption of GPG MasterKey with fingerprint %s failed", key.Fingerprint)
log.Printf("Encryption of PGP MasterKey with fingerprint %s failed", key.Fingerprint)
return fmt.Errorf(`could not encrypt data key with PGP key.
\tgolang.org/x/crypto/openpgp error: %s
\tGPG binary error: %s`, openpgpErr, binaryErr)
@@ -170,21 +170,21 @@ func (key *MasterKey) decryptWithCryptoOpenpgp() ([]byte, error) {
log.Printf("Decryption of GPG MasterKey with fingerprint %s successful", key.Fingerprint)
return b, nil
}
return nil, fmt.Errorf("The key could not be decrypted with any of the GPG entries")
return nil, fmt.Errorf("The key could not be decrypted with any of the PGP entries")
}
// Decrypt uses PGP to obtain the data key from the EncryptedKey store in the MasterKey and returns it
func (key *MasterKey) Decrypt() ([]byte, error) {
log.Printf("Attempting decryption of GPG MasterKey with fingerprint %s", key.Fingerprint)
log.Printf("Attempting decryption of PGP MasterKey with fingerprint %s", key.Fingerprint)
dataKey, openpgpErr := key.decryptWithCryptoOpenpgp()
if openpgpErr == nil {
log.Printf("Decryption of GPG MasterKey with fingerprint %s succeeded", key.Fingerprint)
log.Printf("Decryption of PGP MasterKey with fingerprint %s succeeded", key.Fingerprint)
return dataKey, nil
}
log.Print("Decryption with golang's openpgp package failed, falling back to the GPG binary")
dataKey, binaryErr := key.decryptWithGPGBinary()
if binaryErr == nil {
log.Printf("Decryption of GPG MasterKey with fingerprint %s succeeded", key.Fingerprint)
log.Printf("Decryption of PGP MasterKey with fingerprint %s succeeded", key.Fingerprint)
return dataKey, nil
}
log.Printf("Decryption of GPG MasterKey with fingerprint %s failed", key.Fingerprint)

View File

@@ -6,7 +6,7 @@ import (
"testing/quick"
)
func TestGPG(t *testing.T) {
func TestPGP(t *testing.T) {
key := NewMasterKeyFromFingerprint("1022470DE3F0BC54BC6AB62DE05550BC07FB1A0A")
f := func(x []byte) bool {
if x == nil || len(x) == 0 {
@@ -28,7 +28,7 @@ func TestGPG(t *testing.T) {
}
}
func TestGPGKeySourceFromString(t *testing.T) {
func TestPGPKeySourceFromString(t *testing.T) {
s := "C8C5 2C0A B2A4 8174 01E8 12C8 F3CC 3233 3FAD 9F1E, C8C5 2C0A B2A4 8174 01E8 12C8 F3CC 3233 3FAD 9F1E"
ks := MasterKeysFromFingerprintString(s)
expected := "C8C52C0AB2A4817401E812C8F3CC32333FAD9F1E"