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:
parent
0f35072bc4
commit
222decb919
9 changed files with 28 additions and 7 deletions
|
|
@ -7,10 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Security
|
### Security
|
||||||
- Updated underlying crypto library
|
- Updated underlying crypto library
|
||||||
|
- Improved memory zeroing in helpers
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed test `TestMultipleKeyMessageEncryption`
|
- Fixed test `TestMultipleKeyMessageEncryption`
|
||||||
- Fixed garbage collection issues when compiled on gomobile, by copying byte slices
|
- Fixed garbage collection issues when compiled on gomobile, by copying byte slices
|
||||||
|
- Password encrypted binary files now have the correct flags
|
||||||
|
- Fixed missing space in `Hash` header of cleartext messages
|
||||||
|
|
||||||
|
## Changed
|
||||||
|
- Providing empty passphrase does no longer throw an error when unlocking an unencrypted private key
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- SHA256 fingerprint support
|
- SHA256 fingerprint support
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package constants
|
||||||
|
|
||||||
// Constants for armored data.
|
// Constants for armored data.
|
||||||
const (
|
const (
|
||||||
ArmorHeaderVersion = "GopenPGP 0.0.1 (" + Version + ")"
|
ArmorHeaderVersion = "GopenPGP 2.0.0"
|
||||||
ArmorHeaderComment = "https://gopenpgp.org"
|
ArmorHeaderComment = "https://gopenpgp.org"
|
||||||
PGPMessageHeader = "PGP MESSAGE"
|
PGPMessageHeader = "PGP MESSAGE"
|
||||||
PGPSignatureHeader = "PGP SIGNATURE"
|
PGPSignatureHeader = "PGP SIGNATURE"
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,10 @@ func (key *Key) Lock(passphrase []byte) (*Key, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if passphrase == nil {
|
||||||
|
return lockedKey, nil
|
||||||
|
}
|
||||||
|
|
||||||
err = lockedKey.entity.PrivateKey.Encrypt(passphrase)
|
err = lockedKey.entity.PrivateKey.Encrypt(passphrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "gopenpgp: error in locking key")
|
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 !isLocked {
|
||||||
|
if passphrase == nil {
|
||||||
|
return key.Copy()
|
||||||
|
}
|
||||||
return nil, errors.New("gopenpgp: key is not locked")
|
return nil, errors.New("gopenpgp: key is not locked")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ func (msg *ClearTextMessage) GetArmored() (string, error) {
|
||||||
return "", err
|
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 += msg.GetString()
|
||||||
str += "\r\n"
|
str += "\r\n"
|
||||||
str += armSignature
|
str += armSignature
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
// * password: A password that will be derived into an encryption key
|
// * password: A password that will be derived into an encryption key
|
||||||
// * output : The encrypted data as PGPMessage
|
// * output : The encrypted data as PGPMessage
|
||||||
func EncryptMessageWithPassword(message *PlainMessage, password []byte) (*PGPMessage, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -99,14 +99,16 @@ func EncryptSessionKeyWithPassword(sk *SessionKey, password []byte) ([]byte, err
|
||||||
|
|
||||||
// ----- INTERNAL FUNCTIONS ------
|
// ----- INTERNAL FUNCTIONS ------
|
||||||
|
|
||||||
func passwordEncrypt(message []byte, password []byte) ([]byte, error) {
|
func passwordEncrypt(message []byte, password []byte, isBinary bool) ([]byte, error) {
|
||||||
var outBuf bytes.Buffer
|
var outBuf bytes.Buffer
|
||||||
|
|
||||||
config := &packet.Config{
|
config := &packet.Config{
|
||||||
Time: getTimeGenerator(),
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ func SignCleartextMessageArmored(privateKey string, passphrase []byte, text stri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer unlockedKey.ClearPrivateParams()
|
||||||
|
|
||||||
keyRing, err := crypto.NewKeyRing(unlockedKey)
|
keyRing, err := crypto.NewKeyRing(unlockedKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ func EncryptSignMessageArmored(
|
||||||
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer unlockedKeyObj.ClearPrivateParams()
|
||||||
|
|
||||||
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -126,6 +127,7 @@ func DecryptMessageArmored(
|
||||||
if privateKeyUnlocked, err = privateKeyObj.Unlock(passphrase); err != nil {
|
if privateKeyUnlocked, err = privateKeyObj.Unlock(passphrase); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer privateKeyUnlocked.ClearPrivateParams()
|
||||||
|
|
||||||
if privateKeyRing, err = crypto.NewKeyRing(privateKeyUnlocked); err != nil {
|
if privateKeyRing, err = crypto.NewKeyRing(privateKeyUnlocked); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -168,6 +170,7 @@ func DecryptVerifyMessageArmored(
|
||||||
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer unlockedKeyObj.ClearPrivateParams()
|
||||||
|
|
||||||
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -214,6 +217,7 @@ func DecryptVerifyAttachment(
|
||||||
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer unlockedKeyObj.ClearPrivateParams()
|
||||||
|
|
||||||
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ func UpdatePrivateKeyPassphrase(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer unlocked.ClearPrivateParams()
|
||||||
|
|
||||||
locked, err := unlocked.Lock(newPassphrase)
|
locked, err := unlocked.Lock(newPassphrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
unlocked.ClearPrivateParams()
|
|
||||||
return locked.Armor()
|
return locked.Armor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,13 +37,13 @@ func GenerateKey(name, email string, passphrase []byte, keyType string, bits int
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer key.ClearPrivateParams()
|
||||||
|
|
||||||
locked, err := key.Lock(passphrase)
|
locked, err := key.Lock(passphrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
key.ClearPrivateParams()
|
|
||||||
return locked.Armor()
|
return locked.Armor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ func EncryptSignAttachment(
|
||||||
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
if unlockedKeyObj, err = privateKeyObj.Unlock(passphrase); err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
defer unlockedKeyObj.ClearPrivateParams()
|
||||||
|
|
||||||
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
if privateKeyRing, err = crypto.NewKeyRing(unlockedKeyObj); err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue