Class: Fluent::Plugin::SslCheckInput::SslClient
- Inherits:
-
Object
- Object
- Fluent::Plugin::SslCheckInput::SslClient
- Defined in:
- lib/fluent/plugin/in_ssl_check.rb
Overview
ssl client
to check ssl status
Instance Attribute Summary collapse
-
#ca_file ⇒ Object
readonly
Returns the value of attribute ca_file.
-
#ca_path ⇒ Object
readonly
Returns the value of attribute ca_path.
-
#cert ⇒ Object
readonly
Returns the value of attribute cert.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#sni ⇒ Object
readonly
Returns the value of attribute sni.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#verify_mode ⇒ Object
readonly
Returns the value of attribute verify_mode.
Instance Method Summary collapse
-
#initialize(host:, port:, ca_path: nil, ca_file: nil, sni: true, verify_mode: OpenSSL::SSL::VERIFY_PEER, cert: nil, key: nil, timeout: 5) ⇒ SslClient
constructor
rubocop:disable Metrics/ParameterLists.
- #ssl_context ⇒ Object
-
#ssl_info ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #store ⇒ Object
Constructor Details
#initialize(host:, port:, ca_path: nil, ca_file: nil, sni: true, verify_mode: OpenSSL::SSL::VERIFY_PEER, cert: nil, key: nil, timeout: 5) ⇒ SslClient
rubocop:disable Metrics/ParameterLists
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 248 def initialize(host:, port:, ca_path: nil, ca_file: nil, sni: true, verify_mode: OpenSSL::SSL::VERIFY_PEER, cert: nil, key: nil, timeout: 5) @host = host @port = port @ca_path = ca_path @ca_file = ca_file @sni = sni @verify_mode = verify_mode @cert = cert @key = key @timeout = timeout end |
Instance Attribute Details
#ca_file ⇒ Object (readonly)
Returns the value of attribute ca_file.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def ca_file @ca_file end |
#ca_path ⇒ Object (readonly)
Returns the value of attribute ca_path.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def ca_path @ca_path end |
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def cert @cert end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def host @host end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def key @key end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def port @port end |
#sni ⇒ Object (readonly)
Returns the value of attribute sni.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def sni @sni end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def timeout @timeout end |
#verify_mode ⇒ Object (readonly)
Returns the value of attribute verify_mode.
245 246 247 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 245 def verify_mode @verify_mode end |
Instance Method Details
#ssl_context ⇒ Object
293 294 295 296 297 298 299 300 301 302 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 293 def ssl_context OpenSSL::SSL::SSLContext.new.tap do |ssl_context| ssl_context.verify_mode = verify_mode ssl_context.cert_store = store ssl_context.min_version = nil ssl_context.max_version = OpenSSL::SSL::TLS1_2_VERSION ssl_context.cert = OpenSSL::X509::Certificate.new(File.open(cert)) if cert ssl_context.key = OpenSSL::PKey::RSA.new(File.open(key)) if key end end |
#ssl_info ⇒ Object
rubocop:enable Metrics/ParameterLists
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 263 def ssl_info info = SslInfo.new(host: host, port: port) begin Timeout.timeout(timeout) do tcp_socket = TCPSocket.open(host, port) ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context) ssl_socket.hostname = host if sni ssl_socket.connect ssl_socket.sysclose tcp_socket.close # cert_store.verify(ssl_socket.peer_cert, ssl_socket.peer_cert_chain) info.cert = ssl_socket.peer_cert info.cert_chain = ssl_socket.peer_cert_chain info.ssl_version = ssl_socket.ssl_version end rescue StandardError => e info.error = e end info end |
#store ⇒ Object
285 286 287 288 289 290 291 |
# File 'lib/fluent/plugin/in_ssl_check.rb', line 285 def store OpenSSL::X509::Store.new.tap do |store| store.set_default_paths store.add_path(ca_path) if ca_path store.add_file(ca_file) if ca_file end end |