You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cmd/vicadmin/server.go
+94-4Lines changed: 94 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,9 @@ import (
19
19
"compress/gzip"
20
20
"crypto/tls"
21
21
"crypto/x509"
22
+
"fmt"
22
23
"html/template"
24
+
"io"
23
25
"net"
24
26
"net/http"
25
27
"net/url"
@@ -75,6 +77,83 @@ const (
75
77
genericErrorMessage="Internal Server Error; see /var/log/vic/vicadmin.log for details"// for http errors that shouldn't be displayed in the browser to the user
76
78
)
77
79
80
+
// Conn is a wrapper struct around net.Conn that implements custom functionality (TLS Check)
81
+
typeConnstruct {
82
+
net.Conn
83
+
bbyte
84
+
errerror
85
+
UncertainTLSbool
86
+
}
87
+
88
+
// Read checks for TLS in the connection and returns number of bytes read
89
+
func (c*Conn) Read(b []byte) (int, error) {
90
+
// one time check to determine if TLS is in the connection
91
+
ifc.UncertainTLS {
92
+
iflen(b) ==0 {
93
+
return0, fmt.Errorf("invalid length of byte array, cannot proceed with TLS check")
94
+
}
95
+
c.UncertainTLS=false
96
+
b[0] =c.b
97
+
// if there's more bytes to read
98
+
iflen(b) >1&&c.err==nil {
99
+
// recurse on next byte
100
+
n, e:=c.Conn.Read(b[1:])
101
+
// close connection if error during reading
102
+
ife!=nil {
103
+
c.Conn.Close()
104
+
}
105
+
// return total number of bytes read (+ current) and pass error e
106
+
returnn+1, e
107
+
}
108
+
// only one byte read
109
+
return1, c.err
110
+
}
111
+
// using the default Conn read
112
+
returnc.Conn.Read(b)
113
+
}
114
+
115
+
// TLSRedirectListener is a wrapper struct around net.Listener that implements custom functionality (TLS Check)
116
+
typeTLSRedirectListenerstruct {
117
+
net.Listener
118
+
addrstring
119
+
config*tls.Config
120
+
}
121
+
122
+
// Accept overrides the default listener Accept and adds a TLS check
0 commit comments