aggcat 0.3.6 → 0.3.7

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
2
  SHA1:
3
- metadata.gz: 01641fbe96bead5bc86b7402eab8390c0fdd0dce
4
- data.tar.gz: ead27f7fae30610e910d654a77c0e546950155ed
3
+ metadata.gz: 172de361ab101826185ef380d9bedb25dc49625f
4
+ data.tar.gz: 5329c6ec211c0c579cc42d2462fdff121329febd
5
5
  SHA512:
6
- metadata.gz: e49815f6255d7cbe96c0e2d98ffc37b8390b00871285447f79200f55ea60165332b5f74d7f9acfc8bffde592065f4d04e1fc42d493424d347de2afbcc9a407d7
7
- data.tar.gz: bab45121780df51e5072f6afcfd42ec7677ac0c001237549be886d097896352b890a33ced5530a715bf0ecd9f46da8c8e1f5e169c4a842c3777a1db1715e2320
6
+ metadata.gz: 8870135366674d325a409cdc391af4ae5545da5245c22876d00288b2d43e225c4a588579e9ed8062837ef3e44251708eb800e5915aca198ba833012a4a2c6c93
7
+ data.tar.gz: 67ba0e628d8aacb31d7569dd333802fd6829cf0aceb4b3249c12702a8cff97d15eb7dc11abda949c7fd69a107d70d122ab7fd33a52c80e6372a81d99dd0b6126
data/Gemfile CHANGED
@@ -1,8 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake'
4
-
5
3
  group :test do
4
+ gem 'rake'
6
5
  gem 'minitest'
7
6
  gem 'test-unit'
8
7
  gem 'simplecov', :require => false
data/README.md CHANGED
@@ -36,6 +36,10 @@ Aggcat.configure do |config|
36
36
  config.consumer_key = 'your consumer key'
37
37
  config.consumer_secret = 'your consumer secret'
38
38
  config.certificate_path = '/path/to/your/certificate/key'
39
+ # if your certificate is a string, instead of specify the path you can set the value like so
40
+ # Note certificate_value takes precedence over certificate_path
41
+ # Also make sure your certificate has newline characters as appropriate
42
+ config.certificate_value = "-----BEGIN RSA PRIVATE KEY-----\nasdf123FOO$BAR\n...\n-----END RSA PRIVATE KEY-----"
39
43
  end
40
44
 
41
45
  # alternatively, specify configuration options when instantiating an Aggcat::Client
@@ -43,7 +47,7 @@ client = Aggcat::Client.new(
43
47
  issuer_id: 'your issuer id',
44
48
  consumer_key: 'your consumer key',
45
49
  consumer_secret: 'your consumer secret',
46
- certificate_path: '/path/to/your/certificate/key',
50
+ certificate_path: '/path/to/your/certificate/key', # OR certificate_value: "--BEGIN RSA KEY--..."
47
51
  customer_id: 'scope for all requests'
48
52
  )
49
53
 
@@ -26,6 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'builder', '>= 3.0'
27
27
  spec.add_dependency 'activesupport', '>= 3.2'
28
28
 
29
- spec.add_development_dependency 'rake'
30
29
  spec.add_development_dependency 'bundler'
31
30
  end
@@ -73,13 +73,17 @@ module Aggcat
73
73
  assertion = %[<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_#{reference_id}" IssueInstant="#{iso8601(now)}" Version="2.0"><saml2:Issuer>#{@issuer_id}</saml2:Issuer><saml2:Subject><saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">#{user_id}</saml2:NameID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"></saml2:SubjectConfirmation></saml2:Subject><saml2:Conditions NotBefore="#{iso8601(now-5*60)}" NotOnOrAfter="#{iso8601(now+10*60)}"><saml2:AudienceRestriction><saml2:Audience>#{@issuer_id}</saml2:Audience></saml2:AudienceRestriction></saml2:Conditions><saml2:AuthnStatement AuthnInstant="#{iso8601(now)}" SessionIndex="_#{reference_id}"><saml2:AuthnContext><saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml2:AuthnContextClassRef></saml2:AuthnContext></saml2:AuthnStatement></saml2:Assertion>]
74
74
  digest = Base64.encode64(OpenSSL::Digest::SHA1.digest(assertion)).strip
75
75
  signed_info = %[<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#_#{reference_id}"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>#{digest}</ds:DigestValue></ds:Reference></ds:SignedInfo>]
76
- key = OpenSSL::PKey::RSA.new(File.read(@certificate_path))
76
+ key = OpenSSL::PKey::RSA.new(certificate)
77
77
  signature_value = Base64.encode64(key.sign(OpenSSL::Digest::SHA1.new(nil), signed_info)).gsub(/\n/, '')
78
78
  signature = %[<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#_#{reference_id}"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>#{digest}</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>#{signature_value}</ds:SignatureValue></ds:Signature>]
79
79
  assertion_with_signature = assertion.sub(/saml2:Issuer\>\<saml2:Subject/, "saml2:Issuer>#{signature}<saml2:Subject")
80
80
  Base64.encode64(assertion_with_signature)
81
81
  end
82
82
 
83
+ def certificate
84
+ @certificate_value ||= File.read(@certificate_path)
85
+ end
86
+
83
87
  def iso8601(time)
84
88
  time.strftime(TIME_FORMAT)
85
89
  end
@@ -1,9 +1,9 @@
1
1
  module Aggcat
2
2
  module Configurable
3
3
 
4
- attr_writer :issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id, :open_timeout, :read_timeout, :verbose
4
+ KEYS = [:issuer_id, :consumer_key, :consumer_secret, :certificate_value, :certificate_path, :customer_id, :open_timeout, :read_timeout, :verbose]
5
5
 
6
- KEYS = [:issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id, :open_timeout, :read_timeout, :verbose]
6
+ attr_writer *KEYS
7
7
 
8
8
  def configure
9
9
  yield self
@@ -1,3 +1,3 @@
1
1
  module Aggcat
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  end
@@ -27,6 +27,24 @@ class AggcatTest < Test::Unit::TestCase
27
27
  assert_equal 30, configurable.instance_variable_get(:'@read_timeout')
28
28
  end
29
29
 
30
+ def test_configure_certificate_by_value
31
+ cert_value = File.read("#{fixture_path}/cert.key")
32
+ configurable = Aggcat.configure do |config|
33
+ config.issuer_id = 'issuer_id'
34
+ config.consumer_key = 'consumer_key'
35
+ config.consumer_secret = 'consumer_secret'
36
+ config.certificate_value = cert_value
37
+ config.open_timeout = 5
38
+ config.read_timeout = 30
39
+ end
40
+ assert_equal 'issuer_id', configurable.instance_variable_get(:'@issuer_id')
41
+ assert_equal 'consumer_key', configurable.instance_variable_get(:'@consumer_key')
42
+ assert_equal 'consumer_secret', configurable.instance_variable_get(:'@consumer_secret')
43
+ assert_equal cert_value, configurable.instance_variable_get(:'@certificate_value')
44
+ assert_equal 5, configurable.instance_variable_get(:'@open_timeout')
45
+ assert_equal 30, configurable.instance_variable_get(:'@read_timeout')
46
+ end
47
+
30
48
  def test_scope
31
49
  client1 = Aggcat.scope('1')
32
50
  assert_true client1.is_a?(Aggcat::Client)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene Drabkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.2'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: bundler
85
71
  requirement: !ruby/object:Gem::Requirement