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

SignatureDoesNotMatch when CultureInfo is thai #1026

Open
KeNJiKunG opened this issue Mar 1, 2024 · 1 comment
Open

SignatureDoesNotMatch when CultureInfo is thai #1026

KeNJiKunG opened this issue Mar 1, 2024 · 1 comment

Comments

@KeNJiKunG
Copy link

The requests always return SignatureDoesNotMatch when CultureInfo.CurrentCulture is 'th-TH' but works when CultureInfo.CurrentCulture is 'en-GB'.

I found these codes will generated Authorization token with non-gregorian year which is incorrect.

private string GetScope(string region, DateTime signingDate, bool isSts = false)
{
return $"{signingDate:yyyyMMdd}/{region}/{GetService(isSts)}/aws4_request";
}

private string GetStringToSign(string region, DateTime signingDate,
string canonicalRequestHash, bool isSts = false)
{
var scope = GetScope(region, signingDate, isSts);
return $"AWS4-HMAC-SHA256\n{signingDate:yyyyMMddTHHmmssZ}\n{scope}\n{canonicalRequestHash}";
}

Here is my reproducible code.

using System.Globalization;
using Minio;

public class Program
{
    public static async Task Main(string[] args)
    {
        CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("th-TH");
        // CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");

        var http = new HttpClient(new MyHttpClientHandler());

        var endpoint = "play.min.io";
        var accessKey = "USERNAME"; // <--- Replace with a valid access key.
        var secretKey = "PASSWORD"; // <--- Replace with a valid secret key.

        var factory = new MinioClientFactory(config =>
        {
            config.WithEndpoint(endpoint)
                    .WithCredentials(accessKey, secretKey)
                    .WithHttpClient(http, true)
                    .WithSSL();

            // config.SetTraceOn(new ReqeustLogger());
        });

        var client = factory.CreateClient().Build();

        // client.SetTraceOn(new ReqeustLogger());

        var isExists = await client.BucketExistsAsync(new Minio.DataModel.Args.BucketExistsArgs()
            .WithBucket("my-every-not-existing-random-bucket-2")
        );

        Console.WriteLine(isExists);

        var download = await client.GetObjectAsync(new Minio.DataModel.Args.GetObjectArgs()
            .WithBucket("my-every-not-existing-random-bucket-2")
            .WithObject("Not exists")
            .WithCallbackStream((stream) => { })
        );

        Console.WriteLine(download);
    }
}

public class MyHttpClientHandler : HttpClientHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var respons = await base.SendAsync(request, cancellationToken);

        Console.WriteLine( request.Headers );

        Console.WriteLine(respons.Headers);

        return respons;
    }
}
@asdword
Copy link

asdword commented May 14, 2024

I also have the same problem. add this code before executing any minio actions for reset current culture

CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

worked for me.

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

No branches or pull requests

2 participants