cert_munger 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +1 -0
- data/README.md +2 -2
- data/lib/cert_munger/formatter.rb +22 -1
- data/lib/cert_munger/string.rb +6 -3
- data/lib/cert_munger/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f3d57b7cab1e4d9a8e8e12854e7df697a67d4aa
|
4
|
+
data.tar.gz: 1b05487531aa24fe809d72b4042363702dc18a19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfeab5bd41b934d4838c42c6ecd83b3917eb3cb312eee4f1b689c95ae86474e8e92b5da0be7ec576e842453dc52e357ccabcd3c0273c6a79368c903edeb7a516
|
7
|
+
data.tar.gz: 8d2fa7bd0d5f54cab96cbae8d15bc546e23f09d4d573a7b750ddf2c35b58a69537ab2e3ad02bfe3e0dc52b3f11818c9daf5e2b8da3d404cfd3cef061d9e1aa70
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/cert_munger.png)](http://badge.fury.io/rb/cert_munger)
|
1
|
+
# CertMunger [![Gem Version](https://badge.fury.io/rb/cert_munger.png)](http://badge.fury.io/rb/cert_munger)
|
2
2
|
|
3
|
-
|
3
|
+
[![Travis CI](https://travis-ci.org/stevenhaddox/cert_munger.svg?branch=master)](https://travis-ci.org/stevenhaddox/cert_munger) [![Dependency Status](https://gemnasium.com/stevenhaddox/cert_munger.png)](https://gemnasium.com/stevenhaddox/cert_munger) [![Coverage Status](https://coveralls.io/repos/stevenhaddox/cert_munger/badge.png)](https://coveralls.io/r/stevenhaddox/cert_munger) [![Code Climate](https://codeclimate.com/github/stevenhaddox/cert_munger/badges/gpa.svg)](https://codeclimate.com/github/stevenhaddox/cert_munger) [![Inline docs](http://inch-ci.org/github/stevenhaddox/cert_munger.svg?branch=master)](http://inch-ci.org/github/stevenhaddox/cert_munger)
|
4
4
|
|
5
5
|
A gem that takes string input for X509 certificates and attempts to reformat
|
6
6
|
them into a valid certificate. This gem extends the core String class to add
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'logging'
|
2
|
+
|
3
|
+
# Custom exception for strings that can't be parsed as X509 Certificates
|
2
4
|
class UnparsableCertError < TypeError; end
|
3
5
|
|
4
6
|
#
|
@@ -6,24 +8,31 @@ class UnparsableCertError < TypeError; end
|
|
6
8
|
# formatted certificate.
|
7
9
|
#
|
8
10
|
module CertMunger
|
11
|
+
# Enables `include CertMunger` to also extend class methods
|
9
12
|
def self.included(base)
|
10
13
|
base.extend(ClassMethods)
|
11
14
|
end
|
12
15
|
|
16
|
+
# Instance variable accessor for CertMunger#to_cert
|
13
17
|
def to_cert(raw_cert)
|
14
18
|
self.class.send(:to_cert, raw_cert)
|
15
19
|
end
|
16
20
|
|
17
21
|
#
|
18
|
-
#
|
22
|
+
# Class methods provided by CertMunger module
|
19
23
|
#
|
20
24
|
module ClassMethods
|
25
|
+
# logger method to return Rails logger if defined, else logging logger
|
21
26
|
def logger
|
22
27
|
return @logger if @logger
|
23
28
|
logger = Logging.logger[self] unless @logger
|
24
29
|
@logger ||= Kernel.const_defined?('Rails') ? Rails.logger : logger
|
25
30
|
end
|
26
31
|
|
32
|
+
# Attempts to munge a string into a valid X509 certificate
|
33
|
+
#
|
34
|
+
# @param raw_cert [String] The string of text you wish to parse into a cert
|
35
|
+
# @return [OpenSSL::X509::Certificate]
|
27
36
|
def to_cert(raw_cert)
|
28
37
|
logger.debug "CertMunger raw_cert:\n#{raw_cert}"
|
29
38
|
new_cert = build_cert(raw_cert)
|
@@ -33,6 +42,10 @@ module CertMunger
|
|
33
42
|
OpenSSL::X509::Certificate.new new_cert
|
34
43
|
end
|
35
44
|
|
45
|
+
# Creates a temporary cert and orchestrates certificate body reformatting
|
46
|
+
#
|
47
|
+
# @param raw_cert [String] The string of text you wish to parse into a cert
|
48
|
+
# @return [String] reformatted and (hopefully) parseable certificate string
|
36
49
|
def build_cert(raw_cert)
|
37
50
|
tmp_cert = ['-----BEGIN CERTIFICATE-----']
|
38
51
|
if raw_cert.lines.count == 1
|
@@ -45,6 +58,10 @@ module CertMunger
|
|
45
58
|
tmp_cert.join("\n").rstrip
|
46
59
|
end
|
47
60
|
|
61
|
+
# Attempts to reformat one-line certificate bodies
|
62
|
+
#
|
63
|
+
# @param raw_cert [String] The string of text you wish to parse into a cert
|
64
|
+
# @return [String] reformatted certificate body
|
48
65
|
def one_line_contents(raw_cert)
|
49
66
|
cert_contents = raw_cert.split('\n')
|
50
67
|
cert_contents.pop
|
@@ -52,6 +69,10 @@ module CertMunger
|
|
52
69
|
cert_contents.map! { |el| el.match('\W+[t|n|r](.*)')[1] }
|
53
70
|
end
|
54
71
|
|
72
|
+
# Attempts to reformat multi-line certificate bodies
|
73
|
+
#
|
74
|
+
# @param raw_cert [String] The string of text you wish to parse into a cert
|
75
|
+
# @return [String] reformatted certificate body
|
55
76
|
def multi_line_contents(raw_cert)
|
56
77
|
cert_contents = raw_cert.split(/[-](.*)[-]/)[2]
|
57
78
|
cert_contents.lines.map do |line|
|
data/lib/cert_munger/string.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
1
|
+
#
|
2
|
+
# Extend the core String class to include `.to_cert` && `.to_cert!`
|
3
|
+
#
|
4
|
+
class String
|
2
5
|
include CertMunger
|
3
6
|
|
4
7
|
# Returns an X509 certificate after parsing the value of this object.
|
5
|
-
# Returns false if an X509 certificate cannot be created
|
8
|
+
# Returns false if an X509 certificate cannot be created
|
6
9
|
def to_cert
|
7
10
|
begin
|
8
11
|
new_cert = self.class.send(:to_cert, self)
|
@@ -14,7 +17,7 @@ class String # rubocop:disable Documentation
|
|
14
17
|
end
|
15
18
|
|
16
19
|
# Similar to {#to_cert}, but raises an error unless the string can be
|
17
|
-
# explicitly parsed to an X509 certifcate
|
20
|
+
# explicitly parsed to an X509 certifcate
|
18
21
|
def to_cert!
|
19
22
|
begin
|
20
23
|
new_cert = self.class.send(:to_cert, self)
|
data/lib/cert_munger/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cert_munger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Haddox
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- ".gitignore"
|
198
198
|
- ".rubocop.yml"
|
199
199
|
- ".travis.yml"
|
200
|
+
- ".yardopts"
|
200
201
|
- Gemfile
|
201
202
|
- LICENSE.txt
|
202
203
|
- README.md
|
metadata.gz.sig
CHANGED
Binary file
|