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

Blazor WASM .NET 5 RC2 and Azure Cosmos DB - System.Security.Cryptography.Algorithms is not supported on this platform #26450

Closed
dotnetspark opened this issue Sep 30, 2020 · 13 comments
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. External This is an issue in a component not contained in this repository. It is open for tracking purposes. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly

Comments

@dotnetspark
Copy link

dotnetspark commented Sep 30, 2020

Bug

I have a vanilla Blazor WASM (standalone) application reading a container from Azure Cosmos DB. Before upgrading to .NET 5 RC1 it was working fine. This is the same application I had issues with in #26043. After upgrading packages to RC2 I still get exceptions (see image below) in the Developer Console.

Program.cs

public class Program
{
	public static async Task Main(string[] args)
	{
		var builder = WebAssemblyHostBuilder.CreateDefault(args);
		builder.RootComponents.Add<App>("app");

		builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
		builder.Services.AddHttpClient();
		builder.Services.AddSingleton<CosmosClient>(serviceProvider =>
		{
			IHttpClientFactory httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();

			CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
			{
				HttpClientFactory = httpClientFactory.CreateClient,
				ConnectionMode = ConnectionMode.Gateway
			};

			return new CosmosClient("<endpoint-connectionString>", cosmosClientOptions);
		});

		await builder.Build().RunAsync();
	}
}

Packages

    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rtm.20479.13" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rtm.20479.13" PrivateAssets="all" />
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.13.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0-alpha.1.20420.3" />
    <PackageReference Include="System.Net.Http.Json" Version="6.0.0-alpha.1.20420.3" />

Exceptions

image

@dotnetspark dotnetspark changed the title Blazor WASM .NET 5 RC2 and Azure Cosmos DB - Failed to find a valid digest in the 'integrity' attribute resource...with computed SHA-256 Blazor WASM .NET 5 RC2 and Azure Cosmos DB - System.Security.Cryptography.Algorithms is not supported on this platform Sep 30, 2020
@campersau
Copy link
Contributor

campersau commented Sep 30, 2020

@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Sep 30, 2020
@javiercn
Copy link
Member

@ylr-research thanks for contacting us.

As described by @campersau this is a known limitation in 5.0.

@HaoK
Copy link
Member

HaoK commented Sep 30, 2020

We believe things are better in RC2, @lewing can you confirm?

@HaoK HaoK added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Sep 30, 2020
@ghost ghost added the Status: Resolved label Sep 30, 2020
@HaoK HaoK closed this as completed Sep 30, 2020
@lewing
Copy link
Member

lewing commented Sep 30, 2020

SHA256 hashes are in net5.0 but not HMACSHA256 so this will still fail.

@dotnetspark
Copy link
Author

dotnetspark commented Oct 2, 2020

@HaoK I have installed the RC2 (see image) and the must current packages, and this still fails.
image

    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rtm.20502.9" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rtm.20502.9" PrivateAssets="all" />
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.13.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0-alpha.1.20420.3" />
    <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.0-rtm.20502.9" />
    <PackageReference Include="System.Net.Http.Json" Version="6.0.0-alpha.1.20420.3" />

@lewing, in my code I don't specify which encryption method should be use. Thus, I'd say is defaulted in the AzureCosmos SDK.

@dotnetspark
Copy link
Author

dotnetspark commented Oct 2, 2020

as a matter of fact, here it is where AzureCosmos SDK is defaulting the encryption method.
image

        public GatewayAccountReader(Uri serviceEndpoint,
                IComputeHash stringHMACSHA256Helper,
                bool hasResourceToken,
                string resourceToken,
                ConnectionPolicy connectionPolicy,
                CosmosHttpClient httpClient)
        {
            this.httpClient = httpClient;
            this.serviceEndpoint = serviceEndpoint;
            this.authKeyHashFunction = stringHMACSHA256Helper;
            this.hasAuthKeyResourceToken = hasResourceToken;
            this.authKeyResourceToken = resourceToken;
            this.connectionPolicy = connectionPolicy;
        }

@ealsur do I have a way to set the encryption method?

@ealsur
Copy link

ealsur commented Oct 2, 2020

The code uses byte[] hashPayLoad = stringHMACSHA256Helper.ComputeHash(payload.Buffer); which seems to have this implementation: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Authorization/SecureStringHMACSHA256Helper.cs#L20

Currently I don't see anything in the public contract of the SDK to inject your implementation, I'm guessing that the hash is part of the contract of the service, right @j82w?

@lewing
Copy link
Member

lewing commented Oct 2, 2020

@ealsur I suspect the correct link is https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Authorization/StringHMACSHA256Hash.cs

@j82w
Copy link

j82w commented Oct 3, 2020

@lewing SecureString isn't recommended for new development.

@lewing
Copy link
Member

lewing commented Oct 3, 2020

right, I was just trying to point out the correct file. I've edited the comment for clarity.

@mkArtakMSFT mkArtakMSFT removed ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved labels Oct 8, 2020
@mkArtakMSFT mkArtakMSFT reopened this Oct 8, 2020
@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Oct 8, 2020

Folks are claiming above that this wasn't resolved in RC2. @lewing can you please share a summary of what's the current state of this? Is there pending work here?

@lewing
Copy link
Member

lewing commented Oct 8, 2020

This will not be fixed in .NET 5.0 see the discussion here Azure/azure-cosmos-dotnet-v3#1865 (comment)

We plan to fix this in .NET 6.0

@mkArtakMSFT
Copy link
Member

Thanks @lewing.
Closing this as there is nothing we can do here. @ylr-research please use the referenced issue to track progress.

@mkArtakMSFT mkArtakMSFT added External This is an issue in a component not contained in this repository. It is open for tracking purposes. bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Oct 9, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Nov 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. External This is an issue in a component not contained in this repository. It is open for tracking purposes. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

No branches or pull requests

8 participants