logstash-input-tcp 6.0.6-java → 6.1.0-java

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
  SHA256:
3
- metadata.gz: 4dbdf0afaf0e9956001477eff23f9dcc7bdeaa82bffdb696ab66657000802662
4
- data.tar.gz: 94b90ca185e259f016ed8a40b8303306ffd00bc9f50256db510cd29a448510f7
3
+ metadata.gz: 26d542f495a0b506903b944a54ce0cdab39b93714fadfca025f8b2233ac22135
4
+ data.tar.gz: 17b2c70fc10f1d1132956c6cf45f752c2e0b992d819e0c54e568882f2da0dada
5
5
  SHA512:
6
- metadata.gz: 8d2572a98f74bf028d2c2ac5bcfeddd651090fb96af903faec94dea3c8ac373f69bfb823fdd9c14e0b5f2711f1e05e7c8b8203e10d3f2ca004217f176df37f37
7
- data.tar.gz: b9856bbd395f4080ceaa8029bcb4f348704c3f65d82c5564ee1e7130b40f3f32a931c9939f003cac81e244490544463e6139cf7d8800ba2d80cf6b902aba3d07
6
+ metadata.gz: d03c07e5980298f23fe7309528a1eaef3b5ebc45948362582c9ed922c5c257e24affdca65d92f859b55507f1a3f2b9766c6e09e2949d40cb6a51ed55f48b1646
7
+ data.tar.gz: 817c0305eff54d5fb35ee66a0b4633cfbcce93a2c2adb43be9d71d9c6dedfb71a4d0a07e7ed665b0267839526716eb721ad8c0dc2c3e1e732430988193e97035
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 6.1.0
2
+ - Feat: improve SSL error logging/unwrapping [#178](https://github.com/logstash-plugins/logstash-input-tcp/pull/178)
3
+ - Fix: the plugin will no longer have a side effect of adding the Bouncy-Castle security provider at runtime
4
+
5
+ ## 6.0.10
6
+ - bumping dependency commons-io [#174](https://github.com/logstash-plugins/logstash-input-tcp/pull/174)
7
+
8
+ ## 6.0.9
9
+ - [DOC] Reorder options alphabetically [#171](https://github.com/logstash-plugins/logstash-input-tcp/pull/171)
10
+
11
+ ## 6.0.8
12
+ - [DOC] better description for `tcp_keep_alive` option [#169](https://github.com/logstash-plugins/logstash-input-tcp/pull/169)
13
+
14
+ ## 6.0.7
15
+ - Fix: reduce error logging (to info level) on connection resets [#168](https://github.com/logstash-plugins/logstash-input-tcp/pull/168)
16
+ - Refactor: only patch Socket classes once (on first input)
17
+ - Refactor: use a proper log4j logger (in Java to avoid surprises when unwrapping `LogStash::Logging::Logger`)
18
+
1
19
  ## 6.0.6
2
20
  - Updated Netty dependencies. Additionally, this release removes the dependency on `tcnative` +
3
21
  `boringssl`, using JVM supplied ciphers instead. This may result in fewer ciphers being available if the JCE
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-input-tcp.svg)](https://travis-ci.org/logstash-plugins/logstash-input-tcp)
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-input-tcp.svg)](https://travis-ci.com/logstash-plugins/logstash-input-tcp)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
data/docs/index.asciidoc CHANGED
@@ -78,6 +78,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
78
78
  [cols="<,<,<",options="header",]
79
79
  |=======================================================================
80
80
  |Setting |Input type|Required
81
+ | <<plugins-{type}s-{plugin}-dns_reverse_lookup_enabled>> |<<boolean,boolean>>|No
81
82
  | <<plugins-{type}s-{plugin}-host>> |<<string,string>>|No
82
83
  | <<plugins-{type}s-{plugin}-mode>> |<<string,string>>, one of `["server", "client"]`|No
83
84
  | <<plugins-{type}s-{plugin}-port>> |<<number,number>>|Yes
@@ -90,7 +91,6 @@ This plugin supports the following configuration options plus the <<plugins-{typ
90
91
  | <<plugins-{type}s-{plugin}-ssl_key_passphrase>> |<<password,password>>|No
91
92
  | <<plugins-{type}s-{plugin}-ssl_verify>> |<<boolean,boolean>>|No
92
93
  | <<plugins-{type}s-{plugin}-tcp_keep_alive>> |<<boolean,boolean>>|No
93
- | <<plugins-{type}s-{plugin}-dns_reverse_lookup_enabled>> |<<boolean,boolean>>|No
94
94
  |=======================================================================
95
95
 
96
96
  Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
@@ -98,6 +98,16 @@ input plugins.
98
98
 
99
99
  &nbsp;
100
100
 
101
+ [id="plugins-{type}s-{plugin}-dns_reverse_lookup_enabled"]
102
+ ===== `dns_reverse_lookup_enabled`
103
+
104
+ * Value type is <<boolean,boolean>>
105
+ * Default value is `true`
106
+
107
+ It is possible to avoid DNS reverse-lookups by disabling this setting. If disabled,
108
+ the address metadata that is added to events will contain the source address as-specified
109
+ at the TCP layer and IPs will not be resolved to hostnames.
110
+
101
111
  [id="plugins-{type}s-{plugin}-host"]
102
112
  ===== `host`
103
113
 
@@ -202,17 +212,9 @@ For input, sets the field `sslsubject` to that of the client certificate.
202
212
  * Value type is <<boolean,boolean>>
203
213
  * Default value is `false`
204
214
 
205
- Instruct the socket to use TCP keep alives. Uses OS defaults for keep alive settings.
206
-
207
- [id="plugins-{type}s-{plugin}-dns_reverse_lookup_enabled"]
208
- ===== `dns_reverse_lookup_enabled`
209
-
210
- * Value type is <<boolean,boolean>>
211
- * Default value is `true`
212
-
213
- It is possible to avoid DNS reverse-lookups by disabling this setting. If disabled,
214
- the address metadata that is added to events will contain the source address as-specified
215
- at the TCP layer and IPs will not be resolved to hostnames.
215
+ Instruct the socket to use TCP keep alive. If it's `true` then the underlying socket
216
+ will use the OS defaults settings for keep alive. If it's `false` it doesn't configure any
217
+ keep alive setting for the underlying socket.
216
218
 
217
219
 
218
220
  [id="plugins-{type}s-{plugin}-common-options"]
@@ -6,7 +6,6 @@ require "logstash/inputs/base"
6
6
  require "logstash/util/socket_peer"
7
7
  require "logstash-input-tcp_jars"
8
8
  require "logstash/inputs/tcp/decoder_impl"
9
- require "logstash/inputs/tcp/compat_ssl_options"
10
9
 
11
10
  require "socket"
12
11
  require "openssl"
@@ -61,7 +60,8 @@ require "openssl"
61
60
  # }
62
61
  class LogStash::Inputs::Tcp < LogStash::Inputs::Base
63
62
 
64
- java_import org.logstash.tcp.InputLoop
63
+ java_import 'org.logstash.tcp.InputLoop'
64
+ java_import 'org.logstash.tcp.SslContextBuilder'
65
65
 
66
66
  config_name "tcp"
67
67
 
@@ -103,7 +103,8 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
103
103
  # Useful when the CA chain is not necessary in the system store.
104
104
  config :ssl_extra_chain_certs, :validate => :array, :default => []
105
105
 
106
- # Validate client certificates against these authorities. You can define multiple files or paths. All the certificates will be read and added to the trust store.
106
+ # Validate client certificates against these authorities. You can define multiple files or paths.
107
+ # All the certificates will be read and added to the trust store.
107
108
  config :ssl_certificate_authorities, :validate => :array, :default => []
108
109
 
109
110
  # Instruct the socket to use TCP keep alives. Uses OS defaults for keep alive settings.
@@ -119,15 +120,21 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
119
120
  PROXY_PORT_FIELD = "proxy_port".freeze
120
121
  SSLSUBJECT_FIELD = "sslsubject".freeze
121
122
 
122
- PLUGIN_GLOBAL_MUTEX = Mutex.new
123
- private_constant :PLUGIN_GLOBAL_MUTEX
123
+ # Monkey patch TCPSocket and SSLSocket to include socket peer
124
+ # @private
125
+ def self.patch_socket_peer!
126
+ unless TCPSocket < ::LogStash::Util::SocketPeer
127
+ TCPSocket.send :include, ::LogStash::Util::SocketPeer
128
+ end
129
+ unless OpenSSL::SSL::SSLSocket < ::LogStash::Util::SocketPeer
130
+ OpenSSL::SSL::SSLSocket.send :include, ::LogStash::Util::SocketPeer
131
+ end
132
+ end
124
133
 
125
134
  def initialize(*args)
126
135
  super(*args)
127
136
 
128
- # monkey patch TCPSocket and SSLSocket to include socket peer
129
- TCPSocket.module_eval{include ::LogStash::Util::SocketPeer}
130
- OpenSSL::SSL::SSLSocket.module_eval{include ::LogStash::Util::SocketPeer}
137
+ self.class.patch_socket_peer!
131
138
 
132
139
  # threadsafe socket bookkeeping
133
140
  @server_socket = nil
@@ -142,24 +149,14 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
142
149
  fix_streaming_codecs
143
150
 
144
151
  if server?
145
- ssl_context = get_ssl_context(SslOptions)
146
-
147
- # RubyObject#to_java is not threadsafe, and we cannot guarantee
148
- # that ours is the only reference to the underlying logger, which
149
- # is memoized at a class level.
150
- log4j_logger = PLUGIN_GLOBAL_MUTEX.synchronize do
151
- @logger.to_java(org.apache.logging.log4j.Logger)
152
- end
153
-
154
- @loop = InputLoop.new(@host, @port, DecoderImpl.new(@codec, self), @tcp_keep_alive,
155
- ssl_context, log4j_logger)
152
+ @loop = InputLoop.new(@host, @port, DecoderImpl.new(@codec, self), @tcp_keep_alive, java_ssl_context)
156
153
  end
157
154
  end
158
155
 
159
156
  def run(output_queue)
160
157
  @output_queue = output_queue
161
158
  if server?
162
- @logger.info("Starting tcp input listener", :address => "#{@host}:#{@port}", :ssl_enable => "#{@ssl_enable}")
159
+ @logger.info("Starting tcp input listener", :address => "#{@host}:#{@port}", :ssl_enable => @ssl_enable)
163
160
  @loop.run
164
161
  else
165
162
  run_client()
@@ -252,12 +249,10 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
252
249
  rescue Errno::ECONNRESET
253
250
  @logger.debug? && @logger.debug("Connection reset by peer", :client => peer)
254
251
  rescue OpenSSL::SSL::SSLError => e
255
- # Fixes issue #23
256
- @logger.error("SSL Error", :exception => e, :backtrace => e.backtrace)
257
- socket.close rescue nil
252
+ @logger.error("SSL error", :client => peer, :message => e.message, :exception => e.class, :backtrace => e.backtrace)
258
253
  rescue => e
259
254
  # if plugin is stopping, don't bother logging it as an error
260
- !stop? && @logger.error("An error occurred. Closing connection", :client => peer, :exception => e, :backtrace => e.backtrace)
255
+ !stop? && @logger.error("An error occurred, closing connection", :client => peer, :message => e.message, :exception => e.class, :backtrace => e.backtrace)
261
256
  ensure
262
257
  # catch all rescue nil on close to discard any close errors or invalid socket
263
258
  socket.close rescue nil
@@ -293,7 +288,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
293
288
  @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
294
289
  end
295
290
  rescue => e
296
- @logger.error("Could not inititalize SSL context", :exception => e, :backtrace => e.backtrace)
291
+ @logger.error("Could not inititalize SSL context", :message => e.message, :exception => e.class, :backtrace => e.backtrace)
297
292
  raise e
298
293
  end
299
294
 
@@ -323,7 +318,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
323
318
 
324
319
  socket
325
320
  rescue OpenSSL::SSL::SSLError => e
326
- @logger.error("SSL Error", :exception => e, :backtrace => e.backtrace)
321
+ @logger.error("SSL Error", :message => e.message, :exception => e.class, :backtrace => e.backtrace)
327
322
  # catch all rescue nil on close to discard any close errors or invalid socket
328
323
  socket.close rescue nil
329
324
  sleep(1) # prevent hammering peer
@@ -365,15 +360,33 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
365
360
  @socket_mutex.synchronize{@connection_sockets.keys.dup}
366
361
  end
367
362
 
368
- def get_ssl_context(options_class)
369
- ssl_context = options_class.builder
370
- .set_is_ssl_enabled(@ssl_enable)
363
+ def java_ssl_context
364
+ SslContextBuilder.new
365
+ .set_ssl_enabled(@ssl_enable)
371
366
  .set_should_verify(@ssl_verify)
372
367
  .set_ssl_cert(@ssl_cert)
373
368
  .set_ssl_key(@ssl_key)
374
- .set_ssl_key_passphrase(@ssl_key_passphrase.value)
369
+ .set_ssl_key_password(@ssl_key_passphrase.value)
375
370
  .set_ssl_extra_chain_certs(@ssl_extra_chain_certs.to_java(:string))
376
371
  .set_ssl_certificate_authorities(@ssl_certificate_authorities.to_java(:string))
377
- .build.toSslContext()
372
+ .build_context
373
+ rescue java.lang.IllegalArgumentException => e
374
+ @logger.error("SSL configuration invalid", error_details(e))
375
+ raise LogStash::ConfigurationError, e
376
+ rescue java.lang.Exception => e
377
+ @logger.error("SSL configuration failed", error_details(e, true))
378
+ raise e
378
379
  end
380
+
381
+ def error_details(e, trace = false)
382
+ error_details = { :exception => e.class, :message => e.message }
383
+ error_details[:backtrace] = e.backtrace if trace || @logger.debug?
384
+ cause = e.cause
385
+ if cause && e != cause
386
+ error_details[:cause] = { :exception => cause.class, :message => cause.message }
387
+ error_details[:cause][:backtrace] = cause.backtrace if trace || @logger.debug?
388
+ end
389
+ error_details
390
+ end
391
+
379
392
  end
@@ -38,8 +38,8 @@ class DecoderImpl
38
38
  pp_info = pp_hdr.split(/\s/)
39
39
  # PROXY proto clientip proxyip clientport proxyport
40
40
  if pp_info[0] != "PROXY"
41
- @tcp.logger.error("invalid proxy protocol header label", :hdr => pp_hdr)
42
- raise IOError
41
+ @tcp.logger.error("Invalid proxy protocol header label", :header => pp_hdr)
42
+ raise IOError.new("Invalid proxy protocol header label #{pp_hdr.inspect}")
43
43
  else
44
44
  @proxy_address = pp_info[3]
45
45
  @proxy_port = pp_info[5]
@@ -22,6 +22,11 @@ Gem::Specification.new do |s|
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
24
 
25
+ s.add_runtime_dependency 'logstash-core', '>= 6.7.0'
26
+
27
+ # we depend on bouncycastle's bcpkix-jdk15on being on the class-path
28
+ s.add_runtime_dependency 'jruby-openssl', '>= 0.10.2', '< 0.12'
29
+
25
30
  # line vs streaming codecs required for fix_streaming_codecs
26
31
  # TODO: fix_streaming_codecs should be refactored to not
27
32
  # require the codecs to be installed.
data/version CHANGED
@@ -1 +1 @@
1
- 6.0.6
1
+ 6.1.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-tcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.6
4
+ version: 6.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -30,6 +30,40 @@ dependencies:
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 6.7.0
39
+ name: logstash-core
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 6.7.0
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.10.2
53
+ - - "<"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.12'
56
+ name: jruby-openssl
57
+ prerelease: false
58
+ type: :runtime
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.10.2
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.12'
33
67
  - !ruby/object:Gem::Dependency
34
68
  requirement: !ruby/object:Gem::Requirement
35
69
  requirements:
@@ -173,12 +207,11 @@ files:
173
207
  - docs/index.asciidoc
174
208
  - lib/logstash-input-tcp_jars.rb
175
209
  - lib/logstash/inputs/tcp.rb
176
- - lib/logstash/inputs/tcp/compat_ssl_options.rb
177
210
  - lib/logstash/inputs/tcp/decoder_impl.rb
178
211
  - logstash-input-tcp.gemspec
179
212
  - spec/inputs/tcp_spec.rb
180
213
  - spec/spec_helper.rb
181
- - vendor/jar-dependencies/org/logstash/inputs/logstash-input-tcp/6.0.6/logstash-input-tcp-6.0.6.jar
214
+ - vendor/jar-dependencies/org/logstash/inputs/logstash-input-tcp/6.1.0/logstash-input-tcp-6.1.0.jar
182
215
  - version
183
216
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
184
217
  licenses:
@@ -1,147 +0,0 @@
1
- require 'openssl'
2
- require "logstash/util/loggable"
3
-
4
- # Simulate a normal SslOptions builder:
5
- #
6
- # ssl_context = SslOptions.builder
7
- # .set_is_ssl_enabled(@ssl_enable)
8
- # .set_should_verify(@ssl_verify)
9
- # .set_ssl_cert(@ssl_cert)
10
- # .set_ssl_key(@ssl_key)
11
- # .set_ssl_key_passphrase(@ssl_key_passphrase.value)
12
- # .set_ssl_extra_chain_certs(@ssl_extra_chain_certs.to_java(:string))
13
- # .set_ssl_certificate_authorities(@ssl_certificate_authorities.to_java(:string))
14
- # .build.toSslContext()
15
- class SslOptions
16
- include LogStash::Util::Loggable
17
-
18
- java_import 'io.netty.handler.ssl.ClientAuth'
19
- java_import 'io.netty.handler.ssl.SslContextBuilder'
20
- java_import 'java.security.cert.X509Certificate'
21
- java_import 'javax.crypto.Cipher'
22
- java_import 'org.bouncycastle.asn1.pkcs.PrivateKeyInfo'
23
- java_import 'org.bouncycastle.jce.provider.BouncyCastleProvider'
24
- java_import 'org.bouncycastle.openssl.PEMKeyPair'
25
- java_import 'org.bouncycastle.openssl.PEMParser'
26
- java_import 'org.bouncycastle.openssl.PEMEncryptedKeyPair'
27
- java_import 'org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter'
28
- java_import 'org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder'
29
- java_import 'org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder'
30
- java_import 'org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo'
31
-
32
- def self.builder
33
- new
34
- end
35
-
36
- def set_is_ssl_enabled(boolean)
37
- @ssl_enabled = boolean
38
- self
39
- end
40
-
41
- def set_should_verify(boolean)
42
- @ssl_verify = boolean
43
- self
44
- end
45
-
46
- def set_ssl_cert(path)
47
- @ssl_cert_path = path
48
- self
49
- end
50
-
51
- def set_ssl_key(path)
52
- @ssl_key_path = path
53
- self
54
- end
55
-
56
- def set_ssl_key_passphrase(passphrase)
57
- @ssl_key_passphrase = passphrase
58
- self
59
- end
60
-
61
- def set_ssl_extra_chain_certs(certs)
62
- @ssl_extra_chain_certs = certs
63
- self
64
- end
65
-
66
- def set_ssl_certificate_authorities(certs)
67
- @ssl_certificate_authorities = certs
68
- self
69
- end
70
-
71
- def build; self; end
72
-
73
- def toSslContext
74
- return nil unless @ssl_enabled
75
-
76
- # Check key strength
77
- logger.warn("JCE Unlimited Strength Jurisdiction Policy not installed - max key length is 128 bits") unless Cipher.getMaxAllowedKeyLength("AES") > 128
78
- # create certificate object
79
- cf = java.security.cert.CertificateFactory.getInstance("X.509")
80
- cert_chain = []
81
- fetch_certificates_from_file(@ssl_cert_path, cf) do |cert|
82
- cert_chain << cert
83
- end
84
-
85
- # convert key from pkcs1 to pkcs8 and get PrivateKey object
86
- pem_parser = PEMParser.new(java.io.FileReader.new(@ssl_key_path))
87
- java.security.Security.addProvider(BouncyCastleProvider.new)
88
- converter = JcaPEMKeyConverter.new
89
- case obj = pem_parser.readObject
90
- when PEMKeyPair # unencrypted pkcs#1
91
- private_key = converter.getKeyPair(obj).private
92
- when PrivateKeyInfo # unencrypted pkcs#8
93
- private_key = converter.getPrivateKey(obj)
94
- when PEMEncryptedKeyPair # encrypted pkcs#1
95
- key_char_array = @ssl_key_passphrase.to_java.toCharArray
96
- decryptor = JcePEMDecryptorProviderBuilder.new.build(key_char_array)
97
- key_pair = obj.decryptKeyPair(decryptor)
98
- private_key = converter.getKeyPair(key_pair).private
99
- when PKCS8EncryptedPrivateKeyInfo # encrypted pkcs#8
100
- key_char_array = @ssl_key_passphrase.to_java.toCharArray
101
- key = JceOpenSSLPKCS8DecryptorProviderBuilder.new.build(key_char_array)
102
- private_key = converter.getPrivateKey(obj.decryptPrivateKeyInfo(key))
103
- else
104
- raise "Could not recognize 'ssl_key' format. Class: #{obj.class}"
105
- end
106
-
107
- @ssl_extra_chain_certs.each do |file|
108
- fetch_certificates_from_file(file, cf) do |cert|
109
- cert_chain << cert
110
- end
111
- end
112
- sslContextBuilder = SslContextBuilder.forServer(private_key, @ssl_key_passphrase, cert_chain.to_java(X509Certificate))
113
-
114
- trust_certs = []
115
-
116
- @ssl_certificate_authorities.each do |file|
117
- fetch_certificates_from_file(file, cf) do |cert|
118
- trust_certs << cert
119
- end
120
- end
121
-
122
- if trust_certs.any?
123
- sslContextBuilder.trustManager(trust_certs.to_java(X509Certificate))
124
- end
125
-
126
- sslContextBuilder.clientAuth(@ssl_verify ? ClientAuth::REQUIRE : ClientAuth::NONE)
127
- sslContextBuilder.build()
128
- end
129
-
130
- private
131
- def fetch_certificates_from_file(file, cf)
132
- fis = java.io.FileInputStream.new(file)
133
-
134
- while (fis.available > 0) do
135
- cert = generate_certificate(cf, fis)
136
- yield cert if cert
137
- end
138
- ensure
139
- fis.close if fis
140
- end
141
-
142
- def generate_certificate(cf, fis)
143
- cf.generateCertificate(fis)
144
- rescue Java::JavaSecurityCert::CertificateException => e
145
- raise e unless e.cause.message == "Empty input"
146
- end
147
- end