diff options
| author | Adnan Maolood <[email protected]> | 2020-10-28 13:40:25 -0400 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-10-28 13:41:24 -0400 |
| commit | fbd97a62dec02ad22b7cf520cfc6ab519ea0e990 (patch) | |
| tree | 8a19117713cddce2d3ed2d31c24bec59fe616a48 /examples | |
| parent | Add ErrInputRequired and ErrCertificateRequired (diff) | |
| download | go-gemini-fbd97a62dec02ad22b7cf520cfc6ab519ea0e990.tar.xz go-gemini-fbd97a62dec02ad22b7cf520cfc6ab519ea0e990.zip | |
Refactor client certificates
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/client.go | 25 | ||||
| -rw-r--r-- | examples/server.go | 5 |
2 files changed, 11 insertions, 19 deletions
diff --git a/examples/client.go b/examples/client.go index 169f726..71e7915 100644 --- a/examples/client.go +++ b/examples/client.go @@ -46,21 +46,11 @@ func init() { } return err } - 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(req.URL.Hostname(), req.URL.Path); err == nil { - return cert - } - // Otherwise, generate a certificate - fmt.Println("Generating client certificate for", req.URL.Hostname()+req.URL.Path) - duration := time.Hour - cert, err := gemini.NewCertificate("", duration) - if err != nil { - return nil - } - // Store and return the certificate - store.Add(req.URL.Hostname()+req.URL.Path, cert) - return &cert + client.CreateCertificate = func(hostname, path string) (tls.Certificate, error) { + fmt.Println("Generating client certificate for", hostname, path) + return gemini.CreateCertificate(gemini.CertificateOptions{ + Duration: time.Hour, + }) } client.GetInput = func(prompt string, sensitive bool) (string, bool) { fmt.Printf("%s: ", prompt) @@ -69,8 +59,7 @@ func init() { } } -// sendRequest sends a request to the given URL. -func sendRequest(req *gemini.Request) error { +func doRequest(req *gemini.Request) error { resp, err := client.Do(req) if err != nil { return err @@ -131,7 +120,7 @@ func main() { os.Exit(1) } - if err := sendRequest(req); err != nil { + if err := doRequest(req); err != nil { fmt.Println(err) os.Exit(1) } diff --git a/examples/server.go b/examples/server.go index 9ef4b8d..11ea9ed 100644 --- a/examples/server.go +++ b/examples/server.go @@ -29,7 +29,10 @@ func main() { fallthrough case gmi.ErrCertificateUnknown: // Generate a certificate if one does not exist. - cert, err := gmi.NewCertificate(hostname, time.Minute) + cert, err := gmi.CreateCertificate(gmi.CertificateOptions{ + DNSNames: []string{hostname}, + Duration: time.Hour, + }) if err != nil { // Failed to generate new certificate, abort return nil |