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