Giter Club home page Giter Club logo

gocertifi's Introduction

GoCertifi: SSL Certificates for Golang

This Go package contains a CA bundle that you can reference in your Go code. This is useful for systems that do not have CA bundles that Golang can find itself, or where a uniform set of CAs is valuable.

This is the same CA bundle that ships with the Python Requests library, and is a Golang specific port of certifi. The CA bundle is derived from Mozilla's canonical set.

Usage

You can use the gocertifi package as follows:

import "github.com/certifi/gocertifi"

certPool, err := gocertifi.CACerts()

You can use the returned *x509.CertPool as part of an HTTP transport, for example:

import (
  "net/http"
  "crypto/tls"
)

// Setup an HTTP client with a custom transport
transport := &http.Transport{
  Proxy: ProxyFromEnvironment,
  DialContext: (&net.Dialer{
    Timeout:   30 * time.Second,
    KeepAlive: 30 * time.Second,
    DualStack: true,
  }).DialContext,
  ForceAttemptHTTP2:     true,
  MaxIdleConns:          100,
  IdleConnTimeout:       90 * time.Second,
  TLSHandshakeTimeout:   10 * time.Second,
  ExpectContinueTimeout: 1 * time.Second,
}
// or, starting with go1.13 simply use:
// transport := http.DefaultTransport.(*http.Transport).Clone()

transport.TLSClientConfig = &tls.Config{RootCAs: certPool}
client := &http.Client{Transport: transport}

// Make an HTTP request using our custom transport
resp, err := client.Get("https://example.com")

Detailed Documentation

Import as follows:

import "github.com/certifi/gocertifi"

Errors

var ErrParseFailed = errors.New("gocertifi: error when parsing certificates")

Functions

func CACerts() (*x509.CertPool, error)

CACerts builds an X.509 certificate pool containing the Mozilla CA Certificate bundle. Returns nil on error along with an appropriate error code.

gocertifi's People

Contributors

dolmen avatar gabrielf avatar jeffpaine avatar lukasa avatar mattrobenolt avatar shazow avatar tmm1 avatar

Watchers

 avatar

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.