Add test for invalid (=zero) crypto keys

This commit is contained in:
Alexander Neumann
2015-05-01 17:31:57 +02:00
parent 98dc811536
commit 9010d7bb3a
2 changed files with 52 additions and 5 deletions
+10 -5
View File
@@ -88,13 +88,13 @@ func OpenKey(s *Server, name string, password string) (*Key, error) {
}
k.name = name
// test if polynomial is valid and irreducible
if k.master.ChunkerPolynomial == 0 {
return nil, errors.New("Polynomial for content defined chunking is zero")
if !k.Valid() {
return nil, errors.New("Invalid key for repository")
}
if !k.master.ChunkerPolynomial.Irreducible() {
return nil, errors.New("Polynomial for content defined chunking is invalid")
// test if the chunker polynomial is present in the master key
if k.master.ChunkerPolynomial == 0 {
return nil, errors.New("Polynomial for content defined chunking is zero")
}
debug.Log("OpenKey", "Master keys loaded, polynomial %v", k.master.ChunkerPolynomial)
@@ -279,3 +279,8 @@ func (k *Key) String() string {
func (k Key) Name() string {
return k.name
}
// Valid tests whether the mac and encryption keys are valid (i.e. not zero)
func (k *Key) Valid() bool {
return k.user.Valid() && k.master.Valid()
}