-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
704 lines (632 loc) · 19.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
// genconfig.go - Meson config generation.
// Copyright (C) 2020 Hashcloak.
// genconfig.go - Katzenpost self contained test network.
// Copyright (C) 2017 Yawning Angel, David Stainton.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"bytes"
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"
"github.com/BurntSushi/toml"
currencyConf "github.com/hashcloak/Meson-plugin/pkg/config"
aConfig "github.com/katzenpost/authority/nonvoting/server/config"
vConfig "github.com/katzenpost/authority/voting/server/config"
"github.com/katzenpost/core/crypto/ecdh"
"github.com/katzenpost/core/crypto/eddsa"
"github.com/katzenpost/core/crypto/rand"
sConfig "github.com/katzenpost/server/config"
)
const (
basePort = 30000
nrNodes = 6
nrProviders = 2
nrAuthorities = 3
minimumNodesPerLayer = 2
)
var currencyList = []*currencyConf.Config{
¤cyConf.Config{
Ticker: "gor",
RPCUser: "rpcuser",
RPCPass: "rpcpassword",
RPCURL: "https://goerli.hashcloak.com",
},
¤cyConf.Config{
Ticker: "tbnb",
RPCUser: "rpcuser",
RPCPass: "rpcpassword",
RPCURL: "https://tbinance.hashcloak.com",
},
¤cyConf.Config{
Ticker: "rin",
RPCUser: "rpcuser",
RPCPass: "rpcpassword",
RPCURL: "https://rinkeby.hashcloak.com",
},
}
type katzenpost struct {
baseDir string
outputDir string
authAddress string
logWriter io.Writer
currency int
authConfig *aConfig.Config
votingAuthConfigs []*vConfig.Config
authIdentity *eddsa.PrivateKey
authPubIdentity string
nodeConfigs []*sConfig.Config
lastPort uint16
nodeIdx int
providerIdx int
recipients map[string]*ecdh.PublicKey
voting bool
nrProviders int
nrNodes int
nrVoting int
onlyMixNode bool
onlyProviderNode bool
publicIPAddress string
nameOfSingleNode string
}
func (s *katzenpost) genProviderConfig(name string) (cfg *sConfig.Config, err error) {
cfg, err = s.genMixNodeConfig(name)
cfg.Server.Identifier = name
cfg.Server.IsProvider = true
cfg.Management = new(sConfig.Management)
cfg.Management.Enable = true
cfg.Provider = new(sConfig.Provider)
loopCfg := new(sConfig.Kaetzchen)
loopCfg.Capability = "loop"
loopCfg.Endpoint = "+loop"
cfg.Provider.Kaetzchen = append(cfg.Provider.Kaetzchen, loopCfg)
/*
keysvrCfg := new(sConfig.Kaetzchen)
keysvrCfg.Capability = "keyserver"
keysvrCfg.Endpoint = "+keyserver"
cfg.Provider.Kaetzchen = append(cfg.Provider.Kaetzchen, keysvrCfg)
*/
cfg.Provider.EnableUserRegistrationHTTP = true
userRegistrationPort := 10000 + s.lastPort
cfg.Provider.UserRegistrationHTTPAddresses = []string{fmt.Sprintf("0.0.0.0:%d", userRegistrationPort)}
cfg.Provider.AdvertiseUserRegistrationHTTPAddresses = []string{fmt.Sprintf("http://%s:%d", s.publicIPAddress, userRegistrationPort)}
// Plugin configs
// echo server
pluginConf := make(map[string]interface{})
pluginConf["log_dir"] = s.baseDir
pluginConf["log_level"] = cfg.Logging.Level
echoPlugin := sConfig.CBORPluginKaetzchen{
Disable: false,
Capability: "echo",
Endpoint: "+echo",
Command: "/go/bin/echo_server",
MaxConcurrency: 1,
Config: pluginConf,
}
cfg.Provider.CBORPluginKaetzchen = append(cfg.Provider.CBORPluginKaetzchen, &echoPlugin)
// panda serever
pluginConf = make(map[string]interface{})
pluginConf["log_dir"] = s.baseDir
pluginConf["log_level"] = cfg.Logging.Level
pluginConf["fileStore"] = s.baseDir + "/panda.storage"
pandaPlugin := sConfig.CBORPluginKaetzchen{
Disable: false,
Capability: "panda",
Endpoint: "+panda",
Command: "/go/bin/panda_server",
MaxConcurrency: 1,
Config: pluginConf,
}
cfg.Provider.CBORPluginKaetzchen = append(cfg.Provider.CBORPluginKaetzchen, &pandaPlugin)
// memspool
pluginConf = make(map[string]interface{})
// leaving this one out until it can be proven that it won't crash the spool plugin
//pluginconf["log_dir"] = s.basedir
pluginConf["log_dir"] = s.baseDir
pluginConf["data_store"] = s.baseDir + "/memspool.storage"
spoolPlugin := sConfig.CBORPluginKaetzchen{
Disable: false,
Capability: "spool",
Endpoint: "+spool",
Command: "/go/bin/memspool",
MaxConcurrency: 1,
Config: pluginConf,
}
cfg.Provider.CBORPluginKaetzchen = append(cfg.Provider.CBORPluginKaetzchen, &spoolPlugin)
// Meson
curConf := currencyList[s.currency]
s.currency++
if s.currency >= len(currencyList) {
s.currency = 0
}
curConf.LogDir = s.baseDir
curConf.LogLevel = cfg.Logging.Level
pluginConf = make(map[string]interface{})
pluginConf["f"] = s.baseDir + "/currency.toml"
pluginConf["log_dir"] = s.baseDir
pluginConf["log_level"] = cfg.Logging.Level
mesonPlugin := sConfig.CBORPluginKaetzchen{
Disable: false,
Capability: curConf.Ticker,
Endpoint: "+" + curConf.Ticker,
Command: "/go/bin/Meson",
MaxConcurrency: 1,
Config: pluginConf,
}
cfg.Provider.CBORPluginKaetzchen = append(cfg.Provider.CBORPluginKaetzchen, &mesonPlugin)
// generate currency.toml
os.Mkdir(filepath.Join(s.outputDir, identifier(cfg)), 0700)
fileName := filepath.Join(
s.outputDir, identifier(cfg), "currency.toml",
)
f, err := os.Create(fileName)
if err != nil {
return nil, err
}
defer f.Close()
// Serialize the descriptor.
enc := toml.NewEncoder(f)
err = enc.Encode(curConf)
if err != nil {
return nil, err
}
return cfg, cfg.FixupAndValidate()
}
func (s *katzenpost) genMixNodeConfig(name string) (cfg *sConfig.Config, err error) {
priv := filepath.Join(s.outputDir, name, "identity.private.pem")
public := filepath.Join(s.outputDir, name, "identity.public.pem")
_, err = eddsa.Load(priv, public, rand.Reader)
if err != nil {
return nil, err
}
cfg = new(sConfig.Config)
if s.voting {
peers := []*sConfig.Peer{}
for _, peer := range s.votingAuthConfigs {
idKey, err := s.apk(peer).MarshalText()
if err != nil {
return nil, err
}
linkKey, err := s.alk(peer).MarshalText()
if err != nil {
return nil, err
}
p := &sConfig.Peer{
Addresses: peer.Authority.Addresses,
IdentityPublicKey: string(idKey),
LinkPublicKey: string(linkKey),
}
if len(peer.Authority.Addresses) == 0 {
panic("wtf")
}
peers = append(peers, p)
}
cfg.PKI = &sConfig.PKI{
Voting: &sConfig.Voting{
Peers: peers,
},
}
} else {
cfg.PKI = new(sConfig.PKI)
cfg.PKI.Nonvoting = new(sConfig.Nonvoting)
cfg.PKI.Nonvoting.Address = fmt.Sprintf(s.authAddress+":%d", basePort)
idKey := []byte(s.authPubIdentity)
if s.authIdentity != nil {
idKey, err = s.authIdentity.PublicKey().MarshalText()
if err != nil {
return nil, err
}
}
cfg.PKI.Nonvoting.PublicKey = string(idKey)
}
// Server section.
cfg.Server = new(sConfig.Server)
cfg.Server.Identifier = name
cfg.Server.Addresses = []string{fmt.Sprintf("0.0.0.0:%d", s.lastPort)}
cfg.Server.AltAddresses = map[string][]string{
"tcp4": []string{fmt.Sprintf(s.publicIPAddress+":%d", s.lastPort)},
}
cfg.Server.OnlyAdvertiseAltAddresses = true
cfg.Server.DataDir = s.baseDir
cfg.Server.IsProvider = false
// Debug section.
cfg.Debug = new(sConfig.Debug)
cfg.Debug.DisableRateLimit = true
cfg.Debug.SendDecoyTraffic = false
// This needs to be 1 because during runtime the default
// value of this is the number of cores of the computer.
// In docker this number is 1 but if one runs this script
// on a personal computer the value becomes much more than
// what docker is capable of handling. Take a look at:
// https://github.com/katzenpost/server/blob/master/config/config.go#L261
cfg.Debug.NumSphinxWorkers = 1
cfg.Debug.ConnectTimeout = 120000 // 2 mins
cfg.Debug.HandshakeTimeout = 600000
// Logging section.
cfg.Logging = new(sConfig.Logging)
cfg.Logging.File = "katzenpost.log"
cfg.Logging.Level = "DEBUG"
return cfg, cfg.FixupAndValidate()
}
func (s *katzenpost) genNodeConfig(isProvider bool, isVoting bool) error {
var err error
var cfg *sConfig.Config
var name string
if isProvider {
name = fmt.Sprintf("provider-%d", s.providerIdx)
} else {
name = fmt.Sprintf("node-%d", s.nodeIdx)
}
if s.nameOfSingleNode != "" {
name = s.nameOfSingleNode
}
os.Mkdir(filepath.Join(s.outputDir, name), 0700)
if isProvider {
cfg, err = s.genProviderConfig(name)
if err != nil {
return err
}
s.providerIdx++
} else {
cfg, err = s.genMixNodeConfig(name)
if err != nil {
return err
}
s.nodeIdx++
}
s.nodeConfigs = append(s.nodeConfigs, cfg)
s.lastPort++
return nil
}
func (s *katzenpost) genAuthConfig() error {
authLogFile := s.baseDir + "/" + "authority.log"
cfg := new(aConfig.Config)
// Authority section.
cfg.Authority = new(aConfig.Authority)
cfg.Authority.Addresses = []string{fmt.Sprintf("0.0.0.0:%d", basePort)}
cfg.Authority.DataDir = filepath.Join(s.baseDir)
// Logging section.
cfg.Logging = new(aConfig.Logging)
cfg.Logging.File = authLogFile
cfg.Logging.Level = "DEBUG"
name := "nonvoting"
os.Mkdir(filepath.Join(s.outputDir, name), 0700)
// Generate keys
priv := filepath.Join(s.outputDir, name, "identity.private.pem")
public := filepath.Join(s.outputDir, name, "identity.public.pem")
idKey, err := eddsa.Load(priv, public, rand.Reader)
s.authIdentity = idKey
s.authPubIdentity = idKey.PublicKey().String()
if err != nil {
return err
}
// Debug section.
cfg.Debug = new(aConfig.Debug)
cfg.Debug.MinNodesPerLayer = minimumNodesPerLayer
if cfg.Debug.MinNodesPerLayer > s.nrNodes {
return fmt.Errorf("Not enough nodes to fill up each layer")
}
cfg.Debug.Layers = s.nrNodes / cfg.Debug.MinNodesPerLayer
if err := cfg.FixupAndValidate(); err != nil {
return err
}
s.authConfig = cfg
return nil
}
func (s *katzenpost) genVotingAuthoritiesCfg(numAuthorities int) error {
parameters := &vConfig.Parameters{}
configs := []*vConfig.Config{}
// initial generation of key material for each authority
peersMap := make(map[[eddsa.PublicKeySize]byte]*vConfig.AuthorityPeer)
for i := 0; i < numAuthorities; i++ {
cfg := new(vConfig.Config)
cfg.Logging = &vConfig.Logging{
Disable: false,
File: "katzenpost.log",
Level: "DEBUG",
}
cfg.Parameters = parameters
cfg.Authority = &vConfig.Authority{
Identifier: fmt.Sprintf("authority-%v", i),
Addresses: []string{fmt.Sprintf("0.0.0.0:%d", s.lastPort)},
DataDir: filepath.Join(s.baseDir, fmt.Sprintf("authority-%d", i)),
}
os.Mkdir(s.outputDir+"/"+cfg.Authority.Identifier, 0700)
s.lastPort++
priv := filepath.Join(cfg.Authority.DataDir, "identity.private.pem")
public := filepath.Join(cfg.Authority.DataDir, "identity.public.pem")
idKey, err := eddsa.Load(priv, public, rand.Reader)
if err != nil {
return err
}
cfg.Debug = &vConfig.Debug{
IdentityKey: idKey,
Layers: 3,
MinNodesPerLayer: 1,
GenerateOnly: false,
}
configs = append(configs, cfg)
authorityPeer := &vConfig.AuthorityPeer{
IdentityPublicKey: s.apk(cfg),
LinkPublicKey: s.alk(cfg),
Addresses: cfg.Authority.Addresses,
}
peersMap[s.apk(cfg).ByteArray()] = authorityPeer
}
// tell each authority about it's peers
for i := 0; i < numAuthorities; i++ {
peers := []*vConfig.AuthorityPeer{}
for id, peer := range peersMap {
if !bytes.Equal(id[:], s.apk(configs[i]).Bytes()) {
peers = append(peers, peer)
}
}
configs[i].Authorities = peers
}
s.votingAuthConfigs = configs
return nil
}
func (s *katzenpost) generateWhitelist() ([]*aConfig.Node, []*aConfig.Node, error) {
mixes := []*aConfig.Node{}
providers := []*aConfig.Node{}
for _, nodeCfg := range s.nodeConfigs {
if nodeCfg.Server.IsProvider {
provider := &aConfig.Node{
Identifier: nodeCfg.Server.Identifier,
IdentityKey: s.spk(nodeCfg),
}
providers = append(providers, provider)
continue
}
mix := &aConfig.Node{
IdentityKey: s.spk(nodeCfg),
}
mixes = append(mixes, mix)
}
return providers, mixes, nil
}
func (s *katzenpost) generateVotingWhitelist() ([]*vConfig.Node, []*vConfig.Node, error) {
mixes := []*vConfig.Node{}
providers := []*vConfig.Node{}
for _, nodeCfg := range s.nodeConfigs {
if nodeCfg.Server.IsProvider {
provider := &vConfig.Node{
Identifier: nodeCfg.Server.Identifier,
IdentityKey: s.spk(nodeCfg),
}
providers = append(providers, provider)
continue
}
mix := &vConfig.Node{
IdentityKey: s.spk(nodeCfg),
}
mixes = append(mixes, mix)
}
return providers, mixes, nil
}
func (s *katzenpost) generateNonVotingMixnetConfigs() {
if err := s.genAuthConfig(); err != nil {
log.Fatalf("Failed to generate authority config: %v", err)
}
s.generateNodesOfMixnet()
// The node lists.
if providers, mixes, err := s.generateWhitelist(); err == nil {
s.authConfig.Mixes = mixes
s.authConfig.Providers = providers
} else {
log.Fatalf("Failed to generateWhitelist with %s", err)
}
if err := saveCfg(s.outputDir, s.authConfig); err != nil {
log.Fatalf("Failed to saveCfg of authority with %s", err)
}
}
func (s *katzenpost) generateVotingMixnetConfigs() {
if err := s.genVotingAuthoritiesCfg(s.nrVoting); err != nil {
log.Fatalf("getVotingAuthoritiesCfg failed: %s", err)
}
s.generateNodesOfMixnet()
providerWhitelist, mixWhitelist, err := s.generateVotingWhitelist()
if err != nil {
panic(err)
}
for _, aCfg := range s.votingAuthConfigs {
aCfg.Mixes = mixWhitelist
aCfg.Providers = providerWhitelist
}
for _, aCfg := range s.votingAuthConfigs {
if err := saveCfg(s.outputDir, aCfg); err != nil {
log.Fatalf("Failed to saveCfg of authority with %s", err)
}
}
}
func (s *katzenpost) generateNodesOfMixnet() {
// Generate the provider configs.
for i := 0; i < s.nrProviders; i++ {
if err := s.genNodeConfig(true, s.voting); err != nil {
log.Fatalf("Failed to generate provider config: %v", err)
}
}
// Generate the node configs.
for i := 0; i < s.nrNodes; i++ {
if err := s.genNodeConfig(false, s.voting); err != nil {
log.Fatalf("Failed to generate node config: %v", err)
}
}
}
func main() {
var err error
nrNodes := flag.Int("n", nrNodes, "Number of mixes.")
nrProviders := flag.Int("p", nrProviders, "Number of providers.")
voting := flag.Bool("v", false, "Generate voting configuration.")
nrVoting := flag.Int("nv", nrAuthorities, "Number of voting authorities.")
baseDir := flag.String("b", "/conf", "Path to for DataDir in the config files.")
outputDir := flag.String("o", "./output", "Output path of the generate config files.")
authAddress := flag.String("a", "127.0.0.1", "Non-voting authority public ip address.")
mixNodeConfig := flag.Bool("node", false, "Only generate a mix node config.")
providerNodeConfig := flag.Bool("provider", false, "Only generate a provider node config.")
publicIPAddress := flag.String("ipv4", "", "The public ipv4 address of the single node.")
name := flag.String("name", "", "The name of the node.")
authPubIdentity := flag.String("authID", "", "Authority public ID.")
flag.Parse()
s := &katzenpost{
lastPort: basePort + 1,
recipients: make(map[string]*ecdh.PublicKey),
}
outDir, err := filepath.Abs(*outputDir)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(-1)
}
s.outputDir = outDir
s.baseDir = *baseDir
err = os.Mkdir(s.outputDir, 0700)
if err != nil && err.(*os.PathError).Err.Error() != "file exists" {
fmt.Fprintf(os.Stderr, "Failed to create output directory: %v\n", err)
os.Exit(-1)
}
s.authAddress = *authAddress
s.voting = *voting
s.nrProviders = *nrProviders
s.nrNodes = *nrNodes
s.nrVoting = *nrVoting
s.onlyMixNode = *mixNodeConfig
s.onlyProviderNode = *providerNodeConfig
s.publicIPAddress = *publicIPAddress
s.nameOfSingleNode = *name
s.authPubIdentity = *authPubIdentity
if s.onlyMixNode || s.onlyProviderNode {
if s.onlyMixNode && s.onlyProviderNode {
fmt.Fprintf(os.Stderr, "Please specify one of either -node or -provider config\n")
os.Exit(-1)
}
if s.nameOfSingleNode == "" {
fmt.Fprintf(os.Stderr, "Name not provided to provide a name with the -name flag\n")
os.Exit(-1)
}
if s.authPubIdentity == "" {
fmt.Fprintf(os.Stderr, "Need to provide an authority identity\n")
os.Exit(-1)
}
if s.publicIPAddress == "" {
fmt.Fprintf(os.Stderr, "Ip address not provided to provide a name with the -name flag\n")
os.Exit(-1)
}
err = s.genNodeConfig(s.onlyProviderNode, *voting)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(-1)
}
} else {
if s.publicIPAddress == "" {
s.publicIPAddress = s.authAddress
}
if *voting {
s.generateVotingMixnetConfigs()
} else {
s.generateNonVotingMixnetConfigs()
}
}
for _, v := range s.nodeConfigs {
if err := saveCfg(outDir, v); err != nil {
log.Fatalf("%s", err)
}
}
}
func basedir(cfg interface{}) string {
switch cfg.(type) {
case *sConfig.Config:
return cfg.(*sConfig.Config).Server.DataDir
case *aConfig.Config:
return cfg.(*aConfig.Config).Authority.DataDir
case *vConfig.Config:
return cfg.(*vConfig.Config).Authority.DataDir
default:
log.Fatalf("identifier() passed unexpected type")
return ""
}
}
func configName(cfg interface{}) string {
switch cfg.(type) {
case *sConfig.Config:
return "katzenpost.toml"
case *aConfig.Config:
return "authority.toml"
case *vConfig.Config:
return "authority.toml"
default:
log.Fatalf("identifier() passed unexpected type")
return ""
}
}
func identifier(cfg interface{}) string {
switch cfg.(type) {
case *sConfig.Config:
return cfg.(*sConfig.Config).Server.Identifier
case *aConfig.Config:
return "nonvoting"
case *vConfig.Config:
return cfg.(*vConfig.Config).Authority.Identifier
default:
log.Fatalf("identifier() passed unexpected type")
return ""
}
}
func saveCfg(outputDir string, cfg interface{}) error {
os.Mkdir(filepath.Join(outputDir, identifier(cfg)), 0700)
fileName := filepath.Join(
outputDir, identifier(cfg), configName(cfg),
)
log.Printf("saveCfg of %s", fileName)
f, err := os.Create(fileName)
if err != nil {
return err
}
defer f.Close()
// Serialize the descriptor.
enc := toml.NewEncoder(f)
return enc.Encode(cfg)
}
// links beteween voting authorities
func (s *katzenpost) apk(a *vConfig.Config) *eddsa.PublicKey {
priv := filepath.Join(s.outputDir, a.Authority.Identifier, "identity.private.pem")
public := filepath.Join(s.outputDir, a.Authority.Identifier, "identity.public.pem")
idKey, err := eddsa.Load(priv, public, rand.Reader)
if err != nil {
panic(err)
}
return idKey.PublicKey()
}
// links between mix and providers
func (s *katzenpost) spk(a *sConfig.Config) *eddsa.PublicKey {
priv := filepath.Join(s.outputDir, a.Server.Identifier, "identity.private.pem")
public := filepath.Join(s.outputDir, a.Server.Identifier, "identity.public.pem")
idKey, err := eddsa.Load(priv, public, rand.Reader)
if err != nil {
panic(err)
}
return idKey.PublicKey()
}
func (s *katzenpost) alk(a *vConfig.Config) *ecdh.PublicKey {
linkpriv := filepath.Join(s.outputDir, a.Authority.Identifier, "link.private.pem")
linkpublic := filepath.Join(s.outputDir, a.Authority.Identifier, "link.public.pem")
linkKey, err := ecdh.Load(linkpriv, linkpublic, rand.Reader)
if err != nil {
panic(err)
}
return linkKey.PublicKey()
}