summaryrefslogtreecommitdiff
path: root/contrib/tlsauth/approver.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-10-09 08:56:53 -0600
committertjpcc <tjp@ctrl-c.club>2023-10-09 08:56:53 -0600
commitcedcf58ea7d729acb6ed1a9ab7aec1ae38aed102 (patch)
treec04144501fa461b840cea96951f23d926b596ff7 /contrib/tlsauth/approver.go
parent1a14f01df1c220f1b8a0dcee1eada007aca8d43f (diff)
more useful tlsauth.Approver type
the predicate function should be able to see the whole context and request
Diffstat (limited to 'contrib/tlsauth/approver.go')
-rw-r--r--contrib/tlsauth/approver.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/contrib/tlsauth/approver.go b/contrib/tlsauth/approver.go
index 064056d..ed442ce 100644
--- a/contrib/tlsauth/approver.go
+++ b/contrib/tlsauth/approver.go
@@ -1,17 +1,27 @@
package tlsauth
-import "crypto/x509"
+import (
+ "context"
+ "crypto/x509"
+
+ "tildegit.org/tjp/sliderule"
+)
// Approver is a function that validates a certificate.
//
// It should not be have to handle a nil argument.
-type Approver func(*x509.Certificate) bool
+type Approver func(context.Context, *sliderule.Request) bool
// RequireSpecificIdentity builds an approver that demands one specific client certificate.
-func RequireSpecificIdentity(identity *x509.Certificate) Approver { return identity.Equal }
+func RequireSpecificIdentity(identity *x509.Certificate) Approver {
+ return func(_ context.Context, request *sliderule.Request) bool {
+ cert := Identity(request)
+ return cert != nil && identity.Equal(cert)
+ }
+}
// Allow is an approver which permits anything.
-func Allow(_ *x509.Certificate) bool { return true }
+func Allow(_ context.Context, _ *sliderule.Request) bool { return true }
// Reject is an approver which denies everything.
-func Reject(_ *x509.Certificate) bool { return false }
+func Reject(_ context.Context, _ *sliderule.Request) bool { return false }