Class: TLSmap::App

Inherits:
Object
  • Object
show all
Defined in:
lib/tls_map.rb,
lib/tls_map/nss.rb,
lib/tls_map/iana.rb,
lib/tls_map/gnutls.rb,
lib/tls_map/output.rb,
lib/tls_map/openssl.rb,
lib/tls_map/extractor.rb,
lib/tls_map/ciphersuiteinfo.rb

Overview

TLS mapping

Direct Known Subclasses

CLI

Defined Under Namespace

Classes: Extended, Extractor

Constant Summary collapse

NSS_URL =
'https://raw.githubusercontent.com/nss-dev/nss/master/lib/ssl/sslproto.h'
IANA_URL =
'https://www.iana.org/assignments/tls-parameters/tls-parameters-4.csv'
GNUTLS_URL =
'https://gitlab.com/gnutls/gnutls/raw/master/lib/algorithms/ciphersuites.c'
OPENSSL_URL =
'https://raw.githubusercontent.com/openssl/openssl/master/include/openssl/tls1.h'
OPENSSL_URL2 =
'https://raw.githubusercontent.com/openssl/openssl/master/include/openssl/ssl3.h'

Instance Method Summary collapse

Constructor Details

#initializeApp

Will automatically fetch source files and parse them.



21
22
23
24
25
26
27
28
29
30
# File 'lib/tls_map.rb', line 21

def initialize
  @iana_file = Utils.tmpfile('iana', IANA_URL)
  @openssl_file = Utils.tmpfile('openssl', OPENSSL_URL)
  @openssl_file2 = Utils.tmpfile('openssl', OPENSSL_URL2)
  @gnutls_file = Utils.tmpfile('gnutls', GNUTLS_URL)
  @nss_file = Utils.tmpfile('nss', NSS_URL)

  @tls_map = []
  parse
end

Instance Method Details

#bulk_search(critera, file, output = :all) ⇒ Array<Hash>

Search for corresponding cipher algorithms in other libraries in bulk

Parameters:

  • critera (Symbol)

    The type of term. Accepted values: :codepoint, :iana, :openssl, :gnutls, :nss.

  • file (String)

    File containing the cipher algorithm names, one per line.

  • output (Symbol) (defaults to: :all)

    The corresponding type to be included in the return value. Accepted values: :all (default), :codepoint, :iana, :openssl, :gnutls, :nss.

Returns:

  • (Array<Hash>)

    The corresponding type, same as #search return value but one per line stored in an array.



67
68
69
70
71
72
73
# File 'lib/tls_map.rb', line 67

def bulk_search(critera, file, output = :all)
  res = []
  File.foreach(file) do |line|
    res.push(search(critera, line.chomp, output))
  end
  res
end

#export(filename, format) ⇒ Object

Export the mapping to a file, supporting various formats.

Parameters:

  • filename (String)

    The output file name to write to.

  • format (Symbol)

    Supported formats: :markdown (a markdown table), :json_pretty (expanded JSON), :json_compact (minified JSON), :marshal (Ruby marshalized hash).



41
42
43
44
45
46
47
48
49
# File 'lib/tls_map/output.rb', line 41

def export(filename, format)
  case format
  when :markdown      then output_markdown(filename)
  when :json_pretty   then output_json_pretty(filename)
  when :json_compact  then output_json_compact(filename)
  when :marshal       then output_marshal(filename)
  else                     raise "Wrong format: #{format}"
  end
end

#search(critera, term, output = :all) ⇒ Hash

Search for corresponding cipher algorithms in other libraries

Parameters:

  • critera (Symbol)

    The type of term. Accepted values: :codepoint, :iana, :openssl, :gnutls, :nss.

  • term (String)

    The cipher algorithm name.

  • output (Symbol) (defaults to: :all)

    The corresponding type to be included in the return value. Accepted values: :all (default), :codepoint, :iana, :openssl, :gnutls, :nss.

Returns:

  • (Hash)

    The corresponding type matching term.



47
48
49
50
51
52
53
54
55
56
# File 'lib/tls_map.rb', line 47

def search(critera, term, output = :all)
  @tls_map.each do |alg|
    term = term.upcase if critera == :codepoint
    next unless alg[critera] == term
    return alg if output == :all

    return { output => alg[output] }
  end
  {}
end