Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Oct 24, 2024
1 parent 56851b9 commit 58fe53f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
8 changes: 4 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions test/result/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 58fe53f

Please sign in to comment.