aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/message/msg_core.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet/message/msg_core.go')
-rw-r--r--src/gnunet/message/msg_core.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/gnunet/message/msg_core.go b/src/gnunet/message/msg_core.go
index 245c61d..208b438 100644
--- a/src/gnunet/message/msg_core.go
+++ b/src/gnunet/message/msg_core.go
@@ -36,17 +36,17 @@ type EphKeyBlock struct {
36 Purpose *crypto.SignaturePurpose // signature purpose: SIG_ECC_KEY 36 Purpose *crypto.SignaturePurpose // signature purpose: SIG_ECC_KEY
37 CreateTime util.AbsoluteTime // Time of key creation 37 CreateTime util.AbsoluteTime // Time of key creation
38 ExpireTime util.RelativeTime // Time to live for key 38 ExpireTime util.RelativeTime // Time to live for key
39 EphemeralKey []byte `size:"32"` // Ephemeral EdDSA public key 39 EphemeralKey *util.PeerPublicKey // Ephemeral EdDSA public key
40 PeerID *util.PeerID // Peer identity (EdDSA public key) 40 PeerID *util.PeerID // Peer identity (EdDSA public key)
41} 41}
42 42
43// EphemeralKeyMsg announces a new transient key for a peer. The key is signed 43// EphemeralKeyMsg announces a new transient key for a peer. The key is signed
44// by the issuing peer. 44// by the issuing peer.
45type EphemeralKeyMsg struct { 45type EphemeralKeyMsg struct {
46 MsgSize uint16 `order:"big"` // total size of message 46 MsgSize uint16 `order:"big"` // total size of message
47 MsgType uint16 `order:"big"` // CORE_EPHEMERAL_KEY (88) 47 MsgType uint16 `order:"big"` // CORE_EPHEMERAL_KEY (88)
48 SenderStatus uint32 `order:"big"` // enum PeerStateMachine 48 SenderStatus uint32 `order:"big"` // enum PeerStateMachine
49 Signature []byte `size:"64"` // EdDSA signature 49 Signature *util.PeerSignature `` // EdDSA signature
50 SignedBlock *EphKeyBlock 50 SignedBlock *EphKeyBlock
51} 51}
52 52
@@ -56,7 +56,7 @@ func NewEphemeralKeyMsg() *EphemeralKeyMsg {
56 MsgSize: 160, 56 MsgSize: 160,
57 MsgType: CORE_EPHEMERAL_KEY, 57 MsgType: CORE_EPHEMERAL_KEY,
58 SenderStatus: 1, 58 SenderStatus: 1,
59 Signature: make([]byte, 64), 59 Signature: util.NewPeerSignature(nil),
60 SignedBlock: &EphKeyBlock{ 60 SignedBlock: &EphKeyBlock{
61 Purpose: &crypto.SignaturePurpose{ 61 Purpose: &crypto.SignaturePurpose{
62 Size: 88, 62 Size: 88,
@@ -64,7 +64,7 @@ func NewEphemeralKeyMsg() *EphemeralKeyMsg {
64 }, 64 },
65 CreateTime: util.AbsoluteTimeNow(), 65 CreateTime: util.AbsoluteTimeNow(),
66 ExpireTime: util.NewRelativeTime(12 * time.Hour), 66 ExpireTime: util.NewRelativeTime(12 * time.Hour),
67 EphemeralKey: make([]byte, 32), 67 EphemeralKey: util.NewPeerPublicKey(nil),
68 PeerID: util.NewPeerID(nil), 68 PeerID: util.NewPeerID(nil),
69 }, 69 },
70 } 70 }
@@ -73,8 +73,8 @@ func NewEphemeralKeyMsg() *EphemeralKeyMsg {
73// String returns a human-readable representation of the message. 73// String returns a human-readable representation of the message.
74func (m *EphemeralKeyMsg) String() string { 74func (m *EphemeralKeyMsg) String() string {
75 return fmt.Sprintf("EphKeyMsg{peer=%s,ephkey=%s,create=%s,expire=%s,status=%d}", 75 return fmt.Sprintf("EphKeyMsg{peer=%s,ephkey=%s,create=%s,expire=%s,status=%d}",
76 util.EncodeBinaryToString(m.SignedBlock.PeerID.Key), 76 util.EncodeBinaryToString(m.SignedBlock.PeerID.Data),
77 util.EncodeBinaryToString(m.SignedBlock.EphemeralKey), 77 util.EncodeBinaryToString(m.SignedBlock.EphemeralKey.Data),
78 m.SignedBlock.CreateTime, m.SignedBlock.ExpireTime, 78 m.SignedBlock.CreateTime, m.SignedBlock.ExpireTime,
79 m.SenderStatus) 79 m.SenderStatus)
80} 80}
@@ -85,8 +85,8 @@ func (m *EphemeralKeyMsg) Header() *Header {
85} 85}
86 86
87// Public extracts the public key of an announcing peer. 87// Public extracts the public key of an announcing peer.
88func (m *EphemeralKeyMsg) Public() *ed25519.PublicKey { 88func (m *EphemeralKeyMsg) Public() *util.PeerPublicKey {
89 return m.SignedBlock.PeerID.PublicKey() 89 return util.NewPeerPublicKey(m.SignedBlock.PeerID.Data)
90} 90}
91 91
92// Verify the integrity of the message data using the public key of the 92// Verify the integrity of the message data using the public key of the
@@ -96,7 +96,7 @@ func (m *EphemeralKeyMsg) Verify(pub *ed25519.PublicKey) (bool, error) {
96 if err != nil { 96 if err != nil {
97 return false, err 97 return false, err
98 } 98 }
99 sig, err := ed25519.NewEdSignatureFromBytes(m.Signature) 99 sig, err := ed25519.NewEdSignatureFromBytes(m.Signature.Data)
100 if err != nil { 100 if err != nil {
101 return false, err 101 return false, err
102 } 102 }
@@ -107,10 +107,10 @@ func (m *EphemeralKeyMsg) Verify(pub *ed25519.PublicKey) (bool, error) {
107// key and the corresponding GNUnet message to announce the new key. 107// key and the corresponding GNUnet message to announce the new key.
108func NewEphemeralKey(peerID []byte, ltPrv *ed25519.PrivateKey) (*ed25519.PrivateKey, *EphemeralKeyMsg, error) { 108func NewEphemeralKey(peerID []byte, ltPrv *ed25519.PrivateKey) (*ed25519.PrivateKey, *EphemeralKeyMsg, error) {
109 msg := NewEphemeralKeyMsg() 109 msg := NewEphemeralKeyMsg()
110 copy(msg.SignedBlock.PeerID.Key, peerID) 110 copy(msg.SignedBlock.PeerID.Data, peerID)
111 seed := util.NewRndArray(32) 111 seed := util.NewRndArray(32)
112 prv := ed25519.NewPrivateKeyFromSeed(seed) 112 prv := ed25519.NewPrivateKeyFromSeed(seed)
113 copy(msg.SignedBlock.EphemeralKey, prv.Public().Bytes()) 113 copy(msg.SignedBlock.EphemeralKey.Data, prv.Public().Bytes())
114 114
115 data, err := data.Marshal(msg.SignedBlock) 115 data, err := data.Marshal(msg.SignedBlock)
116 if err != nil { 116 if err != nil {
@@ -120,7 +120,7 @@ func NewEphemeralKey(peerID []byte, ltPrv *ed25519.PrivateKey) (*ed25519.Private
120 if err != nil { 120 if err != nil {
121 return nil, nil, err 121 return nil, nil, err
122 } 122 }
123 copy(msg.Signature, sig.Bytes()) 123 copy(msg.Signature.Data, sig.Bytes())
124 124
125 return prv, msg, nil 125 return prv, msg, nil
126} 126}