Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Fix issue w/iOS13 broker and nonce mismatch (#1667)
Browse files Browse the repository at this point in the history
* update msbuild sdk extras
update ADAL broker error message
update logging for nonce

* add check for v3 broker

* add return ok
  • Loading branch information
jennyf19 authored Oct 9, 2019
1 parent c851168 commit 368c461
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Version 5.2.2
==============
Bug Fixes:
- **Ensures that ADAL.NET works fine with brokers on iOS 13**. On iOS 13, iOS, the broker, may or may not return the source application, which is used by ADAL.NET to verify the response is coming from broker. To maintain secure calls, MSAL.NET will now also create a nonce to send in the broker request and will verify the same nonce is returned in the broker response in the case of a missing source application. [Issue](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1357)
- **Ensures that ADAL.NET works with brokers on iOS 13**. On iOS 13, the iOS broker, may or may not return the source application, which will be used by ADAL.NET to verify that the response is coming from the iOS broker. To maintain secure calls, ADAL.NET will now also create a nonce to send in the broker request and will verify the same nonce is returned in the broker response in the case of a missing source application. [Issue](https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/1642)

Version 5.2.1
==============
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "1.6.61"
"MSBuild.Sdk.Extras": "2.0.41"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static class AdalErrorMessage
public const string RedirectUriContainsFragment = "'redirectUri' must NOT include a fragment component";
public const string ServiceReturnedError = "Service returned error. Check InnerException for more details";
public const string BrokerReponseHashMismatch = "Unencrypted broker response hash did not match the expected hash";
public const string BrokerNonceMismatch = "Broker response nonce does not match the request nonce sent by MSAL.NET." +
public const string BrokerNonceMismatch = "Broker response nonce does not match the request nonce sent by ADAL.NET." +
"Please see https://aka.ms/adal-net-ios-13-broker for more details. ";

public const string StsMetadataRequestFailed =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using Microsoft.Identity.Core.Cache;
using Microsoft.Identity.Core.Helpers;
using Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Broker;
using System.Globalization;

namespace Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform
{
Expand Down Expand Up @@ -131,7 +132,6 @@ public async Task<AdalResultWrapper> AcquireTokenUsingBrokerAsync(IDictionary<st

if (_brokerV3Installed)
{
_brokerRequestNonce = string.Empty;
_brokerRequestNonce = Guid.NewGuid().ToString();
brokerPayload[BrokerParameter.BrokerNonce] = _brokerRequestNonce;
}
Expand Down Expand Up @@ -224,8 +224,8 @@ private AdalResultWrapper ResultFromBrokerResponse(IDictionary<string, string> r
{
response = new TokenResponse
{
Error = AdalError.BrokerReponseHashMismatch,
ErrorDescription = AdalErrorMessage.BrokerReponseHashMismatch
Error = AdalError.BrokerNonceMismatch,
ErrorDescription = AdalErrorMessage.BrokerNonceMismatch
};
}
}
Expand All @@ -237,15 +237,23 @@ private AdalResultWrapper ResultFromBrokerResponse(IDictionary<string, string> r

private bool ValidateBrokerResponseNonceWithRequestNonce(IDictionary<string, string> brokerResponseDictionary)
{
if (!string.IsNullOrEmpty(_brokerRequestNonce))
if (_brokerV3Installed)
{
string brokerResponseNonce = brokerResponseDictionary.ContainsKey(BrokerParameter.BrokerNonce)
? brokerResponseDictionary[BrokerParameter.BrokerNonce]
: null;
string brokerResponseNonce = brokerResponseDictionary[BrokerParameter.BrokerNonce];
bool ok = string.Equals(brokerResponseNonce, _brokerRequestNonce, StringComparison.InvariantCultureIgnoreCase);

return string.Equals(brokerResponseNonce, _brokerRequestNonce);
if (!ok)
{
_logger.Error(
string.Format(
CultureInfo.CurrentCulture,
"Nonce check failed! Broker response nonce is: {0}, \nBroker request nonce is: {1}",
brokerResponseNonce,
_brokerRequestNonce));
}
return ok;
}
return false;
return true;
}

public static void SetBrokerResponse(NSUrl responseUrl)
Expand Down

0 comments on commit 368c461

Please sign in to comment.