Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 2fb47c1

Browse files
committed
resolves #672
1 parent f1bfcfd commit 2fb47c1

File tree

9 files changed

+483
-89
lines changed

9 files changed

+483
-89
lines changed

cmd/keytransparency-server/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ func main() {
193193

194194
// Connect to map server.
195195
var tmap trillian.TrillianMapClient
196+
var tadmin trillian.TrillianAdminClient
196197
if *mapURL != "" {
197198
mconn, err := grpc.Dial(*mapURL, grpc.WithInsecure())
198199
if err != nil {
199200
glog.Exitf("grpc.Dial(%v): %v", *mapURL, err)
200201
}
201202
tmap = trillian.NewTrillianMapClient(mconn)
203+
tadmin = trillian.NewTrillianAdminClient(mconn)
202204
} else {
203205
// Create an in-process readonly mapserver.
204206
tmap, err = newReadonlyMapServer(context.Background(), *mapID, sqldb, factory)
@@ -208,7 +210,7 @@ func main() {
208210
}
209211

210212
// Create gRPC server.
211-
svr := keyserver.New(*logID, tlog, *mapID, tmap, commitments,
213+
svr := keyserver.New(*logID, tlog, *mapID, tmap, tadmin, commitments,
212214
vrfPriv, mutator, auth, authz, factory, mutations)
213215
grpcServer := grpc.NewServer(
214216
grpc.Creds(creds),

core/crypto/vrf/p256/p256.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"encoding/pem"
3434
"errors"
3535
"math/big"
36+
"github.com/golang/glog"
37+
"reflect"
3638
)
3739

3840
var (
@@ -221,6 +223,23 @@ func NewVRFSigner(key *ecdsa.PrivateKey) (*PrivateKey, error) {
221223
return &PrivateKey{key}, nil
222224
}
223225

226+
// Public returns the corresponding public key as bytes.
227+
func (k PrivateKey) Public() ([]byte, error) {
228+
// Copied from: core/crypto/signatures/p256/ecdsa_p256.go
229+
glog.Errorf("reflect.TypeOf(k.PublicKey)=%v", reflect.TypeOf(k.PublicKey))
230+
pkBytes, err := x509.MarshalPKIXPublicKey(&k.PublicKey)
231+
if err != nil {
232+
return nil, err
233+
}
234+
pkPEM := pem.EncodeToMemory(
235+
&pem.Block{
236+
Type: "PUBLIC KEY",
237+
Bytes: pkBytes,
238+
},
239+
)
240+
return pkPEM, nil
241+
}
242+
224243
// NewVRFVerifier creates a verifier object from a public key.
225244
func NewVRFVerifier(pubkey *ecdsa.PublicKey) (*PublicKey, error) {
226245
if *(pubkey.Params()) != *curve.Params() {

core/crypto/vrf/vrf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
type PrivateKey interface {
3131
// Evaluate returns the output of H(f_k(m)) and its proof.
3232
Evaluate(m []byte) (index [32]byte, proof []byte)
33+
// Public returns the corresponding public key as bytes.
34+
Public() ([]byte, error)
3335
}
3436

3537
// PublicKey supports verifying output from the VRF function.

core/keyserver/keyserver.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
authzpb "github.com/google/keytransparency/core/proto/authorization"
3333
tpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
3434
"github.com/google/trillian"
35+
"github.com/google/trillian/crypto/keyspb"
3536
)
3637

3738
const (
@@ -51,6 +52,7 @@ type Server struct {
5152
tlog trillian.TrillianLogClient
5253
mapID int64
5354
tmap trillian.TrillianMapClient
55+
tadmin trillian.TrillianAdminClient
5456
committer commitments.Committer
5557
auth authentication.Authenticator
5658
authz authorization.Authorization
@@ -65,6 +67,7 @@ func New(logID int64,
6567
tlog trillian.TrillianLogClient,
6668
mapID int64,
6769
tmap trillian.TrillianMapClient,
70+
tadmin trillian.TrillianAdminClient,
6871
committer commitments.Committer,
6972
vrf vrf.PrivateKey,
7073
mutator mutator.Mutator,
@@ -77,6 +80,7 @@ func New(logID int64,
7780
tlog: tlog,
7881
mapID: mapID,
7982
tmap: tmap,
83+
tadmin: tadmin,
8084
committer: committer,
8185
vrf: vrf,
8286
mutator: mutator,
@@ -319,6 +323,39 @@ func (s *Server) UpdateEntry(ctx context.Context, in *tpb.UpdateEntryRequest) (*
319323
return &tpb.UpdateEntryResponse{Proof: resp}, nil
320324
}
321325

326+
// GetDomainInfo returns all info tight to this specific domain.
327+
//
328+
// This API to get all necessary data needed to verify a particular
329+
// key-server. Data contains for instance the tree-info, like for instance the
330+
// log-/map-id and the corresponding public-keys.
331+
func (s *Server) GetDomainInfo(ctx context.Context, in *tpb.GetDomainInfoRequest) (*tpb.GetDomainInfoResponse, error) {
332+
logTree, err := s.tadmin.GetTree(ctx, &trillian.GetTreeRequest{
333+
TreeId: s.logID,
334+
})
335+
if err != nil {
336+
return nil, err
337+
}
338+
mapTree, err := s.tadmin.GetTree(ctx, &trillian.GetTreeRequest{
339+
TreeId: s.mapID,
340+
})
341+
if err != nil {
342+
return nil, err
343+
}
344+
345+
vrfPub, err := s.vrf.Public()
346+
if err != nil {
347+
return nil, err
348+
}
349+
350+
return &tpb.GetDomainInfoResponse{
351+
Log: logTree,
352+
Map: mapTree,
353+
Vrf: &keyspb.PublicKey{
354+
Der: vrfPub,
355+
},
356+
}, nil
357+
}
358+
322359
func (s *Server) saveCommitment(ctx context.Context, kv *tpb.KeyValue, committed *tpb.Committed) error {
323360
entry := new(tpb.Entry)
324361
if err := proto.Unmarshal(kv.Value, entry); err != nil {

0 commit comments

Comments
 (0)