|
| 1 | +#!/usr/bin/env ruby |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +# Ruby internal |
| 5 | +require 'pp' |
| 6 | +# Project internal |
| 7 | +require 'tls_map' |
| 8 | +require 'tls_map/cli' |
| 9 | +# External |
| 10 | +require 'docopt' |
| 11 | +require 'paint' |
| 12 | + |
| 13 | +doc = <<~DOCOPT |
| 14 | + TLS map |
| 15 | +
|
| 16 | + Usage: |
| 17 | + tls-map search <critera> <term> [-o <output> --force] [--no-color --debug] |
| 18 | + tls-map export <filename> <format> [--force] [--debug] |
| 19 | + tls-map update [--debug] |
| 20 | + tls-map -h | --help |
| 21 | + tls-map --version |
| 22 | +
|
| 23 | + Search options: (offline) |
| 24 | + <critera> The type of term. Accepted values: codepoint, iana, openssl, gnutls, nss. |
| 25 | + <term> The cipher algorithm name. |
| 26 | + -o, --output <output> Displayed fields. Accepted values: all, codepoint, iana, openssl, gnutls, nss. [default: all] |
| 27 | +
|
| 28 | + Export options: (offline) |
| 29 | + <filename> The output file name to write to. |
| 30 | + <format> Supported formats: markdown (a markdown table), json_pretty (expanded JSON), json_compact (minified JSON), marshal (Ruby marshalized hash). |
| 31 | +
|
| 32 | + Update options: (online) DANGEROUS, will break database integrity, force option will be required |
| 33 | +
|
| 34 | + Other options: |
| 35 | + --force Force parsing even if intigrity check failed (DANGEROUS, may result in command execution vulnerability) |
| 36 | + --no-color Disable colorized output |
| 37 | + --debug Display arguments |
| 38 | + -h, --help Show this screen |
| 39 | + --version Show version |
| 40 | +DOCOPT |
| 41 | + |
| 42 | +begin |
| 43 | + args = Docopt.docopt(doc, version: TLSmap::VERSION) |
| 44 | + Paint.mode = 0 if args['--no-color'] |
| 45 | + pp args if args['--debug'] |
| 46 | + if args['search'] |
| 47 | + cli = TLSmap::CLI.new(args['--force']) |
| 48 | + res = cli.search(args['<critera>'].to_sym, args['<term>'], args['--output'].to_sym) |
| 49 | + puts Paint['No match found', :red] if res.empty? |
| 50 | + res.each do |k, v| |
| 51 | + puts "#{Paint[k, :green]}: #{Paint[v, :white]}" |
| 52 | + end |
| 53 | + elsif args['export'] |
| 54 | + cli = TLSmap::CLI.new(args['--force']) |
| 55 | + cli.export(args['<filename>'], args['<format>'].to_sym) |
| 56 | + puts "#{args['<filename>']} exported" |
| 57 | + elsif args['update'] |
| 58 | + cli = TLSmap::CLI.new |
| 59 | + cli.update |
| 60 | + puts 'Database updated' |
| 61 | + end |
| 62 | +rescue Docopt::Exit => e |
| 63 | + puts e.message |
| 64 | +end |
0 commit comments