Created
April 3, 2023 09:09
-
-
Save espen/96f986c7a811172c9f0484c9a7a6e3d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MrSmime | |
class Certificate | |
def present? | |
ENV[certificate_path].present? | |
end | |
def certificate | |
X509::Certificate.new(ENV[certificate_path]) | |
end | |
def certificate_path | |
"SMIME_#{filename(:pem)}" | |
end | |
def ca_bundles | |
pem_header = '-----BEGIN CERTIFICATE-----' | |
# drop(2): blank item, original certificate | |
ENV[certificate_path].split(pem_header).drop(2).map { |cert| | |
X509::Certificate.new(pem_header + cert) | |
} | |
end | |
def private_key | |
PKey::RSA.new(ENV[private_key_path]) | |
end | |
def private_key_path | |
"SMIME_#{filename(:key)}" | |
end | |
def filename(extension) | |
Certificate.filename(@email, extension) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment