-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
187 lines (167 loc) · 5.47 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
// main.go - Katzenpost ping tool
// Copyright (C) 2018, 2019 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 (
"context"
"flag"
"fmt"
mrand "math/rand"
"net/url"
"strings"
"time"
"github.com/katzenpost/client"
"github.com/katzenpost/client/config"
clientConfig "github.com/katzenpost/client/config"
"github.com/katzenpost/core/crypto/ecdh"
"github.com/katzenpost/core/crypto/rand"
"github.com/katzenpost/core/epochtime"
"github.com/katzenpost/core/log"
"github.com/katzenpost/core/pki"
registration "github.com/katzenpost/registration_client"
)
const (
initialPKIConsensusTimeout = 45 * time.Second
)
func randUser() string {
user := [32]byte{}
_, err := rand.Reader.Read(user[:])
if err != nil {
panic(err)
}
return fmt.Sprintf("%x", user[:])
}
func register(cfg *config.Config) (*config.Config, *ecdh.PrivateKey) {
// Retrieve a copy of the PKI consensus document.
backendLog, err := log.New(cfg.Logging.File, "DEBUG", false)
if err != nil {
panic(err)
}
proxyCfg := cfg.UpstreamProxyConfig()
pkiClient, err := cfg.NewPKIClient(backendLog, proxyCfg)
if err != nil {
panic(err)
}
currentEpoch, _, _ := epochtime.FromUnix(time.Now().Unix())
ctx, cancel := context.WithTimeout(context.Background(), initialPKIConsensusTimeout)
defer cancel()
doc, _, err := pkiClient.Get(ctx, currentEpoch)
if err != nil {
panic(err)
}
// Pick a registration Provider.
registerProviders := []*pki.MixDescriptor{}
for _, provider := range doc.Providers {
if provider.RegistrationHTTPAddresses != nil {
registerProviders = append(registerProviders, provider)
}
}
if len(registerProviders) == 0 {
panic("zero registration Providers found in the consensus")
}
mrand.Seed(time.Now().UTC().UnixNano())
registrationProvider := registerProviders[mrand.Intn(len(registerProviders))]
linkKey, err := ecdh.NewKeypair(rand.Reader)
if err != nil {
panic(err)
}
account := &clientConfig.Account{
User: fmt.Sprintf("%x", linkKey.PublicKey().Bytes()),
Provider: registrationProvider.Name,
ProviderKeyPin: registrationProvider.IdentityKey,
}
u, err := url.Parse(registrationProvider.RegistrationHTTPAddresses[0])
if err != nil {
panic(err)
}
registration := &clientConfig.Registration{
Address: u.Host,
Options: ®istration.Options{
Scheme: u.Scheme,
UseSocks: strings.HasPrefix(cfg.UpstreamProxy.Type, "socks"),
SocksNetwork: cfg.UpstreamProxy.Network,
SocksAddress: cfg.UpstreamProxy.Address,
},
}
cfg.Account = account
cfg.Registration = registration
err = client.RegisterClient(cfg, linkKey.PublicKey())
if err != nil {
panic(err)
}
return cfg, linkKey
}
func main() {
var configFile string
var service string
var count int
flag.StringVar(&configFile, "c", "", "configuration file")
flag.StringVar(&service, "s", "", "service name")
flag.IntVar(&count, "n", 5, "count")
flag.Parse()
if service == "" {
panic("must specify service name with -s")
}
cfg, err := config.LoadFile(configFile)
if err != nil {
panic(err)
}
cfg, linkKey := register(cfg)
// create a client and connect to the mixnet Provider
c, err := client.New(cfg)
if err != nil {
panic(err)
}
s, err := c.NewSession(linkKey)
if err != nil {
panic(err)
}
serviceDesc, err := s.GetService(service)
if err != nil {
panic(err)
}
fmt.Printf("Sending %d Sphinx packet payloads to: %s@%s\n", count, serviceDesc.Name, serviceDesc.Provider)
passed := 0
failed := 0
for i := 0; i < count; i++ {
_, err := s.BlockingSendUnreliableMessage(serviceDesc.Name, serviceDesc.Provider, []byte(`Data encryption is used widely to protect the content of Internet
communications and enables the myriad of activities that are popular today,
from online banking to chatting with loved ones. However, encryption is not
sufficient to protect the meta-data associated with the communications.
Modern encrypted communication networks are vulnerable to traffic analysis and
can leak such meta-data as the social graph of users, their geographical
location, the timing of messages and their order, message size, and many other
kinds of meta-data.
Since 1979, there has been active academic research into communication
meta-data protection, also called anonymous communication networking, that has
produced various designs. Of these, mix networks are among the most practical
and can readily scale to millions of users.
The Mix Network workshop will focus on bringing together experts from
the research and practitioner communities to give technical lectures on key
Mix networking topics in relation to attacks, defences, and practical
applications and usage considerations.`))
if err != nil {
failed++
fmt.Printf(".")
continue
}
passed++
fmt.Printf("!")
}
fmt.Printf("\n")
percent := (float64(passed) * float64(100)) / float64(count)
fmt.Printf("Success rate is %f percent %d/%d)\n", percent, passed, count)
c.Shutdown()
}