xml-kit 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 49fff640520abeb3b244774d156af6e18ee85928
4
- data.tar.gz: 92f26fb96366f6a9b8991fa4806f40edeff2d11a
2
+ SHA256:
3
+ metadata.gz: 541ed54ee3640966ee29ba48f0cfbac4e40e5ced11ea356111cc23fc058964f7
4
+ data.tar.gz: 24802b75664d6ea143e2b9f2868fd68f5886a45a38f0012db475c76c753d569d
5
5
  SHA512:
6
- metadata.gz: 000cccaa63a068e24acaa203dfeb80bcd3704f214be8812bb84feacb3d584e920eef7bd1a17d317e6049055a991f9d3c589cf505b4cf9574969a2ed179e19ad7
7
- data.tar.gz: 516d4b2f71e2e9e6bd70d09be1f217234d0d10f5649a73ee97ae5100b32b34af24f42e52705465de3047a0d565c9a61f83c117fb1dfe0dc4149e1ff47413c10c
6
+ metadata.gz: 6615e9d82fa0fbae91f9ef7dde847ce2352931cb9f4590d6262eb79d6115fd728fb4b962e9d52a9cbdd0f8c53f592ea81488eb871a16c7f75cf4859c419fed08
7
+ data.tar.gz: 9a51a0092a026898a1364a69015426c5ee26cc72304c650d13f1fce567bc2c55506aef6d3c7ad47af420ae02d1c5005091c53d2b0862a2f2c111f39afb7217ca
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.2.9
5
+ - 2.3.6
4
6
  - 2.4.3
7
+ - 2.5.0
5
8
  before_install: gem install bundler -v 1.16.0
9
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Xml::Kit
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/xml-kit.svg)](https://rubygems.org/gems/xml-kit)
4
+ [![Code Climate](https://codeclimate.com/github/saml-kit/xml-kit.svg)](https://codeclimate.com/github/saml-kit/xml-kit)
5
+ [![Build Status](https://travis-ci.org/saml-kit/xml-kit.svg)](https://travis-ci.org/saml-kit/xml-kit)
6
+ [![Security](https://hakiri.io/github/saml-kit/xml-kit/master.svg)](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).
@@ -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("password").create
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
@@ -1,23 +1,21 @@
1
1
  module Xml
2
2
  module Kit
3
3
  class KeyPair # :nodoc:
4
- attr_reader :certificate, :private_key, :use
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
- @use == use
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(passphrase).create(algorithm)
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 initialize(passphrase)
7
- @passphrase = passphrase
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
- def create(algorithm = 'AES-256-CBC')
11
- rsa_key = OpenSSL::PKey::RSA.new(2048)
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.to_i
15
- certificate.not_after = (Date.today + 30).to_time.to_i
16
- certificate.public_key = rsa_key.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.sign(rsa_key, OpenSSL::Digest::SHA256.new)
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
@@ -1,5 +1,5 @@
1
1
  module Xml
2
2
  module Kit
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
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 = "http://www.mokhan.ca"
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", "~> 1.8"
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.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: 2017-12-30 00:00:00.000000000 Z
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: '1.8'
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: '1.8'
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: http://www.mokhan.ca
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.6.14
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.