diff --git a/crypto/proton_test.go b/crypto/proton_test.go new file mode 100644 index 00000000..12d20c9c --- /dev/null +++ b/crypto/proton_test.go @@ -0,0 +1,68 @@ +package crypto + +import ( + "encoding/base64" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestForwardeeDecryption(t *testing.T) { + pgp.latestServerTime = 1679044110 + defer func() { + pgp.latestServerTime = testTime + }() + + forwardeeKey, err := NewKeyFromArmored(readTestFile("key_forwardee", false)) + if err != nil { + t.Fatal("Expected no error while unarmoring private keyring, got:", err) + } + + forwardeeKeyRing, err := NewKeyRing(forwardeeKey) + if err != nil { + t.Fatal("Expected no error while building private keyring, got:", err) + } + + pgpMessage, err := NewPGPMessageFromArmored(readTestFile("message_forwardee", false)) + if err != nil { + t.Fatal("Expected no error while reading ciphertext, got:", err) + } + + plainMessage, err := forwardeeKeyRing.Decrypt(pgpMessage, nil, 0) + if err != nil { + t.Fatal("Expected no error while decrypting/verifying, got:", err) + } + + assert.Exactly(t, "Message for Bob", plainMessage.GetString()) +} + +func TestSymmetricKeys(t *testing.T) { + pgp.latestServerTime = 1679044110 + defer func() { + pgp.latestServerTime = testTime + }() + + symmetricKey, err := NewKeyFromArmored(readTestFile("key_symmetric", false)) + if err != nil { + t.Fatal("Expected no error while unarmoring private keyring, got:", err) + } + + symmetricKeyRing, err := NewKeyRing(symmetricKey) + if err != nil { + t.Fatal("Expected no error while building private keyring, got:", err) + } + + binData, _ := base64.StdEncoding.DecodeString("ExXmnSiQ2QCey20YLH6qlLhkY3xnIBC1AwlIXwK/HvY=") + var message = NewPlainMessage(binData) + + ciphertext, err := symmetricKeyRing.Encrypt(message, nil) + if err != nil { + t.Fatal("Expected no error when encrypting, got:", err) + } + + decrypted, err := symmetricKeyRing.Decrypt(ciphertext, nil, 0) + if err != nil { + t.Fatal("Expected no error when decrypting, got:", err) + } + assert.Exactly(t, message.GetBinary(), decrypted.GetBinary()) +} diff --git a/crypto/testdata/key_forwardee b/crypto/testdata/key_forwardee new file mode 100644 index 00000000..adf82ad1 --- /dev/null +++ b/crypto/testdata/key_forwardee @@ -0,0 +1,15 @@ +-----BEGIN PGP PRIVATE KEY BLOCK----- + +xVgEZAdtGBYJKwYBBAHaRw8BAQdAcNgHyRGEaqGmzEqEwCobfUkyrJnY8faBvsf9 +R2c5ZzYAAP9bFL4nPBdo04ei0C2IAh5RXOpmuejGC3GAIn/UmL5cYQ+XzRtjaGFy +bGVzIDxjaGFybGVzQHByb3Rvbi5tZT7CigQTFggAPAUCZAdtGAmQFXJtmBzDhdcW +IQRl2gNflypl1XjRUV8Vcm2YHMOF1wIbAwIeAQIZAQILBwIVCAIWAAIiAQAAJKYA +/2qY16Ozyo5erNz51UrKViEoWbEpwY3XaFVNzrw+b54YAQC7zXkf/t5ieylvjmA/ +LJz3/qgH5GxZRYAH9NTpWyW1AsdxBGQHbRgSCisGAQQBl1UBBQEBB0CxmxoJsHTW +TiETWh47ot+kwNA1hCk1IYB9WwKxkXYyIBf/CgmKXzV1ODP/mRmtiBYVV+VQk5MF +EAAA/1NW8D8nMc2ky140sPhQrwkeR7rVLKP2fe5n4BEtAnVQEB3CeAQYFggAKgUC +ZAdtGAmQFXJtmBzDhdcWIQRl2gNflypl1XjRUV8Vcm2YHMOF1wIbUAAAl/8A/iIS +zWBsBR8VnoOVfEE+VQk6YAi7cTSjcMjfsIez9FYtAQDKo9aCMhUohYyqvhZjn8aS +3t9mIZPc+zRJtCHzQYmhDg== +=lESj +-----END PGP PRIVATE KEY BLOCK----- \ No newline at end of file diff --git a/crypto/testdata/key_symmetric b/crypto/testdata/key_symmetric new file mode 100644 index 00000000..98f702f2 --- /dev/null +++ b/crypto/testdata/key_symmetric @@ -0,0 +1,15 @@ +-----BEGIN PGP PRIVATE KEY BLOCK----- + +xVgEYs/4KxYJKwYBBAHaRw8BAQdA7tIsntXluwloh/H62PJMqasjP00M86fv +/Pof9A968q8AAQDYcgkPKUdWAxsDjDHJfouPS4q5Me3ks+umlo5RJdwLZw4k +zQ1TeW1tZXRyaWMgS2V5wowEEBYKAB0FAmLP+CsECwkHCAMVCAoEFgACAQIZ +AQIbAwIeAQAhCRDkNhFDvaU8vxYhBDJNoyEFquVOCf99d+Q2EUO9pTy/5XQA +/1F2YPouv0ydBDJU3EOS/4bmPt7yqvzciWzeKVEOkzYuAP9OsP7q/5ccqOPX +mmRUKwd82/cNjdzdnWZ8Tq89XMwMAMdqBGLP+CtkCfFyZxOMF0BWLwAE8pLy +RVj2n2K7k6VvrhyuTqDkFDUFALiSLrEfnmTKlsPYS3/YzsODF354ccR63q73 +3lmCrvFRyaf6AHvVrBYPbJR+VhuTjZTwZKvPPKv0zVdSqi5JDEQiocJ4BBgW +CAAJBQJiz/grAhsMACEJEOQ2EUO9pTy/FiEEMk2jIQWq5U4J/3135DYRQ72l +PL+fEQEA7RaRbfa+AtiRN7a4GuqVEDZi3qtQZ2/Qcb27/LkAD0sA/3r9drYv +jyu46h1fdHHyo0HS2MiShZDZ8u60JnDltloD +=8TxH +-----END PGP PRIVATE KEY BLOCK----- \ No newline at end of file diff --git a/crypto/testdata/message_forwardee b/crypto/testdata/message_forwardee new file mode 100644 index 00000000..cd44ecf1 --- /dev/null +++ b/crypto/testdata/message_forwardee @@ -0,0 +1,8 @@ +-----BEGIN PGP MESSAGE----- + +wV4DB27Wn97eACkSAQdA62TlMU2QoGmf5iBLnIm4dlFRkLIg+6MbaatghwxK+Ccw +yGZuVVMAK/ypFfebDf4D/rlEw3cysv213m8aoK8nAUO8xQX3XQq3Sg+EGm0BNV8E +0kABEPyCWARoo5klT1rHPEhelnz8+RQXiOIX3G685XCWdCmaV+tzW082D0xGXSlC +7lM8r1DumNnO8srssko2qIja +=pVRa +-----END PGP MESSAGE----- \ No newline at end of file diff --git a/go.mod b/go.mod index 8d21b6cc..e36fa78e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ProtonMail/gopenpgp/v2 go 1.17 require ( - github.com/ProtonMail/go-crypto v1.1.0-alpha.1 + github.com/ProtonMail/go-crypto v1.1.0-alpha.1-proton github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.0 diff --git a/go.sum b/go.sum index 260c5803..59ae5ecd 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/ProtonMail/go-crypto v1.1.0-alpha.1 h1:iKLDnKGL+3u4Q5OjYgixAxWdkkGBPidCQumqVryUgtY= -github.com/ProtonMail/go-crypto v1.1.0-alpha.1/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +github.com/ProtonMail/go-crypto v1.1.0-alpha.1-proton h1:R+MMcIpg1nTjsYabIeFNR18j2V+3WT25xClrsrR0O6A= +github.com/ProtonMail/go-crypto v1.1.0-alpha.1-proton/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=