Class: TLSmap::App

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

Overview

TLS mapping

Direct Known Subclasses

CLI

Defined Under Namespace

Classes: Cipher, 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 Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Will automatically fetch source files and parse them.



26
27
28
29
30
31
32
33
34
35
# File 'lib/tls_map.rb', line 26

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 Attribute Details

#tls_mapHash (readonly)

Get the mapping of all TLS cipher suites

Returns:

  • (Hash)

    mapping of all TLS cipher suites



23
24
25
# File 'lib/tls_map.rb', line 23

def tls_map
  @tls_map
end

Class Method Details

.search(tls_map, criteria, term, output = :all) ⇒ Object

Stateless version of #search.

Examples:

tm = TLSmap::App.new
TLSmap::App.search(tm.tls_map, :iana, 'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256')
# => {:codepoint=>"CCA9", :iana=>"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
      :openssl=>"ECDHE-ECDSA-CHACHA20-POLY1305", :gnutls=>"ECDHE_ECDSA_CHACHA20_POLY1305",
      :nss=>"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"}
# or to use with the Cipher class
ci = TLSmap::App::Cipher.new(:iana, 'TLS_DH_anon_WITH_RC4_128_MD5', tm.tls_map)

Parameters:

  • tls_map (Hash)

    mapping of all TLS cipher suites returned by #tls_map.

  • criteria (Symbol)

    Same as criteria from #search

  • term (String)

    Same as term from #search

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

    Same as output from #search

See Also:



77
78
79
80
81
82
83
84
85
86
# File 'lib/tls_map.rb', line 77

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

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

Instance Method Details

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

Search for corresponding cipher algorithms in other libraries in bulk

Parameters:

  • criteria (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.



97
98
99
100
101
102
103
# File 'lib/tls_map.rb', line 97

def bulk_search(criteria, file, output = :all)
  res = []
  File.foreach(file) do |line|
    res.push(search(criteria, 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/app/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(criteria, term, output = :all) ⇒ Hash

Search for corresponding cipher algorithms in other libraries

Parameters:

  • criteria (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.



52
53
54
55
56
57
58
59
60
61
# File 'lib/tls_map.rb', line 52

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

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