aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Fix <brf@hoi-polloi.org>2020-05-24 15:14:14 +0200
committerBernd Fix <brf@hoi-polloi.org>2020-05-24 15:14:14 +0200
commit58968de4f88aad3014ca1cfd5ce3d99590733642 (patch)
tree7b23354ad8a7a8d3771b1daf89c4274f90f3859f
parentfdf23180919ec42422694f1f1801eead1ea576e8 (diff)
downloadgnunet-go-58968de4f88aad3014ca1cfd5ce3d99590733642.tar.gz
gnunet-go-58968de4f88aad3014ca1cfd5ce3d99590733642.zip
Milestone #3 (RC2)
-rw-r--r--src/cmd/revoke-zonekey/main.go47
-rw-r--r--src/gnunet/service/revocation/module.go2
-rw-r--r--src/gnunet/service/revocation/pow.go48
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() {
53 flag.StringVar(&filename, "f", "", "Name of file to store revocation") 53 flag.StringVar(&filename, "f", "", "Name of file to store revocation")
54 flag.Parse() 54 flag.Parse()
55 55
56 if len(filename) == 0 {
57 log.Fatal("Missing '-f' argument (filename fot revocation data)")
58 }
59
56 // define layout of persistant data 60 // define layout of persistant data
57 var revData struct { 61 var revData struct {
58 Rd *revocation.RevData // Revocation data 62 Rd *revocation.RevData // Revocation data
@@ -112,16 +116,38 @@ func main() {
112 } 116 }
113 117
114 // Start or continue calculation 118 // Start or continue calculation
115 startTime := util.AbsoluteTimeNow()
116 ctx, cancelFcn := context.WithCancel(context.Background()) 119 ctx, cancelFcn := context.WithCancel(context.Background())
117 wg := new(sync.WaitGroup) 120 wg := new(sync.WaitGroup)
118 wg.Add(1) 121 wg.Add(1)
119 go func() { 122 go func() {
120 defer wg.Done() 123 defer wg.Done()
121 if result, last := revData.Rd.Compute(ctx, bits, revData.Last); result != 32 { 124
125 startTime := util.AbsoluteTimeNow()
126 result, last := revData.Rd.Compute(ctx, bits, revData.Last)
127 if result != 32 {
122 log.Printf("Incomplete revocation: Only %d of 32 PoWs available!\n", result) 128 log.Printf("Incomplete revocation: Only %d of 32 PoWs available!\n", result)
129 } else {
130 log.Println("Revocation data object:")
131 log.Println(" 0x" + hex.EncodeToString(revData.Rd.Blob()))
132 log.Println("Status:")
133 rc := revData.Rd.Verify(false)
134 switch {
135 case rc == -1:
136 log.Println(" Missing/invalid signature")
137 case rc == -2:
138 log.Println(" Expired revocation")
139 case rc == -3:
140 log.Println(" Wrong PoW sequence order")
141 case rc < 25:
142 log.Println(" Difficulty to small")
143 default:
144 log.Printf(" Difficulty: %d\n", rc)
145 }
146 }
147 if !cont || last != revData.Last {
123 revData.Last = last 148 revData.Last = last
124 revData.T = util.AbsoluteTimeNow().Diff(startTime) 149 revData.T = util.AbsoluteTimeNow().Diff(startTime)
150
125 log.Println("Writing revocation data to file...") 151 log.Println("Writing revocation data to file...")
126 file, err := os.Create(filename) 152 file, err := os.Create(filename)
127 if err != nil { 153 if err != nil {
@@ -144,23 +170,6 @@ func main() {
144 if err = file.Close(); err != nil { 170 if err = file.Close(); err != nil {
145 log.Fatal("Error closing file: " + err.Error()) 171 log.Fatal("Error closing file: " + err.Error())
146 } 172 }
147 } else {
148 log.Println("Revocation data object:")
149 log.Println(" 0x" + hex.EncodeToString(revData.Rd.Blob()))
150 log.Println("Status:")
151 rc := revData.Rd.Verify()
152 switch {
153 case rc == -1:
154 log.Println(" Missing/invalid signature")
155 case rc == -2:
156 log.Println(" Expired revocation")
157 case rc == -3:
158 log.Println(" Wrong PoW sequence order")
159 case rc < 25:
160 log.Println(" Difficulty to small")
161 default:
162 log.Printf(" Difficulty: %d\n", rc)
163 }
164 } 173 }
165 }() 174 }()
166 175
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
94// Revoke 94// Revoke
95func (s *RevocationModule) Revoke(ctx *service.SessionContext, rd *RevData) (success bool, err error) { 95func (s *RevocationModule) Revoke(ctx *service.SessionContext, rd *RevData) (success bool, err error) {
96 // verify the revocation data 96 // verify the revocation data
97 rc := rd.Verify() 97 rc := rd.Verify(true)
98 switch { 98 switch {
99 case rc == -1: 99 case rc == -1:
100 logger.Println(logger.WARN, "[revocation] Revoke: Missing/invalid signature") 100 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 {
173// than the minimum (25) indicates invalid PoWs; a value of -1 indicates 173// than the minimum (25) indicates invalid PoWs; a value of -1 indicates
174// a failed signature; -2 indicates an expired revocation and -3 for a 174// a failed signature; -2 indicates an expired revocation and -3 for a
175// "out-of-order" PoW sequence. 175// "out-of-order" PoW sequence.
176func (rd *RevData) Verify() int { 176func (rd *RevData) Verify(withSig bool) int {
177 177
178 // (1) check signature 178 // (1) check signature
179 sigBlock := &SignedRevData{ 179 if withSig {
180 Purpose: &crypto.SignaturePurpose{ 180 sigBlock := &SignedRevData{
181 Size: 48, 181 Purpose: &crypto.SignaturePurpose{
182 Purpose: enums.SIG_REVOCATION, 182 Size: 48,
183 }, 183 Purpose: enums.SIG_REVOCATION,
184 ZoneKey: rd.ZoneKey, 184 },
185 Timestamp: rd.Timestamp, 185 ZoneKey: rd.ZoneKey,
186 } 186 Timestamp: rd.Timestamp,
187 sigData, err := data.Marshal(sigBlock) 187 }
188 if err != nil { 188 sigData, err := data.Marshal(sigBlock)
189 return -1 189 if err != nil {
190 } 190 return -1
191 pkey := ed25519.NewPublicKeyFromBytes(rd.ZoneKey) 191 }
192 sig, err := ed25519.NewEcSignatureFromBytes(rd.Signature) 192 pkey := ed25519.NewPublicKeyFromBytes(rd.ZoneKey)
193 if err != nil { 193 sig, err := ed25519.NewEcSignatureFromBytes(rd.Signature)
194 return -1 194 if err != nil {
195 } 195 return -1
196 valid, err := pkey.EcVerify(sigData, sig) 196 }
197 if err != nil || !valid { 197 valid, err := pkey.EcVerify(sigData, sig)
198 return -1 198 if err != nil || !valid {
199 return -1
200 }
199 } 201 }
200 202
201 // (2) check PoWs 203 // (2) check PoWs
@@ -240,8 +242,8 @@ func (rd *RevData) Compute(ctx context.Context, bits int, last uint64) (int, uin
240 for i, pow := range rd.PoWs { 242 for i, pow := range rd.PoWs {
241 // handle "new" pow value: set it to last_pow+1 243 // handle "new" pow value: set it to last_pow+1
242 // this ensures a correctly sorted pow list by design. 244 // this ensures a correctly sorted pow list by design.
243 if pow == 0 { 245 if pow == 0 && last != 0 {
244 pow = last 246 pow, last = last, 0
245 } 247 }
246 if pow == 0 && i > 0 { 248 if pow == 0 && i > 0 {
247 pow = rd.PoWs[i-1] + 1 249 pow = rd.PoWs[i-1] + 1