summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-20 23:08:01 +0700
committerShulhan <ms@kilabit.info>2023-09-20 23:08:01 +0700
commitc059dcca2a54919a1111bc1a2b286e11b4fc4d36 (patch)
treeb721a8c6a301532f746b2b064d6978b886e2203f
parent1307df8af1926698819bc593e0aed91e57ff68d2 (diff)
downloadawwan-c059dcca2a54919a1111bc1a2b286e11b4fc4d36.tar.xz
all: replace rsa.Decrypt/EncryptOAEP with libcrypto.Decrypt/EncryptOaep
The rsa.EncryptAOEP function has a maximum message size that they can encrypt (public key size - 2*hash.Size - 2). To fix this limitation we replace them with the one in libcrypto that extend the functions to allow encrypting and decrypting a larger message.
-rw-r--r--awwan.go4
-rw-r--r--awwan_test.go2
-rw-r--r--go.mod2
-rw-r--r--go.sum4
4 files changed, 6 insertions, 6 deletions
diff --git a/awwan.go b/awwan.go
index ce8c9ac..ced84cd 100644
--- a/awwan.go
+++ b/awwan.go
@@ -145,7 +145,7 @@ func (aww *Awwan) Decrypt(fileVault string) (filePlain string, err error) {
plaintext []byte
)
- plaintext, err = rsa.DecryptOAEP(hash, rand.Reader, aww.privateKey, ciphertext, label)
+ plaintext, err = libcrypto.DecryptOaep(hash, rand.Reader, aww.privateKey, ciphertext, label)
if err != nil {
return ``, fmt.Errorf(`%s: %w`, logp, err)
}
@@ -190,7 +190,7 @@ func (aww *Awwan) Encrypt(file string) (err error) {
ciphertext []byte
)
- ciphertext, err = rsa.EncryptOAEP(hash, rand.Reader, &aww.privateKey.PublicKey, src, label)
+ ciphertext, err = libcrypto.EncryptOaep(hash, rand.Reader, &aww.privateKey.PublicKey, src, label)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
diff --git a/awwan_test.go b/awwan_test.go
index f3949ab..1669158 100644
--- a/awwan_test.go
+++ b/awwan_test.go
@@ -34,7 +34,7 @@ func TestAwwanDecrypt(t *testing.T) {
baseDir: filepath.Join(`testdata`, `decrypt-wrong-privatekey`),
fileVault: `.awwan.env.vault`,
passphrase: "news3cret\r",
- expError: `Decrypt: crypto/rsa: decryption error`,
+ expError: `Decrypt: DecryptOaep: crypto/rsa: decryption error`,
}}
var (
diff --git a/go.mod b/go.mod
index df6edef..308cadd 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,7 @@ go 1.20
require (
git.sr.ht/~shulhan/ciigo v0.10.0
github.com/evanw/esbuild v0.17.10
- github.com/shuLhan/share v0.49.2-0.20230919175205-3b7ac793264a
+ github.com/shuLhan/share v0.49.2-0.20230920155045-e35459d8d13e
)
require (
diff --git a/go.sum b/go.sum
index 3d859ee..a86e3a2 100644
--- a/go.sum
+++ b/go.sum
@@ -4,8 +4,8 @@ git.sr.ht/~shulhan/ciigo v0.10.0 h1:s1SJ3/NzBcbOLmEZ4z1Cx9Vf7ZdDIvm45b7KMCZKzEY=
git.sr.ht/~shulhan/ciigo v0.10.0/go.mod h1:cG6av+ywJZZp96F43kmLB2QWjm2hYiahbsbeTX/vlgk=
github.com/evanw/esbuild v0.17.10 h1:RMwM8ehohA6RSgWVirjnsZ+u9ttNt0gWfRLYCxUbAoc=
github.com/evanw/esbuild v0.17.10/go.mod h1:iINY06rn799hi48UqEnaQvVfZWe6W9bET78LbvN8VWk=
-github.com/shuLhan/share v0.49.2-0.20230919175205-3b7ac793264a h1:7ohg2TOplcnbhfGiIdkPb1fn3D3Qph0ZDRMOkxwM580=
-github.com/shuLhan/share v0.49.2-0.20230919175205-3b7ac793264a/go.mod h1:i5/MNWUy/B+b76J96VTNG8HLE/xZ8mVy+i0oR51y6Jc=
+github.com/shuLhan/share v0.49.2-0.20230920155045-e35459d8d13e h1:rsR3V02nrcSqx6IyZ0YEPekDcBWh3a2D4NJHJF5edXg=
+github.com/shuLhan/share v0.49.2-0.20230920155045-e35459d8d13e/go.mod h1:i5/MNWUy/B+b76J96VTNG8HLE/xZ8mVy+i0oR51y6Jc=
github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc=