Add flag to use Let's Encrypt staging

This commit is contained in:
Anders Pitman 2022-02-17 14:08:32 -07:00
parent f1020aac49
commit ca6667cede
3 changed files with 29 additions and 17 deletions

View File

@ -53,6 +53,7 @@ func Listen() {
allowHttp := flagSet.Bool("allow-http", false, "Allow unencrypted (HTTP) requests") allowHttp := flagSet.Bool("allow-http", false, "Allow unencrypted (HTTP) requests")
publicIp := flagSet.String("public-ip", "", "Public IP") publicIp := flagSet.String("public-ip", "", "Public IP")
behindProxy := flagSet.Bool("behind-proxy", false, "Whether we're running behind another reverse proxy") behindProxy := flagSet.Bool("behind-proxy", false, "Whether we're running behind another reverse proxy")
acmeUseStaging := flagSet.Bool("acme-use-staging", false, "Use ACME (ie Let's Encrypt) staging servers")
err := flagSet.Parse(os.Args[2:]) err := flagSet.Parse(os.Args[2:])
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "%s: parsing flags: %s\n", os.Args[0], err) fmt.Fprintf(os.Stderr, "%s: parsing flags: %s\n", os.Args[0], err)
@ -99,7 +100,11 @@ func Listen() {
} }
//certmagic.DefaultACME.DisableHTTPChallenge = true //certmagic.DefaultACME.DisableHTTPChallenge = true
//certmagic.DefaultACME.DisableTLSALPNChallenge = true //certmagic.DefaultACME.DisableTLSALPNChallenge = true
//certmagic.DefaultACME.CA = certmagic.LetsEncryptStagingCA
if *acmeUseStaging {
certmagic.DefaultACME.CA = certmagic.LetsEncryptStagingCA
}
certConfig := certmagic.NewDefault() certConfig := certmagic.NewDefault()
if *newAdminDomain != "" { if *newAdminDomain != "" {

View File

@ -34,14 +34,15 @@ type Client struct {
} }
type ClientConfig struct { type ClientConfig struct {
ServerAddr string `json:"serverAddr,omitempty"` ServerAddr string `json:"serverAddr,omitempty"`
Token string `json:"token,omitempty"` Token string `json:"token,omitempty"`
ClientName string `json:"clientName,omitempty"` ClientName string `json:"clientName,omitempty"`
User string `json:"user,omitempty"` User string `json:"user,omitempty"`
CertDir string `json:"certDir,omitempty"` CertDir string `json:"certDir,omitempty"`
AcmeEmail string `json:"acmeEmail,omitempty"` AcmeEmail string `json:"acmeEmail,omitempty"`
DnsServer string `json:"dnsServer,omitempty"` AcmeUseStaging bool `json:"acmeUseStaging,omitempty"`
BehindProxy bool `json:"behindProxy,omitempty"` DnsServer string `json:"dnsServer,omitempty"`
BehindProxy bool `json:"behindProxy,omitempty"`
} }
func NewClient(config *ClientConfig) (*Client, error) { func NewClient(config *ClientConfig) (*Client, error) {
@ -81,6 +82,10 @@ func NewClient(config *ClientConfig) (*Client, error) {
certmagic.DefaultACME.Email = config.AcmeEmail certmagic.DefaultACME.Email = config.AcmeEmail
} }
if config.AcmeUseStaging {
certmagic.DefaultACME.CA = certmagic.LetsEncryptStagingCA
}
certConfig := certmagic.NewDefault() certConfig := certmagic.NewDefault()
httpClient := &http.Client{ httpClient := &http.Client{

View File

@ -50,6 +50,7 @@ func main() {
user := flagSet.String("user", "admin", "user") user := flagSet.String("user", "admin", "user")
certDir := flagSet.String("cert-dir", "", "TLS cert directory") certDir := flagSet.String("cert-dir", "", "TLS cert directory")
acmeEmail := flagSet.String("acme-email", "", "Email for ACME (ie Let's Encrypt)") acmeEmail := flagSet.String("acme-email", "", "Email for ACME (ie Let's Encrypt)")
acmeUseStaging := flagSet.Bool("acme-use-staging", false, "Use ACME (ie Let's Encrypt) staging servers")
dnsServer := flagSet.String("dns-server", "", "Custom DNS server") dnsServer := flagSet.String("dns-server", "", "Custom DNS server")
behindProxy := flagSet.Bool("behind-proxy", false, "Whether we're running behind another reverse proxy") behindProxy := flagSet.Bool("behind-proxy", false, "Whether we're running behind another reverse proxy")
@ -71,14 +72,15 @@ func main() {
} }
config := &boringproxy.ClientConfig{ config := &boringproxy.ClientConfig{
ServerAddr: *server, ServerAddr: *server,
Token: *token, Token: *token,
ClientName: *name, ClientName: *name,
User: *user, User: *user,
CertDir: *certDir, CertDir: *certDir,
AcmeEmail: *acmeEmail, AcmeEmail: *acmeEmail,
DnsServer: *dnsServer, AcmeUseStaging: *acmeUseStaging,
BehindProxy: *behindProxy, DnsServer: *dnsServer,
BehindProxy: *behindProxy,
} }
ctx := context.Background() ctx := context.Background()