signrpc: derive custom shared key

With this commit we add the ability to create a shared DH key by using
a custom node private key instead of the node's identity private key.
If no key locator is specified the node's identity private key will be
used as a fallback.
This commit is contained in:
Oliver Gugger 2020-01-06 14:53:24 +01:00
parent 22e1f006b1
commit 4f98642b5e
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
3 changed files with 92 additions and 64 deletions

@ -664,10 +664,14 @@ func (m *VerifyMessageResp) GetValid() bool {
type SharedKeyRequest struct { type SharedKeyRequest struct {
// The ephemeral public key to use for the DH key derivation. // The ephemeral public key to use for the DH key derivation.
EphemeralPubkey []byte `protobuf:"bytes,1,opt,name=ephemeral_pubkey,json=ephemeralPubkey,proto3" json:"ephemeral_pubkey,omitempty"` EphemeralPubkey []byte `protobuf:"bytes,1,opt,name=ephemeral_pubkey,json=ephemeralPubkey,proto3" json:"ephemeral_pubkey,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` //*
XXX_unrecognized []byte `json:"-"` //The optional key locator of the local key that should be used. If this
XXX_sizecache int32 `json:"-"` //parameter is not set then the node's identity private key will be used.
KeyLoc *KeyLocator `protobuf:"bytes,2,opt,name=key_loc,json=keyLoc,proto3" json:"key_loc,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
} }
func (m *SharedKeyRequest) Reset() { *m = SharedKeyRequest{} } func (m *SharedKeyRequest) Reset() { *m = SharedKeyRequest{} }
@ -702,6 +706,13 @@ func (m *SharedKeyRequest) GetEphemeralPubkey() []byte {
return nil return nil
} }
func (m *SharedKeyRequest) GetKeyLoc() *KeyLocator {
if m != nil {
return m.KeyLoc
}
return nil
}
type SharedKeyResponse struct { type SharedKeyResponse struct {
// The shared public key, hashed with sha256. // The shared public key, hashed with sha256.
SharedKey []byte `protobuf:"bytes,1,opt,name=shared_key,json=sharedKey,proto3" json:"shared_key,omitempty"` SharedKey []byte `protobuf:"bytes,1,opt,name=shared_key,json=sharedKey,proto3" json:"shared_key,omitempty"`
@ -762,55 +773,55 @@ func init() {
func init() { proto.RegisterFile("signrpc/signer.proto", fileDescriptor_4ecd772f6c7ffacf) } func init() { proto.RegisterFile("signrpc/signer.proto", fileDescriptor_4ecd772f6c7ffacf) }
var fileDescriptor_4ecd772f6c7ffacf = []byte{ var fileDescriptor_4ecd772f6c7ffacf = []byte{
// 754 bytes of a gzipped FileDescriptorProto // 756 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xed, 0x8e, 0xdb, 0x44, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x5d, 0x8f, 0xdb, 0x44,
0x14, 0xd5, 0x26, 0x6c, 0x92, 0xbd, 0x4e, 0x76, 0xb3, 0xc3, 0xaa, 0xb8, 0x0b, 0x88, 0x60, 0xa9, 0x14, 0xd5, 0x26, 0x6c, 0x92, 0xbd, 0x4e, 0x76, 0xb3, 0xc3, 0xaa, 0xb8, 0x0b, 0x88, 0x60, 0xa9,
0x28, 0x95, 0x20, 0x11, 0x01, 0x21, 0x81, 0x84, 0x84, 0x4a, 0xb5, 0x6a, 0x95, 0xa2, 0x56, 0xce, 0x28, 0x95, 0x20, 0x11, 0x01, 0x21, 0xc1, 0x13, 0x2a, 0xd5, 0xaa, 0x55, 0x8a, 0x5a, 0x39, 0x2b,
0x8a, 0x1f, 0xfd, 0x63, 0x39, 0xce, 0xad, 0x33, 0xb2, 0x63, 0xcf, 0xce, 0x8c, 0xeb, 0xf8, 0x39, 0x1e, 0xfa, 0x62, 0x39, 0xce, 0xad, 0x33, 0xb2, 0x63, 0xcf, 0xce, 0x8c, 0xeb, 0xf8, 0x77, 0xf0,
0x78, 0x35, 0x1e, 0x08, 0xcd, 0x47, 0x1c, 0x3b, 0x05, 0xa4, 0xfe, 0x8a, 0xef, 0x99, 0x3b, 0xe7, 0xd7, 0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xef, 0xe6, 0x29, 0x8d, 0xb7, 0x32,
0x19, 0xca, 0x32, 0xe7, 0xc9, 0x3c, 0xcd, 0x36, 0xf3, 0xb4, 0x7e, 0x67, 0x70, 0x16, 0xad, 0x7b, 0xa3, 0x59, 0x9c, 0xa1, 0x2c, 0x73, 0x9e, 0xcc, 0xd3, 0x6c, 0x33, 0x4f, 0xeb, 0x2f, 0x0c, 0x67,
0xfa, 0xad, 0xf1, 0xc3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x86, 0xd3, 0xf4, 0xe0, 0x4d, 0x06, 0xd1, 0xba, 0xa7, 0xbf, 0x31, 0x3f, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x73, 0xb0, 0xe9, 0x51,
0x00, 0x00, 0x7b, 0x06, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
@ -864,8 +875,9 @@ type SignerClient interface {
// //
//DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key //DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key
//derivation between the ephemeral public key in the request and the node's //derivation between the ephemeral public key in the request and the node's
//identity private key: //key specified in the key_loc parameter (or the node's identity private key
//P_shared = privKeyNodeID * ephemeralPubkey //if no key locator is specified):
//P_shared = privKeyNode * ephemeralPubkey
//The resulting shared public key is serialized in the compressed format and //The resulting shared public key is serialized in the compressed format and
//hashed with sha256, resulting in the final key length of 256bit. //hashed with sha256, resulting in the final key length of 256bit.
DeriveSharedKey(ctx context.Context, in *SharedKeyRequest, opts ...grpc.CallOption) (*SharedKeyResponse, error) DeriveSharedKey(ctx context.Context, in *SharedKeyRequest, opts ...grpc.CallOption) (*SharedKeyResponse, error)
@ -965,8 +977,9 @@ type SignerServer interface {
// //
//DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key //DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key
//derivation between the ephemeral public key in the request and the node's //derivation between the ephemeral public key in the request and the node's
//identity private key: //key specified in the key_loc parameter (or the node's identity private key
//P_shared = privKeyNodeID * ephemeralPubkey //if no key locator is specified):
//P_shared = privKeyNode * ephemeralPubkey
//The resulting shared public key is serialized in the compressed format and //The resulting shared public key is serialized in the compressed format and
//hashed with sha256, resulting in the final key length of 256bit. //hashed with sha256, resulting in the final key length of 256bit.
DeriveSharedKey(context.Context, *SharedKeyRequest) (*SharedKeyResponse, error) DeriveSharedKey(context.Context, *SharedKeyRequest) (*SharedKeyResponse, error)

@ -154,6 +154,12 @@ message VerifyMessageResp {
message SharedKeyRequest { message SharedKeyRequest {
// The ephemeral public key to use for the DH key derivation. // The ephemeral public key to use for the DH key derivation.
bytes ephemeral_pubkey = 1; bytes ephemeral_pubkey = 1;
/**
The optional key locator of the local key that should be used. If this
parameter is not set then the node's identity private key will be used.
*/
KeyLocator key_loc = 2;
} }
message SharedKeyResponse { message SharedKeyResponse {
@ -209,8 +215,9 @@ service Signer {
/* /*
DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key
derivation between the ephemeral public key in the request and the node's derivation between the ephemeral public key in the request and the node's
identity private key: key specified in the key_loc parameter (or the node's identity private key
P_shared = privKeyNodeID * ephemeralPubkey if no key locator is specified):
P_shared = privKeyNode * ephemeralPubkey
The resulting shared public key is serialized in the compressed format and The resulting shared public key is serialized in the compressed format and
hashed with sha256, resulting in the final key length of 256bit. hashed with sha256, resulting in the final key length of 256bit.
*/ */

@ -485,8 +485,9 @@ func (s *Server) VerifyMessage(ctx context.Context,
// DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key // DeriveSharedKey returns a shared secret key by performing Diffie-Hellman key
// derivation between the ephemeral public key in the request and the node's // derivation between the ephemeral public key in the request and the node's
// identity private key: // key specified in the key_loc parameter (or the node's identity private key
// P_shared = privKeyNodeID * ephemeralPubkey // if no key locator is specified):
// P_shared = privKeyNode * ephemeralPubkey
// The resulting shared public key is serialized in the compressed format and // The resulting shared public key is serialized in the compressed format and
// hashed with sha256, resulting in the final key length of 256bit. // hashed with sha256, resulting in the final key length of 256bit.
func (s *Server) DeriveSharedKey(_ context.Context, in *SharedKeyRequest) ( func (s *Server) DeriveSharedKey(_ context.Context, in *SharedKeyRequest) (
@ -503,12 +504,19 @@ func (s *Server) DeriveSharedKey(_ context.Context, in *SharedKeyRequest) (
return nil, fmt.Errorf("unable to parse pubkey: %v", err) return nil, fmt.Errorf("unable to parse pubkey: %v", err)
} }
// By default, use the node identity private key.
locator := keychain.KeyLocator{
Family: keychain.KeyFamilyNodeKey,
Index: 0,
}
if in.KeyLoc != nil {
locator.Family = keychain.KeyFamily(in.KeyLoc.KeyFamily)
locator.Index = uint32(in.KeyLoc.KeyIndex)
}
// Derive our node's private key from the key ring. // Derive our node's private key from the key ring.
idPrivKey, err := s.cfg.KeyRing.DerivePrivKey(keychain.KeyDescriptor{ idPrivKey, err := s.cfg.KeyRing.DerivePrivKey(keychain.KeyDescriptor{
KeyLocator: keychain.KeyLocator{ KeyLocator: locator,
Family: keychain.KeyFamilyNodeKey,
Index: 0,
},
}) })
if err != nil { if err != nil {
err := fmt.Errorf("unable to derive node private key: %v", err) err := fmt.Errorf("unable to derive node private key: %v", err)