Jay Taylor's notes

back to listing index

Introducing CFSSL - CloudFlare's PKI toolkit

[web search]
Original source (blog.cloudflare.com)
Tags: ssl encryption cryptography tools cloudflare blog.cloudflare.com
Clipped on: 2018-02-21

Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.

Introducing CFSSL - CloudFlare's PKI toolkit

10 Jul 2014 by Nick Sullivan.

Today we’re proud to introduce CFSSL—our open source toolkit for everything TLS/SSL. CFSSL is used internally by CloudFlare for bundling TLS/SSL certificates chains, and for our internal Certificate Authority infrastructure. We use this tool for all our TLS certificates.

Creating a certificate bundle is a common pain point for website operators, and doing it right is important for website security AND speed (CloudFlare does both). Getting the correct bundle together is a black art, and can quickly become a debugging nightmare if it's not done correctly. We wrote CFSSL to make bundling easier. By picking the right chain of certificates, CFSSL solves the balancing act between performance, security, and compatibility.

Staying true to our promise to make the web fast and safe, we’re open sourcing CFSSL. We believe CFSSL will be useful for anyone building a site using HTTPS—from website owners to large software-as-a-service companies. CFSSL is written in Go and available on the CloudFlare Github account. It can be used as a web service with a JSON API, and as a handy command line tool.

CFSSL is the result of real-world expertise about how the TLS ecosystem on the Web works that you can gain by working at CloudFlare’s scale. These are hard-won lessons, applied in code. The rest of this blog post serves as an under-the-hood look at how and why CFSSL works, and how you can use it as a certificate bundler or as a lightweight CA.

Image (Asset 1/6) alt=

If you upload your certificate to CloudFlare, this is what is used to create a certificate bundle for your website.

To create a certificate bundle with CFSSL, you need to know which certificates are trusted by the browsers you hope to display content to. In a controlled corporate environment, this is usually easy since every browser is set up with the same configuration; however, it becomes more difficult when creating a bundle for the web.

Different Certs for Different Folks.

Each browser has unique capabilities and configurations, and a certificate bundle that’s trusted in one browser might not be trusted in another; this can happen for several reasons:

  1. Different browsers trust different root certificates.

    Some browsers trust more root certificates than others. For example, the NSS root store used in Firefox trusts 143 certificates; however, Windows 8.1 trusts 391 certificates. So a bundle with a chain that expects the browser to trust a certificate exclusive to the Windows root store will appear as untrusted in Firefox.

  2. Older systems might have old root stores.

    Some browsers run on older systems that have not been updated to trust recently-created certificate authorities. For example, Android 2.2 and earlier don't trust the “GoDaddy Root Certificate Authority G2” because that root certificate was created after they were released.

  3. Older systems don't support modern cryptography.

    Users on Windows XP SP2 and earlier can't validate certificates signed by certain intermediates. This includes the “DigiCert SHA2 High Assurance Server CA” because the hash function SHA-2 used in this certificate was standardised after Windows XP was released.

In order to provide maximum compatibility between SSL chains and browsers, you often have to pick a different certificate chain than the one originally provided to you by your CA. This alternate chain might contain a different set of intermediates that are signed by a different root certificate. Alternate chains can be troublesome. They tend to contain a longer list of certificates than the default chain from the CA, and longer chains cause site connections to be slower. This lag is because the web server needs to send more certificates (i.e. more data) to the browser, and the browser has to spend time verifying more certificates on its end. Picking the right chain can be tricky.

CFSSL helps pick the right certificate chain, selecting for performance, security, and compatibility.

How to Pick the Best Chain.

The chain of trust works by following the keys used to sign certificates, and there can be multiple chains of trust for the same keys.

Image (Asset 2/6) alt=

  • CloudFlare leaf → 2012 GlobalSign Intermediate → GS Root G2.

    This chain is trusted by any browser that trusts GS Root G2, but does not benefit from the stronger cryptographic properties of the SHA-2 hashing algorithm.

  • CloudFlare leaf → 2012 GlobalSign Intermediate → GS cross-signed root.

    This chain is trusted by any browser that trusts the GlobalSign nv-sa root, but uses the older (and weaker) GlobalSign nv-sa root certificate.

  • This last chain is the most common because it’s trusted by more browsers; however, it’s also the longest, and has weaker cryptography.

    CFSSL can create either the most common or the optimal bundle, and if you need help deciding, the documentation that ships with CFSSL has tips on choosing.

    If you decide to create the optimal bundle, there’s a chance it might not work in some browsers; however, CFSSL is configured to let you know specifically which browsers it will not work with. For example, it will warn the user about bundles that contains certificates signed with advanced hash functions such as SHA2; they can be problematic for certain operating systems like Windows XP SP2.

    CFSSL at CloudFlare.

    All paid CloudFlare accounts receive HTTPS service automatically; to make this happen, our engineers do a lot of work behind scenes.

    CloudFlare must obtain a certificate for each site on the service, and we want these certificates to be valid on as many browsers as possible; getting a certificate that works in multiple browsers is a challenge, but CFSSL makes things easier.

    To start, a key-pair is created for the customer through a call to CFSSL's genkey API with the required certificate information:

        "CN": "customer.com",
        "hosts": [
        "key": {
               "algo": "rsa",
               "size": 2048
        "names": [
                        "C": "US",
                        "L": "San Francisco",
                        "O": "Customer",
                        "OU": "Website",
                        "ST": "California"

    Next, the CFSSL service responds with a key and a Certificate Signature Request (CSR). The CSR is sent to the CA to verify a site’s identity. Once the CA has validated the CSR, and the identity of the site, they then return a certificate signed by one of their issuing intermediates.

    Once we have a certificate for a site (whether created by our CA partner or uploaded by the customer), we send the certificate to CFSSL's bundler to create a certificate bundle for the customer.

    By default, we pick the most common chain. For customers who prefer performance to compatibility, we’ll soon introduce an option to rebundle certificates for optimum chains.

    CFSSL as a Certificate Authority.

    CFSSL is not only a tool for bundling a certificate, it can also be used as a CA. This is possible because it covers the basic features of certificate creation including creating a private key, building a certificate signature request, and signing certificates.

    You can create a brand new CA with CFSSL using the -initca option. As we saw above, this takes a JSON blob with the certificate request, and creates a new CA key and certificate:

    $ cfssl gencert -initca ca_csr.json

    This will return a CA certificate and CA key that is valid for signing. The CA is meant to function as an internal tool for creating certificates. CFSSL should be used behind a middle layer that processes incoming requests, and ensures they conform to policy; we use it behind the CloudFlare site as an internal service.

    Here’s an example of signing a certificate with CFSSL on the command line:

    $ cfssl sign -ca-key=test-key.pem -ca=test-cert.pem www.example.com example.csr

    Alternatively, a POST request containing the CSR and hostname can be sent to the CFSSL service via the /api/v1/cfssl/sign endpoint. To run the service call the serve command as follows:

    $ cfssl serve -address=localhost -port=8888 -ca-key=test-key.pem -ca=test-cert.pem

    If you already have a CFSSL instance running (in this case on localhost, but it can be anywhere), you can automate certificate creation with the gencert command’s -remote option. For example, if CFSSL is running on localhost, running the following gives you a private key and a certificate signed by the CA:

    $ cfssl gencert -remote="localhost:8888" www.example.com csr.json

    At CloudFlare we use CFSSL heavily for Railgun and other internal services. Special thanks go to Kyle Isom, Zi Lin, Sebastien Pahl, and Dane Knecht, and the rest of the CloudFlare team for making this release possible.

    Looking Ahead.

    CloudFlare’s mission is to help build a better web, and we believe that improved certificate bundling and certificate authority tools are a step in the right direction. Encrypted sites create a safer, more private internet for everyone; by open-sourcing CFSSL, we’re making this process easier.

    We have big plans for the CA part of this tool. Currently, we run CFSSL on secure locked-down machines, but plan to add stronger hardware security. Adding stronger hardware security involves integrating CFSSL with low-cost Trusted Platform Modules (TPMs). This ensures that private keys stay private, even in the event of a breach.

    For additional information on CFSSL and our other open source projects, check out our Github page. We encourage users to file issues on Github as they find bugs.

    Tagged with Security, TLS, Crypto, CFSSL, Encryption
    Want to learn more about Cloudflare?

    Learn more


    Log in with
    or sign up with Disqus

    Disqus is a discussion network

    • Disqus never moderates or censors. The rules on this community are its own.
    • Don't be a jerk or do anything illegal. Everything is easier that way.

    Read full terms and conditions

    • Image (Asset 4/6) alt=How can one install and configure CFSSL for uses like:

      1) Replace a MS CA for internal network (pc/laptop/servers/users) in a MS domain?
      2) For my own external facing website ?
      3) For external devices connecting into my internal network ?
      4) with ECDSA
      5) auto deploy, auto renewals, auto cleanups, plus can tied to AD.


      • Image (Asset 5/6) alt=neoKushan leaf → GlobalSign SHA2 Intermediate → GS Root G2

        What are the commands needed to create a internet/production ready CA, that can generate certificate for any server on my domain "xxxxx.our.domain.com"?
        What do I need from or give to GlobalSign to get my CA certify? so that I can start creating certs?
        Do I need a special certificate or just generate a CSR on the cfssl server, and buy a 3-year normal certificate?
        How do I go about certifying all my windows servers?
        Can these be scripts using powershell ?

          • Image (Asset 6/6) alt=

            Christopher DemicoliWould you consider giving students free access to some paid CloudFlare features or plans?

          • Deprecating SPDY

            • a month ago

            Šime Vidas …the majority of web browsers now support HTTP/2 where the notable exceptions are the UC Browser …

          • Writing complex macros in Rust: Reverse Polish Notation

            • 21 days ago

            neoKushan It's interesting seeing a Cloudflare blog post about Rust, given how much Cloudflare champions Go for their …

          • Rust 로 복잡한 매크로를 작성하기: 역폴란드 표기법​

            • 1 comment
            • 15 days ago

            indonesiafurnituresPlease Translate to english version

          • US callers
            1 (888) 99-FLARE
            UK callers
            +44 (0)20 3514 6970
            International callers
            +1 (650) 319-8930

            Contact our team

            Cloudflare provides performance and security for any website. More than 6 million websites use Cloudflare.

            There is no hardware or software. Cloudflare works at the DNS level. It takes only 5 minutes to sign up. To learn more, please visit our website

            Full feature list and plan types

            Cloudflare features

            All content © 2018 Cloudflare