Using Cryptonice to check for HTTPS misconfigurations in devsecops workflows

Co-Author: Katie Newbold, F5 Labs Intern, Summer 2020

A huge thanks to Katie Newbold, lead developer on the Cryptonice project, for her amazing work and patience as I constantly moved the goal posts for this project.

---F5 Labs recently published an article Introducing the Cryptonice HTTPS Scanner. Cryptonice is aimed at making it easy for everyone to scan for and diagnose problems with HTTPS configurations. It is provided as a is a command line tool and Python library that allows a user to examine the TLS protocols and ciphers, certificate information, web application headers and DNS records for one or more supplied domain names. You can read more about why Cryptonice was released over at F5 Labs but it basically boils down a few simple reasons. Primarily, many people fire-and-forget their HTTPS configurations which mean they become out of date, and therefore weak, over time. In addition, other protocols, such as DNS can be used to improve upon the strength of TLS but few sites make use of them. Finally, with an increasing shift to automation (i.e. devsecops) it’s important to integrate TLS testing into the application lifecycle.

How do I use Cryptonice?

Since the tool is available as an executable, a Python script, and a Python library, there are a number of ways and means in which you might use Cryptonice. For example:

  1. The executable may be useful for those that do not have Python 3 installed and who want to perform occasional ad-hoc scans against internal or external websites
  2. The Python script may be installed along side other Python tools which could allow an internal security team to perform regular and scriptable scanning of internal sites
  3. The Python library could be used within devops automation workflows to check for valid certificates, protocols and ciphers when new code is pushed into dev or production environments

The aforementioned F5 Labs article provides a quick overview of how to use the command line executable and Python script. But this is DevCentral, after all, so let’s focus on how to use the Python library in your own code.

Using Cryptonice in your own code

Cryptonice can output results to the console but, since we’re coding, we’ll focus on the detailed JSON output that it produces. Since it collects all scan and test results into a Python dictionary, this variable can be read directly, or your code may wish to read in the completed JSON output. More on this later.

First off we’ll need to install the Cryptonice library. With Python 3 installed, we simply use the pip command to download and install it, along with its dependencies.

pip install cryptonice

Installing Cryptonice using pip will also install the dependent libraries: cffi, cryptography , dnspython, http-client, ipaddress, nassl, pycurl, pycparser, six, sslyze, tls-parser, and urllib3. You may see a warning about the cryptography library installation if you have a version that is greater than 2.9, but cryptonice will still function. This warning is generated because the sslyze package currently requires the cryptography library version to be between 2.6 and 2.9.

Creating a simple Cryptonice script

An example script ( is included in the GitHub repository. In this example, the script reads in a fully formatted JSON file called sample_scan.json from the command line (see below) and outputs the results in to a JSON file whose filename is based on the site being scanned.

The only Cryptonice module that needs to be imported in this script is scanner. The JSON input is converted to a dictionary object and sent directly to the scanner_driver function, where the output is written to a JSON file through the writeToJSONFile function.

from cryptonice import scanner
import argparse
import json
def main():
   parser = argparse.ArgumentParser()
   parser.add_argument("input_file", help="JSON input file of scan commands")
   args = parser.parse_args()
   input_file = args.input_file
   with open(input_file) as f:
       input_data = json.load(f)
   output_data, hostname = scanner.scanner_driver(input_data)
   if output_data is None and hostname is None:
       print("Error with input - scan was not completed")
if __name__ == "__main__":


In our example, above, the scanner_driver function is being passed the necessary dictionary object which is created from the JSON file being supplied as a command line parameter.

Alternatively, the dictionary object could be created dynamically in your own code. It must, however, contain the same key/value pairs as our sample input file, below:

This is what the JSON input file must look like:

      "id": string,
      "port": int,
      "scans": [string]
      "http_body": boolean,
      "force_redirect": boolean,
      "print_out": boolean,
      "generate_json": boolean,
      "targets": [string]


If certain parameters (such as “scans”, “tls_parameters”, or “targets”) are excluded completely, the program will abort early and print an error message to the console.

Mimicking command line input

If you would like to mimic the command line input in your own code, you could write a function that accepts a domain name via command line parameter and runs a suite of scans as defined in your variable default_dict:

from cryptonice.scanner import writeToJSONFile, scanner_driver
import argparse
default_dict = {'id': 'default',
               'port': 443,
               'scans': ['TLS', 'HTTP', 'HTTP2', 'DNS'],
               'tls_params': ["certificate_info", "ssl_2_0_cipher_suites", "ssl_3_0_cipher_suites",
                              "tls_1_0_cipher_suites", "tls_1_1_cipher_suites", "tls_1_2_cipher_suites",
                              "tls_1_3_cipher_suites", "http_headers"],
               'http_body': False,
               'print_out': True,
                'generate_json': True,
               'force_redirect': True
def main():
   parser = argparse.ArgumentParser(description="Supply commands to cryptonice")
   parser.add_argument("domain", nargs='+', help="Domain name to scan", type=str)
   args = parser.parse_args()
   domain_name = args.domain
   if not domain_name:
       parser.error('domain (like or is required')
   input_data = default_dict
   input_data.update({'targets': domain_name})
   output_data, hostname = scanner_driver(input_data)
   if output_data is None and hostname is None:
       print("Error with input - scan was not completed")
if __name__ == "__main__":

Using the Cryptonice JSON output

Full documentation for the Cryptonice JSON output will shortly be available on the Cryptonice ReadTheDocs pages and whilst many of the key/value pairs will be self explanatory, let’s take a look at some of the more useful ones.

TLS protocols and ciphers

The tls_scan block contains detailed information about the protocols, ciphers and certificates discovered as part of the handshake with the target site. This can be used to check for expired or expiring certificates, to ensure that old protocols (such as SSLv3) are not in use and to view recommendations.

cipher_suite_supported shows the cipher suite preferred by the target webserver. This is typically the best (read most secure) one available to modern clients. Similarly, highest_tls_version_supported shows the latest available version of the TLS protocol for this site. In this example, cert_recommendations is blank but is a certificate were untrusted or expired this would be a quick place to check for any urgent action that should be taken.

The dns section shows results for cryptographically relevant DNS records, for example Certificate Authority Authorization (CAA) and DKIM (found in the TXT records). In our example, below, we can see a dns_recommendations entry which suggested implementing DNS CAA since no such records can be found for this domain.

      "start":"2020-07-13 14:31:09.719227",
      "end":"2020-07-13 14:31:16.939356"
      "Connection":{ },
      "Headers":{ },
      "Cookies":{ }
            "type":"Basic OCSP Response",
            "valid_from":"2020-01-17 00:00:00",
            "valid_until":"2022-01-16 23:59:59",
      "scan_information":{ },
         "Low - CAA":"Consider creating DNS CAA records to prevent accidental or malicious certificate issuance."

Advanced Cryptonice use - Calling specific modules

There are 6 files in Cryptonice that are necessary for its functioning in other code. and live in the Cryptonice folder, and, and all live in the cryptonice/modules folder. A full scan is run out of the scanner_driver function in, which generates a dictionary object based on the commands it receives via the input parameter dictionary. scanner_driver is modularized, allowing you to call as many or as few of the modules as needed for your purposes. However, if you would like to customize the use of the cryptonice library further, individual modules can be selected and run as well.

You may choose to call the scanner_driver function and have access to all the modules in one location, or you could call on certain modules while excluding others.

Here is an example of a function that calls the tls_scan function in modules/ to specifically make use of the TLS code and none of the other modules.

from cryptonice.modules.gettls import tls_scan
def tls_info():
   ip_address = ""
   host = ""
   commands = ["certificate_info"]
   port = 443
   tls_data = tls_scan(ip_address, host, commands, port)
   cert_0 = tls_data.get("certificate_info").get("certificate_0")
   # Print certificate information
   print(f'Common Name:\t\t\t {cert_0.get("common_name")}')
   print(f'Public Key Algorithm:\t\t {cert_0.get("public_key_algorithm")}')
   print(f'Public Key Size:\t\t {cert_0.get("public_key_size")}')
   if cert_0.get("public_key_algorithm") == "EllipticCurvePublicKey":
       print(f'Curve Algorithm:\t\t {cert_0.get("curve_algorithm")}')
   print(f'Signature Algorithm:\t\t {cert_0.get("signature_algorithm")}')
if __name__ == "__main__":

Getting Started

The modularity of Cryptonice makes it a versatile tool to be used within other projects. Whether you want to use it to test the strength of an internal website using the command line tool or integrate the modules into another project, Cryptonice provides a detailed and easy way to capture certificate information, HTTP headers, DNS restrictions, TLS configuration and more.

We plan to add additional modules to query certificate transparency logs, test for protocols such as HTTP/3 and produce detailed output with guidance on how to improve your cryptographics posture on the web. This is version 1.0, and we encourage the submission of bugs and enhancements to our Github page to provide fixes and new features so that everyone may benefit from them.

The Cryptonice code and binary releases are maintained on the F5 Labs Github pages. Full documentation is currently being added to our ReadTheDocs page and the Cryptonice library is available on PyPi.:


F5 Labs overview:

Source and releases:

PyPi library:



Published Jul 20, 2020
Version 1.0

Was this article helpful?

1 Comment

  • Happy to say that Cryptonice now has a standalone executable for Windows (for those Python shy amongst you) and also support for Ubuntu 20.04.


    Check out the docs on