xml-kit 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xml/kit/certificate.rb +32 -13
- data/lib/xml/kit/self_signed_certificate.rb +1 -1
- data/lib/xml/kit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 763d302952d50ea00aad995aed62996708732c266e32e3fafeea3cc4e9db6c05
|
4
|
+
data.tar.gz: 537a44ee7c79ba0edd4a32d850320845395aa4d1499b2c7138891d20dfe71970
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '01894af70c7d56882b04968eec80650acc3263e98633a8a04f4727d434b860197d6d39bf266f1750b13f8b66aebdc94c4bd3e917244c9def16f55f73e1d296d9'
|
7
|
+
data.tar.gz: ecf023714655c4293064ce8656aa6e65e115b264be25f2d240ddfe5e37f3a2e532fa13f2137d99c6473350b3a98325491e307e42f52a10cf47c1eb0495e6646c
|
data/lib/xml/kit/certificate.rb
CHANGED
@@ -90,24 +90,43 @@ module Xml
|
|
90
90
|
KeyPair.new(x509.to_pem, private_key.to_s, passphrase, use)
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
|
95
|
-
return value if value.is_a?(OpenSSL::X509::Certificate)
|
96
|
-
OpenSSL::X509::Certificate.new(value)
|
93
|
+
def expired?(time = Time.now)
|
94
|
+
x509.not_after <= time
|
97
95
|
end
|
98
96
|
|
99
|
-
def
|
100
|
-
|
97
|
+
def active?(time = Time.now)
|
98
|
+
x509.not_before <= time && !expired?(time)
|
99
|
+
end
|
100
|
+
|
101
|
+
def not_after
|
102
|
+
x509.not_after
|
103
|
+
end
|
101
104
|
|
102
|
-
|
103
|
-
|
105
|
+
def not_before
|
106
|
+
x509.not_before
|
104
107
|
end
|
105
108
|
|
106
|
-
|
107
|
-
value
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
class << self
|
110
|
+
def to_x509(value)
|
111
|
+
return value if value.is_a?(OpenSSL::X509::Certificate)
|
112
|
+
|
113
|
+
value = Base64.decode64(strip(value)) if base64?(value)
|
114
|
+
OpenSSL::X509::Certificate.new(value)
|
115
|
+
end
|
116
|
+
|
117
|
+
def base64?(value)
|
118
|
+
return unless value.is_a?(String)
|
119
|
+
|
120
|
+
sanitized_value = strip(value)
|
121
|
+
!!sanitized_value.match(BASE64_FORMAT)
|
122
|
+
end
|
123
|
+
|
124
|
+
def strip(value)
|
125
|
+
value.
|
126
|
+
gsub(BEGIN_CERT, '').
|
127
|
+
gsub(END_CERT, '').
|
128
|
+
gsub(/[\r\n]|\\r|\\n|\s/, "")
|
129
|
+
end
|
111
130
|
end
|
112
131
|
end
|
113
132
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Xml
|
2
2
|
module Kit
|
3
3
|
class SelfSignedCertificate
|
4
|
-
SUBJECT="/C=CA/ST=
|
4
|
+
SUBJECT="/C=CA/ST=AB/L=Calgary/O=XmlKit/OU=XmlKit/CN=XmlKit"
|
5
5
|
|
6
6
|
def create(algorithm: 'AES-256-CBC', passphrase: nil, key_pair: OpenSSL::PKey::RSA.new(2048))
|
7
7
|
certificate = certificate_for(key_pair.public_key)
|
data/lib/xml/kit/version.rb
CHANGED