aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernd Fix <brf@hoi-polloi.org>2019-12-20 18:18:03 +0100
committerBernd Fix <brf@hoi-polloi.org>2019-12-20 18:18:03 +0100
commit45e698414fa2010fd6aa083e942f6b302897e23d (patch)
tree6736b4be485374c40fcce00960923162ae436a84 /src
parent65f1f9c357307b92a7ee3fc1327f34eb24135667 (diff)
downloadgnunet-go-45e698414fa2010fd6aa083e942f6b302897e23d.tar.gz
gnunet-go-45e698414fa2010fd6aa083e942f6b302897e23d.zip
Removed obsolete files.
Diffstat (limited to 'src')
-rw-r--r--src/gnunet/enums/block.go22
-rw-r--r--src/gnunet/service/gns/crypto.go34
-rw-r--r--src/gnunet/service/gns/crypto_test.go150
-rw-r--r--src/gnunet/service/gns/gns.go279
-rw-r--r--src/gnunet/service/gns/record.go124
-rw-r--r--src/gnunet/util/msg_queue.go3
6 files changed, 0 insertions, 612 deletions
diff --git a/src/gnunet/enums/block.go b/src/gnunet/enums/block.go
deleted file mode 100644
index 2d179a3..0000000
--- a/src/gnunet/enums/block.go
+++ /dev/null
@@ -1,22 +0,0 @@
1package enums
2
3var (
4 BLOCK_TYPE_ANY = 0 // Any type of block, used as a wildcard when searching.
5 BLOCK_TYPE_FS_DBLOCK = 1 // Data block (leaf) in the CHK tree.
6 BLOCK_TYPE_FS_IBLOCK = 2 // Inner block in the CHK tree.
7 BLOCK_TYPE_FS_KBLOCK = 3 // Legacy type, no longer in use.
8 BLOCK_TYPE_FS_SBLOCK = 4 // Legacy type, no longer in use.
9 BLOCK_TYPE_FS_NBLOCK = 5 // Legacy type, no longer in use.
10 BLOCK_TYPE_FS_ONDEMAND = 6 // Type of a block representing a block to be encoded on demand from disk.
11 BLOCK_TYPE_DHT_HELLO = 7 // Type of a block that contains a HELLO for a peer
12 BLOCK_TYPE_TEST = 8 // Block for testing.
13 BLOCK_TYPE_FS_UBLOCK = 9 // Type of a block representing any type of search result (universal).
14 BLOCK_TYPE_DNS = 10 // Block for storing DNS exit service advertisements.
15 BLOCK_TYPE_GNS_NAMERECORD = 11 // Block for storing record data
16 BLOCK_TYPE_REVOCATION = 12 // Block type for a revocation message by which a key is revoked.
17
18 BLOCK_TYPE_REGEX = 22 // Block to store a cadet regex state
19 BLOCK_TYPE_REGEX_ACCEPT = 23 // Block to store a cadet regex accepting state
20 BLOCK_TYPE_SET_TEST = 24 // Block for testing set/consensus.
21 BLOCK_TYPE_CONSENSUS_ELEMENT = 25 // Block type for consensus elements.
22)
diff --git a/src/gnunet/service/gns/crypto.go b/src/gnunet/service/gns/crypto.go
deleted file mode 100644
index 38f25fb..0000000
--- a/src/gnunet/service/gns/crypto.go
+++ /dev/null
@@ -1,34 +0,0 @@
1package gns
2
3import (
4 "crypto/sha256"
5 "crypto/sha512"
6
7 "github.com/bfix/gospel/crypto/ed25519"
8 "gnunet/crypto"
9 "golang.org/x/crypto/hkdf"
10)
11
12// DeriveBlockKey returns a symmetric key to decipher a GNS block
13func DeriveBlockKey(label string, pub *ed25519.PublicKey) (iv *crypto.SymmetricIV, skey *crypto.SymmetricKey) {
14 // generate symmetric key
15 prk := hkdf.Extract(sha512.New, []byte(label), pub.Bytes())
16 rdr := hkdf.Expand(sha256.New, prk, []byte("gns-aes-ctx-key"))
17 skey = crypto.NewSymmetricKey()
18 rdr.Read(skey.AESKey)
19 rdr.Read(skey.TwofishKey)
20 // generate initialization vector
21 rdr = hkdf.Expand(sha256.New, prk, []byte("gns-aes-ctx-iv"))
22 iv = crypto.NewSymmetricIV()
23 rdr.Read(iv.AESIv)
24 rdr.Read(iv.TwofishIv)
25 return
26}
27
28// DecryptBlock for a given zone and label.
29func DecryptBlock(data []byte, zoneKey *ed25519.PublicKey, label string) (out []byte, err error) {
30 // derive key material for decryption
31 iv, skey := DeriveBlockKey(label, zoneKey)
32 // perform decryption
33 return crypto.SymmetricDecrypt(data, skey, iv)
34}
diff --git a/src/gnunet/service/gns/crypto_test.go b/src/gnunet/service/gns/crypto_test.go
deleted file mode 100644
index 2abfb99..0000000
--- a/src/gnunet/service/gns/crypto_test.go
+++ /dev/null
@@ -1,150 +0,0 @@
1package gns
2
3import (
4 "bytes"
5 "encoding/hex"
6 "testing"
7
8 "github.com/bfix/gospel/crypto/ed25519"
9)
10
11var (
12 PUB = []byte{
13 0x93, 0x34, 0x71, 0xF6, 0x99, 0x19, 0x0C, 0x62,
14 0x85, 0xC7, 0x9B, 0x83, 0x9D, 0xCA, 0x83, 0x91,
15 0x38, 0xFA, 0x87, 0xFB, 0xB8, 0xD4, 0xF6, 0xF0,
16 0xF0, 0x4B, 0x7F, 0x0A, 0x48, 0xBF, 0x95, 0xF7,
17 }
18 LABEL = "home"
19)
20
21func TestDeriveBlockKey(t *testing.T) {
22 var (
23 SKEY = []byte{
24 0x1D, 0x86, 0x8E, 0xF7, 0x30, 0x96, 0x3B, 0x39,
25 0x66, 0xE6, 0x49, 0xD8, 0xF1, 0x13, 0x18, 0x39,
26 0x8A, 0x7A, 0xB0, 0xF3, 0xDC, 0xF6, 0xE7, 0x2A,
27 0xF6, 0x65, 0xDE, 0x86, 0x47, 0x7B, 0x20, 0x1B,
28
29 0x21, 0xA6, 0xFA, 0x55, 0x7C, 0x29, 0xF5, 0x94,
30 0x8E, 0x9A, 0x80, 0xB0, 0xB6, 0xD5, 0x4D, 0x38,
31 0x0E, 0x6A, 0x0F, 0x42, 0x4B, 0x27, 0xBB, 0x6A,
32 0x1E, 0xD1, 0x33, 0x08, 0xD6, 0x2E, 0x21, 0x8C,
33 }
34 IV = []byte{
35 0xAC, 0x18, 0x03, 0xB7, 0x8B, 0x1E, 0x09, 0xA9,
36 0xD0, 0x20, 0x47, 0x2B, 0x1B, 0x23, 0xE8, 0x24,
37
38 0xC9, 0x23, 0x9E, 0x61, 0x3A, 0x8D, 0x95, 0xA9,
39 0x3F, 0x6C, 0x1C, 0xC8, 0xCB, 0xD1, 0xBD, 0x6B,
40 }
41 )
42
43 iv, skey := deriveBlockKey(LABEL, ed25519.NewPublicKeyFromBytes(PUB))
44
45 if bytes.Compare(IV[:16], iv.AESIv) != 0 {
46 t.Logf("AES_IV(computed) = %s\n", hex.EncodeToString(iv.AESIv))
47 t.Logf("AES_IV(expected) = %s\n", hex.EncodeToString(IV[:16]))
48 t.Fatal("AES IV mismatch")
49 }
50 if bytes.Compare(IV[16:], iv.TwofishIv) != 0 {
51 t.Logf("Twofish_IV(computed) = %s\n", hex.EncodeToString(iv.TwofishIv))
52 t.Logf("Twofish_IV(expected) = %s\n", hex.EncodeToString(IV[16:]))
53 t.Fatal("Twofish IV mismatch")
54 }
55
56 if bytes.Compare(SKEY[:32], skey.AESKey) != 0 {
57 t.Logf("AES_KEY(computed) = %s\n", hex.EncodeToString(skey.AESKey))
58 t.Logf("AES_KEY(expected) = %s\n", hex.EncodeToString(SKEY[:32]))
59 t.Fatal("AES KEY mismatch")
60 }
61 if bytes.Compare(SKEY[32:], skey.TwofishKey) != 0 {
62 t.Logf("Twofish_KEY(computed) = %s\n", hex.EncodeToString(skey.TwofishKey))
63 t.Logf("Twofish_KEY(expected) = %s\n", hex.EncodeToString(SKEY[32:]))
64 t.Fatal("Twofish KEY mismatch")
65 }
66}
67
68func TestDecryptBlock(t *testing.T) {
69 var (
70 DATA = []byte{
71 0xAC, 0xA5, 0x3C, 0x55, 0x63, 0x21, 0x31, 0x1F,
72 0x11, 0x6E, 0xEF, 0x48, 0xED, 0x53, 0x46, 0x31,
73 0x7C, 0x50, 0xFB, 0x6B, 0xA6, 0xC8, 0x6C, 0x46,
74 0x1E, 0xE3, 0xCA, 0x45, 0xCD, 0x5B, 0xD6, 0x86,
75 0x42, 0x87, 0xEF, 0x18, 0xCE, 0x8E, 0x83, 0x21,
76 0x04, 0xCB, 0xCF, 0x40, 0x7E, 0x0F, 0x51, 0x54,
77 0xE2, 0x3C, 0xDE, 0xE9, 0x22, 0x00, 0xFF, 0x40,
78 0xBB, 0x53, 0xE3, 0x69, 0x99, 0x92, 0x47, 0x97,
79 0xF0, 0x4E, 0x3B, 0x70,
80 }
81 OUT = []byte{
82 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0xAD, 0x0E,
83 0x60, 0x28, 0xFE, 0x80, 0x00, 0x00, 0x00, 0x10,
84 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
85 0x0A, 0x68, 0x6F, 0x69, 0x2D, 0x70, 0x6F, 0x6C,
86 0x6C, 0x6F, 0x69, 0x03, 0x6F, 0x72, 0x67, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00,
91 }
92 )
93
94 out, err := DecryptBlock(DATA, ed25519.NewPublicKeyFromBytes(PUB), LABEL)
95 if err != nil {
96 t.Fatal(err)
97 }
98 if bytes.Compare(out, OUT) != 0 {
99 t.Logf("Decrypt(computed) = %s\n", hex.EncodeToString(out))
100 t.Logf("Decrypt(expected) = %s\n", hex.EncodeToString(OUT))
101 t.Fatal("Decryptions failed")
102 }
103}
104
105func TestVerifyBlock(t *testing.T) {
106 var (
107 SIGNED = []byte{
108 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x0f,
109 0x00, 0x05, 0xad, 0x0e, 0x60, 0x28, 0xfe, 0x80,
110 0xac, 0xa5, 0x3c, 0x55, 0x63, 0x21, 0x31, 0x1f,
111 0x11, 0x6e, 0xef, 0x48, 0xed, 0x53, 0x46, 0x31,
112 0x7c, 0x50, 0xfb, 0x6b, 0xa6, 0xc8, 0x6c, 0x46,
113 0x1e, 0xe3, 0xca, 0x45, 0xcd, 0x5b, 0xd6, 0x86,
114 0x42, 0x87, 0xef, 0x18, 0xce, 0x8e, 0x83, 0x21,
115 0x04, 0xcb, 0xcf, 0x40, 0x7e, 0x0f, 0x51, 0x54,
116 0xe2, 0x3c, 0xde, 0xe9, 0x22, 0x00, 0xff, 0x40,
117 0xbb, 0x53, 0xe3, 0x69, 0x99, 0x92, 0x47, 0x97,
118 0xf0, 0x4e, 0x3b, 0x70,
119 }
120 SIG = []byte{
121 0x09, 0xc9, 0x6a, 0xda, 0x69, 0xce, 0x7c, 0x91,
122 0xbd, 0xa4, 0x59, 0xdc, 0xc9, 0x76, 0xf4, 0x6c,
123 0x62, 0xb7, 0x79, 0x3f, 0x94, 0xb2, 0xf6, 0xf0,
124 0x90, 0x17, 0x4e, 0x2f, 0x68, 0x49, 0xf8, 0xcc,
125
126 0x0b, 0x77, 0x32, 0x32, 0x28, 0x77, 0x2d, 0x2a,
127 0x31, 0x31, 0xc1, 0x2c, 0x44, 0x18, 0xf2, 0x5f,
128 0x1a, 0xe9, 0x8b, 0x2e, 0x65, 0xca, 0x1d, 0xe8,
129 0x22, 0x82, 0x6a, 0x06, 0xe0, 0x6a, 0x5a, 0xe5,
130 }
131 PUB = []byte{
132 0x26, 0x84, 0x1b, 0x24, 0x35, 0xa4, 0x63, 0xe9,
133 0xf0, 0x48, 0xae, 0x3e, 0xf7, 0xe8, 0x1b, 0xca,
134 0x55, 0x9f, 0x4c, 0x1e, 0x16, 0x18, 0xa6, 0xd3,
135 0x5b, 0x91, 0x0d, 0x54, 0x31, 0x6e, 0xbf, 0x97,
136 }
137 )
138 sig, err := ed25519.NewEcSignatureFromBytes(SIG)
139 if err != nil {
140 t.Fatal(err)
141 }
142 dkey := ed25519.NewPublicKeyFromBytes(PUB)
143 ok, err := dkey.EcVerify(SIGNED, sig)
144 if err != nil {
145 t.Fatal(err)
146 }
147 if !ok {
148 t.Fatal("EcDSA verify failed")
149 }
150}
diff --git a/src/gnunet/service/gns/gns.go b/src/gnunet/service/gns/gns.go
deleted file mode 100644
index b95a9e1..0000000
--- a/src/gnunet/service/gns/gns.go
+++ /dev/null
@@ -1,279 +0,0 @@
1package gns
2
3import (
4 "encoding/hex"
5 "io"
6
7 "github.com/bfix/gospel/crypto/ed25519"
8 "github.com/bfix/gospel/data"
9 "github.com/bfix/gospel/logger"
10 "gnunet/config"
11 "gnunet/crypto"
12 "gnunet/enums"
13 "gnunet/message"
14 "gnunet/service"
15 "gnunet/transport"
16 "gnunet/util"
17)
18
19//----------------------------------------------------------------------
20// "GNUnet Name System" service implementation
21//----------------------------------------------------------------------
22
23// GNSService
24type GNSService struct {
25}
26
27// NewGNSService
28func NewGNSService() service.Service {
29 return &GNSService{}
30}
31
32// Start the GNS service
33func (s *GNSService) Start(spec string) error {
34 return nil
35}
36
37// Stop the GNS service
38func (s *GNSService) Stop() error {
39 return nil
40}
41
42// Serve a client channel.
43func (s *GNSService) ServeClient(mc *transport.MsgChannel) {
44 for {
45 // receive next message from client
46 msg, err := mc.Receive()
47 if err != nil {
48 if err == io.EOF {
49 logger.Println(logger.INFO, "[gns] Client channel closed.")
50 } else {
51 logger.Printf(logger.ERROR, "[gns] Message-receive failed: %s\n", err.Error())
52 }
53 break
54 }
55 logger.Printf(logger.INFO, "[gns] Received msg: %v\n", msg)
56
57 // perform lookup
58 var resp message.Message
59 switch m := msg.(type) {
60 case *message.GNSLookupMsg:
61 //----------------------------------------------------------
62 // GNS_LOOKUP
63 //----------------------------------------------------------
64 logger.Println(logger.INFO, "[gns] Lookup request received.")
65 respX := message.NewGNSLookupResultMsg(m.Id)
66 resp = respX
67
68 // perform lookup on block (either from Namecache or DHT)
69 // TODO: run code in a go routine concurrently (would need
70 // access to the message channel to send responses)
71 block, err := s.Lookup(m)
72 if err != nil {
73 logger.Printf(logger.ERROR, "[gns] Failed to lookup block: %s\n", err.Error())
74 break
75 }
76 // handle block
77 if block != nil {
78 logger.Printf(logger.DBG, "[gns] Received block data: %s\n", hex.EncodeToString(block.Block.data))
79
80 // get records from block
81 records, err := block.Records()
82 if err != nil {
83 logger.Printf(logger.ERROR, "[gns] Failed to extract records: %s\n", err.Error())
84 break
85 }
86 if len(records) == 0 {
87 logger.Println(logger.WARN, "[gns] No records in block")
88 break
89 }
90 // process records
91 for i, rec := range records {
92 logger.Printf(logger.DBG, "[gns] Record #%d: %v\n", i, rec)
93
94 // is this the record type we are looking for?
95 if rec.Type == m.Type || int(m.Type) == enums.GNS_TYPE_ANY {
96 // add it to the response message
97 respX.AddRecord(rec)
98 }
99 }
100 }
101
102 default:
103 //----------------------------------------------------------
104 // UNKNOWN message type received
105 //----------------------------------------------------------
106 logger.Printf(logger.ERROR, "[gns] Unhandled message of type (%d)\n", msg.Header().MsgType)
107 continue
108 }
109
110 // send response
111 if err := mc.Send(resp); err != nil {
112 logger.Printf(logger.ERROR, "[gns] Failed to send response: %s\n", err.Error())
113 }
114
115 }
116 // close client connection
117 mc.Close()
118}
119
120// Lookup handles GNU_LOOKUP messages
121func (s *GNSService) Lookup(m *message.GNSLookupMsg) (block *GNSBlock, err error) {
122 // create DHT/NAMECACHE query
123 pkey := ed25519.NewPublicKeyFromBytes(m.Zone)
124 label := m.GetName()
125 query := QueryFromPublickeyDerive(pkey, label)
126
127 // try namecache lookup first
128 if block, err = s.LookupNamecache(query, pkey, label); err != nil {
129 logger.Printf(logger.ERROR, "[gns] Lookup(Namecache): %s\n", err.Error())
130 block = nil
131 return
132 }
133 if block == nil {
134 logger.Println(logger.DBG, "[gns] Lookup(Namecache): no block found")
135 if int(m.Options) == enums.GNS_LO_DEFAULT {
136 // get the block from the DHT
137 if block, err = s.LookupDHT(query, pkey, label); err != nil || block == nil {
138 if err != nil {
139 logger.Printf(logger.ERROR, "[gns] Lookup(DHT): %s\n", err.Error())
140 block = nil
141 } else {
142 logger.Println(logger.DBG, "[gns] Lookup(DHT): no block found")
143 }
144 // lookup fails completely -- no result
145 }
146 }
147 }
148 return
149}
150
151// LookupNamecache
152func (s *GNSService) LookupNamecache(query *crypto.HashCode, zoneKey *ed25519.PublicKey, label string) (block *GNSBlock, err error) {
153 logger.Printf(logger.DBG, "[gns] LookupNamecache(%s)...\n", hex.EncodeToString(query.Bits))
154
155 // assemble Namecache request
156 req := message.NewNamecacheLookupMsg(query)
157 req.Id = uint32(util.NextID())
158 block = nil
159
160 // get response from Namecache service
161 var resp message.Message
162 if resp, err = service.ServiceRequestResponse("gns", "Namecache", config.Cfg.Namecache.Endpoint, req); err != nil {
163 return
164 }
165
166 // handle message depending on its type
167 logger.Println(logger.DBG, "[gns] Handling response from Namecache service")
168 switch m := resp.(type) {
169 case *message.NamecacheLookupResultMsg:
170 // check for matching IDs
171 if m.Id != req.Id {
172 logger.Println(logger.ERROR, "[gns] Got response for unknown ID")
173 break
174 }
175 // check if block was found
176 if len(m.EncData) == 0 {
177 logger.Println(logger.DBG, "[gns] block not found in namecache")
178 break
179 }
180 // check if record has expired
181 if m.Expire.Expired() {
182 logger.Printf(logger.ERROR, "[gns] block expired at %s\n", m.Expire)
183 break
184 }
185
186 // assemble GNSBlock from message
187 block = new(GNSBlock)
188 block.Signature = m.Signature
189 block.DerivedKey = m.DerivedKey
190 sb := new(SignedBlockData)
191 sb.Purpose = new(crypto.SignaturePurpose)
192 sb.Purpose.Purpose = enums.SIG_GNS_RECORD_SIGN
193 sb.Purpose.Size = uint32(16 + len(m.EncData))
194 sb.Expire = m.Expire
195 sb.EncData = m.EncData
196 block.Block = sb
197
198 // verify and decrypt block
199 if err = block.Verify(zoneKey, label); err != nil {
200 break
201 }
202 if err = block.Decrypt(zoneKey, label); err != nil {
203 break
204 }
205 }
206 return
207}
208
209// StoreNamecache
210func (s *GNSService) StoreNamecache(query *crypto.HashCode, block *GNSBlock) error {
211 logger.Println(logger.WARN, "[gns] StoreNamecache() not implemented yet!")
212 return nil
213}
214
215// LookupDHT
216func (s *GNSService) LookupDHT(query *crypto.HashCode, zoneKey *ed25519.PublicKey, label string) (block *GNSBlock, err error) {
217 logger.Printf(logger.DBG, "[gns] LookupDHT(%s)...\n", hex.EncodeToString(query.Bits))
218
219 // assemble DHT request
220 req := message.NewDHTClientGetMsg(query)
221 req.Id = uint64(util.NextID())
222 req.ReplLevel = uint32(enums.DHT_GNS_REPLICATION_LEVEL)
223 req.Type = uint32(enums.BLOCK_TYPE_GNS_NAMERECORD)
224 req.Options = uint32(enums.DHT_RO_DEMULTIPLEX_EVERYWHERE)
225 block = nil
226
227 // get response from DHT service
228 var resp message.Message
229 if resp, err = service.ServiceRequestResponse("gns", "DHT", config.Cfg.DHT.Endpoint, req); err != nil {
230 return
231 }
232
233 // handle message depending on its type
234 logger.Println(logger.DBG, "[gns] Handling response from DHT service")
235 switch m := resp.(type) {
236 case *message.DHTClientResultMsg:
237 // check for matching IDs
238 if m.Id != req.Id {
239 logger.Println(logger.ERROR, "[gns] Got response for unknown ID")
240 break
241 }
242 // check if block was found
243 if len(m.Data) == 0 {
244 logger.Println(logger.DBG, "[gns] block not found in DHT")
245 break
246 }
247 // check if record has expired
248 if m.Expire.Expired() {
249 logger.Printf(logger.ERROR, "[gns] block expired at %s\n", m.Expire)
250 break
251 }
252 // check if result is of requested type
253 if int(m.Type) != enums.BLOCK_TYPE_GNS_NAMERECORD {
254 logger.Println(logger.ERROR, "[gns] DHT response has wrong type")
255 break
256 }
257
258 // get GNSBlock from message
259 block = NewGNSBlock()
260 if err = data.Unmarshal(block, m.Data); err != nil {
261 logger.Printf(logger.ERROR, "[gns] can't read GNS block: %s\n", err.Error())
262 break
263 }
264 // verify and decrypt block
265 if err = block.Verify(zoneKey, label); err != nil {
266 break
267 }
268 if err = block.Decrypt(zoneKey, label); err != nil {
269 break
270 }
271
272 // we got a result from DHT that was not in the namecache,
273 // so store it there now.
274 if err = s.StoreNamecache(query, block); err != nil {
275 logger.Printf(logger.ERROR, "[gns] can't store block in Namecache: %s\n", err.Error())
276 }
277 }
278 return
279}
diff --git a/src/gnunet/service/gns/record.go b/src/gnunet/service/gns/record.go
deleted file mode 100644
index 68ce4a6..0000000
--- a/src/gnunet/service/gns/record.go
+++ /dev/null
@@ -1,124 +0,0 @@
1package gns
2
3import (
4 "fmt"
5
6 "github.com/bfix/gospel/crypto/ed25519"
7 "github.com/bfix/gospel/data"
8 "gnunet/crypto"
9 "gnunet/message"
10 "gnunet/util"
11)
12
13var (
14 ErrBlockNotDecrypted = fmt.Errorf("GNS block not decrypted")
15)
16
17type GNSRecordSet struct {
18 Count uint32 `order:"big"` // number of resource records
19 Records []*message.GNSResourceRecord `size:"Count"` // list of resource records
20 Padding []byte `size:"*"` // padding
21}
22
23func NewGNSRecordSet() *GNSRecordSet {
24 return &GNSRecordSet{
25 Count: 0,
26 Records: make([]*message.GNSResourceRecord, 0),
27 Padding: make([]byte, 0),
28 }
29}
30
31func (rs *GNSRecordSet) AddRecord(rec *message.GNSResourceRecord) {
32 rs.Count++
33 rs.Records = append(rs.Records, rec)
34}
35
36type SignedBlockData struct {
37 Purpose *crypto.SignaturePurpose // Size and purpose of signature (8 bytes)
38 Expire util.AbsoluteTime // Expiration time of the block.
39 EncData []byte `size:"*"` // encrypted GNSRecordSet
40
41 // transient data (not serialized)
42 data []byte // unencrypted GNSRecord set
43}
44
45type GNSBlock struct {
46 Signature []byte `size:"64"` // Signature of the block.
47 DerivedKey []byte `size:"32"` // Derived key used for signing
48 Block *SignedBlockData
49
50 // transient data (not serialized)
51 checked bool // block integrity checked
52 verified bool // block signature verified (internal)
53 decrypted bool // block data decrypted (internal)
54}
55
56func (b *GNSBlock) String() string {
57 return fmt.Sprintf("GNSBlock{Verified=%v,Decrypted=%v,data=[%d]}",
58 b.verified, b.decrypted, len(b.Block.EncData))
59}
60
61func (b *GNSBlock) Records() ([]*message.GNSResourceRecord, error) {
62 // check if block is decrypted
63 if !b.decrypted {
64 return nil, ErrBlockNotDecrypted
65 }
66 // parse block data into record set
67 rs := NewGNSRecordSet()
68 if err := data.Unmarshal(rs, b.Block.data); err != nil {
69 return nil, err
70 }
71 return rs.Records, nil
72}
73
74func (b *GNSBlock) Verify(zoneKey *ed25519.PublicKey, label string) (err error) {
75 // Integrity check performed
76 b.checked = true
77
78 // verify derived key
79 dkey := ed25519.NewPublicKeyFromBytes(b.DerivedKey)
80 dkey2 := crypto.DerivePublicKey(zoneKey, label, "gns")
81 if !dkey.Q.Equals(dkey2.Q) {
82 return fmt.Errorf("Invalid signature key for GNS Block")
83 }
84 // verify signature
85 var (
86 sig *ed25519.EcSignature
87 buf []byte
88 ok bool
89 )
90 if sig, err = ed25519.NewEcSignatureFromBytes(b.Signature); err != nil {
91 return
92 }
93 if buf, err = data.Marshal(b.Block); err != nil {
94 return
95 }
96 if ok, err = dkey.EcVerify(buf, sig); err == nil && !ok {
97 err = fmt.Errorf("Signature verification failed for GNS block")
98 }
99 b.verified = true
100 return
101}
102
103func (b *GNSBlock) Decrypt(zoneKey *ed25519.PublicKey, label string) (err error) {
104 // decrypt payload
105 b.Block.data, err = DecryptBlock(b.Block.EncData, zoneKey, label)
106 b.decrypted = true
107 return
108}
109
110func NewGNSBlock() *GNSBlock {
111 return &GNSBlock{
112 Signature: make([]byte, 64),
113 DerivedKey: make([]byte, 32),
114 Block: &SignedBlockData{
115 Purpose: new(crypto.SignaturePurpose),
116 Expire: *new(util.AbsoluteTime),
117 EncData: nil,
118 data: nil,
119 },
120 checked: false,
121 verified: false,
122 decrypted: false,
123 }
124}
diff --git a/src/gnunet/util/msg_queue.go b/src/gnunet/util/msg_queue.go
deleted file mode 100644
index a4fb2eb..0000000
--- a/src/gnunet/util/msg_queue.go
+++ /dev/null
@@ -1,3 +0,0 @@
1package util
2
3import ()