Hack in command-line specification of domain, cert and key
This commit is contained in:
@@ -2,20 +2,60 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
Domain() string
|
||||
TLS() tls.Certificate
|
||||
TLSConfig() *tls.Config
|
||||
|
||||
SetDomain(string)
|
||||
SetTLS(tls.Certificate)
|
||||
}
|
||||
|
||||
func New(ctx context.Context, filename string) (Interface, error) {
|
||||
return &concrete{domain: "example.com"}, nil
|
||||
return &concrete{
|
||||
filename: filename,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type concrete struct {
|
||||
filename string
|
||||
|
||||
// TODO: these will eventually be persisted to the file in `filename`
|
||||
domain string
|
||||
cert tls.Certificate
|
||||
}
|
||||
|
||||
func (c *concrete) Domain() string {
|
||||
return c.domain
|
||||
}
|
||||
|
||||
func (c *concrete) TLS() tls.Certificate {
|
||||
return c.cert
|
||||
}
|
||||
|
||||
func (c *concrete) TLSConfig() *tls.Config {
|
||||
return &tls.Config{
|
||||
GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||
certCopy := c.TLS()
|
||||
|
||||
return &certCopy, nil
|
||||
},
|
||||
|
||||
ServerName: c.Domain(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *concrete) SetDomain(domain string) {
|
||||
c.domain = domain
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *concrete) SetTLS(cert tls.Certificate) {
|
||||
c.cert = cert
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user