Class: Utility
- Inherits:
-
Object
- Object
- Utility
- Defined in:
- lib/AuthenticationSDK/util/Utility.rb
Class Method Summary collapse
- .getCertificateBasedOnKeyAlias(certificateList, keyAlias) ⇒ Object
- .getCertificateCollectionAndPrivateKeyFromP12(certificateFilePath, keyPass) ⇒ Object
- .isP12GeneratedByCyberSource(filePath, password, logger = nil) ⇒ Object
Instance Method Summary collapse
Class Method Details
.getCertificateBasedOnKeyAlias(certificateList, keyAlias) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/AuthenticationSDK/util/Utility.rb', line 37 def self.getCertificateBasedOnKeyAlias(certificateList, keyAlias) return nil if certificateList.nil? certificateList.find do |cert| cert.subject.to_a.any? { |_, value, _| value.include?(keyAlias) } end end |
.getCertificateCollectionAndPrivateKeyFromP12(certificateFilePath, keyPass) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/AuthenticationSDK/util/Utility.rb', line 45 def self.getCertificateCollectionAndPrivateKeyFromP12(certificateFilePath, keyPass) p12File = File.binread(certificateFilePath) p12Object = OpenSSL::PKCS12.new(p12File, keyPass) privateKey = OpenSSL::PKey::RSA.new(p12Object.key) primaryX5Certificate = p12Object.certificate additionalX5Certificates = p12Object.ca_certs certificateList = [primaryX5Certificate] certificateList.concat(additionalX5Certificates) if additionalX5Certificates return [privateKey, certificateList] end |
.isP12GeneratedByCyberSource(filePath, password, logger = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/AuthenticationSDK/util/Utility.rb', line 60 def self.isP12GeneratedByCyberSource(filePath, password, logger = nil) begin _, certificateList = getCertificateCollectionAndPrivateKeyFromP12(filePath, password) foundCertificate = getCertificateBasedOnKeyAlias(certificateList, Constants::DEFAULT_ALIAS_FOR_MLE_CERT) return !foundCertificate.nil? rescue => e logger&.error("Error while checking if P12 is generated by CyberSource: #{e.message}") return false end end |
Instance Method Details
#getResponseCodeMessage(responseCode) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/AuthenticationSDK/util/Utility.rb', line 8 def getResponseCodeMessage(responseCode) responseCode = responseCode.to_s case responseCode when "200" tempResponseCodeMessage = "Transcation Successful" when "201" tempResponseCodeMessage = "Transcation Successful" when "400" tempResponseCodeMessage = "Bad Request" when "401" tempResponseCodeMessage = "Authentication Failed" when "404" tempResponseCodeMessage = "Not Found" when "403" tempResponseCodeMessage = "Forbidden" when "500" tempResponseCodeMessage = "Internal Server Error" when "502" tempResponseCodeMessage = "Bad Gateway" when "503" tempResponseCodeMessage = "Service Unavailable" when "504" tempResponseCodeMessage = "Gateway Timeout" else tempResponseCodeMessage= '' end return tempResponseCodeMessage end |