fix crash on missing keyring
This commit is contained in:
parent
968888eb0e
commit
99c48c2e4e
3 changed files with 21 additions and 14 deletions
|
|
@ -17,7 +17,7 @@ dille.
|
|||
|
||||
const testAttachmentEncrypted = `0ksB0fHC6Duezx/0TqpK/82HSl8+qCY0c2BCuyrSFoj6Dubd93T3//32jVYa624NYvfvxX+UxFKYKJxG09gFsU1IVc87cWvUgmUmgjU=`
|
||||
|
||||
func TestAttachment_GetKey(t *testing.T) {
|
||||
func TestAttachmentGetKey(t *testing.T) {
|
||||
split, err := SeparateKeyAndData(testPrivateKeyRing, strings.NewReader(testKeyPackets), len(testKeyPackets), -1)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error while decrypting attachment key, got:", err)
|
||||
|
|
@ -28,8 +28,7 @@ func TestAttachment_GetKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAttachment_SetKey(t *testing.T) {
|
||||
|
||||
func TestAttachmentSetKey(t *testing.T) {
|
||||
var packets string
|
||||
var err error
|
||||
|
||||
|
|
@ -48,7 +47,7 @@ func TestAttachment_SetKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAttachnent_EncryptDecrypt(t *testing.T) {
|
||||
func TestAttachnentEncryptDecrypt(t *testing.T) {
|
||||
plainData, _ := base64.StdEncoding.DecodeString(testAttachmentCleartext)
|
||||
|
||||
var pmCrypto = PmCrypto{}
|
||||
|
|
@ -66,7 +65,7 @@ func TestAttachnent_EncryptDecrypt(t *testing.T) {
|
|||
s := string(redecData)
|
||||
|
||||
if testAttachmentCleartext != s {
|
||||
t.Fatalf("Invalid decrypted attachment: expected %v, got %v", testAttachmentCleartext, s)
|
||||
t.Fatalf("Invalid decrypted attachment: expected\n%v\ngot\n%v", testAttachmentCleartext, s)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,18 @@ package crypto
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/ProtonMail/go-pm-mime"
|
||||
"golang.org/x/crypto/openpgp/packet"
|
||||
"io/ioutil"
|
||||
"net/mail"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
|
||||
pmmime "github.com/ProtonMail/go-pm-mime"
|
||||
|
||||
"golang.org/x/crypto/openpgp"
|
||||
"golang.org/x/crypto/openpgp/packet"
|
||||
)
|
||||
|
||||
func (pm PmCrypto) parseMIME(mimeBody string, verifierKey *KeyRing) (*pmmime.BodyCollector, int, []string, []string, error) {
|
||||
|
||||
mm, err := mail.ReadMessage(strings.NewReader(mimeBody))
|
||||
if err != nil {
|
||||
return nil, 0, nil, nil, err
|
||||
|
|
@ -25,10 +27,14 @@ func (pm PmCrypto) parseMIME(mimeBody string, verifierKey *KeyRing) (*pmmime.Bod
|
|||
bodyCollector := pmmime.NewBodyCollector(printAccepter)
|
||||
attachmentsCollector := pmmime.NewAttachmentsCollector(bodyCollector)
|
||||
mimeVisitor := pmmime.NewMimeVisitor(attachmentsCollector)
|
||||
// TODO: build was failing on this unused 'str' variable. This code looks like WIP
|
||||
//str, err := armor.ArmorKey(verifierKey)
|
||||
|
||||
signatureCollector := newSignatureCollector(mimeVisitor, verifierKey.entities, config)
|
||||
var pgpKering openpgp.KeyRing
|
||||
if verifierKey != nil {
|
||||
pgpKering = verifierKey.entities
|
||||
}
|
||||
|
||||
signatureCollector := newSignatureCollector(mimeVisitor, pgpKering, config)
|
||||
|
||||
err = pmmime.VisitAll(bytes.NewReader(mmBodyData), h, signatureCollector)
|
||||
|
||||
verified := signatureCollector.verified
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@ package crypto
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/ProtonMail/go-pm-mime"
|
||||
"golang.org/x/crypto/openpgp"
|
||||
"golang.org/x/crypto/openpgp/packet"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/textproto"
|
||||
|
||||
"github.com/ProtonMail/go-pm-mime"
|
||||
|
||||
"golang.org/x/crypto/openpgp"
|
||||
"golang.org/x/crypto/openpgp/packet"
|
||||
)
|
||||
|
||||
// Use: ios/android only
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue