Implement server certificate store
This commit is contained in:
@@ -52,9 +52,8 @@ func main() {
|
||||
handler.HandleFunc("/admin", admin)
|
||||
handler.HandleFunc("/logout", logout)
|
||||
|
||||
server := &gmi.Server{
|
||||
Certificate: cert,
|
||||
}
|
||||
server := &gmi.Server{}
|
||||
server.CertificateStore.Add("localhost", cert)
|
||||
server.Handle("localhost", handler)
|
||||
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
|
||||
@@ -48,7 +48,7 @@ func init() {
|
||||
}
|
||||
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 {
|
||||
if cert, err := store.Lookup(hostname); err == nil {
|
||||
return cert
|
||||
}
|
||||
// Otherwise, generate a certificate
|
||||
@@ -59,7 +59,7 @@ func init() {
|
||||
return nil
|
||||
}
|
||||
// Store and return the certificate
|
||||
store[hostname] = &cert
|
||||
store.Add(hostname, cert)
|
||||
return &cert
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ func main() {
|
||||
mux := &gmi.ServeMux{}
|
||||
mux.Handle("/", gmi.FileServer(gmi.Dir("/var/www")))
|
||||
|
||||
server := gmi.Server{
|
||||
Certificate: cert,
|
||||
}
|
||||
server := gmi.Server{}
|
||||
server.CertificateStore.Add("localhost", cert)
|
||||
server.Handle("localhost", mux)
|
||||
server.ListenAndServe()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user