Skip to content

Commit 15aac87

Browse files
committed
3rd party: verify third party signatures
1 parent 3ea3bec commit 15aac87

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

biscuit.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ func (b *Biscuit) Authorizer(root ed25519.PublicKey) (Authorizer, error) {
290290
}
291291

292292
currentKey = b.container.Authority.NextKey.Key
293+
currentAlgorithm := b.container.Authority.NextKey.Algorithm
293294
if len(currentKey) != 32 {
294295
return nil, ErrInvalidKeySize
295296
}
@@ -308,7 +309,26 @@ func (b *Biscuit) Authorizer(root ed25519.PublicKey) (Authorizer, error) {
308309
return nil, ErrInvalidSignature
309310
}
310311

312+
if block.ExternalSignature != nil {
313+
// an external signature is present, we need to verify it
314+
if *block.ExternalSignature.PublicKey.Algorithm != pb.PublicKey_Ed25519 {
315+
return nil, UnsupportedAlgorithm
316+
}
317+
318+
// the public key that's part of the signed block is the public key used to sign
319+
// the previous block
320+
algorithm := make([]byte, 4)
321+
binary.LittleEndian.PutUint32(algorithm[0:], uint32(currentAlgorithm.Number()))
322+
toVerify := append(block.Block[:], algorithm...)
323+
toVerify = append(toVerify, currentKey[:]...)
324+
325+
if ok := ed25519.Verify(block.ExternalSignature.PublicKey.Key, toVerify, block.ExternalSignature.Signature); !ok {
326+
return nil, ErrInvalidSignature
327+
}
328+
}
329+
311330
currentKey = block.NextKey.Key
331+
currentAlgorithm = block.NextKey.Algorithm
312332
if len(currentKey) != 32 {
313333
return nil, ErrInvalidKeySize
314334
}

0 commit comments

Comments
 (0)