-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathUtility.rb
51 lines (48 loc) · 1.51 KB
/
Utility.rb
1
2
3
4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'openssl'
require 'base64'
public
class Utility
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
def fetchCert(key_pass, file, key_alias)
p12_file = OpenSSL::PKCS12.new(file, key_pass)
x5_cert_pem = p12_file.certificate
x5_cert_pem.subject.to_a.each do |attribute|
return Base64.strict_encode64(x5_cert_pem.to_der) if attribute[1].include?(key_alias)
end
unless p12_file.ca_certs.nil?
p12_file.ca_certs.each do |cert|
cert.subject.to_a.each do |attribute|
return Base64.strict_encode64(cert.to_der) if attribute[1].include?(key_alias)
end
end
end
nil
end
end