- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我们的 friend 在将私有(private)证书加载到 httpHandler 时遇到问题。
我们正在使用 .net 核心,需要在云中托管所有应用程序。
主要目标是从 SQS 获取消息并在使用数据后执行一些指定的 API 拍摄。
我们的公钥/私钥证书有问题。我们已经尝试了所有可能的加载方式。
public async Task<HttpResponseMessage> VisitHttps()
{
// Proceed for an invalid cerficate
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
// Add the certificate
var handler = new HttpClientHandler();
var cert = GetMyCert();
if (cert != null)
{
handler.ClientCertificates.Add(cert);
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
//handler.PreAuthenticate = true;
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
HttpClient cclient = new HttpClient(handler)
{
//BaseAddress = new Uri("https://someurl.com")
};
cclient.DefaultRequestHeaders.Accept.Clear();
cclient.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
return await cclient.GetAsync("https://some-url.com/ping"); }
GetMyCert() 方法如下所示:
string currentLocation = $"{AppDomain.CurrentDomain.BaseDirectory}key-public.crt";
//var xcert = new X509Certificate2(currentLocation, "password");
////var currentLocationPriv = $"{AppDomain.CurrentDomain.BaseDirectory}key-private.crt";
////var privcert = new X509Certificate2(currentLocationPriv, "password", X509KeyStorageFlags.EphemeralKeySet);
//var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
//certStore.Open(OpenFlags.ReadWrite);
//certStore.Add(xcert);
//certStore.Close();
//return xcert;
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
X509Certificate2 cert;
cert = new X509Certificate2(File.ReadAllBytes(currentLocation), "password", X509KeyStorageFlags.MachineKeySet);
bool result = cert.Verify();
var r2 = result;
return cert;
注释行是我们尝试做的变化。
我们不知道我们还应该尝试什么来处理这个问题。
任何指南都将非常受欢迎
编辑:
我试过在启动类中注册这个,但它似乎不管用。我总是让证书中的私钥字段为空。并将 hasPrivateKey 标记为 false。
private void CreateCert(IServiceCollection services)
{
string currentLocation = $"{AppDomain.CurrentDomain.BaseDirectory}key-public.crt";
var certificate = new X509Certificate2(currentLocation, "password");
services.AddHttpClient("TestClient", client =>
{
client.BaseAddress = new Uri("https://someurl.com");
})
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(certificate);
return handler;
});
}
我的测试代码:
[Fact]
public async Task ShouldPong()
{
var testClient = new TestClient()
{
BaseAddress = new Uri("https://someurl.com")
};
var result = await testClient.GetAsync("/ping");
result.StatusCode.Should().Be(HttpStatusCode.OK);
}
测试客户端:
public class TestClient : HttpClient
{
public TestClient()
:base()
{
}
public TestClient(HttpMessageHandler handler)
: base(handler)
{
}
}
编辑:
将 .crt 文件更改为 .pfx 文件时问题已解决。由于我们访问的 API 托管在 nginx 上。
最佳答案
问题已通过创建 .PFX 文件得到解决。我们访问的服务器托管在需要 .pfx 格式的 nginx 上。 .crt 文件是对 nginx 无效的 PEM 证书。
关于C#、.Net Core 私钥认证httpClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56480160/
如何选择随机哈希键?对于 my Flash+Perl card game我正在尝试从哈希中随机选择一张卡片,其中的键是:“6 黑桃”、“6 俱乐部”等,如下所示: my $card; my $i =
每当我收到对端点的请求时,我都会使用openssl crate 生成随 secret 钥。我将使用新生成的 key 来加密请求数据,并将其作为响应发送回去。 use openssl::rsa::{Rs
我们知道,我们在代码中生成的“随机”数实际上是伪随机数。在Java的情况下,它们默认使用时间戳作为随机种子,并且从该点开始确定性地创建时间戳之后产生的每个随机数。 如果您使用随机数生成密码,并且恶意方
我想用java生成一个128位随 secret 钥。我正在使用以下内容: byte[] byteBucket = new byte[bytelength]; randomizer.nextBytes(
这个问题已经有答案了: Pick random property from a Javascript object (9 个回答) 已关闭 7 个月前。 如果我有以下内容: var liststuff
我做了一些研究,找不到我需要的东西,基本上我想生成一个具有以下格式的随 secret 钥 XXX-XXX-XXXX 最佳答案 这是一个快速的 Javascript 解决方案: let r = Math
在 Firebase 中,可以使用 .childByAutoId() 创建随 secret 钥 let newEntry = FBRef.child("category").childByAutoId
假设我有一个带有大量键的对象: const myObject = { "a": 1, "b": 2, "c": 3, ... } 如果我存储了一个单独的 key 列表,
我需要计算一些字符串的签名,并计划这样做: using (HMACSHA256 hmacSha256 = new HMACSHA256( )) { Byte[] dataToHmac
我的任务是生成随机的 80 字节 key ,我决定遵循以下策略 在我的电脑中sizeof(char)=1 所以我创建了一个英文字母数组 char *p=" "; char a[0..26] and i
我正在设计一个广告系统,该系统根据广告的权重(出价)在广告之间随机轮换。 local ads = local ads = { ["a"] = { views = 0,
我有一个整数列表(员工 ID)它们都是8位长(虽然几乎都是00开头,但实际上都是8位长) 我需要为每个员工生成一个 key : - 5 chars including [A-Z][a-z][0-9]
我使用 KeyPairGenerator 生成 RSA key 对,我注意到它始终生成完全匹配的 key ,而不是应有的随 secret 钥?也许有人知道为什么会这样? 我的代码现在看起来像这样: p
我正在运行一个 FIRESTORE 数据库,我想创建一个具有与 firestore 相同的模式 的随 secret 钥。 在链接中,我找到了创建文档后调用的函数with: 'db.ref.add()'
这个问题已经有答案了: Add a property to a JavaScript object using a variable as the name? (14 个回答) Creating ob
我想生成 1M 随机(出现)唯一字母数字键并将它们存储在数据库中。每个 key 的长度为 8 个字符,并且仅使用子集“abcdefghijk n pqrstuvxyz 和 0-9”。 字母 l、m、o
我想生成像“7HzdUakp”这样的唯一 key 。 我想将其放入数据库(mysql)中,但我想要几乎无限的组合。 我可以使用随机函数生成它,但有时它可以生成相同的 key 两次 已解决 - 我根据“
我有一个我似乎无法弄清楚的基本问题。我正在尝试在 AES-256-CBC 中生成一个可用于加密/解密数据的随 secret 钥。 这是我正在做的: require 'openssl' cipher =
如果您对 Azure 网站使用自动缩放,是否需要设置计算 secret 钥,以便可以在计算机之间共享加密的身份验证 token ? 这里有一个问题,似乎be the same正如我所问的那样。然而,这
我想根据创建日期和时间从 Firebase 中检索数据我还没有找到任何其他方法,而不是通过使用 orderByChild("Create") 创建每个用户的 child 来保存创建日期和时间排序,但是
我是一名优秀的程序员,十分优秀!