Create the certificate store if it does not exist
This commit is contained in:
parent
8facfabec5
commit
fbc1f76194
@ -84,12 +84,10 @@ Gemini takes advantage of client certificates for authentication.
|
||||
|
||||
If a server responds with `StatusCertificateRequired`, clients will generate a
|
||||
certificate for the site and resend the request with the provided certificate.
|
||||
The default client handles this for you. Other clients must specify the fields
|
||||
`CertificateStore` and `GetCertificate`:
|
||||
The default client handles this for you. Other clients must specify the field
|
||||
`GetCertificate`:
|
||||
|
||||
```go
|
||||
// Initialize the certificate store.
|
||||
client.CertificateStore = gmi.CertificateStore{}
|
||||
// GetCertificate is called when a server requests a certificate.
|
||||
// The returned certificate, if not nil, will be used when resending the request.
|
||||
client.GetCertificate = func(hostname string, store gmi.CertificateStore) *tls.Certificate {
|
||||
@ -109,7 +107,6 @@ client.GetCertificate = func(hostname string, store gmi.CertificateStore) *tls.C
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Servers can then authenticate their clients with the fingerprint of their
|
||||
certificates.
|
||||
|
||||
|
@ -276,6 +276,10 @@ func (c *Client) Send(req *Request) (*Response, error) {
|
||||
if req.Certificate != nil {
|
||||
return resp, nil
|
||||
}
|
||||
// Create the certificate store if it does not exist
|
||||
if c.CertificateStore == nil {
|
||||
c.CertificateStore = CertificateStore{}
|
||||
}
|
||||
if c.GetCertificate != nil {
|
||||
if cert := c.GetCertificate(req.Hostname(), c.CertificateStore); cert != nil {
|
||||
req.Certificate = cert
|
||||
|
@ -79,7 +79,7 @@ func login(rw *gmi.ResponseWriter, req *gmi.Request) {
|
||||
sessions[fingerprint] = &session{
|
||||
username: username,
|
||||
}
|
||||
gmi.Redirect(rw, req, "/login#password")
|
||||
gmi.Redirect(rw, req, "/login/password")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -48,8 +48,6 @@ func init() {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
client.CertificateStore = gmi.CertificateStore{}
|
||||
client.GetCertificate = func(hostname string, store gmi.CertificateStore) *tls.Certificate {
|
||||
// If the certificate is in the store, return it
|
||||
if cert, ok := store[hostname]; ok {
|
||||
|
Loading…
Reference in New Issue
Block a user