-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CA file #323
Merged
Merged
CA file #323
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1866909
golangci: disable gochecknoglobals in tests
mmatczuk bce2ff6
fileurl: add test case for data scheme
mmatczuk 9413bfb
readurl: change signature of ReadURL to return []byte and add dedicat…
mmatczuk 5d946f2
readurl: add support for reading data scheme
mmatczuk 4694023
readurl: add ReadFileOrBase64 as a base 64 enabled os.ReadFile wrapper
mmatczuk ae2079b
tls: add support for loading TLS certificate and key from base64 enco…
mmatczuk 90cf3e2
tls: split TLSConfig to TLSClientConfig and TLSServerConfig
mmatczuk bff3ecc
tls: refactor LoadCertificateFromTLSConfig to ConfigureTLSConfig method
mmatczuk 29a3f16
tls: add CAFiles to TLSClientConfig
mmatczuk 98f9849
http_transport: add TLSHandshakeTimeout to TLSClientConfig
mmatczuk 50c920e
bind: extract TLSClientConfig from HTTPTransportConfig
mmatczuk 047a37b
bind: add ca-file flag
mmatczuk 7ab4b07
bind: extract TLSServerConfig from HTTPServerConfig
mmatczuk 18a2dfa
bind: remove tls prefix from tls-[cert,key]-file
mmatczuk ef1352c
e2e/certs: CA signed certificate generation
mmatczuk 0da0f79
e2e: use generated certificates instead of insecure
mmatczuk 64d70dc
gh: update go action to generate certificates
mmatczuk f78e844
bind: rename ca-file to cacert-file for better compatibility with curl
mmatczuk fad0324
gh: on CI failure dump docker-compose.yaml
mmatczuk 9ab4444
http_proxy: log when using custom root CA certificates
mmatczuk 2ec2171
http_proxy: log when using custom root CA certificates
mmatczuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ issues: | |
linters: | ||
- bodyclose | ||
- funlen | ||
- gochecknoglobals | ||
- gocognit | ||
- gomnd | ||
- gosec | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ca.srl | ||
*.crt | ||
*.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.PHONY: certs | ||
certs: | ||
@./gen.sh | ||
|
||
.PHONY: test | ||
test: | ||
@go test -v -tags manual . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//go:build manual | ||
|
||
package certs_test | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/saucelabs/forwarder" | ||
) | ||
|
||
func TestCertificate(t *testing.T) { | ||
server := http.Server{ | ||
Addr: "127.0.0.1:8443", | ||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte("Hello, world!")) | ||
}), | ||
} | ||
defer server.Close() | ||
|
||
go server.ListenAndServeTLS("httpbin.crt", "httpbin.key") | ||
|
||
tlsCfg := &tls.Config{ | ||
ServerName: "httpbin", | ||
} | ||
cfg := forwarder.TLSClientConfig{ | ||
CAFiles: []string{ | ||
"./ca.crt", | ||
}, | ||
} | ||
cfg.ConfigureTLSConfig(tlsCfg) | ||
|
||
tr := http.DefaultTransport.(*http.Transport).Clone() | ||
tr.TLSClientConfig = tlsCfg | ||
|
||
req, err := http.NewRequest("GET", "https://"+server.Addr, http.NoBody) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
res, err := tr.RoundTrip(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if res.StatusCode != http.StatusOK { | ||
t.Fatal("unexpected status code:", res.StatusCode) | ||
} | ||
|
||
tr.CloseIdleConnections() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
# Common variables | ||
CA_ORGANIZATION="Sauce Labs Inc." | ||
CA_KEY="ca.key" | ||
CA_CERT="ca.crt" | ||
CA_SUBJECT="/C=US/O=${CA_ORGANIZATION}" | ||
|
||
EC_CURVE="prime256v1" | ||
|
||
# Generate CA key and self-signed certificate with SHA-256 | ||
openssl ecparam -genkey -name ${EC_CURVE} -out ${CA_KEY} | ||
openssl req -new -x509 -sha256 -days 365 -nodes -key ${CA_KEY} -subj "${CA_SUBJECT}" -out ${CA_CERT} \ | ||
-extensions v3_ca -config <(cat /etc/ssl/openssl.cnf - << EOF | ||
[v3_ca] | ||
subjectKeyIdentifier=hash | ||
authorityKeyIdentifier=keyid:always,issuer | ||
basicConstraints=critical,CA:true | ||
keyUsage=critical,keyCertSign,cRLSign | ||
EOF | ||
) | ||
|
||
# Function to generate certificates for each host name | ||
generate_certificate() { | ||
local HOST_NAME="$1" | ||
local KEY="${HOST_NAME}.key" | ||
local CSR="${HOST_NAME}.csr" | ||
local CERT="${HOST_NAME}.crt" | ||
local SUBJECT="/C=US/O=${CA_ORGANIZATION}/CN=${HOST_NAME}" | ||
|
||
# Generate host key and certificate signing request (CSR) | ||
openssl ecparam -genkey -name ${EC_CURVE} -out ${KEY} | ||
openssl req -new -key ${KEY} -subj "${SUBJECT}" -out ${CSR} | ||
|
||
# Sign the CSR with the CA to generate the host certificate | ||
openssl x509 -req -sha256 -days 365 -in ${CSR} -CA ${CA_CERT} -CAkey ${CA_KEY} -CAcreateserial -out ${CERT}\ | ||
-extensions v3_req -extfile <(cat /etc/ssl/openssl.cnf - << EOF | ||
[v3_req] | ||
basicConstraints=critical,CA:FALSE | ||
authorityKeyIdentifier=keyid,issuer | ||
subjectAltName=@alt_names | ||
keyUsage=digitalSignature,keyEncipherment | ||
[ alt_names ] | ||
DNS.1 = ${HOST_NAME} | ||
DNS.2 = localhost | ||
EOF | ||
) | ||
|
||
# Remove the CSR (not needed anymore) | ||
rm ${CSR} | ||
} | ||
|
||
# Generate certificates for each host name | ||
generate_certificate "proxy" | ||
generate_certificate "upstream-proxy" | ||
generate_certificate "httpbin" | ||
|
||
chmod 644 *.key *.crt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's preserve the same condition as in
WithProtocol
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's https and h2 but sure I can change it.