You've already forked armbian-router
mirror of
https://github.com/armbian/armbian-router.git
synced 2026-01-06 10:37:03 -08:00
Features: - Protocol lists (http, https), managed by http responses - Working TLS Checks - Root certificate parsing for TLS checks - Moving configuration into a Config struct, no more direct viper access
47 lines
774 B
Go
47 lines
774 B
Go
package util
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"github.com/gwatts/rootcerts/certparse"
|
|
log "github.com/sirupsen/logrus"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
defaultDownloadURL = "https://github.com/mozilla/gecko-dev/blob/master/security/nss/lib/ckfw/builtins/certdata.txt?raw=true"
|
|
)
|
|
|
|
func LoadCACerts() (*x509.CertPool, error) {
|
|
res, err := http.Get(defaultDownloadURL)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
certs, err := certparse.ReadTrustedCerts(res.Body)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pool := x509.NewCertPool()
|
|
|
|
var count int
|
|
|
|
for _, cert := range certs {
|
|
if cert.Trust&certparse.ServerTrustedDelegator == 0 {
|
|
continue
|
|
}
|
|
|
|
count++
|
|
|
|
pool.AddCert(cert.Cert)
|
|
}
|
|
|
|
log.WithField("certs", count).Info("Loaded root cas")
|
|
|
|
return pool, nil
|
|
}
|