protonmail: use symetricallyEncrypt in Attachment.Encrypt
This commit is contained in:
parent
6e891b2ae2
commit
3c002e993d
|
@ -82,19 +82,13 @@ func (att *Attachment) Encrypt(ciphertext io.Writer, signed *openpgp.Entity) (cl
|
||||||
return nil, errors.New("cannot encrypt attachment: no attachment key available")
|
return nil, errors.New("cannot encrypt attachment: no attachment key available")
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptedData, err := packet.SerializeSymmetricallyEncrypted(ciphertext, att.unencryptedKey.CipherFunc, att.unencryptedKey.Key, config)
|
// TODO: sign and store signature in att.Signature
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
hints := &openpgp.FileHints{
|
||||||
|
IsBinary: true,
|
||||||
|
FileName: att.Name,
|
||||||
}
|
}
|
||||||
|
return symetricallyEncrypt(ciphertext, att.unencryptedKey, nil, hints, config)
|
||||||
// TODO: sign, see https://github.com/golang/crypto/blob/master/openpgp/write.go#L287
|
|
||||||
|
|
||||||
literalData, err := packet.SerializeLiteral(encryptedData, true, att.Name, 0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return literalData, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAttachment downloads an attachment's payload. The returned io.ReadCloser
|
// GetAttachment downloads an attachment's payload. The returned io.ReadCloser
|
||||||
|
|
|
@ -106,7 +106,7 @@ func generateUnencryptedKey(cipher packet.CipherFunction, config *packet.Config)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func symetricallyEncrypt(ciphertext io.Writer, symKey *packet.EncryptedKey, signer *packet.PrivateKey, config *packet.Config) (plaintext io.WriteCloser, err error) {
|
func symetricallyEncrypt(ciphertext io.Writer, symKey *packet.EncryptedKey, signer *packet.PrivateKey, hints *openpgp.FileHints, config *packet.Config) (plaintext io.WriteCloser, err error) {
|
||||||
// From https://github.com/golang/crypto/blob/master/openpgp/write.go#L172
|
// From https://github.com/golang/crypto/blob/master/openpgp/write.go#L172
|
||||||
|
|
||||||
encryptedData, err := packet.SerializeSymmetricallyEncrypted(ciphertext, symKey.CipherFunc, symKey.Key, config)
|
encryptedData, err := packet.SerializeSymmetricallyEncrypted(ciphertext, symKey.CipherFunc, symKey.Key, config)
|
||||||
|
@ -129,6 +129,10 @@ func symetricallyEncrypt(ciphertext io.Writer, symKey *packet.EncryptedKey, sign
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hints == nil {
|
||||||
|
hints = &openpgp.FileHints{}
|
||||||
|
}
|
||||||
|
|
||||||
w := encryptedData
|
w := encryptedData
|
||||||
if signer != nil {
|
if signer != nil {
|
||||||
// If we need to write a signature packet after the literal
|
// If we need to write a signature packet after the literal
|
||||||
|
@ -136,8 +140,11 @@ func symetricallyEncrypt(ciphertext io.Writer, symKey *packet.EncryptedKey, sign
|
||||||
// encryptedData.
|
// encryptedData.
|
||||||
w = noOpCloser{encryptedData}
|
w = noOpCloser{encryptedData}
|
||||||
}
|
}
|
||||||
|
var epochSeconds uint32
|
||||||
literalData, err := packet.SerializeLiteral(w, false, "", 0)
|
if !hints.ModTime.IsZero() {
|
||||||
|
epochSeconds = uint32(hints.ModTime.Unix())
|
||||||
|
}
|
||||||
|
literalData, err := packet.SerializeLiteral(w, hints.IsBinary, hints.FileName, epochSeconds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,7 @@ func (set *MessagePackageSet) Encrypt(mimeType string, signed *openpgp.Entity) (
|
||||||
encoded := new(bytes.Buffer)
|
encoded := new(bytes.Buffer)
|
||||||
ciphertext := base64.NewEncoder(base64.StdEncoding, encoded)
|
ciphertext := base64.NewEncoder(base64.StdEncoding, encoded)
|
||||||
|
|
||||||
cleartext, err := symetricallyEncrypt(ciphertext, key, signer, config)
|
cleartext, err := symetricallyEncrypt(ciphertext, key, signer, nil, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue