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

Commit 21890be

Browse files
* Removing support for p12 key loading due to issue with OpenSSL 3+
* Updated README to show how key should be loaded instead * Bumping version to 1.3.2
1 parent e0dfd72 commit 21890be

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [References](#references)
1717
- [Usage](#usage)
1818
- [Prerequisites](#prerequisites)
19+
- [Loading the Decryption Key](#loading-the-decryption-key)
1920
- [Adding the Library to Your Project](#adding-the-libraries-to-your-project)
2021
- [Performing Field Level Encryption and Decryption](#performing-payload-encryption-and-decryption)
2122
- [Integrating with OpenAPI Generator API Client Libraries](#integrating-with-openapi-generator-api-client-libraries)
@@ -44,6 +45,21 @@ As part of this set up, you'll receive:
4445
- A public request encryption certificate (aka _Client Encryption Keys_)
4546
- A private response decryption key (aka _Mastercard Encryption Keys_)
4647

48+
#### Loading the Decryption Key <a name="loading-the-decryption-key"></a>
49+
50+
By default, the decryption key will be given in as a PKCS#12 password-protected file.
51+
The key can be loaded using either of the 2 methods below.
52+
53+
1. The following code shows how to load the decryption key using `OpenSSL`:
54+
```ruby
55+
require 'openssl'
56+
57+
is = File.binread("<insert PKCS#12 key file path>");
58+
signing_key = OpenSSL::PKCS12.new(is, "<insert key password>").key;
59+
```
60+
61+
2. Follow our guide on [Exporting Your Signing Key](https://developer.mastercard.com/platform/documentation/security-and-authentication/using-oauth-1a-to-access-mastercard-apis/#exporting-your-signing-key)
62+
4763
### Installation <a name="adding-the-libraries-to-your-project"></a>
4864

4965
If you want to use **mastercard-client-encryption** with [Ruby](https://www.ruby-lang.org/en/), it is available as Gem:

lib/mcapi/encryption/crypto/crypto.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def initialize(config)
2323
@cert = OpenSSL::X509::Certificate.new(IO.binread(config['encryptionCertificate']))
2424
if config['privateKey']
2525
@private_key = OpenSSL::PKey.read(IO.binread(config['privateKey']))
26-
elsif config['keyStore']
27-
@private_key = OpenSSL::PKCS12.new(IO.binread(config['keyStore']), config['keyStorePassword']).key
2826
end
2927
@oaep_hashing_alg = config['oaepPaddingDigestAlgorithm']
3028
@encrypted_value_field_name = config['encryptedValueFieldName']

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def initialize(config)
2323
@cert = OpenSSL::X509::Certificate.new(IO.binread(config['encryptionCertificate']))
2424
if config['privateKey']
2525
@private_key = OpenSSL::PKey.read(IO.binread(config['privateKey']))
26-
elsif config['keyStore']
27-
@private_key = OpenSSL::PKCS12.new(IO.binread(config['keyStore']), config['keyStorePassword']).key
2826
end
2927
@encrypted_value_field_name = config['encryptedValueFieldName'] || 'encryptedData'
3028
@public_key_fingerprint = compute_public_fingerprint

mastercard-client-encryption.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = 'mastercard-client-encryption'
5-
spec.version = '1.3.1'
5+
spec.version = '1.3.2'
66
spec.authors = ['Mastercard']
77
spec.required_ruby_version = '>= 2.4.4'
88

test/test_crypto_config.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ def test_fingerprint_public_certificate_ok__b64
6363
assert_equal 'Z+gOGbilDalFcm4yZyYj1pr/N1qdg8QYECbsTvu3yAA=', fingerprint
6464
end
6565

66-
def test_config_with_private_keystore
67-
config = @test_config.dup
68-
config.delete('privateKey')
69-
config['keyStore'] = './test/res/test_key.p12'
70-
config['keyStoreAlias'] = 'mykeyalias'
71-
config['keyStorePassword'] = 'Password1'
72-
crypto = McAPI::Encryption::Crypto.new(config)
73-
assert(crypto)
74-
end
75-
7666
def test_fingerprint_wrong_type
7767
crypto = McAPI::Encryption::Crypto.new(@test_config)
7868
assert_exp_equals(RuntimeError, 'Selected public fingerprint not supported') do

0 commit comments

Comments
 (0)