Update README.md
This commit is contained in:
parent
4b0f94157c
commit
872f6e2683
38
README.md
38
README.md
|
@ -71,27 +71,25 @@ client.TrustCertificate = func(cert *x509.Certificate, knownHosts *gemini.KnownH
|
||||||
Advanced clients can prompt the user for what to do when encountering an unknown certificate:
|
Advanced clients can prompt the user for what to do when encountering an unknown certificate:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
client := &gemini.Client{
|
client.TrustCertificate: func(cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
|
||||||
TrustCertificate: func(cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
|
err := knownHosts.Lookup(cert)
|
||||||
err := knownHosts.Lookup(cert)
|
if err != nil {
|
||||||
if err != nil {
|
switch err {
|
||||||
switch err {
|
case gemini.ErrCertificateNotTrusted:
|
||||||
case gemini.ErrCertificateNotTrusted:
|
// Alert the user that the certificate is not trusted
|
||||||
// Alert the user that the certificate is not trusted
|
alertUser()
|
||||||
alertUser()
|
case gemini.ErrCertificateUnknown:
|
||||||
case gemini.ErrCertificateUnknown:
|
// Prompt the user to trust the certificate
|
||||||
// Prompt the user to trust the certificate
|
if userTrustsCertificateTemporarily() {
|
||||||
if userTrustsCertificateTemporarily() {
|
// Temporarily trust the certificate
|
||||||
// Temporarily trust the certificate
|
return nil
|
||||||
return nil
|
} else if user.TrustsCertificatePermanently() {
|
||||||
} else if user.TrustsCertificatePermanently() {
|
// Add the certificate to the known hosts file
|
||||||
// Add the certificate to the known hosts file
|
knownHosts.Add(cert)
|
||||||
knownHosts.Add(cert)
|
return nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
}
|
||||||
},
|
return err
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user