(ctx context.Context, wr http.ResponseWriter, req *http.Request)
| 101 | } |
| 102 | |
| 103 | func (auth *HMACAuth) Validate(ctx context.Context, wr http.ResponseWriter, req *http.Request) (string, bool) { |
| 104 | hdr := req.Header.Get("Proxy-Authorization") |
| 105 | if hdr == "" { |
| 106 | return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next) |
| 107 | } |
| 108 | hdr_parts := strings.SplitN(hdr, " ", 2) |
| 109 | if len(hdr_parts) != 2 || strings.ToLower(hdr_parts[0]) != "basic" { |
| 110 | return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next) |
| 111 | } |
| 112 | |
| 113 | token := hdr_parts[1] |
| 114 | data, err := base64.StdEncoding.DecodeString(token) |
| 115 | if err != nil { |
| 116 | return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next) |
| 117 | } |
| 118 | |
| 119 | pair := strings.SplitN(string(data), ":", 2) |
| 120 | if len(pair) != 2 { |
| 121 | return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next) |
| 122 | } |
| 123 | |
| 124 | login := pair[0] |
| 125 | password := pair[1] |
| 126 | |
| 127 | if VerifyHMACLoginAndPassword(auth.secret, login, password) { |
| 128 | if auth.hiddenDomain != "" && |
| 129 | (matchHiddenDomain(req.Host, auth.hiddenDomain) || matchHiddenDomain(req.URL.Host, auth.hiddenDomain)) { |
| 130 | sendAuthTriggeredMsg(wr) |
| 131 | return "", false |
| 132 | } else { |
| 133 | return login, true |
| 134 | } |
| 135 | } |
| 136 | return requireBasicAuth(ctx, wr, req, auth.hiddenDomain, auth.next) |
| 137 | } |
| 138 | |
| 139 | func (auth *HMACAuth) Close() error { |
| 140 | var err error |
nothing calls this directly
no test coverage detected