github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/internal/enforcer/applicationproxy/common/common.go (about) 1 package common 2 3 import ( 4 "crypto/x509/pkix" 5 "encoding/asn1" 6 "net" 7 8 "go.aporeto.io/enforcerd/trireme-lib/policy" 9 ) 10 11 // ListenerType are the types of listeners that can be used. 12 type ListenerType int 13 14 // Values of ListenerType 15 const ( 16 TCPApplication ListenerType = iota 17 TCPNetwork 18 HTTPApplication 19 HTTPNetwork 20 HTTPSApplication 21 HTTPSNetwork 22 ) 23 24 // ExtractExtension returns true and the value of the given oid If any. 25 func ExtractExtension(oid asn1.ObjectIdentifier, extensions []pkix.Extension) (bool, []byte) { 26 27 for _, ext := range extensions { 28 if !ext.Id.Equal(oid) { 29 continue 30 } 31 32 return true, ext.Value 33 } 34 35 return false, nil 36 } 37 38 // GetTLSServerName provides the server name to use in TLS config based on service configuration and destination IP. 39 func GetTLSServerName( 40 addrAndPort string, 41 service *policy.ApplicationService, 42 ) (name string, err error) { 43 44 if service != nil && service.NetworkInfo != nil && len(service.NetworkInfo.FQDNs) != 0 { 45 name = service.NetworkInfo.FQDNs[0] 46 return name, nil 47 } 48 49 name, _, err = net.SplitHostPort(addrAndPort) 50 return name, err 51 }