Provide Handler with client certificate information
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
var client gemini.Client
|
||||
var cert tls.Certificate
|
||||
|
||||
func init() {
|
||||
// Configure a client side certificate.
|
||||
@@ -22,17 +23,20 @@ func init() {
|
||||
// openssl ecparam -genkey -name secp384r1 -out client.key
|
||||
// openssl req -new -x509 -sha256 -key client.key -out client.crt -days 3650
|
||||
//
|
||||
config := tls.Config{}
|
||||
cert, err := tls.LoadX509KeyPair("examples/client/client.crt", "examples/client/client.key")
|
||||
var err error
|
||||
cert, err = tls.LoadX509KeyPair("examples/client/client.crt", "examples/client/client.key")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
config.Certificates = append(config.Certificates, cert)
|
||||
client.TLSConfig = config
|
||||
}
|
||||
|
||||
func makeRequest(url string) {
|
||||
resp, err := client.Request(url)
|
||||
req, err := gemini.NewRequest(url)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Certificates = append(req.Certificates, cert)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"git.sr.ht/~adnano/go-gemini"
|
||||
"log"
|
||||
"net/url"
|
||||
|
||||
"git.sr.ht/~adnano/go-gemini"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -23,13 +23,15 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
config.Certificates = append(config.Certificates, cert)
|
||||
config.ClientAuth = tls.RequestClientCert
|
||||
|
||||
mux := &gemini.Mux{}
|
||||
mux.HandleFunc("/", func(url *url.URL) *gemini.Response {
|
||||
mux.HandleFunc("/", func(req *gemini.RequestInfo) *gemini.Response {
|
||||
log.Printf("Request for %s with certificates %v", req.URL.String(), req.Certificates)
|
||||
return &gemini.Response{
|
||||
Status: gemini.StatusSuccess,
|
||||
Meta: "text/gemini",
|
||||
Body: []byte("You requested " + url.String()),
|
||||
Body: []byte("You requested " + req.URL.String()),
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user