manticore 0.6.3-java → 0.6.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +42 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -1
- data/README.md +2 -0
- data/ext/manticore/org/manticore/Manticore.java +3 -3
- data/lib/manticore/client.rb +32 -24
- data/lib/manticore/version.rb +1 -1
- data/lib/org/manticore/manticore-ext.jar +0 -0
- data/manticore.gemspec +2 -0
- data/spec/manticore/client_spec.rb +40 -1
- data/spec/spec_helper.rb +6 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b846373d0dce20d74cb4e2434868f908006e63
|
4
|
+
data.tar.gz: e136b3550efea6343291f9264d45ff1b6fa24448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a02ebe1e15e565212f135d760cb83eaaaecbd73f8664c9470ef14feb00a163d76a8383918f3b51a28018853c8e88c0bb1f5af7eae28f9f5e0f7840806b70d79
|
7
|
+
data.tar.gz: 74f89a4d46806461ae86b2554ac418ebd3673e8b4c55a4add68da84d88cb54418ada667d1f4673f549782b693982e4f2a4ec84fb41f8248fd9fab1a2a150e817
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
.default: &default
|
2
|
+
variables:
|
3
|
+
TERM: xterm-256color
|
4
|
+
JRUBY_OPTS: --debug
|
5
|
+
cache:
|
6
|
+
paths:
|
7
|
+
- bundler --path vendor/bundle
|
8
|
+
- $HOME/.m2
|
9
|
+
before_script:
|
10
|
+
- apt update && apt install -y git
|
11
|
+
- gem install ruby-maven bundler
|
12
|
+
- bundle install --path vendor/bundle
|
13
|
+
script:
|
14
|
+
- bundle exec rake
|
15
|
+
|
16
|
+
test jruby-9.2:
|
17
|
+
<<: *default
|
18
|
+
image: jruby:9.2
|
19
|
+
artifacts:
|
20
|
+
expire_in: 3 days
|
21
|
+
paths:
|
22
|
+
- coverage
|
23
|
+
|
24
|
+
test jruby-9.1:
|
25
|
+
<<: *default
|
26
|
+
image: jruby:9.1
|
27
|
+
|
28
|
+
test jruby-1.7:
|
29
|
+
<<: *default
|
30
|
+
image: jruby:1.7
|
31
|
+
|
32
|
+
pages:
|
33
|
+
stage: deploy
|
34
|
+
only:
|
35
|
+
- master
|
36
|
+
artifacts:
|
37
|
+
expire_in: 3 days
|
38
|
+
paths:
|
39
|
+
- public
|
40
|
+
script:
|
41
|
+
- mkdir -p public
|
42
|
+
- mv coverage/ public/coverage/
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
## v0.6
|
2
2
|
|
3
|
+
### v0.6.5
|
4
|
+
|
5
|
+
(unreleased)
|
6
|
+
|
7
|
+
### v0.6.4
|
8
|
+
|
9
|
+
* client_cert and client_key now take the literal keys as strings, OpenSSL::X509::Certificate/OpenSSL::PKey::Pkey instances, or key file paths. (#77)
|
10
|
+
* Reduced unnecessary string copying (!78 - thanks @kares)
|
11
|
+
|
12
|
+
### v0.6.2-v0.6.3
|
13
|
+
|
14
|
+
* Fixed the use of authentication information in proxy URLs (#71)
|
15
|
+
* Changed the default encoding to UTF-8 when a response MIME is application/json (#70)
|
16
|
+
|
3
17
|
### v0.6.1
|
4
18
|
|
5
19
|
* Manticore will accept a URI object (which it calls #to_s on) as an alternate to a String for the URL in client#get(url)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Manticore
|
2
2
|
|
3
|
+
**Note**: While I'll continue to maintain the library here, I've moved the canonical copy to Gitlab at https://gitlab.com/cheald/manticore - it is preferred that you submit issues and PRs there.
|
4
|
+
|
3
5
|
[![Build Status](https://travis-ci.org/cheald/manticore.svg?branch=master)](https://travis-ci.org/cheald/manticore)
|
4
6
|
|
5
7
|
Manticore is a fast, robust HTTP client built on the Apache HTTPClient libraries. It is only compatible with JRuby.
|
@@ -66,7 +66,7 @@ public class Manticore implements Library {
|
|
66
66
|
|
67
67
|
private IRubyObject readWholeEntity(ThreadContext context, HttpEntity entity, Encoding encoding) throws IOException {
|
68
68
|
ByteList bl = new ByteList(EntityUtils.toByteArray(entity), false);
|
69
|
-
return RubyString.
|
69
|
+
return RubyString.newString(context.getRuntime(), bl, encoding);
|
70
70
|
}
|
71
71
|
|
72
72
|
private IRubyObject streamEntity(ThreadContext context, HttpEntity entity, Encoding encoding, Block block) throws IOException {
|
@@ -86,7 +86,7 @@ public class Manticore implements Library {
|
|
86
86
|
byte[] tmp = new byte[4096];
|
87
87
|
int l;
|
88
88
|
while((l = instream.read(tmp)) != -1) {
|
89
|
-
block.call( context, RubyString.
|
89
|
+
block.call( context, RubyString.newStringShared(context.getRuntime(), new ByteList(tmp, 0, l, false), encoding) );
|
90
90
|
}
|
91
91
|
} finally {
|
92
92
|
instream.close();
|
@@ -94,4 +94,4 @@ public class Manticore implements Library {
|
|
94
94
|
return context.nil;
|
95
95
|
}
|
96
96
|
}
|
97
|
-
}
|
97
|
+
}
|
data/lib/manticore/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "thread"
|
2
2
|
require "base64"
|
3
3
|
require "weakref"
|
4
|
+
require "openssl_pkcs8_pure"
|
4
5
|
|
5
6
|
module Manticore
|
6
7
|
# @!macro [new] http_method_shared
|
@@ -169,8 +170,8 @@ module Manticore
|
|
169
170
|
# @option options [String] ssl[:keystore_password] (nil) Password used for decrypting the client auth key store
|
170
171
|
# @option options [String] ssl[:keystore_type] (nil) Format of the key store, ie "JKS" or "PKCS12". If left nil, the type will be inferred from the keystore filename.
|
171
172
|
# @option options [String] ssl[:ca_file] (nil) OpenSSL-style path to an X.509 certificate to use to validate SSL certificates
|
172
|
-
# @option options [String]
|
173
|
-
# @option options [String] ssl[:client_key] (nil)
|
173
|
+
# @option options [String|OpenSSL::X509::Certificate] ssl[:client_cert] (nil) A string containing a base64-encoded X.509 certificate, OR a path to an OpenSSL-style X.509 certificate, OR an instance of OpenSSL::X509::Certificate
|
174
|
+
# @option options [String|OpenSSL::PKey::Pkey] ssl[:client_key] (nil) A string containing a base64-encoded RSA key to use for client authentication, OR a path to an OpenSSL-style RSA key, OR an instance of OpenSSL::PKey::PKey
|
174
175
|
# @option options [boolean] ssl[:track_state] (false) Turn on or off connection state tracking. This helps prevent SSL information from leaking across threads, but means that connections
|
175
176
|
# can't be shared across those threads. This should generally be left off unless you know what you're doing.
|
176
177
|
def initialize(options = {})
|
@@ -385,11 +386,13 @@ module Manticore
|
|
385
386
|
def pool_builder(options)
|
386
387
|
http_sf = PlainConnectionSocketFactory.new
|
387
388
|
|
389
|
+
# :nocov:
|
388
390
|
if options[:ignore_ssl_validation]
|
389
391
|
$stderr.puts "The options[:ignore_ssl_validation] setting is deprecated in favor of options[:ssl][:verify]"
|
390
392
|
options[:ssl] ||= {}
|
391
393
|
options[:ssl] = {:verify => !options.delete(:ignore_ssl_validation)}.merge(options[:ssl])
|
392
394
|
end
|
395
|
+
# :nocov:
|
393
396
|
|
394
397
|
https_sf = ssl_socket_factory_from_options options.fetch(:ssl, {})
|
395
398
|
registry = RegistryBuilder.create.register("http", http_sf).register("https", https_sf).build
|
@@ -645,39 +648,44 @@ module Manticore
|
|
645
648
|
keystore_password = (ssl_options[:keystore_password] || "").to_java.toCharArray
|
646
649
|
|
647
650
|
# Support OpenSSL-style bare X.509 certs with an RSA key
|
648
|
-
# This is really dumb - we have to b64-decode the key ourselves, and we can only support PKCS8
|
649
651
|
if ssl_options[:client_cert] && ssl_options[:client_key]
|
650
652
|
key_store ||= blank_keystore
|
651
653
|
certs, key = nil, nil
|
652
|
-
|
653
|
-
|
654
|
-
|
654
|
+
|
655
|
+
cert_str = if ssl_options[:client_cert].is_a?(OpenSSL::X509::Certificate)
|
656
|
+
ssl_options[:client_cert].to_s
|
657
|
+
elsif ssl_options[:client_cert].is_a?(String) && File.exists?(ssl_options[:client_cert])
|
658
|
+
File.read(ssl_options[:client_cert])
|
659
|
+
else
|
660
|
+
ssl_options[:client_cert].to_s
|
661
|
+
end
|
662
|
+
|
663
|
+
cert_stream = java.io.ByteArrayInputStream.new(cert_str.strip.to_java_bytes)
|
664
|
+
certs = CertificateFactory.get_instance("X509").generate_certificates(cert_stream).to_array([].to_java(Certificate))
|
665
|
+
|
666
|
+
key_str = if ssl_options[:client_key].is_a?(OpenSSL::PKey::PKey)
|
667
|
+
ssl_options[:client_key].to_pem_pkcs8
|
668
|
+
elsif ssl_options[:client_key].is_a?(String) && File.exists?(ssl_options[:client_key])
|
669
|
+
File.read(ssl_options[:client_key])
|
670
|
+
else
|
671
|
+
ssl_options[:client_key].to_s
|
672
|
+
end
|
655
673
|
|
656
674
|
# Add each of the keys in the given keyfile into the keystore.
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
key_store.set_key_entry("key-#{Digest::SHA1.hexdigest(body)}", key, keystore_password, certs)
|
666
|
-
end
|
675
|
+
key_parts = key_str.scan(KEY_EXTRACTION_REGEXP)
|
676
|
+
key_parts.each do |type, b64key|
|
677
|
+
body = Base64.decode64 b64key
|
678
|
+
spec = PKCS8EncodedKeySpec.new(body.strip.to_java_bytes)
|
679
|
+
type = type.strip
|
680
|
+
type = "RSA" if type == ""
|
681
|
+
key = KeyFactory.getInstance(type).generatePrivate(spec)
|
682
|
+
key_store.set_key_entry("key-#{Digest::SHA1.hexdigest(body)}", key, keystore_password, certs)
|
667
683
|
end
|
668
684
|
end
|
669
685
|
|
670
686
|
context.load_key_material(key_store, keystore_password) if key_store
|
671
687
|
end
|
672
688
|
|
673
|
-
def get_trust_store(options)
|
674
|
-
get_store :truststore, options
|
675
|
-
end
|
676
|
-
|
677
|
-
def get_key_store(options)
|
678
|
-
get_store :keystore, options
|
679
|
-
end
|
680
|
-
|
681
689
|
def get_store(prefix, options)
|
682
690
|
KeyStore.get_instance(options[:"#{prefix}_type"] || guess_store_type(options[prefix])).tap do |store|
|
683
691
|
instream = open(options[prefix], "rb").to_inputstream
|
data/lib/manticore/version.rb
CHANGED
Binary file
|
data/manticore.gemspec
CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.cert_chain = ['gem-public_cert.pem']
|
26
26
|
end
|
27
27
|
|
28
|
+
spec.add_dependency "openssl_pkcs8_pure"
|
29
|
+
|
28
30
|
spec.add_development_dependency "bundler", "~> 1.3"
|
29
31
|
spec.add_development_dependency "rake"
|
30
32
|
spec.add_development_dependency "jar-dependencies"
|
@@ -166,7 +166,7 @@ describe Manticore::Client do
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
context "when client_cert and client_key are given" do
|
169
|
+
context "when client_cert and client_key are given as file paths" do
|
170
170
|
let(:client) {
|
171
171
|
Manticore::Client.new(
|
172
172
|
:ssl => {
|
@@ -183,6 +183,40 @@ describe Manticore::Client do
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
+
context "when client_cert and client_key are given as OpenSSL::X509::Certificate" do
|
187
|
+
let(:client) {
|
188
|
+
Manticore::Client.new(
|
189
|
+
:ssl => {
|
190
|
+
verify: :strict,
|
191
|
+
ca_file: File.expand_path("../../ssl/root-ca.crt", __FILE__),
|
192
|
+
client_cert: OpenSSL::X509::Certificate.new(File.read(File.expand_path("../../ssl/client.crt", __FILE__))),
|
193
|
+
client_key: OpenSSL::PKey::RSA.new(File.read(File.expand_path("../../ssl/client.key", __FILE__))),
|
194
|
+
},
|
195
|
+
)
|
196
|
+
}
|
197
|
+
|
198
|
+
it "successfully auths requests" do
|
199
|
+
expect(client.get("https://localhost:55445/").body).to match("hello")
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when client_cert and client_key are given as strings" do
|
204
|
+
let(:client) {
|
205
|
+
Manticore::Client.new(
|
206
|
+
:ssl => {
|
207
|
+
verify: :strict,
|
208
|
+
ca_file: File.expand_path("../../ssl/root-ca.crt", __FILE__),
|
209
|
+
client_cert: File.read(File.expand_path("../../ssl/client.crt", __FILE__)),
|
210
|
+
client_key: File.read(File.expand_path("../../ssl/client.key", __FILE__)),
|
211
|
+
},
|
212
|
+
)
|
213
|
+
}
|
214
|
+
|
215
|
+
it "successfully auths requests" do
|
216
|
+
expect(client.get("https://localhost:55445/").body).to match("hello")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
186
220
|
context "when off" do
|
187
221
|
let(:client) { Manticore::Client.new :ssl => {:verify => :disable} }
|
188
222
|
|
@@ -730,11 +764,16 @@ describe Manticore::Client do
|
|
730
764
|
].join("\n"))
|
731
765
|
client.close
|
732
766
|
rescue IOError => e
|
767
|
+
break
|
733
768
|
end
|
734
769
|
end
|
735
770
|
end
|
736
771
|
end
|
737
772
|
|
773
|
+
after do
|
774
|
+
@server.kill
|
775
|
+
end
|
776
|
+
|
738
777
|
let(:client) { Manticore::Client.new keepalive: true, pool_max: 1 }
|
739
778
|
|
740
779
|
it "retries 3 times by default" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manticore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Chris Heald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: openssl_pkcs8_pure
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
15
29
|
requirements:
|
@@ -60,6 +74,7 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- ".gitlab-ci.yml"
|
63
78
|
- ".travis.yml"
|
64
79
|
- APACHE-LICENSE-2.0.txt
|
65
80
|
- CHANGELOG.md
|
@@ -122,7 +137,7 @@ requirements:
|
|
122
137
|
- jar commons-codec:commons-codec, '~> 1.9'
|
123
138
|
- jar org.apache.httpcomponents:httpcore, '~> 4.4.4'
|
124
139
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.6.14.1
|
126
141
|
signing_key:
|
127
142
|
specification_version: 4
|
128
143
|
summary: Manticore is an HTTP client built on the Apache HttpCore components
|