Commit 084dfc04 by claincly Committed by Ian Baker

Fix Basic authentication header

Issue: google/ExoPlayer#9544

The header must include the word "Basic", but the word is missing.

#minor-release

PiperOrigin-RevId: 443386880
parent 3867f8e0
...@@ -45,9 +45,14 @@ import java.security.NoSuchAlgorithmException; ...@@ -45,9 +45,14 @@ import java.security.NoSuchAlgorithmException;
/** HTTP digest authentication (RFC2069). */ /** HTTP digest authentication (RFC2069). */
public static final int DIGEST = 2; public static final int DIGEST = 2;
private static final String DIGEST_FORMAT = /** Basic authorization header format, see RFC7617. */
private static final String BASIC_AUTHORIZATION_HEADER_FORMAT = "Basic %s";
/** Digest authorization header format, see RFC7616. */
private static final String DIGEST_AUTHORIZATION_HEADER_FORMAT =
"Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\""; "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\"";
private static final String DIGEST_FORMAT_WITH_OPAQUE =
private static final String DIGEST_AUTHORIZATION_HEADER_FORMAT_WITH_OPAQUE =
"Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\"," "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\","
+ " opaque=\"%s\""; + " opaque=\"%s\"";
...@@ -107,9 +112,11 @@ import java.security.NoSuchAlgorithmException; ...@@ -107,9 +112,11 @@ import java.security.NoSuchAlgorithmException;
} }
private String getBasicAuthorizationHeaderValue(RtspAuthUserInfo authUserInfo) { private String getBasicAuthorizationHeaderValue(RtspAuthUserInfo authUserInfo) {
return Base64.encodeToString( return Util.formatInvariant(
RtspMessageUtil.getStringBytes(authUserInfo.username + ":" + authUserInfo.password), BASIC_AUTHORIZATION_HEADER_FORMAT,
Base64.DEFAULT); Base64.encodeToString(
RtspMessageUtil.getStringBytes(authUserInfo.username + ":" + authUserInfo.password),
Base64.DEFAULT));
} }
private String getDigestAuthorizationHeaderValue( private String getDigestAuthorizationHeaderValue(
...@@ -137,10 +144,16 @@ import java.security.NoSuchAlgorithmException; ...@@ -137,10 +144,16 @@ import java.security.NoSuchAlgorithmException;
if (opaque.isEmpty()) { if (opaque.isEmpty()) {
return Util.formatInvariant( return Util.formatInvariant(
DIGEST_FORMAT, authUserInfo.username, realm, nonce, uri, response); DIGEST_AUTHORIZATION_HEADER_FORMAT, authUserInfo.username, realm, nonce, uri, response);
} else { } else {
return Util.formatInvariant( return Util.formatInvariant(
DIGEST_FORMAT_WITH_OPAQUE, authUserInfo.username, realm, nonce, uri, response, opaque); DIGEST_AUTHORIZATION_HEADER_FORMAT_WITH_OPAQUE,
authUserInfo.username,
realm,
nonce,
uri,
response,
opaque);
} }
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw ParserException.createForManifestWithUnsupportedFeature(/* message= */ null, e); throw ParserException.createForManifestWithUnsupportedFeature(/* message= */ null, e);
......
...@@ -33,7 +33,7 @@ public class RtspAuthenticationInfoTest { ...@@ -33,7 +33,7 @@ public class RtspAuthenticationInfoTest {
String authenticationRealm = "WallyWorld"; String authenticationRealm = "WallyWorld";
String username = "Aladdin"; String username = "Aladdin";
String password = "open sesame"; String password = "open sesame";
String expectedAuthorizationHeaderValue = "QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n"; String expectedAuthorizationHeaderValue = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n";
RtspAuthenticationInfo authenticator = RtspAuthenticationInfo authenticator =
new RtspAuthenticationInfo( new RtspAuthenticationInfo(
RtspAuthenticationInfo.BASIC, authenticationRealm, /* nonce= */ "", /* opaque= */ ""); RtspAuthenticationInfo.BASIC, authenticationRealm, /* nonce= */ "", /* opaque= */ "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment