xml-kit 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +4 -0
- data/README.md +5 -0
- data/lib/xml/kit/fingerprint.rb +1 -1
- data/lib/xml/kit/key_pair.rb +6 -8
- data/lib/xml/kit/self_signed_certificate.rb +20 -12
- data/lib/xml/kit/version.rb +1 -1
- data/xml-kit.gemspec +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 541ed54ee3640966ee29ba48f0cfbac4e40e5ced11ea356111cc23fc058964f7
|
4
|
+
data.tar.gz: 24802b75664d6ea143e2b9f2868fd68f5886a45a38f0012db475c76c753d569d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6615e9d82fa0fbae91f9ef7dde847ce2352931cb9f4590d6262eb79d6115fd728fb4b962e9d52a9cbdd0f8c53f592ea81488eb871a16c7f75cf4859c419fed08
|
7
|
+
data.tar.gz: 9a51a0092a026898a1364a69015426c5ee26cc72304c650d13f1fce567bc2c55506aef6d3c7ad47af420ae02d1c5005091c53d2b0862a2f2c111f39afb7217ca
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Xml::Kit
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/xml-kit)
|
4
|
+
[](https://codeclimate.com/github/saml-kit/xml-kit)
|
5
|
+
[](https://travis-ci.org/saml-kit/xml-kit)
|
6
|
+
[](https://hakiri.io/github/saml-kit/xml-kit/master)
|
7
|
+
|
3
8
|
Xml::Kit is a toolkit for working with XML. It supports adding [XML
|
4
9
|
Digital Signatures](https://www.w3.org/TR/xmldsig-core/)
|
5
10
|
and [XML Encryption](https://www.w3.org/TR/2002/REC-xmlenc-core-20021210/Overview.html).
|
data/lib/xml/kit/fingerprint.rb
CHANGED
@@ -2,7 +2,7 @@ module Xml
|
|
2
2
|
module Kit
|
3
3
|
# This generates a fingerprint for an X509 Certificate.
|
4
4
|
#
|
5
|
-
# certificate, _ = Xml::Kit::SelfSignedCertificate.new
|
5
|
+
# certificate, _ = Xml::Kit::SelfSignedCertificate.new.create
|
6
6
|
#
|
7
7
|
# puts Xml::Kit::Fingerprint.new(certificate).to_s
|
8
8
|
# # B7:AB:DC:BD:4D:23:58:65:FD:1A:99:0C:5F:89:EA:87:AD:F1:D7:83:34:7A:E9:E4:88:12:DD:46:1F:38:05:93
|
data/lib/xml/kit/key_pair.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
module Xml
|
2
2
|
module Kit
|
3
3
|
class KeyPair # :nodoc:
|
4
|
-
attr_reader :certificate
|
4
|
+
attr_reader :certificate
|
5
|
+
attr_reader :private_key
|
6
|
+
attr_reader :public_key
|
5
7
|
|
6
8
|
def initialize(certificate, private_key, passphrase, use)
|
7
|
-
@use = use
|
8
9
|
@certificate = ::Xml::Kit::Certificate.new(certificate, use: use)
|
9
10
|
@private_key = OpenSSL::PKey::RSA.new(private_key, passphrase)
|
11
|
+
@public_key = @private_key.public_key
|
10
12
|
end
|
11
13
|
|
12
14
|
# Returns true if the key pair is the designated use.
|
13
15
|
#
|
14
16
|
# @param use [Symbol] Can be either `:signing` or `:encryption`.
|
15
17
|
def for?(use)
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def public_key
|
20
|
-
certificate.public_key
|
18
|
+
certificate.for?(use)
|
21
19
|
end
|
22
20
|
|
23
21
|
# Returns a generated self signed certificate with private key.
|
@@ -27,7 +25,7 @@ module Xml
|
|
27
25
|
# @param algorithm [String] the symmetric algorithm to use for encrypting the private key.
|
28
26
|
def self.generate(use:, passphrase: SecureRandom.uuid, algorithm: ::Xml::Kit::Crypto::SymmetricCipher::DEFAULT_ALGORITHM)
|
29
27
|
algorithm = ::Xml::Kit::Crypto::SymmetricCipher::ALGORITHMS[algorithm]
|
30
|
-
certificate, private_key = ::Xml::Kit::SelfSignedCertificate.new
|
28
|
+
certificate, private_key = ::Xml::Kit::SelfSignedCertificate.new.create(algorithm: algorithm, passphrase: passphrase)
|
31
29
|
new(certificate, private_key, passphrase, use)
|
32
30
|
end
|
33
31
|
end
|
@@ -3,24 +3,32 @@ module Xml
|
|
3
3
|
class SelfSignedCertificate
|
4
4
|
SUBJECT="/C=CA/ST=Alberta/L=Calgary/O=XmlKit/OU=XmlKit/CN=XmlKit"
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def create(algorithm: 'AES-256-CBC', passphrase: nil, key_pair: OpenSSL::PKey::RSA.new(2048))
|
7
|
+
certificate = certificate_for(key_pair.public_key)
|
8
|
+
certificate.sign(key_pair, OpenSSL::Digest::SHA256.new)
|
9
|
+
[ certificate.to_pem, export(key_pair, algorithm, passphrase) ]
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
private
|
13
|
+
|
14
|
+
def export(key_pair, algorithm, passphrase)
|
15
|
+
if passphrase.present?
|
16
|
+
cipher = OpenSSL::Cipher.new(algorithm)
|
17
|
+
key_pair.export(cipher, passphrase)
|
18
|
+
else
|
19
|
+
key_pair.export
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def certificate_for(public_key)
|
12
24
|
certificate = OpenSSL::X509::Certificate.new
|
13
25
|
certificate.subject = certificate.issuer = OpenSSL::X509::Name.parse(SUBJECT)
|
14
|
-
certificate.not_before = Time.now
|
15
|
-
certificate.not_after =
|
16
|
-
certificate.public_key =
|
26
|
+
certificate.not_before = Time.now
|
27
|
+
certificate.not_after = certificate.not_before + 30 * 24 * 60 * 60 # 30 days
|
28
|
+
certificate.public_key = public_key
|
17
29
|
certificate.serial = 0x0
|
18
30
|
certificate.version = 2
|
19
|
-
certificate
|
20
|
-
[
|
21
|
-
certificate.to_pem,
|
22
|
-
rsa_key.to_pem(OpenSSL::Cipher.new(algorithm), @passphrase)
|
23
|
-
]
|
31
|
+
certificate
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
data/lib/xml/kit/version.rb
CHANGED
data/xml-kit.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{A simple toolkit for working with XML.}
|
13
13
|
spec.description = %q{A simple toolkit for working with XML.}
|
14
|
-
spec.homepage = "
|
14
|
+
spec.homepage = "https://github.com/saml-kit/xml-kit"
|
15
15
|
spec.license = "MIT"
|
16
16
|
spec.required_ruby_version = '>= 2.2.0'
|
17
17
|
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_dependency "activemodel", ">= 4.2.0"
|
27
27
|
spec.add_dependency "builder", "~> 3.2"
|
28
|
-
spec.add_dependency "nokogiri", "
|
28
|
+
spec.add_dependency "nokogiri", ">= 1.8.1"
|
29
29
|
spec.add_dependency "tilt", "~> 2.0"
|
30
30
|
spec.add_dependency "xmldsig", "~> 0.6"
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.16"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml-kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: nokogiri
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.8.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.8.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: tilt
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +192,7 @@ files:
|
|
192
192
|
- lib/xml/kit/templates/signature.builder
|
193
193
|
- lib/xml/kit/version.rb
|
194
194
|
- xml-kit.gemspec
|
195
|
-
homepage:
|
195
|
+
homepage: https://github.com/saml-kit/xml-kit
|
196
196
|
licenses:
|
197
197
|
- MIT
|
198
198
|
metadata:
|
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
213
|
version: '0'
|
214
214
|
requirements: []
|
215
215
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
216
|
+
rubygems_version: 2.7.3
|
217
217
|
signing_key:
|
218
218
|
specification_version: 4
|
219
219
|
summary: A simple toolkit for working with XML.
|