rsolr-client-cert 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +9 -0
- data/lib/rsolr/client-cert.rb +1 -0
- data/lib/rsolr/client_cert.rb +18 -0
- data/lib/rsolr/client_cert/connection.rb +65 -0
- data/lib/rsolr/client_cert/version.rb +5 -0
- data/rsolr-client-cert.gemspec +26 -0
- data/spec/fixtures/certificate.crt +16 -0
- data/spec/fixtures/dsa_key.key +12 -0
- data/spec/fixtures/rsa_key.key +9 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/unit/client_cert_spec.rb +26 -0
- metadata +153 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# rsolr-client-cert [![Build Status](https://secure.travis-ci.org/mbklein/rsolr-client-cert.png)](http://travis-ci.org/mbklein/rsolr-client-cert)
|
2
|
+
|
3
|
+
<b>rsolr-client-cert</b> provides client certificate authentication for [RSolr](https://github.com/mwmitchell/rsolr).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install rsolr-client-cert
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'rsolr/client_cert'
|
13
|
+
|
14
|
+
client = RSolr::ClientCert.connect :url => 'http://solrserver.com', :ssl_cert_file => '/path/to/certificate.crt',
|
15
|
+
:ssl_key_file => '/path/to/keyfile.key', :ssl_key_pass => 'SuPeRseKrItPaSsWoRd!!11!'
|
16
|
+
|
17
|
+
Or, to create the certificate/key objects manually:
|
18
|
+
|
19
|
+
@my_cert = OpenSSL::X509::Certificate.new(cert_pem)
|
20
|
+
@my_key = OpenSSL::PKey::RSA.new(key_pem, key_pass)
|
21
|
+
client = RSolr::ClientCert.connect :url => 'http://solrserver.com', :ssl_client_cert => @my_cert,
|
22
|
+
:ssl_client_key => @my_key
|
23
|
+
|
24
|
+
Any options that don't start with `:ssl_` will be passed through to `RSolr::Client`. See the
|
25
|
+
[RSolr README](https://github.com/mwmitchell/rsolr/blob/master/README.rdoc) for additional valid
|
26
|
+
options.
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
* Fork the project.
|
31
|
+
* Make your feature addition or bug fix.
|
32
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
33
|
+
* Commit. Please do not mess with rakefile, version, or history. If you want to have your own version,
|
34
|
+
that is fine but bump version in a commit by itself I can ignore when I pull.
|
35
|
+
* Send me a pull request. Bonus points for topic branches.
|
36
|
+
|
37
|
+
## Version History
|
38
|
+
|
39
|
+
- <b>0.5.0</b> Initial release
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rsolr/client_cert'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rsolr'
|
2
|
+
require "rsolr/client_cert/version"
|
3
|
+
require 'rsolr/client_cert/connection'
|
4
|
+
|
5
|
+
module RSolr
|
6
|
+
module ClientCert
|
7
|
+
|
8
|
+
def self.connect(opts)
|
9
|
+
grouped_opts = opts.group_by { |k,v| k.to_s =~ /^ssl_/ ? :ssl : :solr }
|
10
|
+
solr_opts = Hash[grouped_opts[:solr]]
|
11
|
+
ssl_opts = Hash[grouped_opts[:ssl]]
|
12
|
+
connection = Connection.new ssl_opts
|
13
|
+
client_class = opts.delete(:client_class) || RSolr::Client
|
14
|
+
client_class.new connection, solr_opts
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module RSolr
|
4
|
+
module ClientCert
|
5
|
+
class Error < Exception; end
|
6
|
+
|
7
|
+
class Connection
|
8
|
+
attr_reader :ssl_client_cert, :ssl_client_key
|
9
|
+
|
10
|
+
def initialize opts = {}
|
11
|
+
@ssl_client_cert = extract_client_cert(opts)
|
12
|
+
@ssl_client_key = extract_client_key(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute client, request_context
|
16
|
+
resource = RestClient::Resource.new(
|
17
|
+
request_context[:uri].to_s,
|
18
|
+
:ssl_client_cert => ssl_client_cert,
|
19
|
+
:ssl_client_key => ssl_client_key
|
20
|
+
)
|
21
|
+
result = {}
|
22
|
+
resource.send(request_context[:method]) { |response, request, result, &block|
|
23
|
+
result = {
|
24
|
+
:status => response.net_http_res.code.to_i,
|
25
|
+
:headers => response.net_http_res.to_hash,
|
26
|
+
:body => response.net_http_res.body
|
27
|
+
}
|
28
|
+
}
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def extract_key_class(key_text)
|
35
|
+
if key_text =~ /BEGIN (.+) PRIVATE KEY/
|
36
|
+
OpenSSL::PKey.const_get($1.to_sym)
|
37
|
+
else
|
38
|
+
raise Error, "Cannot determine key type"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def extract_client_key(opts)
|
43
|
+
if opts[:ssl_client_key]
|
44
|
+
opts[:ssl_client_key]
|
45
|
+
elsif opts[:ssl_key_file]
|
46
|
+
key_text = File.read(opts[:ssl_key_file])
|
47
|
+
key_class = extract_key_class(key_text)
|
48
|
+
key_class.new(key_text, opts[:ssl_key_pass].to_s)
|
49
|
+
else
|
50
|
+
raise Error, "No :ssl_client_key or :ssl_key_file provided"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_client_cert(opts)
|
55
|
+
if opts[:ssl_client_cert]
|
56
|
+
opts[:ssl_client_cert]
|
57
|
+
elsif opts[:ssl_cert_file]
|
58
|
+
OpenSSL::X509::Certificate.new(File.read(opts[:ssl_cert_file]))
|
59
|
+
else
|
60
|
+
raise Error, "No :ssl_client_key or :ssl_key_file provided"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rsolr/client_cert/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rsolr-client-cert"
|
7
|
+
s.version = RSolr::ClientCert::VERSION
|
8
|
+
s.authors = ["Michael Klein"]
|
9
|
+
s.email = ["mbklein@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/mbklein/rsolr-client-cert"
|
11
|
+
s.summary = %q{Client certificate authentication for RSolr}
|
12
|
+
s.description = %q{Client certificate authentication for RSolr}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here; for example:
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "simplecov"
|
23
|
+
s.add_runtime_dependency "jruby-openssl" if RUBY_PLATFORM == 'java'
|
24
|
+
s.add_runtime_dependency "rsolr"
|
25
|
+
s.add_runtime_dependency "rest-client"
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICbTCCAhegAwIBAgIJAL901ib7qNHbMA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNV
|
3
|
+
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQHEwlQYWxvIEFsdG8x
|
4
|
+
IjAgBgNVBAoTGVJTb2xyIENsaWVudCBDZXJ0IFRlc3RpbmcwHhcNMTIwMjI4MjIw
|
5
|
+
MzI5WhcNMTUwMjI3MjIwMzI5WjBaMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2Fs
|
6
|
+
aWZvcm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMSIwIAYDVQQKExlSU29sciBDbGll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YVQhd3fr9eB+kay6OYQsp2kl26zLVFiwDY4YXTpc9eZS7FGe9TzXUWNJ
|
8
|
+
9QwxQlECgYB4284c3vv96cJ0KtGRX2IDXBAsgRGIQ4RyBbREcgEEpatWCn7T0WZe
|
9
|
+
zI2HRnEVSjn+O2YC0Ym2DWNUmoCtNd9NJucBAnCbBa9E3yS4lXAdBCF7ayyU38jL
|
10
|
+
9R78O9OnB2caXSc4lauxof7Pp9vkJzL/RqvOroajCKZykpvWBeKR9gIUALtnzzgn
|
11
|
+
mV4UIkYewkHsM/TUIkQ=
|
12
|
+
-----END DSA PRIVATE KEY-----
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIBPAIBAAJBANK6Zv2M7H/42RYJggi9NxeEFVswk2864VwOjevrzDQstds/vT2F
|
3
|
+
9ljLVeetk7Zj/39cQzKDuPKGHXq+OH5q2IMCAwEAAQJBAIZtMKwITQop5dogAJqw
|
4
|
+
kcdnk/QTHco0BnUiN7jLN/4DamPMI6DoGoqdkbVt5LuLatU5OT+hqPpC8m6SERVs
|
5
|
+
M7kCIQD6j5lHGlTiEVCEsq8vvl8fZohFsIp8mHu1F7DRs0zK3wIhANdNcoCELOZ7
|
6
|
+
9NeFLPbDCFUwvVGR/79OheZXc510LQrdAiBppIIL6J5BcutwB6a1ip6wrppmR7kc
|
7
|
+
L255PDPhNqf6IQIhAMQ3KeYkD4OSboZIMb1F638wJymC5FAmMPPGuXBC45XlAiEA
|
8
|
+
lYUA4Vrf9Hj5eKGddWTD//2xlwrrKjFLAXO1gOmJF7s=
|
9
|
+
-----END RSA PRIVATE KEY-----
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'rsolr/client_cert'
|
3
|
+
|
4
|
+
describe RSolr::ClientCert do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@fixture_dir = File.expand_path('../../fixtures',__FILE__)
|
8
|
+
@cert_file = File.join(@fixture_dir,'certificate.crt')
|
9
|
+
@key_pass = 'SuPeRseKrItPaSsWoRd!!11!'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should provide an SSL certificate connection with an RSA keyfile" do
|
13
|
+
solr = RSolr::ClientCert.connect :url => 'https://example.edu/solr', :ssl_cert_file => @cert_file,
|
14
|
+
:ssl_key_file => File.join(@fixture_dir, 'rsa_key.key'), :ssl_key_pass => @key_pass
|
15
|
+
solr.connection.ssl_client_cert.should be_a OpenSSL::X509::Certificate
|
16
|
+
solr.connection.ssl_client_key.should be_a OpenSSL::PKey::RSA
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should provide an SSL certificate connection with an RSA keyfile" do
|
20
|
+
solr = RSolr::ClientCert.connect :url => 'https://example.edu/solr', :ssl_cert_file => @cert_file,
|
21
|
+
:ssl_key_file => File.join(@fixture_dir, 'dsa_key.key'), :ssl_key_pass => @key_pass
|
22
|
+
solr.connection.ssl_client_cert.should be_a OpenSSL::X509::Certificate
|
23
|
+
solr.connection.ssl_client_key.should be_a OpenSSL::PKey::DSA
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsolr-client-cert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Klein
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: simplecov
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rsolr
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
type: :runtime
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rest-client
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
type: :runtime
|
89
|
+
version_requirements: *id005
|
90
|
+
description: Client certificate authentication for RSolr
|
91
|
+
email:
|
92
|
+
- mbklein@gmail.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files: []
|
98
|
+
|
99
|
+
files:
|
100
|
+
- .gitignore
|
101
|
+
- .travis.yml
|
102
|
+
- Gemfile
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- lib/rsolr/client-cert.rb
|
106
|
+
- lib/rsolr/client_cert.rb
|
107
|
+
- lib/rsolr/client_cert/connection.rb
|
108
|
+
- lib/rsolr/client_cert/version.rb
|
109
|
+
- rsolr-client-cert.gemspec
|
110
|
+
- spec/fixtures/certificate.crt
|
111
|
+
- spec/fixtures/dsa_key.key
|
112
|
+
- spec/fixtures/rsa_key.key
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/unit/client_cert_spec.rb
|
115
|
+
homepage: https://github.com/mbklein/rsolr-client-cert
|
116
|
+
licenses: []
|
117
|
+
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.8.15
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Client certificate authentication for RSolr
|
148
|
+
test_files:
|
149
|
+
- spec/fixtures/certificate.crt
|
150
|
+
- spec/fixtures/dsa_key.key
|
151
|
+
- spec/fixtures/rsa_key.key
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- spec/unit/client_cert_spec.rb
|