From 03e3c34308641bd935fe75897843de27239b7f50 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Mon, 6 Feb 2017 17:48:08 -0300 Subject: [PATCH] Change server initialization code to use certificates common names --- core/pkg/ingress/controller/util.go | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/core/pkg/ingress/controller/util.go b/core/pkg/ingress/controller/util.go index 7ff154d8f..6637d8142 100644 --- a/core/pkg/ingress/controller/util.go +++ b/core/pkg/ingress/controller/util.go @@ -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) } } + +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 +}