Skip to content

Commit

Permalink
Switch go-crypto to proton branch and add tests for forwarding and sy…
Browse files Browse the repository at this point in the history
…mmetric keys
  • Loading branch information
wussler authored and lubux committed Nov 27, 2024
1 parent da88829 commit 280d7e4
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
77 changes: 77 additions & 0 deletions crypto/proton_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package crypto

import (
"encoding/base64"
"testing"

"github.com/stretchr/testify/assert"
)

func TestForwardeeDecryption(t *testing.T) {
//pgp.latestServerTime = 1679044110

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 := readTestFile("message_forwardee", false)
decryptor, err := PGP().Decryption().
DecryptionKeys(forwardeeKeyRing).
VerifyTime(1679044110).
New()
if err != nil {
t.Fatal(err)
}
plainMessage, err := decryptor.Decrypt([]byte(pgpMessage), Armor)
if err != nil {
t.Fatal("Expected no error while decrypting/verifying, got:", err)
}

assert.Exactly(t, "Message for Bob", plainMessage.String())
}

func TestSymmetricKeys(t *testing.T) {
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=")
pgp := PGP()
encryptor, err := pgp.Encryption().
Recipients(symmetricKeyRing).
SignTime(1679044110).
New()
if err != nil {
t.Fatal(err)
}

ciphertext, err := encryptor.Encrypt(binData)
if err != nil {
t.Fatal("Expected no error when encrypting, got:", err)
}

decryptor, err := pgp.Decryption().
DecryptionKeys(symmetricKeyRing).
VerifyTime(1679044110).
New()
if err != nil {
t.Fatal(err)
}
decrypted, err := decryptor.Decrypt(ciphertext.Bytes(), Bytes)
if err != nil {
t.Fatal("Expected no error when decrypting, got:", err)
}
assert.Exactly(t, binData, decrypted.Bytes())
}
15 changes: 15 additions & 0 deletions crypto/testdata/key_forwardee
Original file line number Diff line number Diff line change
@@ -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-----
15 changes: 15 additions & 0 deletions crypto/testdata/key_symmetric
Original file line number Diff line number Diff line change
@@ -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-----
8 changes: 8 additions & 0 deletions crypto/testdata/message_forwardee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-----BEGIN PGP MESSAGE-----

wV4DB27Wn97eACkSAQdA62TlMU2QoGmf5iBLnIm4dlFRkLIg+6MbaatghwxK+Ccw
yGZuVVMAK/ypFfebDf4D/rlEw3cysv213m8aoK8nAUO8xQX3XQq3Sg+EGm0BNV8E
0kABEPyCWARoo5klT1rHPEhelnz8+RQXiOIX3G685XCWdCmaV+tzW082D0xGXSlC
7lM8r1DumNnO8srssko2qIja
=pVRa
-----END PGP MESSAGE-----

0 comments on commit 280d7e4

Please sign in to comment.