Skip to content

Commit

Permalink
pb: adds custom key types
Browse files Browse the repository at this point in the history
Signed-off-by: Sander Pick <[email protected]>
  • Loading branch information
sanderpick committed Oct 10, 2019
1 parent 862a8f9 commit a37136d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 76 deletions.
2 changes: 0 additions & 2 deletions pb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ all: $(GO)

%.pb.go: %.proto
protoc -I=. -I=$(GOPATH)/src --gogofaster_out=\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
plugins=grpc:\
. $<

Expand Down
105 changes: 46 additions & 59 deletions pb/threads.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pb/threads.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ syntax = "proto3";
package threads.pb;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/textileio/go-textile-core/crypto/pb/crypto.proto";

option (gogoproto.benchgen_all) = true;
option (gogoproto.populate_all) = true;
Expand Down Expand Up @@ -31,7 +30,7 @@ message PushRequest {

bytes signature = 2;

textile.crypto.pb.PublicKey key = 3;
bytes key = 3 [(gogoproto.customtype) = "ProtoPubKey"];

bytes followKey = 4;

Expand Down
1 change: 0 additions & 1 deletion pb/threadspb_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
ma "github.com/multiformats/go-multiaddr"
"github.com/textileio/go-textile-core/crypto"
"github.com/textileio/go-textile-core/crypto/asymmetric"
pbc "github.com/textileio/go-textile-core/crypto/pb"
"github.com/textileio/go-textile-core/crypto/symmetric"
"github.com/textileio/go-textile-core/thread"
tserv "github.com/textileio/go-textile-core/threadservice"
Expand Down Expand Up @@ -192,10 +191,6 @@ func (s *service) push(ctx context.Context, rec thread.Record, id thread.ID, lid
return err
}

pk, err := pbc.PublicKeyToProto(sk.GetPublic())
if err != nil {
return err
}
var keyLog *pb.ProtoPeerID
logKey := s.threads.ReadKey(settings.Thread, settings.KeyLog)
if logKey != nil {
Expand All @@ -205,7 +200,7 @@ func (s *service) push(ctx context.Context, rec thread.Record, id thread.ID, lid
Header: &pb.PushRequest_Header{
From: &pb.ProtoPeerID{ID: s.threads.host.ID()},
Signature: sig,
Key: pk,
Key: &pb.ProtoPubKey{PubKey: sk.GetPublic()},
FollowKey: s.threads.FollowKey(id, lid),
ReadKeyLogID: keyLog,
},
Expand Down Expand Up @@ -514,13 +509,9 @@ func requestPubKey(r *pb.PushRequest) (ic.PubKey, error) {
return nil, fmt.Errorf("cannot extract signing key")
}
} else {
pubk, err = pbc.PublicKeyFromProto(r.Header.Key)
if err != nil {
return nil, fmt.Errorf("cannot unmarshal signing key: %s", err)
}

pubk = r.Header.Key.PubKey
// Verify that the source ID matches the attached key
if !r.Header.From.ID.MatchesPublicKey(pubk) {
if !r.Header.From.ID.MatchesPublicKey(r.Header.Key.PubKey) {
return nil, fmt.Errorf("bad signing key; source ID %s doesn't match key", r.Header.From.ID)
}
}
Expand Down

0 comments on commit a37136d

Please sign in to comment.