@@ -3,16 +3,18 @@ package epochkghandler
3
3
import (
4
4
"bytes"
5
5
"context"
6
+
6
7
"github.com/jackc/pgx/v4"
7
8
"github.com/jackc/pgx/v4/pgxpool"
8
9
pubsub "github.com/libp2p/go-libp2p-pubsub"
9
10
"github.com/pkg/errors"
10
11
"github.com/rs/zerolog/log"
11
- "github.com/shutter-network/rolling-shutter/rolling-shutter/medley"
12
+
12
13
"github.com/shutter-network/shutter/shlib/puredkg"
13
14
"github.com/shutter-network/shutter/shlib/shcrypto"
14
15
15
16
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database"
17
+ "github.com/shutter-network/rolling-shutter/rolling-shutter/medley"
16
18
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2p"
17
19
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2pmsg"
18
20
"github.com/shutter-network/rolling-shutter/rolling-shutter/shdb"
@@ -85,12 +87,15 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
85
87
}
86
88
87
89
func checkKeysErrors (ctx context.Context , decryptionKeys * p2pmsg.DecryptionKeys , pureDKGResult * puredkg.Result , queries * database.Queries ) (pubsub.ValidationResult , error ) {
88
-
89
90
for i , k := range decryptionKeys .Keys {
90
91
epochSecretKey , err := k .GetEpochSecretKey ()
91
92
if err != nil {
92
93
return pubsub .ValidationReject , err
93
94
}
95
+ if i > 0 && bytes .Compare (k .Identity , decryptionKeys .Keys [i - 1 ].Identity ) < 0 {
96
+ return pubsub .ValidationReject , errors .Errorf ("keys not ordered" )
97
+ }
98
+
94
99
eon , err := medley .Uint64ToInt64Safe (decryptionKeys .Eon )
95
100
if err != nil {
96
101
return pubsub .ValidationReject , errors .Wrapf (err , "overflow error while converting eon to int64 %d" , decryptionKeys .Eon )
@@ -102,20 +107,17 @@ func checkKeysErrors(ctx context.Context, decryptionKeys *p2pmsg.DecryptionKeys,
102
107
if err != nil && ! errors .Is (err , pgx .ErrNoRows ) {
103
108
return pubsub .ValidationReject , errors .Wrapf (err , "failed to get decryption key for identity %x from db" , k .Identity )
104
109
}
105
- if bytes .Equal (k .Key , existingDecryptionKey .DecryptionKey ) {
110
+ if ! errors . Is ( err , pgx . ErrNoRows ) && bytes .Equal (k .Key , existingDecryptionKey .DecryptionKey ) {
106
111
continue
107
112
}
113
+
108
114
ok , err := shcrypto .VerifyEpochSecretKey (epochSecretKey , pureDKGResult .PublicKey , k .Identity )
109
115
if err != nil {
110
116
return pubsub .ValidationReject , errors .Wrapf (err , "error while checking epoch secret key for identity %x" , k .Identity )
111
117
}
112
118
if ! ok {
113
119
return pubsub .ValidationReject , errors .Errorf ("epoch secret key for identity %x is not valid" , k .Identity )
114
120
}
115
-
116
- if i > 0 && bytes .Compare (k .Identity , decryptionKeys .Keys [i - 1 ].Identity ) < 0 {
117
- return pubsub .ValidationReject , errors .Errorf ("keys not ordered" )
118
- }
119
121
}
120
122
return pubsub .ValidationAccept , nil
121
123
}
0 commit comments