gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-go] branch master updated: Milestone #3 (RC2)


From: gnunet
Subject: [gnunet-go] branch master updated: Milestone #3 (RC2)
Date: Sun, 24 May 2020 15:20:06 +0200

This is an automated email from the git hooks/post-receive script.

bernd-fix pushed a commit to branch master
in repository gnunet-go.

The following commit(s) were added to refs/heads/master by this push:
     new 58968de  Milestone #3 (RC2)
58968de is described below

commit 58968de4f88aad3014ca1cfd5ce3d99590733642
Author: Bernd Fix <address@hidden>
AuthorDate: Sun May 24 15:14:14 2020 +0200

    Milestone #3 (RC2)
---
 src/cmd/revoke-zonekey/main.go          | 47 +++++++++++++++++++-------------
 src/gnunet/service/revocation/module.go |  2 +-
 src/gnunet/service/revocation/pow.go    | 48 +++++++++++++++++----------------
 3 files changed, 54 insertions(+), 43 deletions(-)

diff --git a/src/cmd/revoke-zonekey/main.go b/src/cmd/revoke-zonekey/main.go
index 2bbd90f..fe0baaa 100644
--- a/src/cmd/revoke-zonekey/main.go
+++ b/src/cmd/revoke-zonekey/main.go
@@ -53,6 +53,10 @@ func main() {
        flag.StringVar(&filename, "f", "", "Name of file to store revocation")
        flag.Parse()
 
+       if len(filename) == 0 {
+               log.Fatal("Missing '-f' argument (filename fot revocation 
data)")
+       }
+
        // define layout of persistant data
        var revData struct {
                Rd      *revocation.RevData // Revocation data
@@ -112,16 +116,38 @@ func main() {
        }
 
        // Start or continue calculation
-       startTime := util.AbsoluteTimeNow()
        ctx, cancelFcn := context.WithCancel(context.Background())
        wg := new(sync.WaitGroup)
        wg.Add(1)
        go func() {
                defer wg.Done()
-               if result, last := revData.Rd.Compute(ctx, bits, revData.Last); 
result != 32 {
+
+               startTime := util.AbsoluteTimeNow()
+               result, last := revData.Rd.Compute(ctx, bits, revData.Last)
+               if result != 32 {
                        log.Printf("Incomplete revocation: Only %d of 32 PoWs 
available!\n", result)
+               } else {
+                       log.Println("Revocation data object:")
+                       log.Println("   0x" + 
hex.EncodeToString(revData.Rd.Blob()))
+                       log.Println("Status:")
+                       rc := revData.Rd.Verify(false)
+                       switch {
+                       case rc == -1:
+                               log.Println("    Missing/invalid signature")
+                       case rc == -2:
+                               log.Println("    Expired revocation")
+                       case rc == -3:
+                               log.Println("    Wrong PoW sequence order")
+                       case rc < 25:
+                               log.Println("    Difficulty to small")
+                       default:
+                               log.Printf("    Difficulty: %d\n", rc)
+                       }
+               }
+               if !cont || last != revData.Last {
                        revData.Last = last
                        revData.T = util.AbsoluteTimeNow().Diff(startTime)
+
                        log.Println("Writing revocation data to file...")
                        file, err := os.Create(filename)
                        if err != nil {
@@ -144,23 +170,6 @@ func main() {
                        if err = file.Close(); err != nil {
                                log.Fatal("Error closing file: " + err.Error())
                        }
-               } else {
-                       log.Println("Revocation data object:")
-                       log.Println("   0x" + 
hex.EncodeToString(revData.Rd.Blob()))
-                       log.Println("Status:")
-                       rc := revData.Rd.Verify()
-                       switch {
-                       case rc == -1:
-                               log.Println("    Missing/invalid signature")
-                       case rc == -2:
-                               log.Println("    Expired revocation")
-                       case rc == -3:
-                               log.Println("    Wrong PoW sequence order")
-                       case rc < 25:
-                               log.Println("    Difficulty to small")
-                       default:
-                               log.Printf("    Difficulty: %d\n", rc)
-                       }
                }
        }()
 
diff --git a/src/gnunet/service/revocation/module.go 
b/src/gnunet/service/revocation/module.go
index b5c8a16..908cc2e 100644
--- a/src/gnunet/service/revocation/module.go
+++ b/src/gnunet/service/revocation/module.go
@@ -94,7 +94,7 @@ func (s *RevocationModule) Query(ctx *service.SessionContext, 
pkey *ed25519.Publ
 // Revoke
 func (s *RevocationModule) Revoke(ctx *service.SessionContext, rd *RevData) 
(success bool, err error) {
        // verify the revocation data
-       rc := rd.Verify()
+       rc := rd.Verify(true)
        switch {
        case rc == -1:
                logger.Println(logger.WARN, "[revocation] Revoke: 
Missing/invalid signature")
diff --git a/src/gnunet/service/revocation/pow.go 
b/src/gnunet/service/revocation/pow.go
index f4b6b9d..4f7fde2 100644
--- a/src/gnunet/service/revocation/pow.go
+++ b/src/gnunet/service/revocation/pow.go
@@ -173,29 +173,31 @@ func (rd *RevData) Sign(skey *ed25519.PrivateKey) error {
 // than the minimum (25) indicates invalid PoWs; a value of -1 indicates
 // a failed signature; -2 indicates an expired revocation and -3 for a
 // "out-of-order" PoW sequence.
-func (rd *RevData) Verify() int {
+func (rd *RevData) Verify(withSig bool) int {
 
        // (1) check signature
-       sigBlock := &SignedRevData{
-               Purpose: &crypto.SignaturePurpose{
-                       Size:    48,
-                       Purpose: enums.SIG_REVOCATION,
-               },
-               ZoneKey:   rd.ZoneKey,
-               Timestamp: rd.Timestamp,
-       }
-       sigData, err := data.Marshal(sigBlock)
-       if err != nil {
-               return -1
-       }
-       pkey := ed25519.NewPublicKeyFromBytes(rd.ZoneKey)
-       sig, err := ed25519.NewEcSignatureFromBytes(rd.Signature)
-       if err != nil {
-               return -1
-       }
-       valid, err := pkey.EcVerify(sigData, sig)
-       if err != nil || !valid {
-               return -1
+       if withSig {
+               sigBlock := &SignedRevData{
+                       Purpose: &crypto.SignaturePurpose{
+                               Size:    48,
+                               Purpose: enums.SIG_REVOCATION,
+                       },
+                       ZoneKey:   rd.ZoneKey,
+                       Timestamp: rd.Timestamp,
+               }
+               sigData, err := data.Marshal(sigBlock)
+               if err != nil {
+                       return -1
+               }
+               pkey := ed25519.NewPublicKeyFromBytes(rd.ZoneKey)
+               sig, err := ed25519.NewEcSignatureFromBytes(rd.Signature)
+               if err != nil {
+                       return -1
+               }
+               valid, err := pkey.EcVerify(sigData, sig)
+               if err != nil || !valid {
+                       return -1
+               }
        }
 
        // (2) check PoWs
@@ -240,8 +242,8 @@ func (rd *RevData) Compute(ctx context.Context, bits int, 
last uint64) (int, uin
        for i, pow := range rd.PoWs {
                // handle "new" pow value: set it to last_pow+1
                // this ensures a correctly sorted pow list by design.
-               if pow == 0 {
-                       pow = last
+               if pow == 0 && last != 0 {
+                       pow, last = last, 0
                }
                if pow == 0 && i > 0 {
                        pow = rd.PoWs[i-1] + 1

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]