summaryrefslogtreecommitdiff
path: root/modules/caddytls/matchers.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-04-25 13:54:48 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-04-25 13:54:48 -0600
commit2d056fbe66849f041a233a0d961639fae3835cbb (patch)
treedc78505933861e01f615470ffc1dd56a852da0b8 /modules/caddytls/matchers.go
parent545f28008e0175491af030f8689cab2112fda9ed (diff)
Initial commit of Storage, TLS, and automatic HTTPS implementations
Diffstat (limited to 'modules/caddytls/matchers.go')
-rw-r--r--modules/caddytls/matchers.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/modules/caddytls/matchers.go b/modules/caddytls/matchers.go
new file mode 100644
index 0000000..c376f87
--- /dev/null
+++ b/modules/caddytls/matchers.go
@@ -0,0 +1,79 @@
+package caddytls
+
+import (
+ "crypto/tls"
+
+ "bitbucket.org/lightcodelabs/caddy2"
+)
+
+type (
+ MatchServerName []string
+
+ // TODO: these others should be enterprise-only, probably
+ MatchProtocol []string // TODO: version or protocol?
+ MatchClientCert struct{} // TODO: client certificate options
+ MatchRemote []string
+ MatchStarlark string
+)
+
+func init() {
+ caddy2.RegisterModule(caddy2.Module{
+ Name: "tls.handshake_match.host",
+ New: func() (interface{}, error) { return MatchServerName{}, nil },
+ })
+ caddy2.RegisterModule(caddy2.Module{
+ Name: "tls.handshake_match.protocol",
+ New: func() (interface{}, error) { return MatchProtocol{}, nil },
+ })
+ caddy2.RegisterModule(caddy2.Module{
+ Name: "tls.handshake_match.client_cert",
+ New: func() (interface{}, error) { return MatchClientCert{}, nil },
+ })
+ caddy2.RegisterModule(caddy2.Module{
+ Name: "tls.handshake_match.remote",
+ New: func() (interface{}, error) { return MatchRemote{}, nil },
+ })
+ caddy2.RegisterModule(caddy2.Module{
+ Name: "tls.handshake_match.starlark",
+ New: func() (interface{}, error) { return new(MatchStarlark), nil },
+ })
+}
+
+func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
+ for _, name := range m {
+ // TODO: support wildcards (and regex?)
+ if hello.ServerName == name {
+ return true
+ }
+ }
+ return false
+}
+
+func (m MatchProtocol) Match(hello *tls.ClientHelloInfo) bool {
+ // TODO: not implemented
+ return false
+}
+
+func (m MatchClientCert) Match(hello *tls.ClientHelloInfo) bool {
+ // TODO: not implemented
+ return false
+}
+
+func (m MatchRemote) Match(hello *tls.ClientHelloInfo) bool {
+ // TODO: not implemented
+ return false
+}
+
+func (m MatchStarlark) Match(hello *tls.ClientHelloInfo) bool {
+ // TODO: not implemented
+ return false
+}
+
+// Interface guards
+var (
+ _ ConnectionMatcher = MatchServerName{}
+ _ ConnectionMatcher = MatchProtocol{}
+ _ ConnectionMatcher = MatchClientCert{}
+ _ ConnectionMatcher = MatchRemote{}
+ _ ConnectionMatcher = new(MatchStarlark)
+)