Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ACME v2 and possibility of generate wildcard certificates #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.0
v1.0.0
35 changes: 15 additions & 20 deletions letsencrypt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (

"github.com/Sirupsen/logrus"
lego "github.com/xenolf/lego/acme"
loge "github.com/xenolf/lego/log"
)

const (
StorageDir = "/etc/letsencrypt"
ProductionApiUri = "https://acme-v01.api.letsencrypt.org/directory"
StagingApiUri = "https://acme-staging.api.letsencrypt.org/directory"
ProductionApiUri = "https://acme-v02.api.letsencrypt.org/directory"
StagingApiUri = "https://acme-staging-v02.api.letsencrypt.org/directory"
)

type KeyType string
Expand Down Expand Up @@ -97,23 +98,16 @@ func NewClient(email string, kt KeyType, apiVer ApiVersion, dnsResolvers []strin
return nil, fmt.Errorf("Could not create client: %v", err)
}

lego.Logger = log.New(ioutil.Discard, "", 0)
loge.Logger = log.New(ioutil.Discard, "", 0)

if acc.Registration == nil {
logrus.Infof("Creating Let's Encrypt account for %s", email)
reg, err := client.Register()
reg, err := client.Register(true)
if err != nil {
return nil, fmt.Errorf("Failed to register account: %v", err)
}

acc.Registration = reg
if acc.Registration.Body.Agreement == "" {
err = client.AgreeToTOS()
if err != nil {
return nil, fmt.Errorf("Could not agree to TOS: %v", err)
}
}

err = acc.Save()
if err != nil {
logrus.Errorf("Could not save account data: %v", err)
Expand All @@ -133,9 +127,9 @@ func NewClient(email string, kt KeyType, apiVer ApiVersion, dnsResolvers []strin
}

if challenge == lego.DNS01 {
client.ExcludeChallenges([]lego.Challenge{lego.HTTP01, lego.TLSSNI01})
client.ExcludeChallenges([]lego.Challenge{lego.HTTP01})
} else if challenge == lego.HTTP01 {
client.ExcludeChallenges([]lego.Challenge{lego.TLSSNI01, lego.DNS01})
client.ExcludeChallenges([]lego.Challenge{lego.DNS01})
}

if len(dnsResolvers) > 0 {
Expand All @@ -153,20 +147,21 @@ func NewClient(email string, kt KeyType, apiVer ApiVersion, dnsResolvers []strin
func (c *Client) EnableLogs() {
logger := logrus.New()
logger.Out = os.Stdout
lego.Logger = log.New(logger.Writer(), "", 0)
loge.Logger = log.New(logger.Writer(), "", 0)
}

// Issue obtains a new SAN certificate from the Lets Encrypt CA
func (c *Client) Issue(certName string, domains []string) (*AcmeCertificate, map[string]error) {
certRes, failures := c.client.ObtainCertificate(domains, true, nil, false)
if len(failures) > 0 {
return nil, failures
func (c *Client) Issue(certName string, domains []string) (*AcmeCertificate, error) {
certRes, err := c.client.ObtainCertificate(domains, true, nil, false)
if err != nil {
return nil, err
}

dnsNames := dnsNamesIdentifier(domains)
acmeCert, err := c.saveCertificate(certName, dnsNames, certRes)
if err != nil {
logrus.Fatalf("Error saving certificate '%s': %v", certName, err)
return nil, err
}

return acmeCert, nil
Expand Down Expand Up @@ -261,7 +256,7 @@ func (c *Client) loadCertificateByName(certName string) (AcmeCertificate, error)
return acmeCert, nil
}

func (c *Client) saveCertificate(certName, dnsNames string, certRes lego.CertificateResource) (*AcmeCertificate, error) {
func (c *Client) saveCertificate(certName, dnsNames string, certRes *lego.CertificateResource) (*AcmeCertificate, error) {
expiryDate, err := lego.GetPEMCertExpiration(certRes.Certificate)
if err != nil {
return nil, fmt.Errorf("Failed to read certificate expiry date: %v", err)
Expand All @@ -272,7 +267,7 @@ func (c *Client) saveCertificate(certName, dnsNames string, certRes lego.Certifi
}

acmeCert := AcmeCertificate{
CertificateResource: certRes,
CertificateResource: *certRes,
ExpiryDate: expiryDate,
SerialNumber: serialNumber,
DnsNames: dnsNames,
Expand Down
8 changes: 3 additions & 5 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ func (c *Context) startup() {

logrus.Infof("Trying to obtain SSL certificate (%s) from Let's Encrypt %s CA", strings.Join(c.Domains, ","), c.Acme.ApiVersion())

acmeCert, failures := c.Acme.Issue(c.CertificateName, c.Domains)
if len(failures) > 0 {
for k, v := range failures {
logrus.Errorf("[%s] Error obtaining certificate: %s", k, v.Error())
}
acmeCert, err = c.Acme.Issue(c.CertificateName, c.Domains)
if err != nil {
logrus.Errorf("[%s] Error obtaining certificate: %s", err, err.Error())
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM alpine:3.5

RUN apk add --no-cache ca-certificates openssl bash

ENV LETSENCRYPT_RELEASE v0.5.0
ENV LETSENCRYPT_RELEASE v1.0.0
ENV SSL_SCRIPT_COMMIT 08278ace626ada71384fc949bd637f4c15b03b53

RUN wget -O /usr/bin/update-rancher-ssl https://raw.githubusercontent.com/rancher/rancher/${SSL_SCRIPT_COMMIT}/server/bin/update-rancher-ssl && \
Expand Down
48 changes: 23 additions & 25 deletions vendor.conf
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# package
github.com/janeczku/rancher-letsencrypt

github.com/aws/aws-sdk-go v1.8.6
github.com/Azure/azure-sdk-for-go v10.0.2-beta
github.com/Azure/go-autorest v8.0.0
github.com/dgrijalva/jwt-go 6c8dedd
github.com/dnsimple/dnsimple-go 5a5b427
github.com/edeckers/auroradnsclient 8b777c1
github.com/go-ini/ini e7fea39
github.com/google/go-querystring 53e6ce1
github.com/gorilla/websocket a91eba7
github.com/JamesClonk/vultr 1.13.0
github.com/jmespath/go-jmespath bd40a43
github.com/juju/ratelimit 77ed1c8
github.com/miekg/dns f282f80
github.com/ovh/go-ovh d220717
github.com/pkg/errors c605e28
github.com/rancher/go-rancher/v2 939fd85
github.com/Sirupsen/logrus v0.11.5
github.com/xenolf/lego aaa8e70
golang.org/x/crypto ab89591
golang.org/x/net 84f0e6f
golang.org/x/sys f845067
golang.org/x/text 767daa1
gopkg.in/ini.v1 e7fea39
gopkg.in/ns1/ns1-go.v2 c563826
gopkg.in/square/go-jose.v1 aa2e30f
github.com/aws/aws-sdk-go v1.14.3
github.com/Azure/azure-sdk-for-go v17.3.0
github.com/Azure/go-autorest v10.10.0
github.com/dgrijalva/jwt-go 6c8dedd
github.com/dnsimple/dnsimple-go 5a5b427
github.com/edeckers/auroradnsclient 8b777c1
github.com/go-ini/ini e7fea39
github.com/google/go-querystring 53e6ce1
github.com/gorilla/websocket a91eba7
github.com/JamesClonk/vultr 1.13.0
github.com/jmespath/go-jmespath bd40a43
github.com/juju/ratelimit 77ed1c8
github.com/miekg/dns f282f80
github.com/ovh/go-ovh d220717
github.com/pkg/errors c605e28
github.com/rancher/go-rancher/v2 939fd85
github.com/Sirupsen/logrus v1.0.5
github.com/xenolf/lego 7fedfd1
golang.org/x/crypto ab89591
golang.org/x/sys f845067
gopkg.in/ini.v1 e7fea39
gopkg.in/ns1/ns1-go.v2 c563826
gopkg.in/square/go-jose.v2 v2.1.6
2 changes: 1 addition & 1 deletion vendor/github.com/Azure/azure-sdk-for-go/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 24 additions & 22 deletions vendor/github.com/Azure/azure-sdk-for-go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading