Skip to content

Commit 1c55d18

Browse files
addressing PR comments
1 parent 9835ddb commit 1c55d18

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

MLE.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ Configure global settings for request MLE using these properties in your `mercha
129129
### Object Configuration
130130

131131
- **Variable**: `mapToControlMLEonAPI`
132-
- **Type**: `Object` or `Map` with string keys and string/boolean values
132+
- **Type**: `Object` or `Map` with string keys and string values
133133
- **Description**: Overrides global MLE settings for specific APIs. The key is the API function name, and the value controls both request and response MLE.
134-
- **Example**: `{ "apiFunctionName": "true::true" }` or `{ "apiFunctionName": true }`
134+
- **Example**: `{ "apiFunctionName": "true::true" }`
135135

136136
#### Structure of Values in Object:
137137

138-
(i) **String format: "requestMLE::responseMLE"** - Control both request and response MLE
138+
(i) **"requestMLE::responseMLE"** - Control both request and response MLE
139139
- `"true::true"` - Enable both request and response MLE
140140
- `"false::false"` - Disable both request and response MLE
141141
- `"true::false"` - Enable request MLE, disable response MLE
@@ -145,9 +145,10 @@ Configure global settings for request MLE using these properties in your `mercha
145145
- `"::false"` - Use global setting for request, disable response MLE
146146
- `"false::"` - Disable request MLE, use global setting for response
147147

148-
(ii) **Boolean format** - Control request MLE only (response uses global setting)
149-
- `true` - Enable request MLE
150-
- `false` - Disable request MLE
148+
(ii) **"requestMLE"** - Control request MLE only (response uses global setting)
149+
- `"true"` - Enable request MLE
150+
- `"false"` - Disable request MLE
151+
151152

152153
<br/>
153154

@@ -194,10 +195,10 @@ var merchantConfig = {
194195
mleForRequestPublicCertPath: "/path/to/public/cert.pem",
195196
requestMleKeyAlias: "Custom_Key_Alias",
196197

197-
// API-specific control with boolean values
198+
// API-specific control with string values
198199
mapToControlMLEonAPI: {
199-
"createPayment": true, // Enable request MLE for this API
200-
"capturePayment": false // Disable request MLE for this API
200+
"createPayment": "true", // Enable request MLE for this API (simple format)
201+
"capturePayment": "false::" // Disable request MLE for this API (full format)
201202
}
202203
};
203204
```
@@ -386,16 +387,17 @@ For Response MLE private key files, the following formats are supported:
386387
- When both new and deprecated parameters are provided, the **new parameter takes precedence**
387388

388389
### (iv) API-level Control Validation
389-
- The `mapToControlMLEonAPI` values are validated for proper format
390-
- Invalid formats (empty values, multiple separators, non-boolean values) will cause configuration errors
390+
- The `mapToControlMLEonAPI` values are validated for proper format using string format
391+
- Invalid formats (empty values, multiple separators) will cause configuration errors
391392
- Empty string after `::` separator will use global defaults
392-
- The object also supports backward compatibility with boolean values, which will be automatically converted to control request MLE only
393+
- **Note**: Boolean values are supported for backward compatibility but are deprecated. Use string format for new implementations
393394

394395
### (v) Configuration Validation
395396
- The SDK performs comprehensive validation of MLE configuration parameters
396397
- Conflicting values between new and deprecated parameters will result in `ConfigException`
397398
- File path validation is performed for certificate and private key files
398-
- Invalid boolean values in `mapToControlMLEonAPI` will cause parsing errors
399+
- Invalid string format values in `mapToControlMLEonAPI` will cause parsing errors
400+
- **Note**: Boolean values in `mapToControlMLEonAPI` are deprecated but still supported for backward compatibility
399401

400402
<br/>
401403

src/authentication/core/MerchantConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ MerchantConfig.prototype.setResponseMlePrivateKey = function setResponseMlePriva
572572
const pemKey = Utility.parseAndReturnPem(
573573
responseMlePrivateKey,
574574
logger,
575-
this.responseMlePrivateKeyFilePassword
575+
this.responseMlePrivateKeyFilePassword,
576+
'responseMlePrivateKeyFilePassword'
576577
);
577578
logger.debug('Successfully parsed response MLE private key');
578579
this.responseMlePrivateKey = pemKey;

src/authentication/util/MLEUtility.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ exports.checkAndDecryptEncryptedResponse = function (responseBody, merchantConfi
7676
logger.debug('LOG_NETWORK_RESPONSE_BEFORE_MLE_DECRYPTION: ' + JSON.stringify(responseBody));
7777

7878
try {
79+
// Private key from config will take precedence over file path.
7980
const privateKey = merchantConfig.getResponseMlePrivateKey() ||
8081
Cache.getMleResponsePrivateKeyFromFilePath(merchantConfig);
8182

src/authentication/util/Utility.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ exports.readPrivateKeyFromPemFile = function(filePath, password, logger) {
284284
}
285285
};
286286

287-
exports.parseAndReturnPem = function(key, logger, password) {
287+
exports.parseAndReturnPem = function(key, logger, password, passwordPropertyName) {
288288
logger.debug(`Parsing private key to PEM format synchronously, key type: ${typeof key}`);
289289

290290
if (typeof key === 'string') {
@@ -298,8 +298,10 @@ exports.parseAndReturnPem = function(key, logger, password) {
298298

299299
// Check if password is provided for encrypted key
300300
if (!password || password.trim() === '') {
301-
logger.error('Password is required for encrypted private key');
302-
throw new Error('Password is required for encrypted private key');
301+
const propertyHint = passwordPropertyName ? ` Please set the '${passwordPropertyName}' property in your configuration.` : '';
302+
const errorMessage = `Password is required for encrypted private key.${propertyHint}`;
303+
logger.error(errorMessage);
304+
throw new Error(errorMessage);
303305
}
304306

305307
try {

0 commit comments

Comments
 (0)