Change server initialization code to use certificates common names

This commit is contained in:
Manuel de Brito Fontes 2017-02-06 17:48:08 -03:00
parent b5819d8f4d
commit 03e3c34308

View file

@ -114,3 +114,51 @@ func mergeLocationAnnotations(loc *ingress.Location, anns map[string]interface{}
glog.Errorf("unexpected error merging extracted annotations in location type: %v", err) glog.Errorf("unexpected error merging extracted annotations in location type: %v", err)
} }
} }
func isDomainName(s string) bool {
// See RFC 1035, RFC 3696.
if len(s) == 0 {
return false
}
if len(s) > 255 {
return false
}
if s[len(s)-1] != '.' { // simplify checking loop: make name end in dot
s += "."
}
last := byte('.')
ok := false // ok once we've seen a letter
partlen := 0
for i := 0; i < len(s); i++ {
c := s[i]
switch {
default:
return false
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_':
ok = true
partlen++
case '0' <= c && c <= '9':
// fine
partlen++
case c == '-':
// byte before dash cannot be dot
if last == '.' {
return false
}
partlen++
case c == '.':
// byte before dot cannot be dot, dash
if last == '.' || last == '-' {
return false
}
if partlen > 63 || partlen == 0 {
return false
}
partlen = 0
}
last = c
}
return ok
}