Class: Cache
- Inherits:
-
Object
- Object
- Cache
- Defined in:
- lib/AuthenticationSDK/util/Cache.rb
Overview
P12 file certificate Cache
Instance Method Summary collapse
- #fetchCachedCertificate(filePath, p12File, keyPass, cacheObj) ⇒ Object
- #getCertificate(p12File, keyPass, cacheObj, currentFileLastModifiedTime) ⇒ Object
Instance Method Details
#fetchCachedCertificate(filePath, p12File, keyPass, cacheObj) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/AuthenticationSDK/util/Cache.rb', line 6 def fetchCachedCertificate(filePath, p12File, keyPass, cacheObj) certCache = cacheObj.read('certiFromP12File') cachedLastModifiedTimeStamp = cacheObj.read('certificateLastModifiedTimeStamp') if File.exist?(filePath) currentFileLastModifiedTime = File.mtime(filePath) if certCache.to_s.empty? || cachedLastModifiedTimeStamp.to_s.empty? certificateFromP12File = getCertificate(p12File, keyPass, cacheObj, currentFileLastModifiedTime) return certificateFromP12File elsif currentFileLastModifiedTime > cachedLastModifiedTimeStamp # Function call to read the file and put values to new cache certificateFromP12File = getCertificate(p12File, keyPass, cacheObj, currentFileLastModifiedTime) return certificateFromP12File else return certCache end else raise Constants::ERROR_PREFIX + Constants::FILE_NOT_FOUND + filePath end end |
#getCertificate(p12File, keyPass, cacheObj, currentFileLastModifiedTime) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/AuthenticationSDK/util/Cache.rb', line 26 def getCertificate(p12File, keyPass, cacheObj, currentFileLastModifiedTime) p12FilePath = OpenSSL::PKCS12.new(p12File, keyPass) # Generating certificate from p12File. x5CertPem = OpenSSL::X509::Certificate.new(p12FilePath.certificate) # Converting Certificate format from PEM TO DER to remove header and footer of the certificate. x5CertDer = Base64.strict_encode64(x5CertPem.to_der) cacheObj.write('certiFromP12File', x5CertDer) cacheObj.write('certificateLastModifiedTimeStamp', currentFileLastModifiedTime) return x5CertDer end |