Git Product home page Git Product logo

rootcerts's Introduction

Root CA Certificates for Go

GoDoc Build Status

This project converts root certificate authority certificates provided by the Mozilla project into a .go package that can be statically compiled into a Go project.

Motivation

Many Go programs need to access remote SSL/TLS services (eg. over https). The crypto/tls package validates remote certificates by loading public CA certificates from the filesystem as provided by the operating system (eg. in /etc/ssl).

This works well, unless the program is running in any environment where these certificates are not installed, are not accessible, or are out of date. This commonly occurs when running Go programs in a minimal docker container or the binary is distributed as-is to end users who may or may not be running the program on a machine with up to date certificates installed/accessible.

Compiling the root certificates into the program provides guaranteed stable access to them without external dependencies.

Alternatives

Instead of compiling the certificates into the binary, one could:

  • Install packages at the OS level and mount /etc/ssl as a volume for the container
  • Add a certificates layer to the image when defining the Dockerfile

Compiling the certificates may, however, be simpler to deploy in many cases and result in a predictable outcome whether the binary is executed in a container or on a host.

Usage

You may either use the certificates provided at the root level of this project, which are periodically refreshed, or use the gencerts tool to create a rootcerts.go file that may be copied into your project.

Calling the UpdateDefaultTransport method will make the certificates available to the default http transport, which is sufficient for many projects.

Using gencerts

The gencerts tool reads a certdata.txt file, either from the local filesystem, or directly from the Mozilla Mercurial site (though note, it uses https by default so does itself require local ca certificates!)

Note also that the format of certdata.txt changes occasionally, which may break the gencerts tool. Relying on -download for a production build process may thus be a bad idea!

gencerts -download -package mypackage -target rootcerts.go

gencerts will generate a rootcerts.go and also a rootcerts_16.go if there are any certificate with a negative serial number. Only Go version 1.6 and later supports such certificates, so rootcerts_16.go uses a build flag to ensure compatibility with older versions of Go.

Other Notes

gencerts only outputs certificates that the certdata.txt file has labeled as a trusted delegator (ie. certificates that are suitable for use a certificate authority).

Certificates may be marked as trusted for servers, email or code signing.

Useful Resources

Some of the information I came across while writing this tool:

Similar Projects

rootcerts's People

Contributors

gwatts avatar hayden-pan avatar

Stargazers

Steffen Uhlig avatar Alejandro Falkowski avatar Tim O'Guin avatar pedoc avatar wwqgtxx avatar Júlio Sandroni avatar 結花 avatar Ryan Boehning avatar Michael Graham avatar Michael Zhuang avatar Matt Toddy avatar David Aparicio avatar Rinor Hoxha avatar Elvin Du avatar  avatar Tamás Gulácsi avatar Nate Woods avatar Ivy Evans avatar  avatar RabitChang avatar Krzysztof Wilczyński avatar  avatar Brian Wojtczak avatar SakuraEntropia avatar Vinicius Freitas avatar Derek Hartley avatar Illarion Kovalchuk avatar Levent Sagiroglu avatar Pavel Brm avatar Krzysztof Antczak avatar Manuel Valls Fernández avatar Wesley Spikes avatar  avatar Markus Kobler avatar

Watchers

 avatar James Cloos avatar Rinor Hoxha avatar SakuraEntropia avatar

rootcerts's Issues

Similar tool / link

Hi, I became aware of this tool and I wanted to reach out to you because a while back I have written something similar. You might be interested in some of the ideas used in breml/rootcerts. It is inspired by the time/tzdata package available in the Go standard library (since 1.15). I have written a proposal for Go as well golang/go#43958.

For what it's worth, you might consider to add a link to my solution as I already added a link to yours (https://github.com/breml/rootcerts#similar-projects).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.