Skip to content

Instantly share code, notes, and snippets.

@espen
Created April 3, 2023 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espen/96f986c7a811172c9f0484c9a7a6e3d1 to your computer and use it in GitHub Desktop.
Save espen/96f986c7a811172c9f0484c9a7a6e3d1 to your computer and use it in GitHub Desktop.
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