Change time global handling (#29)
* Reverse time * Change time handling global * Remove debug functions * Remove *pgp methods
This commit is contained in:
parent
d398098113
commit
136c0a5495
23 changed files with 154 additions and 138 deletions
|
|
@ -10,7 +10,7 @@ import (
|
|||
// SignCleartextMessageArmored signs text given a private key and its passphrase, canonicalizes and trims the newlines,
|
||||
// and returns the PGP-compliant special armoring
|
||||
func SignCleartextMessageArmored(privateKey, passphrase, text string) (string, error) {
|
||||
signingKeyRing, err := pgp.BuildKeyRingArmored(privateKey)
|
||||
signingKeyRing, err := crypto.BuildKeyRingArmored(privateKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ func SignCleartextMessageArmored(privateKey, passphrase, text string) (string, e
|
|||
// VerifyCleartextMessageArmored verifies PGP-compliant armored signed plain text given the public key
|
||||
// and returns the text or err if the verification fails
|
||||
func VerifyCleartextMessageArmored(publicKey, armored string, verifyTime int64) (string, error) {
|
||||
verifyKeyRing, err := pgp.BuildKeyRingArmored(publicKey)
|
||||
verifyKeyRing, err := crypto.BuildKeyRingArmored(publicKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/ProtonMail/gopenpgp/crypto"
|
||||
)
|
||||
|
||||
const signedPlainText = "Signed message\n"
|
||||
|
|
@ -29,7 +30,7 @@ func TestSignClearText(t *testing.T) {
|
|||
verified, err := VerifyCleartextMessageArmored(
|
||||
readTestFile("keyring_publicKey", false),
|
||||
armored,
|
||||
pgp.GetUnixTime(),
|
||||
crypto.GetUnixTime(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot verify message:", err)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import (
|
|||
"github.com/ProtonMail/gopenpgp/crypto"
|
||||
)
|
||||
|
||||
var pgp = crypto.GetGopenPGP()
|
||||
|
||||
// EncryptMessageWithToken encrypts a string with a passphrase using AES256
|
||||
func EncryptMessageWithToken(
|
||||
passphrase, plaintext string,
|
||||
|
|
@ -62,7 +60,7 @@ func EncryptMessageArmored(publicKey, plaintext string) (ciphertext string, err
|
|||
|
||||
var message = crypto.NewPlainMessageFromString(plaintext)
|
||||
|
||||
if publicKeyRing, err = pgp.BuildKeyRingArmored(publicKey); err != nil {
|
||||
if publicKeyRing, err = crypto.BuildKeyRingArmored(publicKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
@ -87,11 +85,11 @@ func EncryptSignMessageArmored(
|
|||
|
||||
var message = crypto.NewPlainMessageFromString(plaintext)
|
||||
|
||||
if publicKeyRing, err = pgp.BuildKeyRingArmored(publicKey); err != nil {
|
||||
if publicKeyRing, err = crypto.BuildKeyRingArmored(publicKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if privateKeyRing, err = pgp.BuildKeyRingArmored(privateKey); err != nil {
|
||||
if privateKeyRing, err = crypto.BuildKeyRingArmored(privateKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +116,7 @@ func DecryptMessageArmored(
|
|||
var pgpMessage *crypto.PGPMessage
|
||||
var message *crypto.PlainMessage
|
||||
|
||||
if privateKeyRing, err = pgp.BuildKeyRingArmored(privateKey); err != nil {
|
||||
if privateKeyRing, err = crypto.BuildKeyRingArmored(privateKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
@ -147,11 +145,11 @@ func DecryptVerifyMessageArmored(
|
|||
var pgpMessage *crypto.PGPMessage
|
||||
var message *crypto.PlainMessage
|
||||
|
||||
if publicKeyRing, err = pgp.BuildKeyRingArmored(publicKey); err != nil {
|
||||
if publicKeyRing, err = crypto.BuildKeyRingArmored(publicKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if privateKeyRing, err = pgp.BuildKeyRingArmored(privateKey); err != nil {
|
||||
if privateKeyRing, err = crypto.BuildKeyRingArmored(privateKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +161,7 @@ func DecryptVerifyMessageArmored(
|
|||
return "", err
|
||||
}
|
||||
|
||||
if message, err = privateKeyRing.Decrypt(pgpMessage, publicKeyRing, pgp.GetUnixTime()); err != nil {
|
||||
if message, err = privateKeyRing.Decrypt(pgpMessage, publicKeyRing, crypto.GetUnixTime()); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
@ -183,11 +181,11 @@ func EncryptSignAttachment(
|
|||
|
||||
var binMessage = crypto.NewPlainMessage(plainData)
|
||||
|
||||
if publicKeyRing, err = pgp.BuildKeyRingArmored(publicKey); err != nil {
|
||||
if publicKeyRing, err = crypto.BuildKeyRingArmored(publicKey); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
if privateKeyRing, err = pgp.BuildKeyRingArmored(privateKey); err != nil {
|
||||
if privateKeyRing, err = crypto.BuildKeyRingArmored(privateKey); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
|
|
@ -220,11 +218,11 @@ func DecryptVerifyAttachment(
|
|||
|
||||
var packets = crypto.NewPGPSplitMessage(keyPacket, dataPacket)
|
||||
|
||||
if publicKeyRing, err = pgp.BuildKeyRingArmored(publicKey); err != nil {
|
||||
if publicKeyRing, err = crypto.BuildKeyRingArmored(publicKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if privateKeyRing, err = pgp.BuildKeyRingArmored(privateKey); err != nil {
|
||||
if privateKeyRing, err = crypto.BuildKeyRingArmored(privateKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -240,7 +238,7 @@ func DecryptVerifyAttachment(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if publicKeyRing.VerifyDetached(message, detachedSignature, pgp.GetUnixTime()) != nil {
|
||||
if publicKeyRing.VerifyDetached(message, detachedSignature, crypto.GetUnixTime()) != nil {
|
||||
return nil, errors.New("gopenpgp: unable to verify attachment")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func TestArmoredTextMessageEncryption(t *testing.T) {
|
|||
t.Fatal("Expected no error when encrypting, got:", err)
|
||||
}
|
||||
|
||||
assert.Exactly(t, true, pgp.IsPGPMessage(armored))
|
||||
assert.Exactly(t, true, crypto.IsPGPMessage(armored))
|
||||
|
||||
decrypted, err := DecryptMessageArmored(
|
||||
readTestFile("keyring_privateKey", false),
|
||||
|
|
@ -62,7 +62,7 @@ func TestArmoredTextMessageEncryptionVerification(t *testing.T) {
|
|||
t.Fatal("Expected no error when encrypting, got:", err)
|
||||
}
|
||||
|
||||
assert.Exactly(t, true, pgp.IsPGPMessage(armored))
|
||||
assert.Exactly(t, true, crypto.IsPGPMessage(armored))
|
||||
|
||||
_, err = DecryptVerifyMessageArmored(
|
||||
readTestFile("mime_publicKey", false), // Wrong public key
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
)
|
||||
|
||||
func TestIOSSignedMessageDecryption(t *testing.T) {
|
||||
testPrivateKeyRing, _ := pgp.BuildKeyRingArmored(readTestFile("keyring_privateKey", false))
|
||||
testPublicKeyRing, _ := pgp.BuildKeyRingArmored(readTestFile("mime_publicKey", false))
|
||||
testPrivateKeyRing, _ := crypto.BuildKeyRingArmored(readTestFile("keyring_privateKey", false))
|
||||
testPublicKeyRing, _ := crypto.BuildKeyRingArmored(readTestFile("mime_publicKey", false))
|
||||
|
||||
// Password defined in base_test
|
||||
err := testPrivateKeyRing.UnlockWithPassphrase(testMailboxPassword)
|
||||
|
|
@ -23,7 +23,7 @@ func TestIOSSignedMessageDecryption(t *testing.T) {
|
|||
t.Fatal("Expected no error when unarmoring, got:", err)
|
||||
}
|
||||
|
||||
decrypted, err := DecryptExplicitVerify(pgpMessage, testPrivateKeyRing, testPublicKeyRing, pgp.GetUnixTime())
|
||||
decrypted, err := DecryptExplicitVerify(pgpMessage, testPrivateKeyRing, testPublicKeyRing, crypto.GetUnixTime())
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when decrypting, got:", err)
|
||||
}
|
||||
|
|
@ -31,14 +31,14 @@ func TestIOSSignedMessageDecryption(t *testing.T) {
|
|||
assert.Exactly(t, constants.SIGNATURE_NO_VERIFIER, decrypted.SignatureVerificationError.Status)
|
||||
assert.Exactly(t, readTestFile("message_plaintext", true), decrypted.Message.GetString())
|
||||
|
||||
testPublicKeyRing, _ = pgp.BuildKeyRingArmored(readTestFile("keyring_publicKey", false))
|
||||
testPublicKeyRing, _ = crypto.BuildKeyRingArmored(readTestFile("keyring_publicKey", false))
|
||||
|
||||
pgpMessage, err = testPublicKeyRing.Encrypt(decrypted.Message, testPrivateKeyRing)
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when encrypting, got:", err)
|
||||
}
|
||||
|
||||
decrypted, err = DecryptExplicitVerify(pgpMessage, testPrivateKeyRing, testPublicKeyRing, pgp.GetUnixTime())
|
||||
decrypted, err = DecryptExplicitVerify(pgpMessage, testPrivateKeyRing, testPublicKeyRing, crypto.GetUnixTime())
|
||||
if err != nil {
|
||||
t.Fatal("Expected no error when decrypting, got:", err)
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func TestIOSSignedMessageDecryption(t *testing.T) {
|
|||
assert.Nil(t, decrypted.SignatureVerificationError)
|
||||
assert.Exactly(t, readTestFile("message_plaintext", true), decrypted.Message.GetString())
|
||||
|
||||
decrypted, err = DecryptExplicitVerify(pgpMessage, testPublicKeyRing, testPublicKeyRing, pgp.GetUnixTime())
|
||||
decrypted, err = DecryptExplicitVerify(pgpMessage, testPublicKeyRing, testPublicKeyRing, crypto.GetUnixTime())
|
||||
assert.NotNil(t, err)
|
||||
assert.Nil(t, decrypted)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue