如何使用.NET的Google Client API获取解码的Play Integnity API代币

发布于 2025-01-27 21:30:46 字数 2254 浏览 2 评论 0 原文

我正在尝试使用 Google客户端API库的名称空间.net for .net for .net for decode filestity令牌,如播放完整性API文档

但是,从图书馆文档中尚不清楚如何执行此操作。似乎应该从 deodeDrentegrityTokenResponse 对象返回解码的令牌有效负载,但是我找不到任何返回此类型的方法。

我希望这种类型将从 deodeStegtegrityToken(DecOdeTrentegrityTokenRequest,string)中返回,但此方法实际上返回了另一种 deodeDoDeNtegrityTokenEctegrityTokenRequest ,这根本无济于事。

是否有人成功使用此库来解码令牌?

参考:

String integrityToken = "...token...";

String serviceAccountEmail = "...service account email...";

var certificate = new X509Certificate2("...key.p12...", "...secret...");

ServiceAccountCredential credential = new ServiceAccountCredential(
     new ServiceAccountCredential.Initializer(serviceAccountEmail)
     {
             Scopes = new[] { PlayIntegrityService.Scope.Playintegrity }
     }.FromCertificate(certificate));

// Create the service.
var service = new PlayIntegrityService(new BaseClientService.Initializer()
{
        HttpClientInitializer = credential,
        ApplicationName = "Play Integrity API Sample",
});

DecodeIntegrityTokenRequest request = new     DecodeIntegrityTokenRequest();
request.IntegrityToken = integrityToken;
DecodeIntegrityTokenResponse response = service.V1.DecodeIntegrityToken(request, "...package name...");

错误CS0029无法隐式转换类型'google.apis.playintegrity.v1.v1.v1.decodeintegritytokenrequest'到'google.apis.playintegrity.v1.data.decodeintegritytokenertegritytokenegritytokenertegritytokenertegritytokenertegritytokenertegritytokenegonsponse'

I am trying to use the Google.Apis.PlayIntegrity.v1 namespace of the Google Client API library for .NET to decode an integrity token, as recommended in the Play Integrity API documentation.

However, it is unclear from the library documentation how to do this. It seems that the decoded token payload is supposed to be returned from a DecodeIntegrityTokenResponse object, yet I can't find any method that returns this type.

I would expect that this type would be returned from DecodeIntegrityToken(DecodeIntegrityTokenRequest, String) but this method actually returns another DecodeIntegrityTokenRequest, which doesn't help at all.

Is anyone successfully using this library to decode the token?

References:

Attempted Code:

String integrityToken = "...token...";

String serviceAccountEmail = "...service account email...";

var certificate = new X509Certificate2("...key.p12...", "...secret...");

ServiceAccountCredential credential = new ServiceAccountCredential(
     new ServiceAccountCredential.Initializer(serviceAccountEmail)
     {
             Scopes = new[] { PlayIntegrityService.Scope.Playintegrity }
     }.FromCertificate(certificate));

// Create the service.
var service = new PlayIntegrityService(new BaseClientService.Initializer()
{
        HttpClientInitializer = credential,
        ApplicationName = "Play Integrity API Sample",
});

DecodeIntegrityTokenRequest request = new     DecodeIntegrityTokenRequest();
request.IntegrityToken = integrityToken;
DecodeIntegrityTokenResponse response = service.V1.DecodeIntegrityToken(request, "...package name...");

Error CS0029 Cannot implicitly convert type 'Google.Apis.PlayIntegrity.v1.V1Resource.DecodeIntegrityTokenRequest' to 'Google.Apis.PlayIntegrity.v1.Data.DecodeIntegrityTokenResponse'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

意中人 2025-02-03 21:30:46

您应该依靠您的IDE来告诉您哪些类型这些对象是

您的代码说 deodeStegrityToken 应该返回 deodeDodeNtegrityTokenResponse 。您是这样声明的,而不是使用 var ,并允许编译器为您弄清楚。

DecodeIntegrityTokenResponse response = service.V1.DecodeIntegrityToken(request, "...package name...");

您的问题是,此方法实际上返回 DecoDeTrentegrityTokenRequest

要获取 decodeTrityTokenResponse 您需要执行请求

var request = service.V1.DecodeIntegrityToken(requestBody, "...package name...");
var result = request.Execute();

完整代码清理

using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.PlayIntegrity.v1;
using Google.Apis.PlayIntegrity.v1.Data;
using Google.Apis.Services;

Console.WriteLine("Hello, World!");


var integrityToken = "...token...";

var serviceAccountEmail = "...service account email...";
var pathToCert = "...key.p12...";
var certPassword = "...secret...";
var packageName = "...package name...";

var certificate = new X509Certificate2(pathToCert, certPassword);

var credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = new[] { PlayIntegrityService.Scope.Playintegrity }
    }.FromCertificate(certificate));

// Create the service.
var service = new PlayIntegrityService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Play Integrity API Sample",
});

var requestBody = new DecodeIntegrityTokenRequest
{
    IntegrityToken = integrityToken
};
var request = service.V1.DecodeIntegrityToken(requestBody, packageName);

var result = request.Execute();

You should rely on your ide to tell you what types these objects are

Your code says that the method DecodeIntegrityToken should return a DecodeIntegrityTokenResponse. You are declaring it as such instead of using var and allowing the compiler to figure it out for you.

DecodeIntegrityTokenResponse response = service.V1.DecodeIntegrityToken(request, "...package name...");

Your problem is that this method actually returns a DecodeIntegrityTokenRequest.

enter image description here

To get a DecodeIntegrityTokenResponse you need to execute the request

var request = service.V1.DecodeIntegrityToken(requestBody, "...package name...");
var result = request.Execute();

Full code cleanup

using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.PlayIntegrity.v1;
using Google.Apis.PlayIntegrity.v1.Data;
using Google.Apis.Services;

Console.WriteLine("Hello, World!");


var integrityToken = "...token...";

var serviceAccountEmail = "...service account email...";
var pathToCert = "...key.p12...";
var certPassword = "...secret...";
var packageName = "...package name...";

var certificate = new X509Certificate2(pathToCert, certPassword);

var credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = new[] { PlayIntegrityService.Scope.Playintegrity }
    }.FromCertificate(certificate));

// Create the service.
var service = new PlayIntegrityService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Play Integrity API Sample",
});

var requestBody = new DecodeIntegrityTokenRequest
{
    IntegrityToken = integrityToken
};
var request = service.V1.DecodeIntegrityToken(requestBody, packageName);

var result = request.Execute();
倾听心声的旋律 2025-02-03 21:30:46

我已经编写了一个示例应用程序,以使用自己的键在C#中验证和验证播放完整性。

官方文档没有C#代码示例。

示例应用程序包含.NET框架和Dotnet Core的代码。

克隆应用程序后,搜索// todo并使用适当的值进行更新。

csharp.playintegrity.decoder

I have written a sample application to decrypt and verify the play integrity in C# using their own keys offline.

The official documentation doesn't have a C# code sample.

The sample application contains code for both .net framework and dotnet core.

Once you clone the applciation, search for //TODO and update with appropriate values.

CSharp.PlayIntegrity.Decoder

尾戒 2025-02-03 21:30:46

您可以通过以下方式在本地解码证明语句。
我正在使用 jose.jwt 在这里使代码更加简单。

var decryptionKey = Convert.FromBase64String("<DECRYPTION KEY>");
var verificationKey = Convert.FromBase64String("<VERIFICATION KEY>");
var signedAttestationStatement = "<ATTESTATION STATEMENT>";

var ecDsa = ECDsa.Create();
ecDsa.ImportSubjectPublicKeyInfo(new ReadOnlySpan<byte>(verificationKey), out _);

var decrypted = Jose.JWT.Decode(signedAttestationStatement, decryptionKey);
var payload = Jose.JWT.Decode(decrypted, ecDsa);

You can decode the attestation statement locally in the following way.
I am using Jose.jwt to make the code simpler here.

var decryptionKey = Convert.FromBase64String("<DECRYPTION KEY>");
var verificationKey = Convert.FromBase64String("<VERIFICATION KEY>");
var signedAttestationStatement = "<ATTESTATION STATEMENT>";

var ecDsa = ECDsa.Create();
ecDsa.ImportSubjectPublicKeyInfo(new ReadOnlySpan<byte>(verificationKey), out _);

var decrypted = Jose.JWT.Decode(signedAttestationStatement, decryptionKey);
var payload = Jose.JWT.Decode(decrypted, ecDsa);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文