cybersource_rest_client 0.0.75 → 0.0.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/lib/AuthenticationSDK/authentication/jwt/JwtToken.rb +6 -17
  3. data/lib/AuthenticationSDK/core/MerchantConfig.rb +132 -54
  4. data/lib/AuthenticationSDK/util/Cache.rb +135 -30
  5. data/lib/AuthenticationSDK/util/CacheValue.rb +18 -0
  6. data/lib/AuthenticationSDK/util/CertificateUtility.rb +124 -0
  7. data/lib/AuthenticationSDK/util/Constants.rb +6 -0
  8. data/lib/AuthenticationSDK/util/JWEUtility.rb +1 -2
  9. data/lib/AuthenticationSDK/util/MLEUtility.rb +26 -35
  10. data/lib/AuthenticationSDK/util/Utility.rb +1 -16
  11. data/lib/cybersource_rest_client/api/batches_api.rb +17 -17
  12. data/lib/cybersource_rest_client/api/billing_agreements_api.rb +6 -6
  13. data/lib/cybersource_rest_client/api/bin_lookup_api.rb +2 -2
  14. data/lib/cybersource_rest_client/api/capture_api.rb +2 -2
  15. data/lib/cybersource_rest_client/api/chargeback_details_api.rb +2 -2
  16. data/lib/cybersource_rest_client/api/chargeback_summaries_api.rb +2 -2
  17. data/lib/cybersource_rest_client/api/conversion_details_api.rb +2 -2
  18. data/lib/cybersource_rest_client/api/create_new_webhooks_api.rb +6 -6
  19. data/lib/cybersource_rest_client/api/credit_api.rb +2 -2
  20. data/lib/cybersource_rest_client/api/customer_api.rb +8 -8
  21. data/lib/cybersource_rest_client/api/customer_payment_instrument_api.rb +10 -10
  22. data/lib/cybersource_rest_client/api/customer_shipping_address_api.rb +10 -10
  23. data/lib/cybersource_rest_client/api/decision_manager_api.rb +10 -10
  24. data/lib/cybersource_rest_client/api/device_de_association_api.rb +7 -7
  25. data/lib/cybersource_rest_client/api/device_search_api.rb +10 -10
  26. data/lib/cybersource_rest_client/api/download_dtd_api.rb +2 -2
  27. data/lib/cybersource_rest_client/api/download_xsd_api.rb +2 -2
  28. data/lib/cybersource_rest_client/api/emv_tag_details_api.rb +4 -4
  29. data/lib/cybersource_rest_client/api/flex_api_api.rb +2 -2
  30. data/lib/cybersource_rest_client/api/instrument_identifier_api.rb +12 -12
  31. data/lib/cybersource_rest_client/api/interchange_clearing_level_details_api.rb +2 -2
  32. data/lib/cybersource_rest_client/api/invoice_settings_api.rb +4 -4
  33. data/lib/cybersource_rest_client/api/invoices_api.rb +87 -12
  34. data/lib/cybersource_rest_client/api/manage_webhooks_api.rb +18 -17
  35. data/lib/cybersource_rest_client/api/merchant_boarding_api.rb +4 -4
  36. data/lib/cybersource_rest_client/api/microform_integration_api.rb +2 -2
  37. data/lib/cybersource_rest_client/api/net_fundings_api.rb +2 -2
  38. data/lib/cybersource_rest_client/api/notification_of_changes_api.rb +2 -2
  39. data/lib/cybersource_rest_client/api/orders_api.rb +4 -4
  40. data/lib/cybersource_rest_client/api/payer_authentication_api.rb +6 -6
  41. data/lib/cybersource_rest_client/api/payment_batch_summaries_api.rb +2 -2
  42. data/lib/cybersource_rest_client/api/payment_instrument_api.rb +8 -8
  43. data/lib/cybersource_rest_client/api/payment_links_api.rb +12 -12
  44. data/lib/cybersource_rest_client/api/payment_tokens_api.rb +2 -2
  45. data/lib/cybersource_rest_client/api/payments_api.rb +12 -12
  46. data/lib/cybersource_rest_client/api/payouts_api.rb +2 -2
  47. data/lib/cybersource_rest_client/api/plans_api.rb +16 -16
  48. data/lib/cybersource_rest_client/api/purchase_and_refund_details_api.rb +2 -2
  49. data/lib/cybersource_rest_client/api/push_funds_api.rb +2 -2
  50. data/lib/cybersource_rest_client/api/refund_api.rb +4 -4
  51. data/lib/cybersource_rest_client/api/report_definitions_api.rb +4 -4
  52. data/lib/cybersource_rest_client/api/report_downloads_api.rb +2 -2
  53. data/lib/cybersource_rest_client/api/report_subscriptions_api.rb +10 -10
  54. data/lib/cybersource_rest_client/api/reports_api.rb +6 -6
  55. data/lib/cybersource_rest_client/api/retrieval_details_api.rb +2 -2
  56. data/lib/cybersource_rest_client/api/retrieval_summaries_api.rb +2 -2
  57. data/lib/cybersource_rest_client/api/reversal_api.rb +4 -4
  58. data/lib/cybersource_rest_client/api/search_transactions_api.rb +4 -4
  59. data/lib/cybersource_rest_client/api/secure_file_share_api.rb +4 -4
  60. data/lib/cybersource_rest_client/api/subscriptions_api.rb +16 -16
  61. data/lib/cybersource_rest_client/api/subscriptions_follow_ons_api.rb +4 -4
  62. data/lib/cybersource_rest_client/api/taxes_api.rb +4 -4
  63. data/lib/cybersource_rest_client/api/token_api.rb +4 -4
  64. data/lib/cybersource_rest_client/api/tokenized_card_api.rb +6 -6
  65. data/lib/cybersource_rest_client/api/transaction_batches_api.rb +8 -8
  66. data/lib/cybersource_rest_client/api/transaction_details_api.rb +2 -2
  67. data/lib/cybersource_rest_client/api/transient_token_data_api.rb +4 -4
  68. data/lib/cybersource_rest_client/api/unified_checkout_capture_context_api.rb +2 -2
  69. data/lib/cybersource_rest_client/api/user_management_api.rb +2 -2
  70. data/lib/cybersource_rest_client/api/user_management_search_api.rb +2 -2
  71. data/lib/cybersource_rest_client/api/verification_api.rb +4 -4
  72. data/lib/cybersource_rest_client/api/void_api.rb +10 -10
  73. data/lib/cybersource_rest_client/api_client.rb +3 -1
  74. data/lib/cybersource_rest_client/ethon_extensions.rb +38 -0
  75. data/lib/cybersource_rest_client/models/create_order_request.rb +269 -269
  76. data/lib/cybersource_rest_client/models/create_webhook.rb +16 -3
  77. data/lib/cybersource_rest_client/models/inline_response_200_10.rb +47 -49
  78. data/lib/cybersource_rest_client/models/{inline_response_200_8__links.rb → inline_response_200_10__links.rb} +18 -17
  79. data/lib/cybersource_rest_client/models/{inline_response_200_9__links_report.rb → inline_response_200_10__links_report.rb} +1 -1
  80. data/lib/cybersource_rest_client/models/{inline_response_200_9_billing.rb → inline_response_200_10_billing.rb} +1 -1
  81. data/lib/cybersource_rest_client/models/inline_response_200_11.rb +292 -0
  82. data/lib/cybersource_rest_client/models/{inline_response_200_10_records.rb → inline_response_200_11_records.rb} +3 -3
  83. data/lib/cybersource_rest_client/models/{inline_response_200_10_response_record.rb → inline_response_200_11_response_record.rb} +2 -2
  84. data/lib/cybersource_rest_client/models/{inline_response_200_10_response_record_additional_updates.rb → inline_response_200_11_response_record_additional_updates.rb} +1 -1
  85. data/lib/cybersource_rest_client/models/{inline_response_200_10_source_record.rb → inline_response_200_11_source_record.rb} +1 -1
  86. data/lib/cybersource_rest_client/models/inline_response_200_2.rb +253 -253
  87. data/lib/cybersource_rest_client/models/inline_response_200_4.rb +12 -10
  88. data/lib/cybersource_rest_client/models/inline_response_200_5.rb +129 -51
  89. data/lib/cybersource_rest_client/models/inline_response_200_6.rb +55 -10
  90. data/lib/cybersource_rest_client/models/{inline_response_200_5_devices.rb → inline_response_200_6_devices.rb} +1 -1
  91. data/lib/cybersource_rest_client/models/inline_response_200_7.rb +10 -55
  92. data/lib/cybersource_rest_client/models/inline_response_200_8.rb +33 -37
  93. data/lib/cybersource_rest_client/models/{inline_response_200_7_devices.rb → inline_response_200_8_devices.rb} +2 -2
  94. data/lib/cybersource_rest_client/models/{inline_response_200_7_payment_processor_to_terminal_map.rb → inline_response_200_8_payment_processor_to_terminal_map.rb} +1 -1
  95. data/lib/cybersource_rest_client/models/inline_response_200_9.rb +47 -86
  96. data/lib/cybersource_rest_client/models/{inline_response_200_8__embedded.rb → inline_response_200_9__embedded.rb} +2 -2
  97. data/lib/cybersource_rest_client/models/{inline_response_200_8__embedded__links.rb → inline_response_200_9__embedded__links.rb} +2 -2
  98. data/lib/cybersource_rest_client/models/{inline_response_200_8__embedded__links_reports.rb → inline_response_200_9__embedded__links_reports.rb} +1 -1
  99. data/lib/cybersource_rest_client/models/{inline_response_200_8__embedded_batches.rb → inline_response_200_9__embedded_batches.rb} +3 -3
  100. data/lib/cybersource_rest_client/models/{inline_response_200_8__embedded_totals.rb → inline_response_200_9__embedded_totals.rb} +1 -1
  101. data/lib/cybersource_rest_client/models/inline_response_200_9__links.rb +16 -17
  102. data/lib/cybersource_rest_client/models/inline_response_201.rb +227 -227
  103. data/lib/cybersource_rest_client/models/inline_response_201_1.rb +218 -218
  104. data/lib/cybersource_rest_client/models/inline_response_201_2.rb +248 -248
  105. data/lib/cybersource_rest_client/models/inline_response_201_2_payout_information.rb +216 -216
  106. data/lib/cybersource_rest_client/models/inline_response_201_2_payout_information_pull_funds.rb +213 -213
  107. data/lib/cybersource_rest_client/models/inline_response_201_2_payout_information_push_funds.rb +417 -417
  108. data/lib/cybersource_rest_client/models/inline_response_201_3.rb +281 -281
  109. data/lib/cybersource_rest_client/models/inline_response_201_3_integration_information.rb +192 -192
  110. data/lib/cybersource_rest_client/models/inline_response_201_3_integration_information_tenant_configurations.rb +253 -253
  111. data/lib/cybersource_rest_client/models/inline_response_201_3_organization_information.rb +217 -217
  112. data/lib/cybersource_rest_client/models/inline_response_201_3_product_information_setups.rb +214 -214
  113. data/lib/cybersource_rest_client/models/inline_response_201_3_registration_information.rb +222 -222
  114. data/lib/cybersource_rest_client/models/inline_response_201_3_setups.rb +219 -219
  115. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_commerce_solutions.rb +209 -209
  116. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments.rb +369 -369
  117. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments_alternative_payment_methods.rb +221 -221
  118. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments_alternative_payment_methods_configuration_status.rb +200 -200
  119. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments_card_processing.rb +199 -199
  120. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments_card_processing_configuration_status.rb +255 -255
  121. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments_card_processing_subscription_status.rb +234 -234
  122. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_payments_digital_payments.rb +189 -189
  123. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_risk.rb +199 -199
  124. data/lib/cybersource_rest_client/models/inline_response_201_3_setups_value_added_services.rb +209 -209
  125. data/lib/cybersource_rest_client/models/inline_response_201_4.rb +222 -222
  126. data/lib/cybersource_rest_client/models/inline_response_201_4_key_information.rb +300 -300
  127. data/lib/cybersource_rest_client/models/inline_response_201_4_key_information_error_information.rb +202 -202
  128. data/lib/cybersource_rest_client/models/inline_response_201_4_key_information_error_information_details.rb +201 -201
  129. data/lib/cybersource_rest_client/models/inline_response_201_5.rb +314 -312
  130. data/lib/cybersource_rest_client/models/inline_response_201_6.rb +277 -277
  131. data/lib/cybersource_rest_client/models/inline_response_201_6_payloads.rb +189 -189
  132. data/lib/cybersource_rest_client/models/inline_response_201_6_payloads_test_payload.rb +190 -190
  133. data/lib/cybersource_rest_client/models/inline_response_201_7.rb +202 -202
  134. data/lib/cybersource_rest_client/models/inline_response_201_order_information.rb +189 -189
  135. data/lib/cybersource_rest_client/models/inline_response_201_order_information_ship_to.rb +315 -315
  136. data/lib/cybersource_rest_client/models/inline_response_201_payment_information.rb +199 -199
  137. data/lib/cybersource_rest_client/models/inline_response_201_payment_information_e_wallet.rb +196 -196
  138. data/lib/cybersource_rest_client/models/inline_response_201_payment_information_tokenized_payment_method.rb +213 -213
  139. data/lib/cybersource_rest_client/models/invoicing_v2_invoice_settings_get200_response_invoice_settings_information.rb +18 -5
  140. data/lib/cybersource_rest_client/models/invoicing_v2_invoices_post201_response_invoice_information.rb +18 -5
  141. data/lib/cybersource_rest_client/models/{notificationsubscriptionsv2webhooks_security_policy_1_config.rb → invoicing_v2_invoices_post201_response_invoice_information_custom_labels.rb} +57 -34
  142. data/lib/cybersource_rest_client/models/invoicing_v2_invoices_publish200_response.rb +268 -0
  143. data/lib/cybersource_rest_client/models/invoicingv2invoice_settings_invoice_settings_information.rb +18 -5
  144. data/lib/cybersource_rest_client/models/notificationsubscriptionsv2webhooks_retry_policy.rb +2 -0
  145. data/lib/cybersource_rest_client/models/notificationsubscriptionsv2webhooks_security_policy.rb +1 -1
  146. data/lib/cybersource_rest_client/models/notificationsubscriptionsv2webhooks_security_policy_config.rb +16 -17
  147. data/lib/cybersource_rest_client/models/{notificationsubscriptionsv2webhooks_security_policy_1_config_additional_config.rb → notificationsubscriptionsv2webhooks_security_policy_config_additional_config.rb} +1 -1
  148. data/lib/cybersource_rest_client/models/pts_v2_payments_post201_response_installment_information.rb +609 -609
  149. data/lib/cybersource_rest_client/models/pts_v2_payments_post201_response_payment_account_information_card.rb +269 -269
  150. data/lib/cybersource_rest_client/models/pts_v2_payments_post201_response_payment_information.rb +364 -364
  151. data/lib/cybersource_rest_client/models/pts_v2_payments_post201_response_payment_information_tokenized_card.rb +309 -309
  152. data/lib/cybersource_rest_client/models/pts_v2_payments_post201_response_payment_information_tokenized_payment_method.rb +213 -213
  153. data/lib/cybersource_rest_client/models/pts_v2_retrieve_payment_token_get400_response.rb +252 -252
  154. data/lib/cybersource_rest_client/models/pts_v2_retrieve_payment_token_get502_response.rb +240 -240
  155. data/lib/cybersource_rest_client/models/ptsv2billingagreements_payment_information_card.rb +258 -258
  156. data/lib/cybersource_rest_client/models/ptsv2billingagreements_payment_information_tokenized_card.rb +275 -275
  157. data/lib/cybersource_rest_client/models/ptsv2intents_event_information.rb +212 -212
  158. data/lib/cybersource_rest_client/models/ptsv2intents_order_information_ship_to.rb +354 -354
  159. data/lib/cybersource_rest_client/models/ptsv2intents_payment_information.rb +220 -220
  160. data/lib/cybersource_rest_client/models/ptsv2intents_payment_information_e_wallet.rb +196 -196
  161. data/lib/cybersource_rest_client/models/ptsv2intents_payment_information_tokenized_payment_method.rb +241 -241
  162. data/lib/cybersource_rest_client/models/ptsv2intents_processing_information.rb +351 -351
  163. data/lib/cybersource_rest_client/models/ptsv2intents_recipient_information.rb +245 -245
  164. data/lib/cybersource_rest_client/models/ptsv2intents_sender_information.rb +277 -277
  165. data/lib/cybersource_rest_client/models/ptsv2intents_sender_information_account.rb +190 -190
  166. data/lib/cybersource_rest_client/models/ptsv2intents_travel_information.rb +211 -211
  167. data/lib/cybersource_rest_client/models/ptsv2intents_travel_information_agency.rb +245 -245
  168. data/lib/cybersource_rest_client/models/ptsv2intentsid_payment_information.rb +189 -189
  169. data/lib/cybersource_rest_client/models/ptsv2paymentreferences_order_information_amount_details.rb +417 -417
  170. data/lib/cybersource_rest_client/models/ptsv2paymentreferences_payment_information_card.rb +275 -275
  171. data/lib/cybersource_rest_client/models/ptsv2payments_installment_information.rb +461 -433
  172. data/lib/cybersource_rest_client/models/ptsv2payments_order_information_amount_details.rb +668 -668
  173. data/lib/cybersource_rest_client/models/ptsv2payments_order_information_line_items.rb +716 -716
  174. data/lib/cybersource_rest_client/models/ptsv2payments_payment_information.rb +356 -356
  175. data/lib/cybersource_rest_client/models/ptsv2payments_payment_information_card.rb +445 -445
  176. data/lib/cybersource_rest_client/models/ptsv2payments_payment_information_payment_type_method.rb +1 -1
  177. data/lib/cybersource_rest_client/models/ptsv2payments_payment_information_tokenized_card.rb +377 -377
  178. data/lib/cybersource_rest_client/models/ptsv2payments_payment_information_tokenized_payment_method.rb +196 -196
  179. data/lib/cybersource_rest_client/models/ptsv2paymentsidcaptures_installment_information.rb +604 -604
  180. data/lib/cybersource_rest_client/models/ptsv2paymentsidcaptures_payment_information_payment_type_method.rb +1 -1
  181. data/lib/cybersource_rest_client/models/ptsv2paymentsidrefunds_payment_information_card.rb +377 -377
  182. data/lib/cybersource_rest_client/models/ptsv2paymenttokens_payment_information.rb +199 -199
  183. data/lib/cybersource_rest_client/models/ptsv2paymenttokens_processing_information.rb +192 -192
  184. data/lib/cybersource_rest_client/models/ptsv2payouts_payment_information_card.rb +258 -258
  185. data/lib/cybersource_rest_client/models/request.rb +199 -199
  186. data/lib/cybersource_rest_client/models/riskv1authenticationresults_payment_information_card.rb +241 -241
  187. data/lib/cybersource_rest_client/models/riskv1authenticationresults_payment_information_tokenized_card.rb +258 -258
  188. data/lib/cybersource_rest_client/models/riskv1authentications_payment_information_tokenized_card.rb +351 -351
  189. data/lib/cybersource_rest_client/models/riskv1authenticationsetups_payment_information_card.rb +268 -268
  190. data/lib/cybersource_rest_client/models/riskv1authenticationsetups_payment_information_tokenized_card.rb +299 -299
  191. data/lib/cybersource_rest_client/models/riskv1decisions_payment_information_card.rb +259 -259
  192. data/lib/cybersource_rest_client/models/riskv1decisions_payment_information_tokenized_card.rb +259 -259
  193. data/lib/cybersource_rest_client/models/riskv1liststypeentries_payment_information_card.rb +224 -224
  194. data/lib/cybersource_rest_client/models/tms_bin_lookup_issuer_information.rb +264 -264
  195. data/lib/cybersource_rest_client/models/tms_bin_lookup_payment_account_information_card.rb +277 -277
  196. data/lib/cybersource_rest_client/models/tms_bin_lookup_payment_account_information_card_brands.rb +213 -213
  197. data/lib/cybersource_rest_client/models/tms_bin_lookup_payment_account_information_features.rb +430 -430
  198. data/lib/cybersource_rest_client/models/tss_v2_transactions_get200_response.rb +11 -1
  199. data/lib/cybersource_rest_client/models/tss_v2_transactions_get200_response_bank_account_validation.rb +211 -0
  200. data/lib/cybersource_rest_client/models/tss_v2_transactions_get200_response_payment_information_brands.rb +201 -201
  201. data/lib/cybersource_rest_client/models/tss_v2_transactions_get200_response_payment_information_card.rb +365 -365
  202. data/lib/cybersource_rest_client/models/tss_v2_transactions_get200_response_processing_information.rb +16 -5
  203. data/lib/cybersource_rest_client/models/tss_v2_transactions_get200_response_processor_information.rb +15 -5
  204. data/lib/cybersource_rest_client/models/tss_v2_transactions_post201_response__embedded_payment_information_card.rb +218 -218
  205. data/lib/cybersource_rest_client/models/tss_v2_transactions_post201_response__embedded_processor_information.rb +245 -245
  206. data/lib/cybersource_rest_client/models/update_order_request.rb +229 -229
  207. data/lib/cybersource_rest_client/models/update_webhook.rb +19 -19
  208. data/lib/cybersource_rest_client.rb +20 -18
  209. metadata +25 -20
  210. data/lib/cybersource_rest_client/models/notificationsubscriptionsv2webhooks_security_policy_1.rb +0 -201
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cc4b4570c87bc2e919ba22258de9cf700cd948e80365e22a9cb836662d26539
4
- data.tar.gz: 1039c93e150231700b175bdceb16800b7b194174576ca7934372bd711179188b
3
+ metadata.gz: 6a4660ce3a2439827b4430b708a803b17fe917e318e7aed05da06f06fc6b12d1
4
+ data.tar.gz: a9bd3db3a6435bb1f41762888ebbeb183570abff85a7244963f2c924ed74c6c5
5
5
  SHA512:
6
- metadata.gz: f2cd65e1d3f83449031b9a4a2784457c7f852deb743060fde4a30c305ba222f48ef8ff7abb57377a24066bdd6fc6a6ba212671572efb0d54a3b8b329eda5020b
7
- data.tar.gz: bdfb74f86a6eedb592cccc8535766f384585535fbd29082e6ef4a0d2cbe459dc7a1eca80cbdfaf9e39354ad85768447b26465ef5fbe92d9ae78963804d18b731
6
+ metadata.gz: 79954c4037b3c493be01acfa324711fa40e3f434d953db784e3cea2f5dd79be0f04d1af185b99c16dc9f6dc2cfd3524ee9c714c1cd441f450eba503b327fa427
7
+ data.tar.gz: b6a82130c16579b41c618a5180c96c8aa1969058ef5bc0615c8fde44f2e24efaf9965bd8e75e650675ad1ddc469cd54ba429ad75a27f9c469986d160739e1cc8
@@ -21,29 +21,18 @@ public
21
21
 
22
22
  jwtBody = ''
23
23
  request_type = merchantconfig_obj.requestType.upcase
24
- filePath = merchantconfig_obj.keysDirectory + '/' + merchantconfig_obj.keyFilename + '.p12'
25
-
26
- if (!File.exist?(filePath))
27
- raise Constants::ERROR_PREFIX + Constants::FILE_NOT_FOUND + File.expand_path(filePath)
28
- end
29
-
30
- p12File = File.binread(filePath)
24
+
31
25
  jwtBody=getJwtBody(request_type, gmtDatetime, merchantconfig_obj)
32
26
  claimSet = JSON.parse(jwtBody)
33
- p12FilePath = OpenSSL::PKCS12.new(p12File, merchantconfig_obj.keyPass)
34
-
35
- # Generating certificate.
36
- cacheObj = ActiveSupport::Cache::MemoryStore.new
37
- x5Cert = Cache.new.fetchCachedCertificate(filePath, p12File, merchantconfig_obj.keyPass, merchantconfig_obj.keyAlias, cacheObj)
38
27
 
39
- # Generating Public key.
40
- publicKey = OpenSSL::PKey::RSA.new(p12FilePath.key.public_key)
28
+ cache_value = Cache.new.fetchCachedP12Certificate(merchantconfig_obj)
29
+ privateKey = cache_value.private_key
30
+ jwt_cert_obj = cache_value.cert
31
+ jwt_cert_in_der= Base64.strict_encode64(jwt_cert_obj.to_der)
41
32
 
42
- #Generating Private Key
43
- privateKey = OpenSSL::PKey::RSA.new(p12FilePath.key)
44
33
 
45
34
  # JWT token-Generates using RS256 algorithm only
46
- x5clist = [x5Cert]
35
+ x5clist = [jwt_cert_in_der]
47
36
  customHeaders = {}
48
37
  customHeaders['v-c-merchant-id'] = merchantconfig_obj.keyAlias
49
38
  customHeaders['x5c'] = x5clist
@@ -2,60 +2,78 @@ require_relative '../util/Constants.rb'
2
2
  require_relative '../util/ExceptionHandler.rb'
3
3
  require_relative '../logging/log_factory.rb'
4
4
  require_relative '../logging/log_configuration.rb'
5
+ require_relative '../util/CertificateUtility.rb'
5
6
 
6
7
  public
7
8
  # This fuction has all the merchantConfig properties getters and setters methods
8
9
  class Merchantconfig
9
10
  def initialize(cybsPropertyObj)
10
- # Common Parameters
11
- @merchantId = cybsPropertyObj['merchantID']
12
- @runEnvironment = cybsPropertyObj['runEnvironment']
13
- @intermediateHost = cybsPropertyObj['intermediateHost']
14
- @defaultDeveloperId = cybsPropertyObj['defaultDeveloperId']
15
- @authenticationType = cybsPropertyObj['authenticationType']
16
- @proxyAddress = cybsPropertyObj['proxyAddress']
17
- @proxyPort = cybsPropertyObj['proxyPort']
18
- @getId = ''
19
- @requestHost = ''
20
- @requestTarget = ''
21
- @requestJsonData = ''
22
- # HTTP Parameters
23
- @merchantSecretKey = cybsPropertyObj['merchantsecretKey']
24
- @merchantKeyId = cybsPropertyObj['merchantKeyId']
25
- # JWT Parameters
26
- @keysDirectory = cybsPropertyObj['keysDirectory']
27
- @keyAlias = cybsPropertyObj['keyAlias']
28
- @keyPass = cybsPropertyObj['keyPass']
29
- @keyFilename = cybsPropertyObj['keyFilename']
30
- @useMetaKey = cybsPropertyObj['useMetaKey']
31
- @portfolioID = cybsPropertyObj['portfolioID']
32
- @solutionId = cybsPropertyObj['solutionId']
33
- # MutualAuth & OAuth Parameters
34
- @enableClientCert = cybsPropertyObj['enableClientCert']
35
- @clientCertDirectory = cybsPropertyObj['clientCertDirectory']
36
- @sslClientCert = cybsPropertyObj['sslClientCert']
37
- @privateKey = cybsPropertyObj['privateKey']
38
- @sslKeyPassword = cybsPropertyObj['sslKeyPassword']
39
- @clientId = cybsPropertyObj['clientId']
40
- @clientSecret = cybsPropertyObj['clientSecret']
41
- @accessToken = cybsPropertyObj['accessToken']
42
- @refreshToken = cybsPropertyObj['refreshToken']
43
- # LogConfiguration
44
- @log_config = LogConfiguration.new(cybsPropertyObj['logConfiguration'])
45
- # Custom Default Headers
46
- @defaultCustomHeaders = cybsPropertyObj['defaultCustomHeaders']
47
- # Path to client JWE pem file directory
48
- @pemFileDirectory = cybsPropertyObj['pemFileDirectory']
49
- @mleKeyAlias = cybsPropertyObj['mleKeyAlias']
50
- @useMLEGlobally = cybsPropertyObj['useMLEGlobally']
51
- @mapToControlMLEonAPI = cybsPropertyObj['mapToControlMLEonAPI']
52
- validateMerchantDetails
53
- logAllProperties(cybsPropertyObj)
54
- validateMLEConfiguration
11
+ # Common Parameters
12
+ @merchantId = cybsPropertyObj['merchantID']
13
+ @runEnvironment = cybsPropertyObj['runEnvironment']
14
+ @intermediateHost = cybsPropertyObj['intermediateHost']
15
+ @defaultDeveloperId = cybsPropertyObj['defaultDeveloperId']
16
+ @authenticationType = cybsPropertyObj['authenticationType']
17
+ @proxyAddress = cybsPropertyObj['proxyAddress']
18
+ @proxyPort = cybsPropertyObj['proxyPort']
19
+ @getId = ''
20
+ @requestHost = ''
21
+ @requestTarget = ''
22
+ @requestJsonData = ''
23
+ # HTTP Parameters
24
+ @merchantSecretKey = cybsPropertyObj['merchantsecretKey']
25
+ @merchantKeyId = cybsPropertyObj['merchantKeyId']
26
+ # JWT Parameters
27
+ @keysDirectory = cybsPropertyObj['keysDirectory']
28
+ @keyAlias = cybsPropertyObj['keyAlias']
29
+ @keyPass = cybsPropertyObj['keyPass']
30
+ @keyFilename = cybsPropertyObj['keyFilename']
31
+ @useMetaKey = cybsPropertyObj['useMetaKey']
32
+ @portfolioID = cybsPropertyObj['portfolioID']
33
+ @solutionId = cybsPropertyObj['solutionId']
34
+ @p12KeyFilePath = nil
35
+ # MutualAuth & OAuth Parameters
36
+ @enableClientCert = cybsPropertyObj['enableClientCert']
37
+ @clientCertDirectory = cybsPropertyObj['clientCertDirectory']
38
+ @sslClientCert = cybsPropertyObj['sslClientCert']
39
+ @privateKey = cybsPropertyObj['privateKey']
40
+ @sslKeyPassword = cybsPropertyObj['sslKeyPassword']
41
+ @clientId = cybsPropertyObj['clientId']
42
+ @clientSecret = cybsPropertyObj['clientSecret']
43
+ @accessToken = cybsPropertyObj['accessToken']
44
+ @refreshToken = cybsPropertyObj['refreshToken']
45
+ # LogConfiguration
46
+ @log_config = LogConfiguration.new(cybsPropertyObj['logConfiguration'])
47
+ # Custom Default Headers
48
+ @defaultCustomHeaders = cybsPropertyObj['defaultCustomHeaders']
49
+ # Keep Alive Time for Connection Pooling
50
+ @keepAliveTime = cybsPropertyObj['keepAliveTime'] || 118 # Default to 118 seconds as same as default of libcurl
51
+ # Path to client JWE pem file directory
52
+ @pemFileDirectory = cybsPropertyObj['pemFileDirectory']
53
+ @mleKeyAlias = cybsPropertyObj['mleKeyAlias']
54
+ @useMLEGlobally = cybsPropertyObj['useMLEGlobally']
55
+ @enableRequestMLEForOptionalApisGlobally = !!(cybsPropertyObj['enableRequestMLEForOptionalApisGlobally'] || cybsPropertyObj['useMLEGlobally'])
56
+ @disableRequestMLEForMandatoryApisGlobally = cybsPropertyObj['disableRequestMLEForMandatoryApisGlobally']
57
+
58
+
59
+ if !cybsPropertyObj['mleForRequestPublicCertPath'].nil? && !cybsPropertyObj['mleForRequestPublicCertPath'].to_s.strip.empty?
60
+ @mleForRequestPublicCertPath = cybsPropertyObj['mleForRequestPublicCertPath'].to_s.strip
61
+ end
62
+
63
+ @mapToControlMLEonAPI = cybsPropertyObj['mapToControlMLEonAPI']
64
+ validateMerchantDetails
65
+ validateMLEConfiguration(cybsPropertyObj)
66
+ @p12KeyFilePath = File.join(@keysDirectory, @keyFilename + ".p12")
67
+ logAllProperties(cybsPropertyObj)
55
68
  end
56
69
 
57
70
  #fall back logic
58
71
  def validateMerchantDetails()
72
+ if !@keepAliveTime.is_a?(Integer)
73
+ err = StandardError.new(Constants::ERROR_PREFIX + "keepAliveTime must be an integer and in seconds")
74
+ raise err
75
+ end
76
+
59
77
  logmessage = ''
60
78
  @log_config.validate(logmessage)
61
79
  @log_obj = Log.new @log_config, "MerchantConfig"
@@ -157,6 +175,9 @@ public
157
175
  elsif !@keyFilename.instance_of? String
158
176
  @keyFilename=@keyFilename.to_s
159
177
  end
178
+ if !check_key_file
179
+ @log_obj.logger.error(ExceptionHandler.new.new_custom_error "Error finding or accessing the Key Directory or Key File. Please review the values in the merchant configuration.")
180
+ end
160
181
  end
161
182
  if @authenticationType.upcase == Constants::AUTH_TYPE_MUTUAL_AUTH
162
183
  if @clientId.to_s.empty?
@@ -230,16 +251,30 @@ public
230
251
  end
231
252
  end
232
253
 
233
- def validateMLEConfiguration
234
- if @useMLEGlobally.nil?
235
- @useMLEGlobally = false
254
+ def validateMLEConfiguration(cybsPropertyObj)
255
+
256
+ if !@useMLEGlobally.nil? && !cybsPropertyObj['enableRequestMLEForOptionalApisGlobally'].nil?
257
+ if @useMLEGlobally != cybsPropertyObj['enableRequestMLEForOptionalApisGlobally']
258
+ raise StandardError.new(Constants::ERROR_PREFIX + "useMLEGlobally and enableRequestMLEForOptionalApisGlobally must have the same value if both are set")
259
+ end
236
260
  end
237
261
 
238
- unless [true, false].include?(@useMLEGlobally)
239
- err = StandardError.new(Constants::ERROR_PREFIX + "useMLEGlobally must be a boolean")
262
+ if @disableRequestMLEForMandatoryApisGlobally.nil?
263
+ @disableRequestMLEForMandatoryApisGlobally = false
264
+ end
265
+
266
+ unless [true, false].include?(@disableRequestMLEForMandatoryApisGlobally)
267
+ err = StandardError.new(Constants::ERROR_PREFIX + "disableRequestMLEForMandatoryApisGlobally must be a boolean")
240
268
  @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
241
269
  raise err
242
270
  end
271
+
272
+ unless [true, false].include?(@enableRequestMLEForOptionalApisGlobally)
273
+ err = StandardError.new(Constants::ERROR_PREFIX + "enableRequestMLEForOptionalApisGlobally must be a boolean")
274
+ @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
275
+ raise err
276
+ end
277
+
243
278
  unless @mapToControlMLEonAPI.nil?
244
279
  unless @mapToControlMLEonAPI.is_a?(Hash) && @mapToControlMLEonAPI.keys.all? {|k| k.is_a?(String)} && @mapToControlMLEonAPI.values.all? { |v| [true, false].include?(v) }
245
280
  err = StandardError.new(Constants::ERROR_PREFIX + "mapToControlMLEonAPI must be a map with boolean values")
@@ -257,18 +292,27 @@ public
257
292
  @mleKeyAlias = Constants::DEFAULT_ALIAS_FOR_MLE_CERT
258
293
  end
259
294
 
260
- mle_configured = @useMLEGlobally
295
+ if @mleForRequestPublicCertPath && !@mleForRequestPublicCertPath.to_s.strip.empty?
296
+ begin
297
+ CertificateUtility.validatePathAndFile(@mleForRequestPublicCertPath, "mleForRequestPublicCertPath", @log_config)
298
+ rescue => err
299
+ @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
300
+ raise err
301
+ end
302
+ end
303
+
304
+ request_mle_configured = @enableRequestMLEForOptionalApisGlobally
261
305
  if !@mapToControlMLEonAPI.nil? && !@mapToControlMLEonAPI.empty?
262
306
  @mapToControlMLEonAPI.each do |_, value|
263
307
  unless [true, false].include?(value) && value
264
- mle_configured = true
308
+ request_mle_configured = true
265
309
  break
266
310
  end
267
311
  end
268
312
  end
269
313
 
270
- if mle_configured && !Constants::AUTH_TYPE_JWT.eql?(@authenticationType)
271
- err = StandardError.new(Constants::ERROR_PREFIX + "MLE can only be used with JWT authentication")
314
+ if request_mle_configured && !Constants::AUTH_TYPE_JWT.eql?(@authenticationType.upcase)
315
+ err = StandardError.new(Constants::ERROR_PREFIX + "Request MLE can only be used with JWT authentication")
272
316
  @log_obj.logger.error(ExceptionHandler.new.new_api_exception err)
273
317
  raise err
274
318
  end
@@ -292,6 +336,35 @@ public
292
336
  @log_obj.logger.info('Merchant Configuration :\n' + propertyObj.to_s)
293
337
  end
294
338
 
339
+ def check_key_file
340
+ # Directory exists?
341
+ unless Dir.exist?(@keysDirectory)
342
+ @log_obj.logger.error("Keys Directory not found. Entered directory : #{@keysDirectory}")
343
+ return false
344
+ end
345
+
346
+ key_file_pathname = File.join(@keysDirectory, @keyFilename + ".p12")
347
+
348
+ # File exists?
349
+ unless File.exist?(key_file_pathname)
350
+ @log_obj.logger.error("Key File not found. Check path/filename entered. Entered path/filename : #{key_file_pathname}")
351
+ return false
352
+ end
353
+
354
+ @log_obj.logger.info("Entered value for Key File Path : #{key_file_pathname}")
355
+
356
+ # Can file be opened for reading?
357
+ begin
358
+ File.open(key_file_pathname, 'rb') do |f|
359
+ # Just open and close
360
+ end
361
+ return true
362
+ rescue => e
363
+ @log_obj.logger.info("File cannot be accessed. Permission denied : #{key_file_pathname}")
364
+ return false
365
+ end
366
+ end
367
+
295
368
  # getter and setter methods
296
369
  attr_accessor :merchantId
297
370
  attr_accessor :merchantSecretKey
@@ -306,6 +379,7 @@ public
306
379
  attr_accessor :keyFilename
307
380
  attr_accessor :useMetaKey
308
381
  attr_accessor :portfolioID
382
+ attr_accessor :keepAliveTime
309
383
  attr_accessor :enableClientCert
310
384
  attr_accessor :clientCertDirectory
311
385
  attr_accessor :sslClientCert
@@ -329,6 +403,10 @@ public
329
403
  attr_accessor :defaultCustomHeaders
330
404
  attr_accessor :pemFileDirectory
331
405
  attr_accessor :useMLEGlobally
406
+ attr_accessor :enableRequestMLEForOptionalApisGlobally
407
+ attr_accessor :disableRequestMLEForMandatoryApisGlobally
408
+ attr_accessor :mleForRequestPublicCertPath
332
409
  attr_accessor :mapToControlMLEonAPI
333
410
  attr_accessor :mleKeyAlias
411
+ attr_accessor :p12KeyFilePath
334
412
  end
@@ -1,48 +1,153 @@
1
1
  require 'openssl'
2
2
  require 'base64'
3
+ require 'active_support'
4
+ require 'thread'
5
+ require_relative 'CacheValue'
6
+ require_relative 'CertificateUtility'
7
+ require_relative '../util/Constants.rb'
8
+ require_relative '../logging/log_factory.rb'
9
+ require_relative '../logging/log_configuration.rb'
10
+
3
11
  public
4
12
  # P12 file certificate Cache
5
13
  class Cache
6
- def fetchCachedCertificate(filePath, p12File, keyPass, keyAlias, cacheObj)
7
- certCache = cacheObj.read(keyAlias.to_s.upcase)
8
- cachedLastModifiedTimeStamp = cacheObj.read(keyAlias.to_s.upcase + '_LastModifiedTime')
9
- if File.exist?(filePath)
10
- currentFileLastModifiedTime = File.mtime(filePath)
11
- if certCache.to_s.empty? || cachedLastModifiedTimeStamp.to_s.empty?
12
- certificateFromP12File = getCertificate(p12File, keyPass, keyAlias, cacheObj, currentFileLastModifiedTime)
13
- return certificateFromP12File
14
- elsif currentFileLastModifiedTime > cachedLastModifiedTimeStamp
15
- # Function call to read the file and put values to new cache
16
- certificateFromP12File = getCertificate(p12File, keyPass, keyAlias, cacheObj, currentFileLastModifiedTime)
17
- return certificateFromP12File
18
- else
19
- return certCache
14
+ @@cache_obj = ActiveSupport::Cache::MemoryStore.new
15
+ @@mutex = Mutex.new
16
+ @@logger
17
+
18
+ def fetchCachedP12Certificate(merchantConfig)
19
+ merchantId = merchantConfig.merchantId
20
+ certificateFilePath = merchantConfig.p12KeyFilePath
21
+
22
+ cacheKey = merchantConfig.keyFilename + "_JWT"
23
+
24
+ @@mutex.synchronize do
25
+ cachedCertificateInfo = @@cache_obj.read(cacheKey)
26
+ fileModifiedTime = File.mtime(certificateFilePath)
27
+
28
+ if !cachedCertificateInfo || cachedCertificateInfo.empty? || fileModifiedTime != cachedCertificateInfo.file_modified_time
29
+ setupCache(cacheKey, certificateFilePath, merchantConfig)
30
+ cachedCertificateInfo = @@cache_obj.read(cacheKey)
31
+ end
32
+
33
+ return cachedCertificateInfo
34
+ end
35
+ end
36
+
37
+ def setupCache(cacheKey, certificateFilePath, merchantConfig)
38
+ if !Cache.class_variable_defined?(:@@logger) || @@logger.nil?
39
+ @@logger = Log.new merchantConfig.log_config, "Cache"
40
+ end
41
+ logger = @@logger.logger
42
+ fileModifiedTime = File.mtime(certificateFilePath)
43
+
44
+ if (cacheKey.end_with?("_JWT"))
45
+ privateKey, certificateList = CertificateUtility.getCertificateCollectionAndPrivateKeyFromP12(certificateFilePath, merchantConfig)
46
+ jwtCertificate = CertificateUtility.getCertificateBasedOnKeyAlias(certificateList, merchantConfig.keyAlias)
47
+
48
+ cacheValue = CacheValue.new(privateKey, jwtCertificate, fileModifiedTime)
49
+
50
+ @@cache_obj.write(cacheKey, cacheValue)
51
+ return
52
+ end
53
+
54
+ if (cacheKey.end_with?(Constants::MLE_CACHE_IDENTIFIER_FOR_CONFIG_CERT))
55
+ certificateList = CertificateUtility.getCertificatesFromPemFile(certificateFilePath)
56
+ mleCertificate = CertificateUtility.getCertificateBasedOnKeyAlias(certificateList, merchantConfig.mleKeyAlias)
57
+ if (!mleCertificate)
58
+ fileName = File.basename(certificateFilePath)
59
+ logger.warn("No certificate found for the specified mle_key_alias '#{merchantConfig.mleKeyAlias}'. Using the first certificate from file #{fileName} as the MLE request certificate.")
60
+ mleCertificate = certificateList[0]
20
61
  end
62
+
63
+ cacheValue = CacheValue.new(nil, mleCertificate, fileModifiedTime)
64
+
65
+ @@cache_obj.write(cacheKey, cacheValue)
66
+ return
67
+ end
68
+
69
+ if (cacheKey.end_with?(Constants::MLE_CACHE_IDENTIFIER_FOR_P12_CERT))
70
+ privateKey, certificateList = CertificateUtility.getCertificateCollectionAndPrivateKeyFromP12(certificateFilePath, merchantConfig)
71
+ mleCertificate = CertificateUtility.getCertificateBasedOnKeyAlias(certificateList, merchantConfig.mleKeyAlias)
72
+ if (!mleCertificate)
73
+ fileName = File.basename(certificateFilePath)
74
+ logger.error("No certificate found for the specified mle_key_alias '#{merchantConfig.mleKeyAlias}' in file #{fileName}.")
75
+ raise ArgumentError, "No certificate found for the specified mle_key_alias '#{merchantConfig.mleKeyAlias}' in file #{fileName}."
76
+ end
77
+
78
+ cacheValue = CacheValue.new(privateKey, mleCertificate, fileModifiedTime)
79
+
80
+ @@cache_obj.write(cacheKey, cacheValue)
81
+ return
82
+ end
83
+ end
84
+
85
+ def getRequestMLECertificateFromCache(merchantConfig)
86
+ if !Cache.class_variable_defined?(:@@logger) || @@logger.nil?
87
+ @@logger = Log.new merchantConfig.log_config, "Cache"
88
+ end
89
+
90
+ logger = @@logger.logger
91
+ merchantId = merchantConfig.merchantId
92
+ certificate_identifier = nil
93
+ certificate_file_path = nil
94
+
95
+ # Priority #1: Get cert from merchantConfig.mleForRequestPublicCertPath if certPath is provided
96
+ if merchantConfig.mleForRequestPublicCertPath && !merchantConfig.mleForRequestPublicCertPath.strip.empty?
97
+ certificate_identifier = Constants::MLE_CACHE_IDENTIFIER_FOR_CONFIG_CERT
98
+ certificate_file_path = merchantConfig.mleForRequestPublicCertPath
99
+ # Priority #2: If mleForRequestPublicCertPath not provided, get mlecert from p12 if provided and jwt auth type
100
+ elsif Constants::AUTH_TYPE_JWT.downcase == merchantConfig.authenticationType.downcase && merchantConfig.p12KeyFilePath
101
+ certificate_identifier = Constants::MLE_CACHE_IDENTIFIER_FOR_P12_CERT
102
+ certificate_file_path = merchantConfig.p12KeyFilePath
103
+ # Priority #3: Get mlecert from default cert in SDK as per CAS or PROD env.
21
104
  else
22
- raise Constants::ERROR_PREFIX + Constants::FILE_NOT_FOUND + filePath
105
+ logger.debug("The certificate to use for MLE for requests is not provided in the merchant configuration. Please ensure that the certificate path is provided.")
106
+ return nil
23
107
  end
108
+
109
+ cache_key = "#{merchantId}_#{certificate_identifier}"
110
+ mle_certificate = getMLECertificateBasedOnCacheKey(merchantConfig, cache_key, certificate_file_path)
111
+
112
+ CertificateUtility.validateCertificateExpiry(mle_certificate, merchantConfig.keyAlias, certificate_identifier, merchantConfig.log_config)
113
+
114
+ mle_certificate
24
115
  end
25
116
 
26
- def getCertificate(p12File, keyPass, keyAlias, cacheObj, currentFileLastModifiedTime)
27
- x5CertDer = Utility.new.fetchCert(keyPass, p12File, keyAlias)
28
- cacheObj.write(keyAlias.to_s.upcase, x5CertDer)
29
- cacheObj.write(keyAlias.to_s.upcase + '_LastModifiedTime', currentFileLastModifiedTime)
30
- x5CertDer
117
+ def getMLECertificateBasedOnCacheKey(merchantConfig, cacheKey, certificateFilePath)
118
+ cachedCertificateInfo = nil
119
+ @@mutex.synchronize do
120
+ cachedCertificateInfo = @@cache_obj.read(cacheKey)
121
+ fileTimestamp = File.mtime(certificateFilePath)
122
+
123
+ if cachedCertificateInfo.nil? || cachedCertificateInfo.file_modified_time != fileTimestamp
124
+ setupCache(cacheKey, certificateFilePath, merchantConfig)
125
+ cachedCertificateInfo = @@cache_obj.read(cacheKey)
126
+ end
127
+ end
128
+
129
+ cachedCertificateInfo ? cachedCertificateInfo.cert : nil
31
130
  end
32
131
 
33
132
  # <b>DEPRECATED:</b> This method has been marked as Deprecated and will be removed in coming releases.
34
- def fetchPEMFileForNetworkTokenization(filePath, cacheObj)
133
+ def fetchPEMFileForNetworkTokenization(filePath)
35
134
  warn("[DEPRECATED] 'fetchPEMFileForNetworkTokenization' method is deprecated and will be removed in coming releases.")
36
- pem_file_cache = cacheObj.read('privateKeyFromPEMFile')
37
- cached_pem_file_last_updated_time = cacheObj.read('cachedLastModifiedTimeOfPEMFile')
38
- if File.exist?(filePath)
39
- current_last_modified_time_of_PEM_file = File.mtime(filePath)
40
- if pem_file_cache.nil? || pem_file_cache.to_s.empty? || current_last_modified_time_of_PEM_file > cached_pem_file_last_updated_time
41
- private_key = JOSE::JWK.from_pem_file filePath
42
- cacheObj.write('privateKeyFromPEMFile', private_key)
43
- cacheObj.write('cachedLastModifiedTimeOfPEMFile', current_last_modified_time_of_PEM_file)
135
+
136
+ # Thread-safe cache access for deprecated method
137
+ @@mutex.synchronize do
138
+ pem_file_cache = @@cache_obj.read('privateKeyFromPEMFile')
139
+ cached_pem_file_last_updated_time = @@cache_obj.read('cachedLastModifiedTimeOfPEMFile')
140
+
141
+ if File.exist?(filePath)
142
+ current_last_modified_time_of_PEM_file = File.mtime(filePath)
143
+ if pem_file_cache.nil? || pem_file_cache.to_s.empty? || current_last_modified_time_of_PEM_file > cached_pem_file_last_updated_time
144
+ private_key = JOSE::JWK.from_pem_file filePath
145
+ @@cache_obj.write('privateKeyFromPEMFile', private_key)
146
+ @@cache_obj.write('cachedLastModifiedTimeOfPEMFile', current_last_modified_time_of_PEM_file)
147
+ end
44
148
  end
149
+
150
+ return @@cache_obj.read('privateKeyFromPEMFile')
45
151
  end
46
- return cacheObj.read('privateKeyFromPEMFile')
47
152
  end
48
153
  end
@@ -0,0 +1,18 @@
1
+ # Cache value object to store certificate data
2
+ class CacheValue
3
+ attr_accessor :private_key, :cert, :file_modified_time
4
+
5
+ def initialize(private_key = nil, cert = nil, file_modified_time = nil)
6
+ @private_key = private_key
7
+ @cert = cert
8
+ @file_modified_time = file_modified_time
9
+ end
10
+
11
+ def to_s
12
+ "CacheValue(private_key: #{@private_key ? 'present' : 'nil'}, cert: #{@cert ? 'present' : 'nil'}, file_modified_time: #{@file_modified_time})"
13
+ end
14
+
15
+ def empty?
16
+ @private_key.nil? && @cert.nil? && @file_modified_time.nil?
17
+ end
18
+ end
@@ -0,0 +1,124 @@
1
+ require 'openssl'
2
+ require_relative '../util/Constants.rb'
3
+ require_relative '../logging/log_factory.rb'
4
+ require_relative '../logging/log_configuration.rb'
5
+
6
+ public
7
+ class CertificateUtility
8
+ @@logger
9
+
10
+ def self.getCertificateCollectionAndPrivateKeyFromP12(certificateFilePath, merchantConfig)
11
+ if !CertificateUtility.class_variable_defined?(:@@logger) || @@logger.nil?
12
+ @@logger = Log.new merchantConfig.log_config, "CertificateUtility"
13
+ end
14
+ logger = @@logger.logger
15
+
16
+ p12File = File.binread(certificateFilePath)
17
+ p12Object = OpenSSL::PKCS12.new(p12File, merchantConfig.keyPass)
18
+
19
+ privateKey = OpenSSL::PKey::RSA.new(p12Object.key)
20
+
21
+ primaryX5Certificate = p12Object.certificate
22
+ additionalX5Certificates = p12Object.ca_certs
23
+
24
+ certificateList = [primaryX5Certificate]
25
+ certificateList.concat(additionalX5Certificates) if additionalX5Certificates
26
+
27
+ return [privateKey, certificateList]
28
+ end
29
+
30
+ def self.getCertificateBasedOnKeyAlias(certificateList, keyAlias)
31
+ return nil if certificateList.nil?
32
+
33
+ certificateList.find do |cert|
34
+ cert.subject.to_a.any? { |_, value, _| value.include?(keyAlias) }
35
+ end
36
+ end
37
+
38
+ def self.getCertificatesFromPemFile(certificateFilePath)
39
+ pem_data = File.read(certificateFilePath)
40
+ certificateList = []
41
+
42
+ pem_data.scan(/-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m) do |certBlock|
43
+ certificateList << OpenSSL::X509::Certificate.new(certBlock)
44
+ end
45
+
46
+ certificateList
47
+ end
48
+
49
+ def self.validateCertificateExpiry(certificate, keyAlias, certificateIdentifier, logConfig)
50
+ if !CertificateUtility.class_variable_defined?(:@@logger) || @@logger.nil?
51
+ @@logger = Log.new logConfig, "CertificateUtility"
52
+ end
53
+ logger = @@logger.logger
54
+
55
+ warning_no_expiry_date = "Certificate does not have expiry date"
56
+ warning_expiring_soon = "Certificate with alias #{keyAlias} is going to expire on %s. Please update the certificate before then."
57
+ warning_expired = "Certificate with alias #{keyAlias} is expired as of %s. Please update the certificate."
58
+
59
+ if Constants::MLE_CACHE_IDENTIFIER_FOR_CONFIG_CERT == certificateIdentifier
60
+ warning_no_expiry_date = "Certificate for MLE Requests does not have expiry date from mleForRequestPublicCertPath in merchant configuration."
61
+ warning_expiring_soon = "Certificate for MLE Requests with alias #{keyAlias} is going to expire on %s. Please update the certificate provided in mleForRequestPublicCertPath in merchant configuration before then."
62
+ warning_expired = "Certificate for MLE Requests with alias #{keyAlias} is expired as of %s. Please update the certificate provided in mleForRequestPublicCertPath in merchant configuration."
63
+ end
64
+
65
+ if Constants::MLE_CACHE_IDENTIFIER_FOR_P12_CERT == certificateIdentifier
66
+ warning_no_expiry_date = "Certificate for MLE Requests does not have expiry date in the P12 file."
67
+ warning_expiring_soon = "Certificate for MLE Requests with alias #{keyAlias} is going to expire on %s. Please update the P12 file before then."
68
+ warning_expired = "Certificate for MLE Requests with alias #{keyAlias} is expired as of %s. Please update the P12 file."
69
+ end
70
+
71
+ not_after = certificate.not_after # This returns a Time object in Ruby's OpenSSL
72
+ if not_after.nil?
73
+ logger.warn(warning_no_expiry_date)
74
+ else
75
+ now = Time.now.utc
76
+ if not_after < now
77
+ logger.warn(warning_expired % [not_after])
78
+ else
79
+ time_to_expire = not_after - now
80
+ days_to_expire = (time_to_expire / 86400).to_i
81
+ if days_to_expire < Constants::CERTIFICATE_EXPIRY_DATE_WARNING_DAYS
82
+ logger.warn(warning_expiring_soon % [not_after])
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def self.validatePathAndFile(filePath, pathType, logConfig)
89
+ if !CertificateUtility.class_variable_defined?(:@@logger) || @@logger.nil?
90
+ @@logger = Log.new logConfig, "CertificateUtility"
91
+ end
92
+ logger = @@logger.logger
93
+
94
+ if filePath.nil? || filePath.strip.empty?
95
+ logger.error("#{pathType} path cannot be null or empty.")
96
+ raise ArgumentError, "#{pathType} path cannot be null or empty."
97
+ end
98
+
99
+ normalized_path = filePath.dup
100
+ if File::SEPARATOR == '\\' && normalized_path =~ %r{^/[A-Za-z]:.*}
101
+ normalized_path = normalized_path[1..-1]
102
+ end
103
+
104
+ path = normalized_path
105
+
106
+ unless File.exist?(path)
107
+ logger.error("#{pathType} does not exist: #{path}")
108
+ raise IOError, "#{pathType} does not exist: #{path}"
109
+ end
110
+
111
+ if File.directory?(path)
112
+ logger.error("#{pathType} does not have valid file: #{path}")
113
+ raise IOError, "#{pathType} does not have valid file: #{path}"
114
+ end
115
+
116
+ begin
117
+ File.open(path, "rb") {} # Just to check readability
118
+ return path
119
+ rescue => e
120
+ logger.error("#{pathType} is not readable: #{path}")
121
+ raise IOError, "#{pathType} is not readable: #{path}"
122
+ end
123
+ end
124
+ end
@@ -169,4 +169,10 @@
169
169
  DEFAULT_ALIAS_FOR_MLE_CERT = 'CyberSource_SJC_US' unless const_defined?(:DEFAULT_ALIAS_FOR_MLE_CERT)
170
170
 
171
171
  CERTIFICATE_EXPIRY_DATE_WARNING_DAYS = 90 unless const_defined?(:CERTIFICATE_EXPIRY_DATE_WARNING_DAYS)
172
+
173
+ MLE_CACHE_IDENTIFIER_FOR_CONFIG_CERT = "mleCertFromMerchantConfig"
174
+
175
+ MLE_CACHE_IDENTIFIER_FOR_P12_CERT = "mleCertFromP12"
176
+
177
+ DEFAULT_KEY_FILE_PATH = File.join(Dir.pwd, "resources")
172
178
  end
@@ -8,8 +8,7 @@ class AuthJWEUtility
8
8
  # <b>DEPRECATED:</b> This method has been marked as Deprecated and will be removed in coming releases. Use <tt>decrypt_jwe_using_private_key()</tt> instead.
9
9
  def self.decrypt_jwe_using_pem(merchant_config, encoded_response)
10
10
  warn("[DEPRECATED] `decrypt_jwe_using_pem()` method is deprecated and will be removed in coming releases. Use `decrypt_jwe_using_private_key()` instead.")
11
- cache_obj = ActiveSupport::Cache::MemoryStore.new
12
- key = Cache.new.fetchPEMFileForNetworkTokenization(merchant_config.pemFileDirectory, cache_obj)
11
+ key = Cache.new.fetchPEMFileForNetworkTokenization(merchant_config.pemFileDirectory)
13
12
  return JOSE::JWE.block_decrypt(key, encoded_response).first
14
13
  end
15
14