forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmw_certificate_check.go
33 lines (26 loc) · 942 Bytes
/
mw_certificate_check.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
package gateway
import (
"net/http"
)
// CertificateCheckMW is used if domain was not detected or multiple APIs bind on the same domain. In this case authentification check happens not on TLS side but on HTTP level using this middleware
type CertificateCheckMW struct {
BaseMiddleware
}
func (m *CertificateCheckMW) Name() string {
return "CertificateCheckMW"
}
func (m *CertificateCheckMW) EnabledForSpec() bool {
return m.Spec.UseMutualTLSAuth
}
func (m *CertificateCheckMW) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int) {
if ctxGetRequestStatus(r) == StatusOkAndIgnore {
return nil, http.StatusOK
}
if m.Spec.UseMutualTLSAuth {
certIDs := append(m.Spec.ClientCertificates, m.Spec.GlobalConfig.Security.Certificates.API...)
if err := m.Gw.CertificateManager.ValidateRequestCertificate(certIDs, r); err != nil {
return err, http.StatusForbidden
}
}
return nil, http.StatusOK
}