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

Return Proper Non-ACME certificate - Fixes Issue 672 #1018

Merged
merged 1 commit into from
Jan 5, 2017

Conversation

dtomcej
Copy link
Contributor

@dtomcej dtomcej commented Jan 4, 2017

Fixes Issue #672

@dtomcej dtomcej changed the title Add regex for wildcard certs Return Proper Non-ACME certificate - Fixes Issue 672 Jan 4, 2017
@trecloux
Copy link
Contributor

trecloux commented Jan 5, 2017

LGTM 👍

@@ -331,6 +334,14 @@ func (a *ACME) CreateLocalConfig(tlsConfig *tls.Config, checkOnDemandDomain func
func (a *ACME) getCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
domain := types.CanonicalDomain(clientHello.ServerName)
account := a.store.Get().(*Account)
//use regex to test for wildcard certs that might have been added into TLSConfig
for k := range a.TLSConfig.NameToCertificate {
selector := "^" + strings.Replace(k, "*.", ".*\\.?", -1) + "$"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtomcej Will this properly not match subdomains of a wildcard?
E,g, If I have a certificate for *.mysite.com, then foo.mysite.com should match but bar.foo.mysite.com should not match.
Should it be strings.Replace(k, "*.", "[^.]*\\.?", -1) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you cannot have a double wildcard certificate, sometimes people issue certs with wildcard subdomains as SANS. Example: *.mysite.com could have a SAN of *.foo.mysite.com, in which case it is up to the certificate to cover the SANs. I also search the SANs of the certificate here as well, so if your cert has both *.mysite.com with a SAN of *.foo.mysite.com, it will be matched either way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is for the possibility of not having SANs. That is, I have a wildcard for *.mydomain.com. It will not cover *.test.mydomain.com, and I don't want to add SANs for that. Instead I want to use the wildcard for *.mydomain.com, but have ACME generate certificates for say bar.foo.mydomain.com.
Will the code as-is allow this, or will it attempt to use the wildcard even though it doesn't apply due to the lack of a SAN?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I see what you are saying. As is, it will serve the static wildcard.

Feel free to open a new PR (Or a new issue with your proposed regex) to update the regex, and we can test it out. Im not against it. I think that if we are going to use ACME as a "fallback" when static certs are added, having them matched by a more accurate regex would be a good thing.

@HJFinch
Copy link

HJFinch commented Jan 30, 2017

Is it possible that this change caused the Default Cert to be always sent?
I am getting weird behavior in traefik with acme where it does not serve the acme certificates even if they are in the json file.

@CyrilPeponnet
Copy link

I have the same issue I think, I have a default wildcard cert (self signed), when I request a ACME cert, it's not used, only the wildcard cert is presented.

emilevauge added a commit that referenced this pull request Mar 7, 2017
Tighten regex match for wildcard certs [Addendum to #1018]
@ldez ldez added this to the 1.2 milestone Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants