class TLSmap::App::Extractor::Testssl

Parsing testssl.sh

Public Class Methods

parse(file) click to toggle source

Extract the ciphers from the testssl output file @param file [String] Path of the testssl output file, beware of the format expected.

See {TLSmap::App::Extractor}

@return [Array<String>] Cipher array (IANA names)

# File lib/tls_map/app/extractor/extractor.rb, line 187
def parse(file)
  data = Utils.json_load_file(file)
  extract_cipher(data)
end

Protected Class Methods

extract_cipher(json_data) click to toggle source

Extract the ciphers from the testssl output file @param json_data [Hash] Ruby hash of the parsed JSON @return [Array<String>] Cipher array (IANA names)

# File lib/tls_map/app/extractor/extractor.rb, line 195
def extract_cipher(json_data)
  cipher = json_data['scanResult'][0]['cipherTests']
  raw = {
    'SSL2.0' => [], 'SSL3.0' => [],
    'TLS1.0' => [], 'TLS1.1' => [], 'TLS1.2' => [], 'TLS1.3' => []
  }
  cipher.each do |node|
    raw[id2prot(node['id'])].push(finding2cipher(node['finding']))
  end
  raw
end
finding2cipher(finding) click to toggle source

Extract the cipher name from testssl finding @param finding [String] testssl finding @return [String] cipher name (IANA names)

# File lib/tls_map/app/extractor/extractor.rb, line 222
def finding2cipher(finding)
  /\s(\w+_\w+)\s/.match(finding).captures[0]
end
id2prot(id) click to toggle source

Convert testssl protocol id to protocol name in TLSmap format @param id [String] testssl protocol id @return [String] protocol name in TLSmap format

# File lib/tls_map/app/extractor/extractor.rb, line 210
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