gpt4 book ai didi

ios - 沙盒苹果支付测试握手失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:33:20 24 4
gpt4 key购买 nike

我在 Apple Pay 沙箱环境中验证商家时遇到问题。取自https://developer.apple.com/reference/applepayjs/applepaysession#2166532 ,一旦我的服务器调用提供的 URL 上的 Start Session 端点,我就会收到 500 错误。

我查了一下,这个 500 错误发生在网络层的某个地方。正如苹果页面 ( https://developer.apple.com/reference/applepayjs/ ) 所列,我需要满足以下要求:

  1. 所有包含 Apple Pay 的页面都必须通过 HTTPS 提供。 完成,服务器有 ssl/https 全站
  2. 要启用商家验证,您的服务器必须允许通过 HTTPS(端口 443 上的 TCP)访问下面 list 1 中提供的 Apple Pay IP 地址。 完成,服务器对端口 443 上的所有 ips 开放
  3. 您的服务器必须支持传输层安全 (TLS) 1.2 协议(protocol)和表 1 中列出的密码套件之一。服务器确实支持 tls 1.2,因为我将 tls 1.2 上的请求发送到 apple pay 的开发服务器(如下)

我一直在使用 Wireshark 检查发生了什么,一旦服务器进入 ChangeCipherSpec 阶段,服务器将密码规范发送回客户端后,我似乎就失败了。 (ssl 程序引用:https://support.f5.com/csp/article/K15292)。正如您从我的图像中看到的那样,我正在与 apple pay 沙箱服务器通信,传递错误提示的相同受支持的 tls 协议(protocol)和密码套件 -> Handshake Failure (40),所以其他事情正在发生,我不知道去哪里看

enter image description here

如果您查看 ServerHello 消息,您可以看到服务器找到并接受了与客户端匹配的密码套件,这也与 apple pay 支持的所需密码之一匹配 enter image description here

enter image description here

我可以根据需要添加其他详细信息

最佳答案

问题是我们的服务器没有默认启用 TLS 1.2。启用 TLS 1.2 并禁用 TLS 1.0 解决了这个问题 - Win 2008

编辑

有一些事情需要发生。我们的服务器在 .net 4.5 上,默认情况下不使用 tls 1.2(苹果要求使用 tls 1.2)。因此,我们将解决方案升级到 .net 4.6,并针对我们的请求强制使用 tls 1.2。此外,我们必须在我们向苹果提出的请求中包含商家 ID 证书(文档中没有很好地提及)。

您可以在此处找到我使用的源代码的 github 存储库 ( https://github.com/justeat/ApplePayJSSample ),但这是我需要放入我的解决方案以使其正常工作的代码(我还必须从我的 mac 上导出我的商家证书给了我一个 .p12 文件的钥匙串(keychain)。我将这个 .p12 文件导入到我服务器的计算机证书库中)

[System.Web.Http.HttpPost]
public async Task<ContentResult> GetApplePaySession([FromBody] string url)
{
// http://stackoverflow.com/a/36912392/1837080
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

// Load the merchant certificate for two-way TLS authentication with the Apple Pay server.
var certificate = LoadMerchantCertificate();

// Get the merchant identifier from the certificate to send in the validation payload.
var merchantIdentifier = GetMerchantIdentifier(certificate);

// Create the JSON payload to POST to the Apple Pay merchant validation URL.
var payload = new ApplePayRequest()
{
merchantIdentifier = merchantIdentifier,
domainName = System.Web.HttpContext.Current.Request.Url.Host,
displayName = "[display name from apple developer portal]"
};

JObject merchantSession;

// Create an HTTP client with the merchant certificate
// for two-way TLS authentication over HTTPS.
using (var httpClient = CreateHttpClient(certificate))
{
var jsonPayload = JsonConvert.SerializeObject(payload);

using (var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"))
{
// POST the data to create a valid Apple Pay merchant session.
using (var response = await httpClient.PostAsync(url, content))
{
response.EnsureSuccessStatusCode();

// Read the opaque merchant session JSON from the response body.
var merchantSessionJson = await response.Content.ReadAsStringAsync();
merchantSession = JObject.Parse(merchantSessionJson);
}
}
}

// Return the merchant session as JSON.
return Content(merchantSession.ToString(), "application/json");
}

#region Apple Pay helper methods

private X509Certificate2 LoadMerchantCertificate()
{
X509Certificate2 certificate;

// Load the certificate from the current user's certificate store. This
// is useful if you do not want to publish the merchant certificate with
// your application, but it is also required to be able to use an X.509
// certificate with a private key if the user profile is not available,
// such as when using IIS hosting in an environment such as Microsoft Azure.
using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);

// when using thumbprint from mmc, look at:
// http://stackoverflow.com/a/14852713
// there is a hidden character that you must delete
var certificates = store.Certificates.Find(
X509FindType.FindByThumbprint,
"[thumbprint]",
validOnly: false);

if (certificates.Count < 1)
{
throw new InvalidOperationException(
// ReSharper disable once UseStringInterpolation
string.Format(
"Could not find Apple Pay merchant certificate with thumbprint '{0}' from store '{1}' in location '{2}'.",
"‎[thumpprint]", store.Name, store.Location));
}

certificate = certificates[0];
}

return certificate;
}

private string GetMerchantIdentifier(X509Certificate2 certificate)
{
// This OID returns the ASN.1 encoded merchant identifier
var extension = certificate.Extensions["1.2.840.113635.100.6.32"];

// Convert the raw ASN.1 data to a string containing the ID
return extension == null ? string.Empty : Encoding.ASCII.GetString(extension.RawData).Substring(2);
}

private HttpClient CreateHttpClient(X509Certificate2 certificate)
{
var handler = new WebRequestHandler();
handler.ClientCertificates.Add(certificate);

return new HttpClient(handler, disposeHandler: true);
}

#endregion

关于ios - 沙盒苹果支付测试握手失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43522299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com