Skip to content

Commit

Permalink
Add support for preferred chain option
Browse files Browse the repository at this point in the history
  • Loading branch information
project0 committed Oct 1, 2021
1 parent 20f37a7 commit 96aaebe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
29 changes: 16 additions & 13 deletions certstore/certstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ func (u User) GetPrivateKey() crypto.PrivateKey {
}

type CertStore struct {
user *User
email string
client *lego.Client
sync *sync.Mutex
storage store.Store
user *User
email string
preferredChain string
client *lego.Client
sync *sync.Mutex
storage store.Store
}

func NewCertStore(acmeDirectory string, email string, challengeProvider challenge.Provider, storage store.Store) (*CertStore, error) {
func NewCertStore(acmeDirectory string, email string, challengeProvider challenge.Provider, storage store.Store, preferredChain string) (*CertStore, error) {
var err error
cs := &CertStore{
sync: &sync.Mutex{},
email: email,
storage: storage,
sync: &sync.Mutex{},
email: email,
storage: storage,
preferredChain: preferredChain,
}

// ensure we have a user
Expand Down Expand Up @@ -159,10 +161,11 @@ func (c *CertStore) GetCertificate(request *CertRequest) (*CertificateResource,
}

req := certificate.ObtainRequest{
Domains: request.domains(),
Bundle: false,
PrivateKey: nil,
MustStaple: false,
Domains: request.domains(),
Bundle: false,
PrivateKey: nil,
MustStaple: false,
PreferredChain: c.preferredChain,
}
acmeCerts, err := c.client.Certificate.Obtain(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion certstore/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func removeDuplicates(elements []string) []string {
result := []string{}

for v := range elements {
if encountered[elements[v]] == true {
if encountered[elements[v]] {
// Do not add duplicate.
} else {
// Record this element as an encountered element.
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func main() {
Usage: "DNS challenge provider name",
EnvVar: flagSetHelperEnvKey("PROVIDER"),
},
cli.StringFlag{
Name: "preferred-chain",
Value: "",
Usage: "If the CA offers multiple certificate chains, prefer the chain with an issuer matching this Subject Common Name. If no match, the default offered chain will be used.",
EnvVar: flagSetHelperEnvKey("PREFERRED-CHAIN"),
},
cli.StringFlag{
Name: "dns.listen",
Value: ":53",
Expand Down Expand Up @@ -125,7 +131,7 @@ func main() {
}
}

certStore, err = certstore.NewCertStore(c.String("server"), email, dnsprovider, storage)
certStore, err = certstore.NewCertStore(c.String("server"), email, dnsprovider, storage, c.String("preferred-chain"))
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 96aaebe

Please sign in to comment.