tka,types/key: implement direct node-key signatures
Signed-off-by: Tom DNetto <tom@tailscale.com>
This commit is contained in:
34
tka/sig_test.go
Normal file
34
tka/sig_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package tka
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSigDirect(t *testing.T) {
|
||||
nodeKeyPub := []byte{1, 2, 3, 4}
|
||||
|
||||
// Verification key (the key used to sign)
|
||||
pub, priv := testingKey25519(t, 1)
|
||||
key := Key{Kind: Key25519, Public: pub, Votes: 2}
|
||||
|
||||
sig := NodeKeySignature{
|
||||
SigKind: SigDirect,
|
||||
KeyID: key.ID(),
|
||||
Pubkey: nodeKeyPub,
|
||||
}
|
||||
sigHash := sig.sigHash()
|
||||
sig.Signature = ed25519.Sign(priv, sigHash[:])
|
||||
|
||||
if sig.sigHash() != sigHash {
|
||||
t.Errorf("sigHash changed after signing: %x != %x", sig.sigHash(), sigHash)
|
||||
}
|
||||
|
||||
if err := sig.verifySignature(key); err != nil {
|
||||
t.Fatalf("verifySignature() failed: %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user