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

Add option to allow non-standard Common Name (CN) in SSL certificate verification. #705

Merged
merged 2 commits into from
Dec 11, 2021

Conversation

jsimonweb
Copy link
Contributor

Fixes #704

Copy link
Collaborator

@kardianos kardianos left a comment

Choose a reason for hiding this comment

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

So remove new option entirely, then auto select based on host name. See comments for detail. Also please re-write function now according to inline code comment.

}
if insecureSkipVerify {
config.InsecureSkipVerify = true
if !allowNonstandardHostname {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The core issue is that Go TLS does not consider a hostname with ":" to be valid. I generally agree, but here we are.

In this case, remove all code and documentation regarding the new option. rather, do a check in config.ServerName if it contains a ":". If that is the case, then do the alternative check.

// replacing. This does not disable VerifyConnection.
config.InsecureSkipVerify = true
config.VerifyConnection = func(cs tls.ConnectionState) error {
commonName := cs.PeerCertificates[0].Subject.CommonName
Copy link
Collaborator

Choose a reason for hiding this comment

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

This verify Connection function doesn't open the "insecure Skip Verify" bool. If insecure skip verify is true, then do an early return.

var config tls.Config
config.ServerName = hostInCertificate
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like how SetupTLS is not structured now. Please do the following:

func SetupTLS() {
config := tls.Config {
    ServerName: hostInCertificate,

    // comment
    DynamicRecordSizingDisabled: true,

}
if len(certificate) == 0 {
    return &config, nil
}
ReadFile(certificate)
if strings.Contains(config.ServerName, ":") {
    // new code
    return &config, nil
}
// orig code
return &config, nil
}

@kardianos
Copy link
Collaborator

Okay, so this LGTM, with one change: it needs to be for only go1.15+ only. I coded this up, but couldn't make it commit well, so I'm going to merge and push a follow up.

@kardianos kardianos merged commit 324eb10 into denisenkom:master Dec 11, 2021
@jsimonweb jsimonweb deleted the add-option-for-custom-CN branch December 11, 2021 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow non-standard Common Name (CN) for SSL verification of connections with provided certificates.
2 participants