-
Notifications
You must be signed in to change notification settings - Fork 46
Updating handling of ssl error received in Android WebView's onReceivedSslError callback, Fixes AB#3268908 #2691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0df648
f5fc124
7bcaedd
fb6a49e
a13fc59
86919d0
9451180
4dbb633
6521932
46424d9
e0d3ddb
f31093d
a3c99eb
402548b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| // THE SOFTWARE. | ||
| package com.microsoft.identity.common.internal.ui.webview; | ||
|
|
||
| import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Browser.SSL_HELP_URL; | ||
|
|
||
| import android.app.Activity; | ||
| import android.graphics.Bitmap; | ||
| import android.net.Uri; | ||
|
|
@@ -41,23 +43,33 @@ | |
|
|
||
| import com.microsoft.identity.common.adal.internal.AuthenticationConstants; | ||
| import com.microsoft.identity.common.internal.ui.webview.challengehandlers.ChallengeFactory; | ||
| import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback; | ||
| import com.microsoft.identity.common.internal.ui.webview.challengehandlers.IChallengeHandler; | ||
| import com.microsoft.identity.common.internal.ui.webview.challengehandlers.NtlmChallenge; | ||
| import com.microsoft.identity.common.internal.ui.webview.challengehandlers.NtlmChallengeHandler; | ||
| import com.microsoft.identity.common.internal.util.StringUtil; | ||
| import com.microsoft.identity.common.java.exception.ClientException; | ||
| import com.microsoft.identity.common.java.flighting.CommonFlight; | ||
| import com.microsoft.identity.common.java.flighting.CommonFlightsManager; | ||
| import com.microsoft.identity.common.java.logging.DiagnosticContext; | ||
| import com.microsoft.identity.common.java.opentelemetry.AttributeName; | ||
| import com.microsoft.identity.common.java.opentelemetry.OTelUtility; | ||
| import com.microsoft.identity.common.java.providers.RawAuthorizationResult; | ||
| import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback; | ||
| import com.microsoft.identity.common.logging.Logger; | ||
|
|
||
| import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Browser.SSL_HELP_URL; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.LongCounter; | ||
|
|
||
| public abstract class OAuth2WebViewClient extends WebViewClient { | ||
| /* constants */ | ||
| private static final String TAG = OAuth2WebViewClient.class.getSimpleName(); | ||
|
|
||
| private static final LongCounter sWebViewSslErrorCount = OTelUtility.createLongCounter( | ||
| "web_view_ssl_error_count", | ||
| "Number of SSL errors received in onReceivedSslError" | ||
| ); | ||
|
|
||
| private final IAuthorizationCompletionCallback mCompletionCallback; | ||
| private final OnPageLoadedCallback mPageLoadedCallback; | ||
| private final Activity mActivity; | ||
|
|
@@ -89,12 +101,13 @@ IAuthorizationCompletionCallback getCompletionCallback() { | |
| */ | ||
| OAuth2WebViewClient(@NonNull final Activity activity, | ||
| @NonNull final IAuthorizationCompletionCallback completionCallback, | ||
| @NonNull final OnPageLoadedCallback pageLoadedCallback) { | ||
| //the validation of redirect url and authorization request should be in upper level before launching the webview. | ||
| @NonNull final OnPageLoadedCallback pageLoadedCallback | ||
| ) { | ||
| // the validation of redirect url and authorization request should be in upper level before launching the webview. | ||
| mActivity = activity; | ||
| mCompletionCallback = completionCallback; | ||
| mPageLoadedCallback = pageLoadedCallback; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler, | ||
|
|
@@ -171,17 +184,21 @@ public void onReceivedSslError(final WebView view, | |
| final SslErrorHandler handler, | ||
| final SslError error) { | ||
| // Developer does not have option to control this for now | ||
| final String methodTag = TAG + ":onReceivedSslError"; | ||
| super.onReceivedSslError(view, handler, error); | ||
| handler.cancel(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add broker telemetry to track if SSL error was seen in web view flow. For OneAuth, this needs different wiring which I don't see we currently have. So, that would be separate change. As we discussed, I will first rollout this for broker and keep disabled for OneAuth and MSAL Android. Once we have seen that there's no change in issues in broker. We will expand change to OneAuth. Meanwhile, I can work with OneAuth how can we track this in OneAuth telemetry. This may be non-trivial work. |
||
|
|
||
| final String errMsg = "Received SSL Error during request. For more info see: " + SSL_HELP_URL; | ||
|
|
||
| Logger.error(TAG + ":onReceivedSslError", errMsg, null); | ||
|
|
||
| // Send the result back to the calling activity | ||
| mCompletionCallback.onChallengeResponseReceived( | ||
| RawAuthorizationResult.fromException( | ||
| new ClientException("Code:" + ERROR_FAILED_SSL_HANDSHAKE, error.toString()))); | ||
| final String errMsg = "Received SSL Error during request. For more info see: " + SSL_HELP_URL + ". Error: " + error.toString(); | ||
|
|
||
| Logger.warn(methodTag, errMsg); | ||
| final Attributes attributes = Attributes.builder() | ||
| .put(AttributeName.web_view_ssl_primary_error_code.name(), error.getPrimaryError()) | ||
| .build(); | ||
| sWebViewSslErrorCount.add(1, attributes); | ||
| if (!CommonFlightsManager.INSTANCE.getFlightsProvider().isFlightEnabled(CommonFlight.SHOULD_PRESERVE_WEBVIEW_FLOW_ON_SSL_ERROR)) { | ||
| // Send the result back to the calling activity | ||
| mCompletionCallback.onChallengeResponseReceived( | ||
| RawAuthorizationResult.fromException( | ||
| new ClientException("Code:" + ERROR_FAILED_SSL_HANDSHAKE, error.toString()))); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see 'cancel' being called anymore in the flight-off scenario. But it seems like tests are validating that it is. Is the job getting done
supermethod invocation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, super calls it hence removed.