Skip to content
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

Pop updated #2105

Merged
merged 20 commits into from
Nov 4, 2020
Merged

Pop updated #2105

merged 20 commits into from
Nov 4, 2020

Conversation

trwalke
Copy link
Member

@trwalke trwalke commented Oct 15, 2020

Updates for #2013

Exposing ICrypto provider to allow users to pass in their own
adding pop config object
refactoring iCryptoProvider
Adding config object to pop api
refactoring
/// <item>MSAL creates, reads and stores a key in memory that will be cycled every 8 hours.</item>
/// </list>
/// </remarks>
public T WithProofOfPosession(PopAuthenticationConfiguration popAuthenticationConfiguration)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be the only POP method. Let's delete the old one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a breaking change?
would we do that because it's an experimental feature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, experimental features can introduce breaking changes at any time.

/// <summary>
/// This will be populated with the POP authentication header.
/// </summary>
public AuthenticationHeaderValue PopAuthenticationRequestHeader {get; private set;}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this is. If you're not sure either, delete it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to populate the user provided HTTP Request headers with the authentication headers calculated form the key. Im assuming this is no longer needed?

This value was already being used for tests.

Copy link
Member

@bgavrilMS bgavrilMS Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really make that much sense since this is a config option, but developers cannot set this property.

The way consumers are supposed to retrieve the pop token is via AuthenticationResult. We can provide more covenient mechasism upon demand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 var r2 = await confidentialApp.AcquireTokenForClient(s_keyvaultScope)
              .WithProofOfPosession(popConfig)
              .ExecuteAsync(CancellationToken.None)
              .ConfigureAwait(false);

image

/// A provider that can handle the asymmetric key operations needed by POP, that encapsulates a pair of public and private keys
/// and some typical crypto operations
/// </summary>
public IPoPCryptoProvider PopCryptoProvider { get; set; }
Copy link
Member

@bgavrilMS bgavrilMS Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should actually put this crypto provider at the Application level instead of the Request level ? This way we can cache things like Thumbprint.

I suggest that for now we go with this and we discuss this in the API Review.

With the current implementation, we have to compute the thumbprint of the JWK at every request. If we moved the PoPAuthenticationScheme at app level, we'd compute it less often...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bgavrilMS: Could there be that there is a need for a PopAuthenticationScheme per resource? or per endpoint?

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, see inline comments.

@@ -19,9 +20,7 @@ namespace Microsoft.Identity.Client.AuthScheme.PoP
internal class PoPAuthenticationScheme : IAuthenticationScheme
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: some places it' has PoP and some have Pop. maybe go with Pop?

/// <item>MSAL creates, reads and stores a key in memory that will be cycled every 8 hours.</item>
/// </list>
/// </remarks>
public T WithProofOfPosession(PopAuthenticationConfiguration popAuthenticationConfiguration)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a breaking change?
would we do that because it's an experimental feature?

@@ -822,6 +822,11 @@ public static class MsalError
/// </summary>
public const string CryptoNet45 = "crypto_net45";

/// <summary>
/// Proof of posession authentication attempt is missing a an endpoint to bing to.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Proof of posession authentication attempt is missing a an endpoint to bing to.
/// Proof of posession authentication attempt is missing an endpoint to bind to.

@@ -11,6 +11,7 @@ internal class JsonWebTokenConstants
internal class Algorithms
{
public const string RsaSha256 = "RS256";
public const string EdcSha256 = "ES256";
Copy link
Member Author

@trwalke trwalke Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I was referring to. Elliptic curve can be ES256/ES384/ES512 etc. This value will need to be updated based on the conical JWK created by the elliptic curve keys.

@bgavrilMS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//Need to update header to signal EC key is being used
if (JWK[JsonWebKeyParameterNames.Kty].ToString() == JsonWebKeyParameterNames.EC)
{
return JsonWebTokenConstants.Algorithms.EdcSha256;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add support for other elliptic curve key sizes here. currently only 256 is supported.
@bgavrilMS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few comments and suggestions

/// A provider that can handle the asymmetric key operations needed by POP, that encapsulates a pair of public and private keys
/// and some typical crypto operations
/// </summary>
public IPoPCryptoProvider PopCryptoProvider { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bgavrilMS: Could there be that there is a need for a PopAuthenticationScheme per resource? or per endpoint?

/// See https://docs.microsoft.com/en-us/azure/key-vault/keys/about-keys#signverify for ECD
/// See https://docs.microsoft.com/en-us/azure/key-vault/keys/about-keys#signverify-1 for RSA
/// </summary>
string CryptographicAlgorithm { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are symmetric key algorithm supported? if not, do we want to mention it?

@@ -11,6 +11,7 @@ internal class JsonWebTokenConstants
internal class Algorithms
{
public const string RsaSha256 = "RS256";
public const string EdcSha256 = "ES256";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove popConfig.PopAuthenticationRequestHeader and rely on AuthenticationResult instead. Otherwise LGTM!

trwalke and others added 12 commits October 22, 2020 08:17
# Conflicts:
#	tests/Microsoft.Identity.Test.Common/Core/Helpers/ECDCertificatePopCryptoProvider.cs
#	tests/Microsoft.Identity.Test.Common/Core/Helpers/RSACertificatePopCryptoProvider.cs
#	tests/Microsoft.Identity.Test.Integration/Microsoft.Identity.Test.Integration.csproj
#	tests/Microsoft.Identity.Test.Unit/ExceptionTests/ExperimentalFeatureTests.cs
Refactoring
…onConfiguration.cs

Co-authored-by: Jean-Marc Prieur <jmprieur@microsoft.com>
@trwalke trwalke merged commit c085471 into master Nov 4, 2020
@trwalke trwalke deleted the trwalke/PopPart2 branch June 22, 2021 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants