fix authentication when algorithm field is not supported (#558)

(https://github.com/bluenviron/mediamtx/issues/3116)

This fixes authentication issues with some TP-LINK cameras.
This commit is contained in:
Alessandro Ros
2024-05-15 10:21:30 +02:00
committed by GitHub
parent 9f6428bdb8
commit f283abc2e7
11 changed files with 373 additions and 209 deletions

View File

@@ -6,18 +6,44 @@ import (
)
// GenerateWWWAuthenticate generates a WWW-Authenticate header.
func GenerateWWWAuthenticate(methods []headers.AuthMethod, realm string, nonce string) base.HeaderValue {
func GenerateWWWAuthenticate(methods []ValidateMethod, realm string, nonce string) base.HeaderValue {
if methods == nil {
methods = []headers.AuthMethod{headers.AuthDigestSHA256, headers.AuthDigestMD5, headers.AuthBasic}
methods = []ValidateMethod{ValidateMethodBasic, ValidateMethodDigestMD5, ValidateMethodSHA256}
}
var ret base.HeaderValue
for _, m := range methods {
ret = append(ret, headers.Authenticate{
Method: m,
Realm: realm,
Nonce: nonce, // used only by digest
}.Marshal()...)
var a base.HeaderValue
switch m {
case ValidateMethodBasic:
a = headers.Authenticate{
Method: headers.AuthMethodBasic,
Realm: realm,
}.Marshal()
case ValidateMethodDigestMD5:
aa := headers.AuthAlgorithmMD5
a = headers.Authenticate{
Method: headers.AuthMethodDigest,
Realm: realm,
Nonce: nonce,
Algorithm: &aa,
}.Marshal()
default: // sha256
aa := headers.AuthAlgorithmSHA256
a = headers.Authenticate{
Method: headers.AuthMethodDigest,
Realm: realm,
Nonce: nonce,
Algorithm: &aa,
}.Marshal()
}
ret = append(ret, a...)
}
return ret
}