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")
|
||||
}
|
||||
|
||||
encryptedData, err := packet.SerializeSymmetricallyEncrypted(ciphertext, att.unencryptedKey.CipherFunc, att.unencryptedKey.Key, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// TODO: sign and store signature in att.Signature
|
||||
|
||||
hints := &openpgp.FileHints{
|
||||
IsBinary: true,
|
||||
FileName: att.Name,
|
||||
}
|
||||
|
||||
// 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
|
||||
return symetricallyEncrypt(ciphertext, att.unencryptedKey, nil, hints, config)
|
||||
}
|
||||
|
||||
// GetAttachment downloads an attachment's payload. The returned io.ReadCloser
|
||||
|
|
|
@ -106,7 +106,7 @@ func generateUnencryptedKey(cipher packet.CipherFunction, config *packet.Config)
|
|||
}, 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
|
||||
|
||||
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
|
||||
if signer != nil {
|
||||
// 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.
|
||||
w = noOpCloser{encryptedData}
|
||||
}
|
||||
|
||||
literalData, err := packet.SerializeLiteral(w, false, "", 0)
|
||||
var epochSeconds uint32
|
||||
if !hints.ModTime.IsZero() {
|
||||
epochSeconds = uint32(hints.ModTime.Unix())
|
||||
}
|
||||
literalData, err := packet.SerializeLiteral(w, hints.IsBinary, hints.FileName, epochSeconds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -302,7 +302,7 @@ func (set *MessagePackageSet) Encrypt(mimeType string, signed *openpgp.Entity) (
|
|||
encoded := new(bytes.Buffer)
|
||||
ciphertext := base64.NewEncoder(base64.StdEncoding, encoded)
|
||||
|
||||
cleartext, err := symetricallyEncrypt(ciphertext, key, signer, config)
|
||||
cleartext, err := symetricallyEncrypt(ciphertext, key, signer, nil, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue