manticore 0.6.3-java → 0.6.4-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b96d1eb1f7f1e5b6885a5f08e24ba394ac9fac0
4
- data.tar.gz: 1ff15070f745905119d536ae7df328ce845990a6
3
+ metadata.gz: 00b846373d0dce20d74cb4e2434868f908006e63
4
+ data.tar.gz: e136b3550efea6343291f9264d45ff1b6fa24448
5
5
  SHA512:
6
- metadata.gz: 1f08d3632cbe683ce2456e4cde41d05545bdf5926992067f06f25af1477d9a31bac90d797a88a4f4d4a7a56477afd9f725981958ac3082e501c18199da4875b3
7
- data.tar.gz: d2231b58a53b86bd77af5c2f27f79d9a4ece0d72cffbace8c1a830fefcd33a84f5c710f93d1e55e76637ab48d5966c79f466ee40c911418a59e4ce440576a8c7
6
+ metadata.gz: 6a02ebe1e15e565212f135d760cb83eaaaecbd73f8664c9470ef14feb00a163d76a8383918f3b51a28018853c8e88c0bb1f5af7eae28f9f5e0f7840806b70d79
7
+ data.tar.gz: 74f89a4d46806461ae86b2554ac418ebd3673e8b4c55a4add68da84d88cb54418ada667d1f4673f549782b693982e4f2a4ec84fb41f8248fd9fab1a2a150e817
@@ -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/
@@ -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
@@ -11,4 +11,5 @@ group :development, :test do
11
11
  gem "rack", "~> 1.5"
12
12
  gem "rake-compiler"
13
13
  gem "gserver"
14
- end
14
+ gem "simplecov"
15
+ end
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.newStringShared(context.getRuntime(), bl, encoding);
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.newString(context.getRuntime(), new ByteList(tmp, 0, l, true), encoding) );
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
+ }
@@ -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] ssl[:client_cert] (nil) OpenSSL-style path to an X.509 certificate to use for client authentication
173
- # @option options [String] ssl[:client_key] (nil) OpenSSL-style path to an RSA key to use for client authentication
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
- open(ssl_options[:client_cert]) do |fp|
653
- certs = CertificateFactory.get_instance("X509").generate_certificates(fp.to_inputstream).to_array([].to_java(Certificate))
654
- end
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
- open(ssl_options[:client_key]) do |fp|
658
- key_parts = fp.read.scan(KEY_EXTRACTION_REGEXP)
659
- key_parts.each do |type, b64key|
660
- body = Base64.decode64 b64key
661
- spec = PKCS8EncodedKeySpec.new(body.to_java_bytes)
662
- type = type.strip
663
- type = "RSA" if type == ""
664
- key = KeyFactory.getInstance(type).generatePrivate(spec)
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
@@ -1,3 +1,3 @@
1
1
  module Manticore
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -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
@@ -1,6 +1,12 @@
1
1
  # encoding: utf-8
2
2
  require "rubygems"
3
3
  require "bundler/setup"
4
+ require "simplecov"
5
+
6
+ SimpleCov.start do
7
+ add_filter "spec/"
8
+ end
9
+
4
10
  require "manticore"
5
11
  require "zlib"
6
12
  require "json"
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.3
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-05-28 00:00:00.000000000 Z
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.4.8
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