Commit 1655428

mo <mo.khan@gmail.com>
2017-12-02 03:27:49
extract constant for default SUBJECT. tag: v0.2.2
1 parent babd11b
Changed files (1)
lib/saml/kit/self_signed_certificate.rb
@@ -1,6 +1,8 @@
 module Saml
   module Kit
     class SelfSignedCertificate
+      SUBJECT="/C=CA/ST=Alberta/L=Calgary/O=SamlKit/OU=SamlKit/CN=SamlKit"
+
       def initialize(password)
         @password = password
       end
@@ -9,7 +11,7 @@ module Saml
         rsa_key = OpenSSL::PKey::RSA.new(2048)
         public_key = rsa_key.public_key
         certificate = OpenSSL::X509::Certificate.new
-        certificate.subject = certificate.issuer = OpenSSL::X509::Name.parse("/C=CA/ST=Alberta/L=Calgary/O=SamlKit/OU=SamlKit/CN=SamlKit")
+        certificate.subject = certificate.issuer = OpenSSL::X509::Name.parse(SUBJECT)
         certificate.not_before = DateTime.now.beginning_of_day
         certificate.not_after = 30.days.from_now
         certificate.public_key = public_key
@@ -17,8 +19,13 @@ module Saml
         certificate.version = 2
         factory = OpenSSL::X509::ExtensionFactory.new
         factory.subject_certificate = factory.issuer_certificate = certificate
-        certificate.extensions = [ factory.create_extension("basicConstraints","CA:TRUE", true), factory.create_extension("subjectKeyIdentifier", "hash"), ]
-        certificate.add_extension(factory.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always"))
+        certificate.extensions = [
+          factory.create_extension("basicConstraints","CA:TRUE", true),
+          factory.create_extension("subjectKeyIdentifier", "hash"),
+        ]
+        certificate.add_extension(
+          factory.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
+        )
         certificate.sign(rsa_key, OpenSSL::Digest::SHA256.new)
         [
           certificate.to_pem,