-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3f15f6
commit a301410
Showing
7 changed files
with
174 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.out | ||
*.pem | ||
*.jar |
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,45 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func helloHandler(w http.ResponseWriter, r *http.Request) { | ||
// Write "Hello, world!" to the response body | ||
io.WriteString(w, "Hello, world!\n") | ||
} | ||
|
||
func main() { | ||
// Set up a /hello resource handler | ||
http.HandleFunc("/hello", helloHandler) | ||
|
||
// Create a CA certificate pool and add cert.pem to it | ||
caCert, err := ioutil.ReadFile("cert-backend.pem") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
caCertPool := x509.NewCertPool() | ||
caCertPool.AppendCertsFromPEM(caCert) | ||
|
||
// Create the TLS Config with the CA pool and enable Client certificate validation | ||
tlsConfig := &tls.Config{ | ||
ClientCAs: caCertPool, | ||
ClientAuth: tls.RequireAndVerifyClientCert, | ||
} | ||
tlsConfig.BuildNameToCertificate() | ||
|
||
// Create a Server instance to listen on port 8443 with the TLS config | ||
server := &http.Server{ | ||
Addr: ":8444", | ||
TLSConfig: tlsConfig, | ||
} | ||
|
||
// Listen to HTTPS connections with the server certificate and wait | ||
log.Fatal(server.ListenAndServeTLS("cert-backend.pem", "cert-backend-key.pem")) | ||
} | ||
|
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,2 @@ | ||
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -out cert-backend.pem -keyout cert-backend-key.pem -subj "/CN=localhost" | ||
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -out cert-frontend.pem -keyout cert-frontend-key.pem -subj "/CN=mtls.oto.tools" |
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 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
// Read the key pair to create certificate | ||
cert, err := tls.LoadX509KeyPair("cert-backend.pem", "cert-backend-key.pem") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a CA certificate pool and add cert.pem to it | ||
caCert, err := ioutil.ReadFile("cert-backend.pem") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
caCertPool := x509.NewCertPool() | ||
caCertPool.AppendCertsFromPEM(caCert) | ||
|
||
// Create a HTTPS client and supply the created CA pool and certificate | ||
client := &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
RootCAs: caCertPool, | ||
Certificates: []tls.Certificate{cert}, | ||
}, | ||
}, | ||
} | ||
|
||
// Request /hello via the created HTTPS client over port 8443 via GET | ||
r, err := client.Get("https://localhost:8444/hello") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Read the response body | ||
defer r.Body.Close() | ||
body, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Print the response body to stdout | ||
fmt.Printf("%s\n", body) | ||
} |
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 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
// Read the key pair to create certificate | ||
cert, err := tls.LoadX509KeyPair("cert-frontend.pem", "cert-frontend-key.pem") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a CA certificate pool and add cert.pem to it | ||
caCert, err := ioutil.ReadFile("cert-frontend-key.pem") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
caCertPool := x509.NewCertPool() | ||
caCertPool.AppendCertsFromPEM(caCert) | ||
|
||
// Create a HTTPS client and supply the created CA pool and certificate | ||
client := &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
RootCAs: caCertPool, | ||
Certificates: []tls.Certificate{cert}, | ||
}, | ||
}, | ||
} | ||
|
||
// Request /hello via the created HTTPS client over port 8443 via GET | ||
r, err := client.Get("https://mtls.oto.tools:8443/") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Read the response body | ||
defer r.Body.Close() | ||
body, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Print the response body to stdout | ||
fmt.Printf("%s\n", body) | ||
} |
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,13 @@ | ||
sh ./certs.sh | ||
go run backend.go & | ||
go run clientbackend.go > clientbackend.out | ||
# TODO: assert clientbackend.out content | ||
# TODO: get otoroshi.jar here | ||
# TODO: java -Dapp.domain=oto.tools -jar otoroshi.jar & | ||
# TODO: delete existing certs in otoroshi | ||
# TODO: inject certs in otoroshi | ||
# TODO: waits 10sec | ||
# TODO: go run clientfrontend.go > clientfrontend.out | ||
# TODO: assert clientfrontend.out content | ||
killall go >> /dev/null | ||
killall java >> /dev/null |