Add session key size check (#62)
* Add session key size check Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
This commit is contained in:
parent
3b2e53c586
commit
8c04ff64a5
3 changed files with 50 additions and 4 deletions
|
|
@ -62,10 +62,16 @@ func DecryptSessionKeyWithPassword(keyPacket, password []byte) (*SessionKey, err
|
|||
for _, s := range symKeys {
|
||||
key, cipherFunc, err := s.Decrypt(password)
|
||||
if err == nil {
|
||||
return &SessionKey{
|
||||
sk := &SessionKey{
|
||||
Key: key,
|
||||
Algo: getAlgo(cipherFunc),
|
||||
}, nil
|
||||
}
|
||||
|
||||
if err = sk.checkSize(); err != nil {
|
||||
return nil, errors.Wrap(err, "gopenpgp: unable to decrypt session key with password")
|
||||
}
|
||||
|
||||
return sk, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +93,10 @@ func EncryptSessionKeyWithPassword(sk *SessionKey, password []byte) ([]byte, err
|
|||
return nil, errors.New("gopenpgp: password can't be empty")
|
||||
}
|
||||
|
||||
if err = sk.checkSize(); err != nil {
|
||||
return nil, errors.Wrap(err, "gopenpgp: unable to encrypt session key with password")
|
||||
}
|
||||
|
||||
config := &packet.Config{
|
||||
DefaultCipher: cf,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue