Skip to content

Commit 20b0d62

Browse files
committed
merged collectiveSigning.go
2 parents 68e2dd6 + 73830bb commit 20b0d62

File tree

9 files changed

+137
-83
lines changed

9 files changed

+137
-83
lines changed

app/conode/server.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,11 @@ func (s *Server) Run(role string) {
339339
// AnnounceFunc will keep the timestamp generated for this round
340340
func (s *Server) AnnounceFunc() sign.AnnounceFunc {
341341
return func(am *sign.AnnouncementMessage) {
342-
t := time.Time{}
343-
if err := t.UnmarshalBinary(am.Message); err != nil {
342+
var t int64
343+
if err := binary.Read(bytes.NewBuffer(am.Message), binary.LittleEndian, &t); err != nil {
344344
dbg.Lvl1("Unmashaling timestamp has failed")
345345
}
346-
s.Timestamp = t.Unix()
346+
s.Timestamp = t
347347
}
348348
}
349349

@@ -408,15 +408,8 @@ func (s *Server) AggregateCommits(view int) []byte {
408408

409409
// pull out to be Merkle Tree leaves
410410
s.Leaves = make([]hashid.HashId, 0)
411-
buf := new(bytes.Buffer)
412-
if err := binary.Write(buf, binary.LittleEndian, s.Timestamp); err != nil {
413-
dbg.Lvl2("Timestamp have not been marshalled ! ", err)
414-
}
415-
bbuf := buf.Bytes()
416411
for _, msg := range Queue[PROCESSING] {
417-
// append timestamp on the msg
418-
leaf := append(msg.Tsm.Sreq.Val, bbuf...)
419-
s.Leaves = append(s.Leaves, hashid.HashId(leaf))
412+
s.Leaves = append(s.Leaves, hashid.HashId(msg.Tsm.Sreq.Val))
420413
}
421414
s.mux.Unlock()
422415

app/conode/stamp/stamp.go

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ type SignatureFile struct {
6969
Challenge string
7070
// The signature response
7171
Response string
72+
// The aggregated commitment used for signing
73+
Commitment string
7274
}
7375

7476
// Our crypto-suite used in the program
@@ -259,34 +261,65 @@ func VerifySignature(file, sigFile string) bool {
259261
// Message is your own hash, and reply contains the inclusion proof + signature
260262
// on the aggregated message
261263
func verifySignature(message hashid.HashId, reply *defs.StampReply) bool {
264+
// First check if the challenge is ok
265+
if err := verifyChallenge(suite, reply); err != nil {
266+
dbg.Lvl1("Challenge-check : FAILED (", err, ")")
267+
return false
268+
}
269+
dbg.Lvl1("Challenge-check : OK")
270+
// Then check if the signature is ok
262271
sig := defs.BasicSignature{
263272
Chall: reply.SigBroad.C,
264273
Resp: reply.SigBroad.R0_hat,
265274
}
266275
public, _ := cliutils.ReadPub64(suite, strings.NewReader(conf.AggPubKey))
267-
if err := SchnorrVerify(suite, reply.MerkleRoot, public, sig); err != nil {
276+
// Incorporate the timestamp in the message since the verification process
277+
// is done by reconstructing the challenge
278+
var b bytes.Buffer
279+
if err := binary.Write(&b, binary.LittleEndian, reply.Timestamp); err != nil {
280+
dbg.Lvl1("Error marshaling the timestamp for signature verification")
281+
}
282+
msg := append(b.Bytes(), []byte(reply.MerkleRoot)...)
283+
if err := SchnorrVerify(suite, msg, public, sig); err != nil {
268284
dbg.Lvl1("Signature-check : FAILED (", err, ")")
269285
return false
270286
}
271287
dbg.Lvl1("Signature-check : OK")
272288

273-
// Verify inclusion proof
274-
// First, concat the timestamp to the message
275-
buf := []byte(message)
276-
bt := new(bytes.Buffer)
277-
if err := binary.Write(bt, binary.LittleEndian, reply.Timestamp); err != nil {
278-
dbg.Fatal("Timestamp have not been appended to the message. Abort")
279-
}
280-
messageConcat := append(buf, bt.Bytes()...)
281-
// Then check the proof
282-
if !proof.CheckProof(suite.Hash, reply.MerkleRoot, hashid.HashId(messageConcat), reply.Prf) {
289+
// finally check the proof
290+
if !proof.CheckProof(suite.Hash, reply.MerkleRoot, hashid.HashId(message), reply.Prf) {
283291
dbg.Lvl1("Inclusion-check : FAILED")
284292
return false
285293
}
286294
dbg.Lvl1("Inclusion-check : OK")
287295
return true
288296
}
289297

298+
// verifyChallenge will recontstruct the challenge in order to see if any of the
299+
// components of the challenge has been spoofed or not. It may be a different
300+
// timestamp .
301+
func verifyChallenge(suite abstract.Suite, reply *defs.StampReply) error {
302+
303+
// marshal the V
304+
pbuf, err := reply.SigBroad.V0_hat.MarshalBinary()
305+
if err != nil {
306+
return err
307+
}
308+
c := suite.Cipher(pbuf)
309+
// concat timestamp and merkle root
310+
var b bytes.Buffer
311+
if err := binary.Write(&b, binary.LittleEndian, reply.Timestamp); err != nil {
312+
return err
313+
}
314+
cbuf := append(b.Bytes(), reply.MerkleRoot...)
315+
c.Message(nil, nil, cbuf)
316+
challenge := suite.Secret().Pick(c)
317+
if challenge.Equal(reply.SigBroad.C) {
318+
return nil
319+
}
320+
return errors.New("Challenge reconstructed is not equal to the one given ><")
321+
}
322+
290323
// A simple verification of a schnorr signature given the message
291324
//TAKEN FROM SIG_TEST from abstract
292325
func SchnorrVerify(suite abstract.Suite, message []byte, publicKey abstract.Point, sig defs.BasicSignature) error {
@@ -322,24 +355,29 @@ func WriteSignatureFile(nameSig, file string, hash []byte, stamp *defs.StampRepl
322355
for _, pr := range stamp.Prf {
323356
p = append(p, base64.StdEncoding.EncodeToString(pr))
324357
}
325-
// Write challenge and response part
358+
// Write challenge and response + commitment part
326359
var bufChall bytes.Buffer
327360
var bufResp bytes.Buffer
361+
var bufCommit bytes.Buffer
328362
if err := cliutils.WriteSecret64(suite, &bufChall, stamp.SigBroad.C); err != nil {
329363
dbg.Fatal("Could not write secret challenge :", err)
330364
}
331365
if err := cliutils.WriteSecret64(suite, &bufResp, stamp.SigBroad.R0_hat); err != nil {
332366
dbg.Fatal("Could not write secret response : ", err)
333367
}
368+
if err := cliutils.WritePub64(suite, &bufCommit, stamp.SigBroad.V0_hat); err != nil {
369+
dbg.Fatal("Could not write aggregated commitment : ", err)
370+
}
334371
// Signature file struct containing everything needed
335372
sigStr := &SignatureFile{
336-
Name: file,
337-
Timestamp: stamp.Timestamp,
338-
Hash: base64.StdEncoding.EncodeToString(hash),
339-
Proof: p,
340-
Root: base64.StdEncoding.EncodeToString(stamp.MerkleRoot),
341-
Challenge: bufChall.String(),
342-
Response: bufResp.String(),
373+
Name: file,
374+
Timestamp: stamp.Timestamp,
375+
Hash: base64.StdEncoding.EncodeToString(hash),
376+
Proof: p,
377+
Root: base64.StdEncoding.EncodeToString(stamp.MerkleRoot),
378+
Challenge: bufChall.String(),
379+
Response: bufResp.String(),
380+
Commitment: bufCommit.String(),
343381
}
344382

345383
// Print to the screen, and write to file
@@ -382,7 +420,11 @@ func ReadSignatureFile(name string) ([]byte, *defs.StampReply, error) {
382420
if err != nil {
383421
dbg.Fatal("Could not read secret challenge : ", err)
384422
}
385-
reply.SigBroad.C, err = cliutils.ReadSecret64(suite, strings.NewReader(sigStr.Challenge))
423+
if reply.SigBroad.C, err = cliutils.ReadSecret64(suite, strings.NewReader(sigStr.Challenge)); err != nil {
424+
dbg.Fatal("Could not read the aggregate commitment :", err)
425+
}
426+
reply.SigBroad.V0_hat, err = cliutils.ReadPub64(suite, strings.NewReader(sigStr.Commitment))
427+
386428
return hash, reply, err
387429

388430
}

deploy/platform/deterlab.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,48 +39,48 @@ import (
3939

4040
type Deterlab struct {
4141
// The login on the platform
42-
Login string
42+
Login string
4343
// The outside host on the platform
44-
Host string
44+
Host string
4545
// The name of the project
46-
Project string
46+
Project string
4747
// Name of the Experiment - also name of hosts
48-
Experiment string
48+
Experiment string
4949
// Directory of applications
50-
AppDir string
50+
AppDir string
5151
// Directory where everything is copied into
52-
DeployDir string
52+
DeployDir string
5353
// Directory for building
54-
BuildDir string
54+
BuildDir string
5555
// Working directory of deterlab
56-
DeterDir string
56+
DeterDir string
5757
// Where the main logging machine resides
5858
MasterLogger string
5959
// DNS-resolvable names
60-
Phys []string
60+
Phys []string
6161
// VLAN-IP names
62-
Virt []string
62+
Virt []string
6363

6464
// Which app to run
65-
App string
65+
App string
6666
// Number of machines
67-
Machines int
67+
Machines int
6868
// Number of loggers
69-
Loggers int
69+
Loggers int
7070
// Number of Rounds
71-
Rounds int
71+
Rounds int
7272
// Channel to communication stopping of experiment
73-
sshDeter chan string
73+
sshDeter chan string
7474
// Whether the simulation is started
75-
started bool
75+
started bool
7676
// Debugging-level: 0 is none - 5 is everything
77-
Debug int
77+
Debug int
7878

7979
// All hostnames used concatenated with the port
80-
Hostnames []string
80+
Hostnames []string
8181

8282
// Testing the connection?
83-
TestConnect bool
83+
TestConnect bool
8484
}
8585

8686
func (d *Deterlab) Configure() {
@@ -145,7 +145,7 @@ func (d *Deterlab) Build(build string) error {
145145
// go won't compile on an absolute path so we need to
146146
// convert it to a relative one
147147
src_rel, _ := filepath.Rel(d.DeterDir, src)
148-
out, err := cliutils.Build("./" + src_rel, dest, "386", "freebsd")
148+
out, err := cliutils.Build("./"+src_rel, dest, "386", "freebsd")
149149
if err != nil {
150150
cliutils.KillGo()
151151
dbg.Lvl1(out)
@@ -159,7 +159,7 @@ func (d *Deterlab) Build(build string) error {
159159
// deter has an amd64, linux architecture
160160
src_rel, _ := filepath.Rel(d.DeterDir, src)
161161
dbg.Lvl3("Relative-path is", src, src_rel, d.DeterDir)
162-
out, err := cliutils.Build("./" + src_rel, dest, "amd64", "linux")
162+
out, err := cliutils.Build("./"+src_rel, dest, "amd64", "linux")
163163
if err != nil {
164164
cliutils.KillGo()
165165
dbg.Lvl1(out)
@@ -294,22 +294,22 @@ func (d *Deterlab) Deploy(rc RunConfig) error {
294294
*/
295295

296296
// copy the webfile-directory of the logserver to the remote directory
297-
err := exec.Command("cp", "-a", d.DeterDir + "/logserver/webfiles",
298-
d.DeterDir + "/cothority.conf", d.DeployDir).Run()
297+
err := exec.Command("cp", "-a", d.DeterDir+"/logserver/webfiles",
298+
d.DeterDir+"/cothority.conf", d.DeployDir).Run()
299299
if err != nil {
300300
dbg.Fatal("error copying webfiles:", err)
301301
}
302302
build, err := ioutil.ReadDir(d.BuildDir)
303303
for _, file := range build {
304-
err = exec.Command("cp", d.BuildDir + "/" + file.Name(), d.DeployDir).Run()
304+
err = exec.Command("cp", d.BuildDir+"/"+file.Name(), d.DeployDir).Run()
305305
if err != nil {
306306
dbg.Fatal("error copying build-file:", err)
307307
}
308308
}
309309

310310
dbg.Lvl1("Copying over to", d.Login, "@", d.Host)
311311
// Copy everything over to deterlabs
312-
err = cliutils.Rsync(d.Login, d.Host, d.DeployDir + "/", "remote/")
312+
err = cliutils.Rsync(d.Login, d.Host, d.DeployDir+"/", "remote/")
313313
if err != nil {
314314
dbg.Fatal(err)
315315
}
@@ -333,7 +333,7 @@ func (d *Deterlab) Start() error {
333333
"-t",
334334
fmt.Sprintf("%s@%s", d.Login, d.Host),
335335
"-L",
336-
"8081:" + d.MasterLogger + ":10000")
336+
"8081:"+d.MasterLogger+":10000")
337337
err = cmd.Start()
338338
if err != nil {
339339
dbg.Fatal("failed to setup portforwarding for logging server")
@@ -399,13 +399,13 @@ func (d *Deterlab) createHosts() error {
399399
d.Phys = make([]string, 0, num_servers)
400400
d.Virt = make([]string, 0, num_servers)
401401
for i := 1; i <= num_servers; i++ {
402-
d.Phys = append(d.Phys, fmt.Sprintf("server-%d.%s.%s", i - 1, d.Experiment, name))
402+
d.Phys = append(d.Phys, fmt.Sprintf("server-%d.%s.%s", i-1, d.Experiment, name))
403403
d.Virt = append(d.Virt, fmt.Sprintf("%s%d", ip, i))
404404
}
405405

406406
// only take the machines we need
407-
d.Phys = d.Phys[:nmachs + nloggers]
408-
d.Virt = d.Virt[:nmachs + nloggers]
407+
d.Phys = d.Phys[:nmachs+nloggers]
408+
d.Virt = d.Virt[:nmachs+nloggers]
409409
d.MasterLogger = d.Phys[0]
410410

411411
return nil
@@ -419,7 +419,7 @@ func (d *Deterlab) LoadAndCheckDeterlabVars() {
419419
deter := Deterlab{}
420420
err := app.ReadTomlConfig(&deter, "deter.toml", d.DeterDir)
421421
d.Host, d.Login, d.Project, d.Experiment, d.Loggers =
422-
deter.Host, deter.Login, deter.Project, deter.Experiment, deter.Loggers
422+
deter.Host, deter.Login, deter.Project, deter.Experiment, deter.Loggers
423423

424424
if err != nil {
425425
dbg.Lvl1("Couldn't read config-file - asking for default values")
@@ -430,15 +430,15 @@ func (d *Deterlab) LoadAndCheckDeterlabVars() {
430430
}
431431

432432
if d.Login == "" {
433-
d.Login = readString("Please enter the login-name on " + d.Host, "")
433+
d.Login = readString("Please enter the login-name on "+d.Host, "")
434434
}
435435

436436
if d.Project == "" {
437437
d.Project = readString("Please enter the project on deterlab", "SAFER")
438438
}
439439

440440
if d.Experiment == "" {
441-
d.Experiment = readString("Please enter the Experiment on " + d.Project, "Dissent-CS")
441+
d.Experiment = readString("Please enter the Experiment on "+d.Project, "Dissent-CS")
442442
}
443443

444444
if d.Loggers == 0 {

lib/coconet/networkMessg.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package coconet
22

33
import (
4+
dbg "github.com/dedis/cothority/lib/debug_lvl"
45
"github.com/dedis/protobuf"
56
)
67

@@ -15,5 +16,6 @@ func (nm *NetworkMessg) MarshalBinary() ([]byte, error) {
1516
}
1617

1718
func (nm *NetworkMessg) UnmarshalBinary(data []byte) error {
19+
dbg.Print("UnmarshalBinary : ", len(data), " bytes")
1820
return protobuf.Decode(data, nm)
1921
}

lib/coconet/tcpconn.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package coconet
33
import (
44
"encoding/json"
55
"errors"
6-
"math/rand"
76
"net"
87
"sync"
9-
"time"
108
//"runtime/debug"
119

1210
dbg "github.com/dedis/cothority/lib/debug_lvl"
@@ -158,9 +156,9 @@ func (tc *TCPConn) GetData(bum BinaryUnmarshaler) error {
158156
dec := tc.dec
159157
tc.encLock.Unlock()
160158

161-
if Latency != 0 {
162-
time.Sleep(time.Duration(rand.Intn(Latency)) * time.Millisecond)
163-
}
159+
//if Latency != 0 {
160+
// time.Sleep(time.Duration(rand.Intn(Latency)) * time.Millisecond)
161+
//}
164162
err := dec.Decode(bum)
165163
if err != nil {
166164
if IsTemporary(err) {
@@ -169,7 +167,7 @@ func (tc *TCPConn) GetData(bum BinaryUnmarshaler) error {
169167
}
170168
// if it is an irrecoverable error
171169
// close the channel and return that it has been closed
172-
if err != io.EOF && err.Error() != "read tcp4"{
170+
if err != io.EOF && err.Error() != "read tcp4" {
173171
dbg.Lvl2("Couldn't decode packet at", tc.name, "error:", err)
174172
} else {
175173
dbg.Lvl3("Closing connection by EOF: ", err)

0 commit comments

Comments
 (0)