Class: TLSmap::App::Extractor::Testssl

Inherits:
Object
  • Object
show all
Defined in:
lib/tls_map/app/extractor/extractor.rb

Overview

Parsing testssl.sh

Class Method Summary collapse

Class Method Details

.extract_cipher(json_data) ⇒ Array<String>

Extract the ciphers from the testssl output file

Parameters:

  • json_data (Hash)

    Ruby hash of the parsed JSON

Returns:

  • (Array<String>)

    Cipher array (IANA names)



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/tls_map/app/extractor/extractor.rb', line 232

def extract_cipher(json_data) # rubocop:disable Metrics/MethodLength
  cipher = json_data['scanResult'][0]['cipherTests']
  raw = {
    'SSL2.0' => [], 'SSL3.0' => [],
    'TLS1.0' => [], 'TLS1.1' => [], 'TLS1.2' => [], 'TLS1.3' => []
  }
  cipher.each do |node|
    node_id = node['id']
    # patch for 3.2+ format, see https://github.com/testssl/testssl.sh/issues/1994
    next if node_id.match?(/supportedciphers_.+/)

    raw[id2prot(node_id)].push(finding2cipher(node['finding']))
  end
  raw
end

.finding2cipher(finding) ⇒ String

Extract the cipher name from testssl finding

Parameters:

  • finding (String)

    testssl finding

Returns:

  • (String)

    cipher name (IANA names)



263
264
265
# File 'lib/tls_map/app/extractor/extractor.rb', line 263

def finding2cipher(finding)
  /\s(\w+_\w+)\s/.match(finding).captures[0]
end

.id2prot(id) ⇒ String

Convert testssl protocol id to protocol name in TLSmap format

Parameters:

  • id (String)

    testssl protocol id

Returns:

  • (String)

    protocol name in TLSmap format



251
252
253
254
255
256
257
258
# File 'lib/tls_map/app/extractor/extractor.rb', line 251

def id2prot(id)
  prot = {
    'ssl2' => 'SSL2.0', 'ssl3' => 'SSL3.0', 'tls1' => 'TLS1.0',
    'tls1_1' => 'TLS1.1', 'tls1_2' => 'TLS1.2', 'tls1_3' => 'TLS1.3'
  }
  protv = id.match(/cipher-(\w+)_x\w+/).captures[0]
  prot[protv]
end

.parse(file) ⇒ Array<String>

Extract the ciphers from the testssl output file

Parameters:

  • file (String)

    Path of the testssl output file, beware of the format expected.
    See TLSmap::App::Extractor

Returns:

  • (Array<String>)

    Cipher array (IANA names)



224
225
226
227
# File 'lib/tls_map/app/extractor/extractor.rb', line 224

def parse(file)
  data = Utils.json_load_file(file)
  extract_cipher(data)
end