Merge pull request #3065 from halseth/non-nil-curve-pubkey

[reliable payments] channeldb/graph: don't nil curve of returned PubKey
This commit is contained in:
Olaoluwa Osuntokun 2019-05-09 16:41:49 -07:00 committed by GitHub
commit c4319dafd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 7 deletions

@ -1982,7 +1982,6 @@ func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
return nil, err return nil, err
} }
l.pubKey = key l.pubKey = key
l.pubKey.Curve = nil
return key, nil return key, nil
} }

@ -41,14 +41,9 @@ var (
testFeatures = lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures) testFeatures = lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures)
) )
func createTestVertex(db *DB) (*LightningNode, error) { func createLightningNode(db *DB, priv *btcec.PrivateKey) (*LightningNode, error) {
updateTime := prand.Int63() updateTime := prand.Int63()
priv, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return nil, err
}
pub := priv.PubKey().SerializeCompressed() pub := priv.PubKey().SerializeCompressed()
n := &LightningNode{ n := &LightningNode{
HaveNodeAnnouncement: true, HaveNodeAnnouncement: true,
@ -65,6 +60,15 @@ func createTestVertex(db *DB) (*LightningNode, error) {
return n, nil return n, nil
} }
func createTestVertex(db *DB) (*LightningNode, error) {
priv, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return nil, err
}
return createLightningNode(db, priv)
}
func TestNodeInsertionAndDeletion(t *testing.T) { func TestNodeInsertionAndDeletion(t *testing.T) {
t.Parallel() t.Parallel()
@ -3005,3 +3009,54 @@ func compareEdgePolicies(a, b *ChannelEdgePolicy) error {
} }
return nil return nil
} }
// TestLightningNodeSigVerifcation checks that we can use the LightningNode's
// pubkey to verify signatures.
func TestLightningNodeSigVerification(t *testing.T) {
t.Parallel()
// Create some dummy data to sign.
var data [32]byte
if _, err := prand.Read(data[:]); err != nil {
t.Fatalf("unable to read prand: %v", err)
}
// Create private key and sign the data with it.
priv, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
t.Fatalf("unable to crete priv key: %v", err)
}
sign, err := priv.Sign(data[:])
if err != nil {
t.Fatalf("unable to sign: %v", err)
}
// Sanity check that the signature checks out.
if !sign.Verify(data[:], priv.PubKey()) {
t.Fatalf("signature doesn't check out")
}
// Create a LightningNode from the same private key.
db, cleanUp, err := makeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
defer cleanUp()
node, err := createLightningNode(db, priv)
if err != nil {
t.Fatalf("unable to create node: %v", err)
}
// And finally check that we can verify the same signature from the
// pubkey returned from the lightning node.
nodePub, err := node.PubKey()
if err != nil {
t.Fatalf("unable to get pubkey: %v", err)
}
if !sign.Verify(data[:], nodePub) {
t.Fatalf("unable to verify sig")
}
}