Fix various minor issues (#45)

* Update header version to 2.0.0

* Add space to cleartext message armouring

* Fix password encrypted binary files

* Clear key private params in helpers

* Do not unlock key if private key is nil

* Document changes

* Use defer for ClearPrivateKeyParams
This commit is contained in:
wussler 2020-04-27 21:01:23 +02:00 committed by GitHub
parent 0f35072bc4
commit 222decb919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 7 deletions

View file

@ -104,6 +104,10 @@ func (key *Key) Lock(passphrase []byte) (*Key, error) {
return nil, err
}
if passphrase == nil {
return lockedKey, nil
}
err = lockedKey.entity.PrivateKey.Encrypt(passphrase)
if err != nil {
return nil, errors.Wrap(err, "gopenpgp: error in locking key")
@ -136,6 +140,9 @@ func (key *Key) Unlock(passphrase []byte) (*Key, error) {
}
if !isLocked {
if passphrase == nil {
return key.Copy()
}
return nil, errors.New("gopenpgp: key is not locked")
}

View file

@ -366,7 +366,7 @@ func (msg *ClearTextMessage) GetArmored() (string, error) {
return "", err
}
str := "-----BEGIN PGP SIGNED MESSAGE-----\r\nHash:SHA512\r\n\r\n"
str := "-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: SHA512\r\n\r\n"
str += msg.GetString()
str += "\r\n"
str += armSignature

View file

@ -15,7 +15,7 @@ import (
// * password: A password that will be derived into an encryption key
// * output : The encrypted data as PGPMessage
func EncryptMessageWithPassword(message *PlainMessage, password []byte) (*PGPMessage, error) {
encrypted, err := passwordEncrypt(message.GetBinary(), password)
encrypted, err := passwordEncrypt(message.GetBinary(), password, message.IsBinary())
if err != nil {
return nil, err
}
@ -99,14 +99,16 @@ func EncryptSessionKeyWithPassword(sk *SessionKey, password []byte) ([]byte, err
// ----- INTERNAL FUNCTIONS ------
func passwordEncrypt(message []byte, password []byte) ([]byte, error) {
func passwordEncrypt(message []byte, password []byte, isBinary bool) ([]byte, error) {
var outBuf bytes.Buffer
config := &packet.Config{
Time: getTimeGenerator(),
}
encryptWriter, err := openpgp.SymmetricallyEncrypt(&outBuf, password, nil, config)
hints := &openpgp.FileHints{IsBinary: isBinary}
encryptWriter, err := openpgp.SymmetricallyEncrypt(&outBuf, password, hints, config)
if err != nil {
return nil, err
}