aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-10-27 23:34:06 -0400
committerAdnan Maolood <[email protected]>2020-10-27 23:34:06 -0400
commitd1dcf070fff5e1215d2869ac8a1fafacf5a75e1e (patch)
treed1be50e8ab08be7299e04bb891097f51fea7441d /examples
parentclient: Follow redirects (diff)
downloadgo-gemini-d1dcf070fff5e1215d2869ac8a1fafacf5a75e1e.tar.xz
go-gemini-d1dcf070fff5e1215d2869ac8a1fafacf5a75e1e.zip
Restrict client certificates to certain paths
Diffstat (limited to 'examples')
-rw-r--r--examples/client.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/examples/client.go b/examples/client.go
index 5180f5c..e2e1669 100644
--- a/examples/client.go
+++ b/examples/client.go
@@ -8,7 +8,6 @@ import (
"crypto/x509"
"fmt"
"io/ioutil"
- "net/url"
"os"
"time"
@@ -47,22 +46,27 @@ func init() {
}
return err
}
- client.GetCertificate = func(hostname string, store *gemini.CertificateStore) *tls.Certificate {
+ client.GetCertificate = func(req *gemini.Request, store *gemini.ClientCertificateStore) *tls.Certificate {
// If the certificate is in the store, return it
- if cert, err := store.Lookup(hostname); err == nil {
+ if cert, err := store.Lookup(req.URL.Hostname(), req.URL.Path); err == nil {
return cert
}
// Otherwise, generate a certificate
- fmt.Println("Generating client certificate for", hostname)
+ fmt.Println("Generating client certificate for", req.URL.Hostname()+req.URL.Path)
duration := time.Hour
- cert, err := gemini.NewCertificate(hostname, duration)
+ cert, err := gemini.NewCertificate("", duration)
if err != nil {
return nil
}
// Store and return the certificate
- store.Add(hostname, cert)
+ store.Add(req.URL.Hostname()+req.URL.Path, cert)
return &cert
}
+ client.GetInput = func(prompt string, sensitive bool) (string, bool) {
+ fmt.Printf("%s: ", prompt)
+ scanner.Scan()
+ return scanner.Text(), true
+ }
}
// sendRequest sends a request to the given URL.