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

Cannot use .NET Core AWSSDK with WASM #1895

Open
2 tasks
genifycom opened this issue Aug 6, 2021 · 5 comments
Open
2 tasks

Cannot use .NET Core AWSSDK with WASM #1895

genifycom opened this issue Aug 6, 2021 · 5 comments
Labels
doc-developerguide documentation This is a problem with documentation. feature-request A feature should be added or improved. module/blazor p2 This is a standard priority issue queued

Comments

@genifycom
Copy link

AWS SDK uses HmacSHA256 or HmacSHA1 for signing requests depending on the configuration which are not available in WASM

Microsoft plans to introduce HMACSHA* algorithms in .NET 7.

Describe the Feature

Use an alternative signing method for WASM

Is your Feature Request related to a problem?

It would be extremely useful to have AWSSDK .NET Core functions available from Blazor WebAssembly

Proposed Solution

Offer an alternative signing algorithm

Describe alternatives you've considered

Additional Context

Environment

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@ashishdhingra ashishdhingra transferred this issue from aws/aws-lambda-dotnet Aug 6, 2021
@ashishdhingra ashishdhingra added feature-request A feature should be added or improved. module/blazor module/sdk-core labels Aug 6, 2021
@tmay57
Copy link

tmay57 commented Aug 10, 2021

This issue is broader than just signing requests. Here are a list of the System.Security.Cryptography lib api used in aws-sdk-net that are not currently supported in WASM:
ICryptoTransform
SymmetricAlgorithm
PaddingMode.PKCS7
CipherMode.CBC
Aes
CryptoStream
CryptoStreamMode.Read
KeyedHashAlgorithm
HMACSHA256()
HMACSHA1()
HashAlgorithm
HashAlgorithmName
RSAParameters
RSACryptoServiceProvider
RSAEncryptionPadding.Pkcs1
CipherMode.ECB
AsymmetricProvider
SymmetricProvider
System.Security.Cryptography.X509Certificates
X509Certificate2

To generate this list yourself and explore specific details, follow these steps:

git clone https://github.com/aws/aws-sdk-net.git

Open the aws-sdk-net/sdk/AWSSDK.NetStandard.sln in Visual Studio.
Use “find in files” on the search string “System.Security.Cryptography”. About 20 files are found with references.

Examine each file for references to the Cryptography library. For each file, comment out the using reference and then look at each reference that code analysis indicates has an error. Compare that reference to the list of api currently supported in the WASM version of the Cryptography library. https://docs.microsoft.com/en-us/dotnet/core/compatibility/cryptography/5.0/cryptography-apis-not-supported-on-blazor-webassembly

Any reference not currently supported by the WASM version of the Cryptography library will throw an exception when used in a Blazor client.

Perhaps you guys could have a heart-to-heart with the .NET team about this.

@adamhathcock
Copy link

I'm interested in this too. Looks like the runtime issue is here: dotnet/runtime#40074 looks like it got bumped to .NET 7

Perhaps bouncycastle could be used? The portable version might work: https://github.com/novotnyllc/bc-csharp

I realize changing to anything else is non-trivial.

@github-actions
Copy link

github-actions bot commented Oct 3, 2022

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 3, 2022
@github-actions github-actions bot closed this as completed Oct 5, 2022
@ashovlin
Copy link
Member

Reopening while troubleshooting a scenario from an internal user now that .NET 7 has launched.

Targeting .NET 7 (and configuring CORS for my bucket) I am now able to run the following in a Blazor WebAssembly app.

@page "/s3"

@using Amazon;
@using Amazon.S3;
@using Amazon.S3.Model;

<PageTitle>Load From S3</PageTitle>

<p>Message from S3: @s3Message</p>

<button class="btn btn-primary" @onclick="LoadFromS3">Click me</button>

@code {
    private string s3Message = "";

    private async Task LoadFromS3()
    {
        var credentials = <redacted>;

        var config = new AmazonS3Config
        {
            UseAlternateUserAgentHeader = true,
            RegionEndpoint = Amazon.RegionEndpoint.USEast1
        };

        var client = new AmazonS3Client(credentials, config);

        var request = new GetObjectRequest
        {
            BucketName = "<bucket>",
            Key = "<key>"
        };

        var response = await client.GetObjectAsync(request);
        s3Message = new StreamReader(response.ResponseStream).ReadToEnd();
    }
}

Needing UseAlternateUserAgentHeader is somewhat subtle, we may want to consider improving our documentation and/or more fully testing the SDK in Blazor WebAssembly and .NET 7.

@ashovlin ashovlin reopened this Jan 10, 2023
@ashishdhingra ashishdhingra added the p2 This is a standard priority issue label Mar 16, 2023
@skirk-mpr
Copy link

skirk-mpr commented Oct 29, 2023

@ashovlin -- thanks for sharing/point this work around [this is super exciting given my desire to use the AWS SDK with a Blazor WASM app]!

I was able to reproduce this exactly on my end with updating the CORS policy on my target bucket and retrieving data from an object in a bucket, as well as with ListObjectsV2Async. However, if I try some other S3 operations that are not specific to a bucket (which one can enable CORS on -- e.g. ListBuckets) - I get a CORS error. Is this expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-developerguide documentation This is a problem with documentation. feature-request A feature should be added or improved. module/blazor p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

6 participants