/
clientconf.go
693 lines (596 loc) · 20.1 KB
/
clientconf.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
package main
import (
"bufio"
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"log"
"net"
"os"
"reflect"
"regexp"
"strings"
toml "github.com/pelletier/go-toml"
pb "github.com/refraction-networking/conjure/proto"
"google.golang.org/protobuf/proto"
)
func printClientConf(clientConf *pb.ClientConf) {
fmt.Printf("Generation: %d\n", clientConf.GetGeneration())
if clientConf.GetDefaultPubkey() != nil {
fmt.Printf("Default Pubkey: %s\n", hex.EncodeToString(clientConf.GetDefaultPubkey().Key[:]))
}
if clientConf.GetConjurePubkey() != nil {
fmt.Printf("Conjure Pubkey: %s\n", hex.EncodeToString(clientConf.GetConjurePubkey().Key[:]))
}
if clientConf.DecoyList != nil {
decoys := clientConf.DecoyList.TlsDecoys
fmt.Printf("Decoy List: %d decoys\n", len(decoys))
for i, decoy := range decoys {
ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, decoy.GetIpv4Addr())
ip6 := net.IP(decoy.GetIpv6Addr())
fmt.Printf("%d:\n %s (%s / [%s])\n", i, decoy.GetHostname(), ip.To4().String(), ip6.To16().String())
if decoy.GetPubkey() != nil {
fmt.Printf(" pubkey: %s\n", hex.EncodeToString(decoy.GetPubkey().Key[:]))
}
if decoy.GetTimeout() != 0 {
fmt.Printf(" timeout: %d ms\n", decoy.GetTimeout())
}
if decoy.GetTcpwin() != 0 {
fmt.Printf(" tcpwin: %d bytes\n", decoy.GetTcpwin())
}
}
}
phantoms := clientConf.GetPhantomSubnetsList()
if phantoms != nil {
fmt.Printf("\nPhantom Subnets List:\n")
var index uint = 0
for _, block := range phantoms.GetWeightedSubnets() {
fmt.Printf("\nweight: %d, support random port: %v, subnets:\n", block.GetWeight(), block.GetRandomizeDstPort())
for _, subnet := range block.GetSubnets() {
fmt.Printf(" %d: %s\n", index, subnet)
index++
}
}
}
if clientConf.DnsRegConf != nil {
fmt.Printf("DNS registrar:\n")
fmt.Printf(" method: %+v\n", clientConf.DnsRegConf.GetDnsRegMethod());
fmt.Printf(" target: %+v\n", clientConf.DnsRegConf.GetTarget());
fmt.Printf(" domain: %+v\n", clientConf.DnsRegConf.GetDomain());
fmt.Printf(" pubkey: %+v\n", hex.EncodeToString(clientConf.DnsRegConf.GetPubkey()));
fmt.Printf(" utls: %+v\n", clientConf.DnsRegConf.GetUtlsDistribution());
fmt.Printf(" stun: %+v\n", clientConf.DnsRegConf.GetStunServer());
}
}
// Single line, not nice for printing, but good for diffs
func decoyToStr(decoy *pb.TLSDecoySpec) string {
ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, decoy.GetIpv4Addr())
ip6 := net.IP(decoy.GetIpv6Addr())
pk_s := ""
if decoy.GetPubkey() != nil {
pk_s = hex.EncodeToString(decoy.GetPubkey().Key[:])
}
return fmt.Sprintf("%s (%s / [%s]) pk: %s to: %d win: %d",
decoy.GetHostname(), ip.To4().String(), ip6.To16().String(),
pk_s, decoy.GetTimeout(), decoy.GetTcpwin())
}
func keyToStr(key *pb.PubKey) string {
if key == nil {
return ""
}
return hex.EncodeToString(key.Key[:])
}
func phantomsToMap(list *pb.PhantomSubnetsList) (map[string]uint, []string) {
var index uint = 0
out_map := make(map[string]uint)
var out_list []string
if list == nil {
return out_map, out_list
}
for _, block := range list.GetWeightedSubnets() {
for _, subnet := range block.GetSubnets() {
subnet_str := fmt.Sprintf("weight: %d, %s", block.GetWeight(), subnet)
out_map[subnet_str] = index
out_list = append(out_list, subnet_str)
index++
}
}
return out_map, out_list
}
func printPairs(clientConf *pb.ClientConf) {
ip := ""
for _, decoy := range clientConf.DecoyList.TlsDecoys {
decoy_ip4 := make(net.IP, 4)
binary.BigEndian.PutUint32(decoy_ip4, decoy.GetIpv4Addr())
decoy_ip6 := net.IP(decoy.GetIpv6Addr())
if decoy_ip4.To4().String() != "0.0.0.0" {
ip = decoy_ip4.To4().String()
} else {
ip = decoy_ip6.To16().String()
}
fmt.Printf("%s,%s\n", ip, decoy.GetHostname())
}
}
func printDiff(old *pb.ClientConf, new_fn string) {
new := parseClientConf(new_fn)
if old.GetGeneration() != new.GetGeneration() {
fmt.Printf("- Generation: %d\n", old.GetGeneration())
fmt.Printf("+ Generation: %d\n", new.GetGeneration())
}
old_key := keyToStr(old.GetDefaultPubkey())
new_key := keyToStr(new.GetDefaultPubkey())
if old_key != new_key {
if old_key != "" {
fmt.Printf("- Default Pubkey: %s\n", old_key)
}
if new_key != "" {
fmt.Printf("+ Default Pubkey: %s\n", new_key)
}
}
old_cj_key := keyToStr(old.GetConjurePubkey())
new_cj_key := keyToStr(new.GetConjurePubkey())
if old_cj_key != new_cj_key {
if old_cj_key != "" {
fmt.Printf("- Conjure Pubkey: %s\n", old_cj_key)
}
if new_cj_key != "" {
fmt.Printf("+ Conjure Pubkey: %s\n", new_cj_key)
}
}
if old.DecoyList == nil {
return
}
odecoys := old.DecoyList.TlsDecoys
ndecoys := new.DecoyList.TlsDecoys
fmt.Printf("Decoy List: %d -> %d decoys\n", len(odecoys), len(ndecoys))
n := len(odecoys)
if len(ndecoys) > n {
n = len(ndecoys)
}
// Map of decoy => index in respective array
old_decoys := make(map[string]int)
new_decoys := make(map[string]int)
all_decoys := make(map[string]int) // List of all decoys (union of both)
for i := 0; i < n; i++ {
if i < len(odecoys) {
od := odecoys[i] // Old Decoy
old_decoys[decoyToStr(od)] = i
all_decoys[decoyToStr(od)] = 1
}
if i < len(ndecoys) {
nd := ndecoys[i] // New Decoy
new_decoys[decoyToStr(nd)] = i
all_decoys[decoyToStr(nd)] = 1
}
}
// Since we don't really care about order, we don't need a fancy diff like Meyers
// Just find the ones that are in old and not in new first
removed_idxs := make(map[int]int) // indexes in odecoys
added_idxs := make(map[int]int) // indexes in ndecoys
for k := range all_decoys {
old_idx, in_old := old_decoys[k]
new_idx, in_new := new_decoys[k]
if in_old && in_new {
// In both
} else if in_old {
removed_idxs[old_idx] = -1
} else if in_new {
added_idxs[new_idx] = -1
}
}
for i := 0; i < len(all_decoys); i++ {
_, del := removed_idxs[i]
_, add := added_idxs[i]
if del {
fmt.Printf("- %d: %s\n", i, decoyToStr(odecoys[i]))
}
if add {
fmt.Printf("+ %d: %s\n", i, decoyToStr(ndecoys[i]))
}
}
old_phantom_map, old_phantoms := phantomsToMap(old.GetPhantomSubnetsList())
new_phantom_map, new_phantoms := phantomsToMap(new.GetPhantomSubnetsList())
for i, phantom := range old_phantoms {
_, in_new := new_phantom_map[phantom]
if !in_new {
fmt.Printf("- %d: %s\n", i, phantom)
}
}
for i, phantom := range new_phantoms {
_, in_old := old_phantom_map[phantom]
if !in_old {
fmt.Printf("+ %d: %s\n", i, phantom)
}
}
}
func parseClientConf(fname string) *pb.ClientConf {
clientConf := &pb.ClientConf{}
buf, err := os.ReadFile(fname)
if err != nil {
log.Fatal("Error reading file:", err)
}
err = proto.Unmarshal(buf, clientConf)
if err != nil {
log.Fatal("Error parsing ClientConf", err)
}
return clientConf
}
func parsePubkey(pubkey string) []byte {
pubkey_bin, err := hex.DecodeString(pubkey)
if err != nil {
log.Fatal("Error parsing pubkey:", err)
}
if len(pubkey_bin) != 32 {
log.Fatal("Error: pubkey length: expected 32, got ", len(pubkey_bin))
}
return pubkey_bin
}
func updateDecoy(decoy *pb.TLSDecoySpec, host string, ip string, pubkey string, delpubkey bool, timeout int, tcpwin int) {
if host != "" {
decoy.Hostname = &host
}
if ip != "" {
ip4 := net.ParseIP(ip).To4()
if ip4 != nil {
uintIp4 := binary.BigEndian.Uint32(ip4)
decoy.Ipv4Addr = &uintIp4
} else {
ip6 := net.ParseIP(ip).To16()
fmt.Printf("%v", ip6.String())
decoy.Ipv6Addr = []byte(ip6)
}
}
if pubkey != "" {
decoy.Pubkey.Key = parsePubkey(pubkey)
}
if delpubkey {
decoy.Pubkey = nil
}
if timeout != 0 {
t := uint32(timeout)
decoy.Timeout = &t
}
if tcpwin != 0 {
t := uint32(tcpwin)
decoy.Tcpwin = &t
}
}
func addSubnets(subnets []string, weight *uint, randomizeDstPort *bool, clientConf *pb.ClientConf) {
if *weight == 0 {
log.Fatal("Error: -add-subnet requires the weight flag to be set to a non-zero 32-bit unsinged integer")
}
for _, s := range subnets {
_, _, err := net.ParseCIDR(s)
if err != nil {
log.Fatal("Error: " + s + " is not a valid CIDR block")
}
}
var weight32 = uint32(*weight)
// add new item to PhantomSubnetsList.WeightedSubnets
var newPhantomSubnet = pb.PhantomSubnets{
Weight: &weight32,
Subnets: subnets,
RandomizeDstPort: randomizeDstPort,
}
clientConf.PhantomSubnetsList.WeightedSubnets = append(clientConf.PhantomSubnetsList.WeightedSubnets, &newPhantomSubnet)
}
func deleteSubnet(index int, clientConf *pb.ClientConf) {
if index < 0 {
log.Fatal("Error: -delete-subnet requires a positive index")
}
var blockRange int = 0
var weightedSubnets = &clientConf.PhantomSubnetsList.WeightedSubnets
for blockIndex, block := range *weightedSubnets {
blockRange += len(block.Subnets)
if blockRange > index {
fmt.Printf("index: %d, block_range: %d, len_block: %d\n", index, blockRange, len(block.Subnets))
var indexInBlock = index - (blockRange - len(block.Subnets))
block.Subnets[indexInBlock] = block.Subnets[len(block.Subnets)-1]
block.Subnets = block.Subnets[:len(block.Subnets)-1]
if len(block.Subnets) == 0 { // delete group if no longer contains subnets
(*weightedSubnets)[blockIndex] = (*weightedSubnets)[len(*weightedSubnets)-1]
(*weightedSubnets)[len(*weightedSubnets)-1] = nil
*weightedSubnets = (*weightedSubnets)[:len(*weightedSubnets)-1]
}
return
}
}
log.Fatal("Error: Index " + fmt.Sprint(index) + " provided to -delete-subnet is out of range")
}
func deleteStringSubnet(subnetStr string, clientConf *pb.ClientConf) error {
_, subnet, err := net.ParseCIDR(subnetStr)
if err != nil {
return err
}
remainingDecoys := []*pb.TLSDecoySpec{}
for _, decoy := range clientConf.DecoyList.TlsDecoys {
ip4 := make(net.IP, 4)
binary.BigEndian.PutUint32(ip4, decoy.GetIpv4Addr())
ip6 := net.IP(decoy.GetIpv6Addr())
if !(subnet.Contains(ip4) || subnet.Contains(ip6)) {
remainingDecoys = append(remainingDecoys, decoy)
}
}
clientConf.DecoyList.TlsDecoys = remainingDecoys
return nil
}
func deleteStringPattern(pattern string, clientConf *pb.ClientConf) error {
remainingDecoys := []*pb.TLSDecoySpec{}
r, err := regexp.Compile(pattern)
if err != nil {
return err
}
for _, decoy := range clientConf.DecoyList.TlsDecoys {
if !r.MatchString(*decoy.Hostname) {
remainingDecoys = append(remainingDecoys, decoy)
}
}
clientConf.DecoyList.TlsDecoys = remainingDecoys
return nil
}
func decoysToDeleteFromFile(filename string, clientConf *pb.ClientConf) error {
f_read, err := os.Open(filename)
if err != nil {
return err
}
defer f_read.Close()
var lines []string
scanner := bufio.NewScanner(f_read)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
remainingDecoys := clientConf.DecoyList.TlsDecoys
for idx, decoy := range clientConf.DecoyList.TlsDecoys {
decoy_ip4 := make(net.IP, 4)
binary.BigEndian.PutUint32(decoy_ip4, decoy.GetIpv4Addr())
decoy_ip6 := net.IP(decoy.GetIpv6Addr())
for _, line := range lines {
pair := strings.Split(line, ",")
ip := pair[0]
sni := pair[1]
if strings.Contains(ip, ":") {
if ip == decoy_ip6.To16().String() && sni == decoy.GetHostname() {
remainingDecoys = append(remainingDecoys[:idx], remainingDecoys[idx+1:]...)
}
} else {
if ip == decoy_ip4.To16().String() && sni == decoy.GetHostname() {
remainingDecoys = append(remainingDecoys[:idx], remainingDecoys[idx+1:]...)
}
}
}
clientConf.DecoyList.TlsDecoys = remainingDecoys
}
return nil
}
func dnsRegMethodFromStr(method string) (pb.DnsRegMethod, error) {
switch strings.ToLower(method) {
case "udp":
return pb.DnsRegMethod_UDP, nil
case "dot":
return pb.DnsRegMethod_DOT, nil
case "doh":
return pb.DnsRegMethod_DOH, nil
case "":
return 0, nil
}
return 0, fmt.Errorf("unknown reg method: %v", method)
}
// updateDNSReg updates fields in cc.DnsRegConf with non-zero fields in new
func updateDNSReg(cc *pb.ClientConf, new *pb.DnsRegConf) {
if cc.DnsRegConf == nil {
cc.DnsRegConf = &pb.DnsRegConf{}
}
oldVal := reflect.ValueOf(cc.DnsRegConf).Elem()
newVal := reflect.ValueOf(new).Elem()
for i := 0; i < oldVal.NumField(); i++ {
if newVal.Field(i).IsZero() {
continue
}
// if field is pointer, also check if the value that it points to is a zero value
if newVal.Field(i).Kind() == reflect.Pointer && newVal.Field(i).Elem().IsZero() {
continue
}
oldVal.Field(i).Set(newVal.Field(i))
}
}
func main() {
var fname = flag.String("f", "", "`ClientConf` file to parse")
var out_fname = flag.String("o", "", "`output` file name to write new/modified config")
var generation = flag.Int("generation", 0, "New/modified generation")
var next_gen = flag.Bool("next-gen", false, "Assign the next generation number to the created ClientConf based on the provided one")
var pubkey = flag.String("pubkey", "", "New/modified (decoy) pubkey. If -add or -update, applies to specific decoy. If -all applies to all decoys. Otherwise, applies to default pubkey.")
var cjPubkey = flag.String("cjpubkey", "", "New/modified (decoy) conjure pubkey. If -add or -update, applies to specific decoy. If -all applies to all decoys. Otherwise, applies to default pubkey.")
var delpubkey = flag.Bool("delpubkey", false, "Delete pubkey from decoy with index specified in -update (or from all decoys if -all)")
var add = flag.Bool("add", false, "If set, modify fields of all decoys in list with provided pubkey/timeout/tcpwin/host/ip")
var delete = flag.Int("delete", -1, "Specifies `index` of decoy to delete")
var deleteStr = flag.String("delete-str", "", "Specifies pattern of decoy hostnames to delete")
var deleteDecoysBySubnet = flag.String("delete-decoys-subnet", "", "Specifies subnet of decoy addresses to delete")
var update = flag.Int("update", -1, "Specifies `index` of decoy to update")
var host = flag.String("host", "", "New/modified decoy host")
var ip = flag.String("ip", "", "New/modified IP address")
var timeout = flag.Int("timeout", 0, "New/modified timeout")
var tcpwin = flag.Int("tcpwin", 0, "New/modified tcpwin")
var dnsTarget = flag.String("dns-target", "", "DoH/DoT/UDP address of DNS server to be used in the DNS registrar")
var dnsMethodStr = flag.String("dns-method", "", "DNS registration method to use in the DNS registrar (one of DoH/DoT/UDP)")
var dnsDomain = flag.String("dns-domain", "", "Domain of target DNS registrar")
var dnsPubkeyStr = flag.String("dns-pubkey", "", "Pubkey of target DNS registrar")
var dnsUTLS = flag.String("dns-utls", "", "UTLS distribution to be used in DoT and DoH connections in the DNS registrar")
var dnsStunServer = flag.String("dns-stun", "", "STUN server to be used in the DNS registrar")
var add_subnets = flag.String("add-subnets", "", "Add a subnet or list of space-separated subnets between double quotes (\"127.0.0.1/24 2001::/32\" etc.), requires additional weight flag")
var delete_subnet = flag.Int("delete-subnet", -1, "Specifies the index of a subnet to delete")
var weight = flag.Uint("weight", 0, "Subnet weight when add-subnets is used")
var randomizeDstPort = flag.Bool("randomize-dst-port", true, "Specifies if the subnet supports randomized port")
var subnet_file = flag.String("subnet-file", "", "Path to TOML file containing lists of subnets to use in config. TOML should be formatted like: \n"+
"[[WeightedSubnets]] \n\tWeight = 9 \n\tSubnets = [\"192.122.190.0/24\", \"2001:48a8:687f:1::/64\"] \n"+
"[[WeightedSubnets]] \n\tWeight = 1 \n\tSubnets = [\"141.219.0.0/16\", \"35.8.0.0/16\"]",
)
var all = flag.Bool("all", false, "If set, replace all pubkeys/timeouts/tcpwins in decoy list with pubkey/timeout/tcpwin if provided")
var noout = flag.Bool("noout", false, "Don't print ClientConf")
var diff = flag.String("diff", "", "A second conf to diff against (-f old -diff new)")
var rm_decoys = flag.String("rm-decoys", "", "File of decoys to delete from ClientConf.\n"+
"Each line in the file has to be in the following format:\n"+
"ip,sni\n",
)
var print_pairs = flag.Bool("print-pairs", false, "Print pairs of decoys ip,sni")
flag.Parse()
clientConf := &pb.ClientConf{}
// Parse ClientConf
if *fname != "" {
clientConf = parseClientConf(*fname)
}
// Use subnet-file
if *subnet_file != "" {
data, err := os.ReadFile(*subnet_file)
if err != nil {
log.Fatalf("error opening configuration file: %v", err)
}
subnets := pb.PhantomSubnetsList{}
err = toml.Unmarshal(data, &subnets)
if err != nil {
log.Fatalf("error unmarshalling data into PhantomSubnetList structure %v", err)
}
clientConf.PhantomSubnetsList = &subnets
}
// Delete a subnet
if *delete_subnet != -1 {
deleteSubnet(*delete_subnet, clientConf)
}
// Deletes decoys based on pattern for decoy hostname
if *deleteStr != "" {
err := deleteStringPattern(*deleteStr, clientConf)
if err != nil {
log.Fatalf("failed string pattern decoy delete: %v", err)
}
}
// Delete decoys based on subnet of decoy address
if *deleteDecoysBySubnet != "" {
err := deleteStringSubnet(*deleteDecoysBySubnet, clientConf)
if err != nil {
log.Fatalf("failed subnet based decoy delete: %v", err)
}
}
// Delete decoys based on a given file path containing line(s) of "ip,sni" decoys
if *rm_decoys != "" {
err := decoysToDeleteFromFile(*rm_decoys, clientConf)
if err != nil {
log.Fatalf("failed file based decoy delete %v", err)
}
}
// Add a subnet
if *add_subnets != "" {
subnets := strings.Split(*add_subnets, " ")
addSubnets(subnets, weight, randomizeDstPort, clientConf)
}
// Update generation
if *generation != 0 {
gen := uint32(*generation)
clientConf.Generation = &gen
} else if *next_gen {
gen := clientConf.GetGeneration()
gen++
clientConf.Generation = &gen
}
// Update pubkey
if *pubkey != "" {
if *add || *update != -1 {
// Skip. -add or -delete will use pubkey
} else {
// Update default public key
if clientConf.DefaultPubkey == nil {
k := pb.PubKey{}
key_type := pb.KeyType_AES_GCM_128
k.Type = &key_type
clientConf.DefaultPubkey = &k
}
clientConf.DefaultPubkey.Key = parsePubkey(*pubkey)
}
}
// Update Conjure Pubkey.
if *cjPubkey != "" {
if *add || *update != -1 {
// Skip. -add or -delete will use pubkey
} else {
// Update default public key
if clientConf.ConjurePubkey == nil {
k := pb.PubKey{}
key_type := pb.KeyType_AES_GCM_128
k.Type = &key_type
clientConf.ConjurePubkey = &k
}
clientConf.ConjurePubkey.Key = parsePubkey(*cjPubkey)
}
}
// Update all decoys
if *all {
for _, decoy := range clientConf.DecoyList.TlsDecoys {
updateDecoy(decoy, *host, *ip, *pubkey, *delpubkey, *timeout, *tcpwin)
}
}
// Update a single decoy from the list
if *update != -1 {
decoy := clientConf.DecoyList.TlsDecoys[*update]
updateDecoy(decoy, *host, *ip, *pubkey, *delpubkey, *timeout, *tcpwin)
}
// Delete a decoy
if *delete != -1 {
idx := *delete
decoys := clientConf.DecoyList.TlsDecoys
clientConf.DecoyList.TlsDecoys = append(decoys[:idx], decoys[idx+1:]...)
}
// Add a decoy
if *add {
if *host == "" || *ip == "" {
log.Fatal("Error: -add requires -host and -ip")
}
if *update != -1 {
log.Fatal("Error: -add cannot be used with -update")
}
decoy := pb.TLSDecoySpec{}
updateDecoy(&decoy, *host, *ip, *pubkey, *delpubkey, *timeout, *tcpwin)
if clientConf.DecoyList == nil {
tls_spec := pb.DecoyList{}
clientConf.DecoyList = &tls_spec
}
clientConf.DecoyList.TlsDecoys = append(clientConf.DecoyList.TlsDecoys, &decoy)
}
dnsRegMethod, err := dnsRegMethodFromStr(*dnsMethodStr)
if err != nil {
log.Fatalf("Error parsing DNS registration method: %v", err)
}
var dnsPubkey []byte
if *dnsPubkeyStr != "" {
dnsPubkey = parsePubkey(*dnsPubkeyStr)
}
updateDNSReg(clientConf, &pb.DnsRegConf{
DnsRegMethod: &dnsRegMethod,
Target: dnsTarget,
Domain: dnsDomain,
Pubkey: dnsPubkey,
UtlsDistribution: dnsUTLS,
StunServer: dnsStunServer,
})
if !*noout {
if *diff != "" {
printDiff(clientConf, *diff)
} else {
printClientConf(clientConf)
}
}
// Print pairs of decoy addresses (ip,sni)
if *print_pairs {
printPairs(clientConf)
}
if *out_fname != "" {
buf, err := proto.Marshal(clientConf)
if err != nil {
log.Fatal("Error writing output:", err)
}
err = os.WriteFile(*out_fname, buf[:], 0644)
if err != nil {
log.Fatal("Error writing output:", err)
}
}
}