25 lines
584 B
Go
25 lines
584 B
Go
package cdp
|
|
|
|
import (
|
|
"crypto/subtle"
|
|
"net/http"
|
|
)
|
|
|
|
// endpointBasicAuth is the request HTTP Basic authentication
|
|
// for validating requests
|
|
type endpointBasicAuth struct {
|
|
Username []byte
|
|
Password []byte
|
|
}
|
|
|
|
func (epbo *endpointBasicAuth) IsRequestAuthenticated(r *http.Request) bool {
|
|
username, password, ok := r.BasicAuth()
|
|
if !ok {
|
|
return false
|
|
}
|
|
sum := subtle.ConstantTimeCompare([]byte(username), epbo.Username)
|
|
sum += subtle.ConstantTimeCompare([]byte(password), epbo.Password)
|
|
// ConstantTimeCompare returns 1 if both slices have equal contents
|
|
return sum == 2
|
|
}
|