Documentation
¶
Overview ¶
Package badcerts is a library to handle bad (e.g. self-signed) certificates.
It provides a function you could use in your http.Client, to handle the case that you do not want to disable https certificate validation altogether, but you want to whitelist one (or more) bad (self-signed, expired, wrong common name, etc.) cert(s) because you have to. ¯\_(ツ)_/¯
This library is inspired by https://github.com/tam7t/hpkp
Example ¶
package main import ( "net/http" "go.yhsif.com/badcerts" ) func main() { // This is the cert fingerprint from https://self-signed.badssl.com/ // // You can get it by: // // go get -u go.yhsif.com/badcerts/cmd/badcerts-fingerprint // badcerts-fingerprint -url https://self-signed.badssl.com/ myCertFingerprint := "9SLklscvzMYj8f+52lp5ze/hY0CFHyLSPQzSpYYIBm8=" client := &http.Client{ Transport: &http.Transport{ DialTLS: badcerts.DialTLSWithWhitelistCerts( badcerts.IsSelfSignedError, myCertFingerprint, ), }, } // Now client can handle https://self-signed.badssl.com/ just fine: // // _, err := client.Get("https://self-signed.badssl.com/") // if err != nil { // panic(err) // } // fmt.Println("Everything is awesome.") // // And it will still return error for other bad certificates. // Satisfy compiler _ = client }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DialTLSWithWhitelistCerts ¶
func DialTLSWithWhitelistCerts( errorFunc ErrorFunc, certFingerprints ...string, ) func(network, addr string) (net.Conn, error)
DialTLSWithWhitelistCerts returns a DialTLS implementation.
First it tries standard tls.Dial. If nothing is wrong, it returns the result directly.
If the error satisfies errorFunc, it dials again without cert verification, then checks the fingerprint of the cert against the given certs. If the fingerprint matches it returns the connection without error, otherwise it returns the original error when calling standard tls.Dial.
As a result this function works with all the standard trusted root CAs plus the ones with matching cert fingerprints, and nothing else.
func Fingerprint ¶
func Fingerprint(cert *x509.Certificate) string
Fingerprint returns the sha256 of an x509 certificate signature, encoded with standard base64.
func IsSelfSignedError ¶
IsSelfSignedError is an ErrorFunc returns true for self-signed certs.
Types ¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
badcerts-fingerprint
Command badcerts-fingerprint provides a tool to get cert fingerprint(s) to be used in badcerts library.
|
Command badcerts-fingerprint provides a tool to get cert fingerprint(s) to be used in badcerts library. |