From 16b0cee0b6b46ada0b7f8eb811d18442757f6b56 Mon Sep 17 00:00:00 2001 From: claincly Date: Thu, 21 Apr 2022 16:37:15 +0100 Subject: [PATCH] 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 --- RELEASENOTES.md | 2 ++ .../rtsp/RtspAuthenticationInfo.java | 27 ++++++++++++++----- .../rtsp/RtspAuthenticationInfoTest.java | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index ba1f7962de..62b4913a68 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -65,6 +65,8 @@ ([#47](https://github.com/androidx/media/pull/47)). * Add RTP reader for WAV ([#56](https://github.com/androidx/media/pull/56)). + * Fix RTSP basic authorization header. + ([#9544](https://github.com/google/ExoPlayer/issues/9544)). * Session: * Fix NPE in MediaControllerImplLegacy ([#59](https://github.com/androidx/media/pull/59)) diff --git a/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfo.java b/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfo.java index 0ecdbc9fe4..d6e8a7db58 100644 --- a/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfo.java +++ b/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfo.java @@ -47,9 +47,14 @@ import java.security.NoSuchAlgorithmException; /** HTTP digest authentication (RFC2069). */ 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\""; - 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\"," + " opaque=\"%s\""; @@ -109,9 +114,11 @@ import java.security.NoSuchAlgorithmException; } private String getBasicAuthorizationHeaderValue(RtspAuthUserInfo authUserInfo) { - return Base64.encodeToString( - RtspMessageUtil.getStringBytes(authUserInfo.username + ":" + authUserInfo.password), - Base64.DEFAULT); + return Util.formatInvariant( + BASIC_AUTHORIZATION_HEADER_FORMAT, + Base64.encodeToString( + RtspMessageUtil.getStringBytes(authUserInfo.username + ":" + authUserInfo.password), + Base64.DEFAULT)); } private String getDigestAuthorizationHeaderValue( @@ -139,10 +146,16 @@ import java.security.NoSuchAlgorithmException; if (opaque.isEmpty()) { return Util.formatInvariant( - DIGEST_FORMAT, authUserInfo.username, realm, nonce, uri, response); + DIGEST_AUTHORIZATION_HEADER_FORMAT, authUserInfo.username, realm, nonce, uri, response); } else { 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) { throw ParserException.createForManifestWithUnsupportedFeature(/* message= */ null, e); diff --git a/libraries/exoplayer_rtsp/src/test/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfoTest.java b/libraries/exoplayer_rtsp/src/test/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfoTest.java index f7abd0f8c8..a6c910916b 100644 --- a/libraries/exoplayer_rtsp/src/test/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfoTest.java +++ b/libraries/exoplayer_rtsp/src/test/java/androidx/media3/exoplayer/rtsp/RtspAuthenticationInfoTest.java @@ -33,7 +33,7 @@ public class RtspAuthenticationInfoTest { String authenticationRealm = "WallyWorld"; String username = "Aladdin"; String password = "open sesame"; - String expectedAuthorizationHeaderValue = "QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n"; + String expectedAuthorizationHeaderValue = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n"; RtspAuthenticationInfo authenticator = new RtspAuthenticationInfo( RtspAuthenticationInfo.BASIC, authenticationRealm, /* nonce= */ "", /* opaque= */ "");