最近,应用商店服务器 API 中添加了一种新的 API查找订单 ID 。以及由 App Store 签名的此 API 响应的JWSTransaction ,采用 JSON Web 签名格式。我们想用 go 来验证一下。
我们尝试过什么
type JWSTransaction struct {
BundleID string `json:"bundleId"`
InAppOwnershipType string `json:"inAppOwnershipType"`
TransactionID string `json:"transactionId"`
ProductID string `json:"productId"`
PurchaseDate int64 `json:"purchaseDate"`
Type string `json:"type"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate"`
}
func (ac *JWSTransaction) Valid() error {
return nil
}
func (a *AppStore) readPrivateKeyFromFile(keyFile string) (*ecdsa.PrivateKey, error) {
bytes, err := ioutil.ReadFile(keyFile)
if err …Run Code Online (Sandbox Code Playgroud) 我已经在这里发布了类似的问题,但我意识到我的问题可能更多地与 x509 证书有关,而不是与 JWS 一般有关。
事情是这样的,我对 JWS 还很陌生,Apple 现在将它们作为服务器到服务器通信的一部分进行传输。我试图了解如何完全保证JWS的有效性,因为据我了解,签名验证仅意味着整个JWS没有被篡改。我不知道如何实际验证此有效负载确实来自受信任的来源(又名Apple)。
这是我到目前为止所得到的(PHP):
//1. explode jws and decode what's needed
$components = explode('.', $jws);
$headerJson = json_decode(base64_decode($components[0]),true);
$signature = base64Url_decode($components[2]);
//2. extract all certificates from 'x5c' header
foreach ($headerJson['x5c'] as $x5c){
$c = '-----BEGIN CERTIFICATE-----'.PHP_EOL;
$c .= chunk_split($x5c,64,PHP_EOL);
$c .= '-----END CERTIFICATE-----'.PHP_EOL;
$certificates[] = openssl_x509_read($c);
}
//3. verify validity of certificate chain (each one is signed by the next, except root cert)
for($i = 0; $i < count($certificates); $i++){ …Run Code Online (Sandbox Code Playgroud) 我正在 Node.JS 中编写后端代码来验证来自 Google SafetyNet API 的 JWS。我很惊讶没有为此找到现成的模块,因此我开始使用可用的库来研究 JWS 的一些简单验证:
首先,谷歌表示需要执行以下步骤:
- 从 JWS 消息中提取 SSL 证书链。
- 验证 SSL 证书链并使用 SSL 主机名匹配来验证叶证书是否已颁发给主机名 attest.android.com。
- 使用证书来验证 JWS 消息的签名。
- 检查 JWS 消息的数据,确保其与原始请求中的数据匹配。特别是,请确保时间戳已经过验证,并且应用程序签名证书的随机数、包名称和哈希值与预期值匹配。
(来自https://developer.android.com/training/safetynet/attestation#verify-attestation-response)
我发现node-jose提供了一个简单的接口来验证JWS,并且它有一个允许嵌入密钥的选项。我试图准确了解此过程的作用以及它是否足以验证 JWS 的真实性?
const {JWS} = require('node-jose');
const result = await JWS.createVerify({allowEmbeddedKey: true}).verify(jws);
if (result.key.kid === 'attest.android.com') {
// Are we good to go or do we manually need to verify the certificate chain further?
}
Run Code Online (Sandbox Code Playgroud)
使用嵌入式密钥是否确实可以x5c使用根 CA 以及针对证书的签名来验证嵌入式证书链?或者我是否需要明确从 Google 获取公钥来单独验证证书?
然后,一个有点相关的问题涉及 Google 用于执行此验证的 API:有一个 …