-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'unreality-extended-sans'
- Loading branch information
Showing
5 changed files
with
464 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,18 @@ | ||
package tlsutil | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
|
||
"golang.org/x/net/idna" | ||
"go.step.sm/crypto/x509util" | ||
) | ||
|
||
// SanitizeName converts the given domain to its ASCII form. | ||
func SanitizeName(domain string) (string, error) { | ||
if domain == "" { | ||
return "", errors.New("empty server name") | ||
} | ||
|
||
// Note that this conversion is necessary because some server names in the handshakes | ||
// started by some clients (such as cURL) are not converted to Punycode, which will | ||
// prevent us from obtaining certificates for them. In addition, we should also treat | ||
// example.com and EXAMPLE.COM as equivalent and return the same certificate for them. | ||
// Fortunately, this conversion also helped us deal with this kind of mixedcase problems. | ||
// | ||
// Due to the "σςΣ" problem (see https://unicode.org/faq/idn.html#22), we can't use | ||
// idna.Punycode.ToASCII (or just idna.ToASCII) here. | ||
name, err := idna.Lookup.ToASCII(domain) | ||
if err != nil { | ||
return "", errors.New("server name contains invalid character") | ||
} | ||
|
||
return name, nil | ||
} | ||
var SanitizeName = x509util.SanitizeName | ||
|
||
// SanitizeHost returns the ASCII form of the host part in a host:port address. | ||
func SanitizeHost(host string) (string, error) { | ||
if h, _, err := net.SplitHostPort(host); err == nil { | ||
return SanitizeName(h) | ||
return x509util.SanitizeName(h) | ||
} | ||
return SanitizeName(host) | ||
return x509util.SanitizeName(host) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.