1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-06-19 00:27:39 +02:00

Issue: 2236 - adds an option to append CA certificates (#2237)

* adding append option for custom CA certs

* updated test for changed GetCertPool signature, added testing to check functionality of empty and non-empty store

* adding legacy options as well

* update associated documentation

* fixing code climate complaints - reduce number of return statements

* Apply suggestions from code review

Changes caFilesAppend (and variants) to useSystemTrustStore

Co-authored-by: Jan Larwig <jan@larwig.com>

* Apply suggestions from code review

Fixes extra whitespaces and grammar.

Co-authored-by: Koen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com>

* fix indentation

* update changelog

---------

Co-authored-by: Jan Larwig <jan@larwig.com>
Co-authored-by: Koen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
emsixteeen
2023-10-25 06:36:17 -04:00
committed by GitHub
parent 601477a52c
commit a5006fd606
8 changed files with 82 additions and 27 deletions

View File

@ -14,11 +14,40 @@ import (
"time"
)
func GetCertPool(paths []string) (*x509.CertPool, error) {
func GetCertPool(paths []string, useSystemPool bool) (*x509.CertPool, error) {
if len(paths) == 0 {
return nil, fmt.Errorf("invalid empty list of Root CAs file paths")
}
pool := x509.NewCertPool()
var pool *x509.CertPool
if useSystemPool {
rootPool, err := getSystemCertPool()
if err != nil {
return nil, fmt.Errorf("unable to get SystemCertPool when append is true - #{err}")
}
pool = rootPool
} else {
pool = x509.NewCertPool()
}
return loadCertsFromPaths(paths, pool)
}
func getSystemCertPool() (*x509.CertPool, error) {
rootPool, err := x509.SystemCertPool()
if err != nil {
return nil, err
}
if rootPool == nil {
return nil, fmt.Errorf("SystemCertPool is empty")
}
return rootPool, nil
}
func loadCertsFromPaths(paths []string, pool *x509.CertPool) (*x509.CertPool, error) {
for _, path := range paths {
// Cert paths are a configurable option
data, err := os.ReadFile(path) // #nosec G304