From 58fe53f60fdf591bd0498bc28b6f40399affef51 Mon Sep 17 00:00:00 2001 From: number571 Date: Thu, 24 Oct 2024 14:53:51 +0700 Subject: [PATCH] update --- pkg/client/client.go | 8 ++++---- pkg/client/client_test.go | 15 +++++++++++---- test/result/badge_codelines.svg | 2 +- test/result/coverage.svg | 10 +++++----- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 74fa1c60..a8f6a44f 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -109,9 +109,9 @@ func (p *sClient) encryptWithParams( cipher.EncryptBytes(joiner.NewBytesJoiner32([][]byte{ pkey.GetHasher().ToBytes(), salt, + data, hash, p.fPrivKey.GetDSAPrivKey().SignBytes(hash), - data, })), ).ToBytes(), nil } @@ -141,9 +141,9 @@ func (p *sClient) DecryptMessage(pMapPubKeys asymmetric.IMapPubKeys, pMsg []byte var ( pkid = decSlice[0] salt = decSlice[1] - hash = decSlice[2] - sign = decSlice[3] - data = decSlice[4] + data = decSlice[2] + hash = decSlice[3] + sign = decSlice[4] ) // Get public key from map by pkid (hash) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 83e4c9eb..2511daff 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -169,22 +169,29 @@ func TestDecrypt(t *testing.T) { return } + mapKeys := asymmetric.NewMapPubKeys(pubKey) + + if _, _, err := client.DecryptMessage(mapKeys, enc); err != nil { + t.Error(err) + return + } + enc[0] ^= 1 - if _, _, err := client.DecryptMessage(asymmetric.NewMapPubKeys(), enc); err == nil { + if _, _, err := client.DecryptMessage(mapKeys, enc); err == nil { t.Error("success decrypt with invalid ciphertext (2)") return } enc[0] ^= 1 enc[len(enc)-1] ^= 1 - if _, _, err := client.DecryptMessage(asymmetric.NewMapPubKeys(), enc); err == nil { + if _, _, err := client.DecryptMessage(mapKeys, enc); err == nil { t.Error("success decrypt with invalid ciphertext (3)") return } enc[len(enc)-1] ^= 1 - enc[len(enc)-2000] ^= 1 - if _, _, err := client.DecryptMessage(asymmetric.NewMapPubKeys(), enc); err == nil { + enc[asymmetric.CKEMCiphertextSize+symmetric.CCipherBlockSize+2*encoding.CSizeUint32+hashing.CHasherSize+1] ^= 1 + if _, _, err := client.DecryptMessage(mapKeys, enc); err == nil { t.Error("success decrypt with invalid ciphertext (4)") return } diff --git a/test/result/badge_codelines.svg b/test/result/badge_codelines.svg index 4e65c7da..4d068e9b 100644 --- a/test/result/badge_codelines.svg +++ b/test/result/badge_codelines.svg @@ -1 +1 @@ -code lines: 12543code lines12543 \ No newline at end of file +code lines: 12550code lines12550 \ No newline at end of file diff --git a/test/result/coverage.svg b/test/result/coverage.svg index a2916f48..de0fd1c9 100644 --- a/test/result/coverage.svg +++ b/test/result/coverage.svg @@ -7,7 +7,7 @@ > - + - + - + - + client.go