ЛР7 на 4: HTTPS, mTLS, OpenBao AppRole и ротация leaf.
Skeleton contracts / contracts (pull_request) Blocked by required conditions

Smoke/security/grade4/persistence/failover пройдены; REPORT и DEFENSE.
This commit is contained in:
2026-12-02 23:08:27 +03:00
parent 20afc2c790
commit 2f2047909f
182 changed files with 15169 additions and 90 deletions
+37
View File
@@ -0,0 +1,37 @@
package httpx
import (
"net/http"
"strings"
"gavrilenko-sxdees/lab7/internal/dto"
)
const (
BasicChallenge = `Basic realm="messenger", charset="UTF-8"`
BearerChallenge = `Bearer realm="messenger"`
)
func BearerToken(r *http.Request) (string, bool) {
const prefix = "Bearer "
header := r.Header.Get("Authorization")
if len(header) <= len(prefix) || !strings.EqualFold(header[:len(prefix)], prefix) {
return "", false
}
token := strings.TrimSpace(header[len(prefix):])
return token, token != ""
}
func WriteUnauthorized(w http.ResponseWriter, challenge, requestID string) {
w.Header().Set("WWW-Authenticate", challenge)
WriteError(
w,
http.StatusUnauthorized,
dto.ErrorCodeUnauthorized,
"unauthorized",
requestID,
)
}