Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 0002dda

Browse files
Merge pull request #12 from talha-API/main
Adding support for A128/192GCM decryption
2 parents 1009e22 + dbeb8cd commit 0002dda

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

lib/mcapi/encryption/crypto/jwe-crypto.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def decrypt_data(encrypted_data:)
8484

8585
if enc_method == "A256GCM"
8686
enc_string = "aes-256-gcm"
87+
elsif enc_method == "A128GCM"
88+
enc_string = "aes-128-gcm"
89+
elsif enc_method == "A192GCM"
90+
enc_string = "aes-192-gcm"
8791
elsif enc_method == "A128CBC-HS256"
8892
cek = cek.byteslice(16, cek.length)
8993
enc_string = "aes-128-cbc"
@@ -98,6 +102,12 @@ def decrypt_data(encrypted_data:)
98102
if enc_method == "A256GCM"
99103
cipher.auth_data = encrypted_header
100104
cipher.auth_tag = cipher_tag
105+
elsif enc_method == "A128GCM"
106+
cipher.auth_data = encrypted_header
107+
cipher.auth_tag = cipher_tag
108+
elsif enc_method == "A192GCM"
109+
cipher.auth_data = encrypted_header
110+
cipher.auth_tag = cipher_tag
101111
end
102112

103113
cipher.update(cipher_text) + cipher.final
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"request": {
3+
"url": "/resource"
4+
},
5+
"body": {
6+
"encrypted_data":"eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.WtvYljbsjdEv-Ttxx1p6PgyIrOsLpj1FMF9NQNhJUAHlKchAo5QImgEgIdgJE7HC2KfpNcHiQVqKKZq_y201FVzpicDkNzlPJr5kIH4Lq-oC5iP0agWeou9yK5vIxFRP__F_B8HSuojBJ3gDYT_KdYffUIHkm_UysNj4PW2RIRlafJ6RKYanVzk74EoKZRG7MIr3pTU6LIkeQUW41qYG8hz6DbGBOh79Nkmq7Oceg0ZwCn1_MruerP-b15SGFkuvOshStT5JJp7OOq82gNAOkMl4fylEj2-vADjP7VSK8GlqrA7u9Tn-a4Q28oy0GOKr1Z-HJgn_CElknwkUTYsWbg.PKl6_kvZ4_4MjmjW.AH6pGFkn7J49hBQcwg.zdyD73TcuveImOy4CRnVpw"
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"request": {
3+
"url": "/resource"
4+
},
5+
"body": {
6+
"encrypted_data":"eyJlbmMiOiJBMTkyR0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.FWC8PVaZoR2TRKwKO4syhSJReezVIvtkxU_yKh4qODNvlVr8t8ttvySJ-AjM8xdI6vNyIg9jBMWASG4cE49jT9FYuQ72fP4R-Td4vX8wpB8GonQj40yLqZyfRLDrMgPR20RcQDW2ThzLXsgI55B5l5fpwQ9Nhmx8irGifrFWOcJ_k1dUSBdlsHsYxkjRKMENu5x4H6h12gGZ21aZSPtwAj9msMYnKLdiUbdGmGG_P8a6gPzc9ih20McxZk8fHzXKujjukr_1p5OO4o1N4d3qa-YI8Sns2fPtf7xPHnwi1wipmCC6ThFLU80r3173RXcpyZkF8Y3UacOS9y1f8eUfVQ.JRE7kZLN4Im1Rtdb.eW_lJ-U330n0QHqZnQ._r5xYVvMCrvICwLz4chjdw"
7+
}
8+
}

test/test_jwe_encryption.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,29 @@ def test_decrypt_field_level
8585
assert !decrypted['body']['encrypted_payload']
8686
end
8787

88-
def test_decrypt_gcm
89-
resp = File.read('./test/mock/jwe-response-gcm.json')
88+
def test_decrypt_a256gcm
89+
resp = File.read('./test/mock/jwe-response-a256gcm.json')
9090
jwe = McAPI::Encryption::JweEncryption.new(@test_config)
9191
decrypted = JSON.parse(jwe.decrypt(resp))
9292
assert_equal decrypted['body']['mapping']['customer_identifier'], 'CUST_12345'
9393
assert !decrypted['body']['encrypted_data']
9494
end
95+
96+
def test_decrypt_a128gcm
97+
resp = File.read('./test/mock/jwe-response-a128gcm.json')
98+
jwe = McAPI::Encryption::JweEncryption.new(@test_config)
99+
decrypted = JSON.parse(jwe.decrypt(resp))
100+
assert_equal decrypted['body']['foo'], 'bar'
101+
assert !decrypted['body']['encrypted_data']
102+
end
103+
104+
def test_decrypt_a192gcm
105+
resp = File.read('./test/mock/jwe-response-a192gcm.json')
106+
jwe = McAPI::Encryption::JweEncryption.new(@test_config)
107+
decrypted = JSON.parse(jwe.decrypt(resp))
108+
assert_equal decrypted['body']['foo'], 'bar'
109+
assert !decrypted['body']['encrypted_data']
110+
end
95111

96112
def test_decrypt_cbc
97113
resp = File.read('./test/mock/jwe-response-cbc.json')

0 commit comments

Comments
 (0)