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

supplement and optimize potoken related services #2129

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens;

parcelable PoToken;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens.internal;

import com.google.android.gms.common.api.internal.IStatusCallback;
import com.google.android.gms.potokens.internal.ITokenCallbacks;

interface IPoTokensService {
void responseStatus(IStatusCallback call, int code) = 1;
// The direction of 'bArr' is not specified. array can be an in, out, or inout parameter.
mar-v-in marked this conversation as resolved.
Show resolved Hide resolved
void responseStatusToken(ITokenCallbacks call, int i, in byte[] bArr) = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens.internal;

import com.google.android.gms.common.api.Status;
import com.google.android.gms.potokens.PoToken;

interface ITokenCallbacks {
// The direction of 'status' is not specified. parcelable/union can be an in, out, or inout parameter.
void responseToken(in Status status, in PoToken token) = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens;

import org.microg.safeparcel.AutoSafeParcelable;

public class PoToken extends AutoSafeParcelable {

@Field(1)
public byte[] data;

public PoToken(byte[] data) {
this.data = data;
}

public static Creator<PoToken> CREATOR = findCreator(PoToken.class);
}
63 changes: 63 additions & 0 deletions play-services-core-proto/src/main/proto/potoken.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

option java_package = "com.google.android.gms.potokens";

option java_multiple_files = true;

message CipherKey {
optional int32 key = 1;
optional bytes value = 3;
}

message KeyData {
optional string typeUrl = 1;
optional CipherKey value = 2;
optional int32 keyMaterialType = 3;
}

message Key {
optional KeyData data = 1;
optional int32 status = 2;
optional int32 keyId = 3;
optional int32 outputPrefixType = 4;
}

message KeySet {
optional int32 keyId = 1;
repeated Key keyList = 2;
}

message PoTokenInfo {
optional int32 key = 6;
optional int32 time = 1;
optional bytes inputData = 2;
optional string pkgName = 3;
optional bytes pkgSignSha256 = 4;
optional bytes tokenData = 5;
}

message GetPoIntegrityTokenRequest {
optional int32 mode = 1;
optional bytes dgResult = 2;
optional bytes dgRandKey = 3;
}

message GetPoIntegrityTokenResponse {
optional bytes desc = 1;
optional int32 code = 2;
optional bytes backup = 3;
// optional bytes d = 4;
// optional bytes e = 5;
}

message PoTokenResult {
optional bytes encryptData = 1;
optional bytes tokenData = 2;
}

message PoTokenResultWrap {
optional PoTokenResult data = 1;
}
8 changes: 8 additions & 0 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@
</intent-filter>
</activity>

<!-- PoToken -->

<service android:name="com.google.android.gms.potokens.internal.PoTokensApiService">
<intent-filter>
<action android:name="com.google.android.gms.potokens.service.START" />
</intent-filter>
</service>

<!-- Other -->

<service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens.internal

import android.util.Log
import androidx.lifecycle.lifecycleScope
import com.google.android.gms.common.Feature
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.internal.ConnectionInfo
import com.google.android.gms.common.internal.GetServiceRequest
import com.google.android.gms.common.internal.IGmsCallbacks
import com.google.android.gms.potokens.utils.PoTokenConstants
import org.microg.gms.BaseService
import org.microg.gms.common.GmsService

const val TAG = "PoTokensApi"

class PoTokensApiService : BaseService(TAG, GmsService.POTOKENS) {
override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
val connectionInfo = ConnectionInfo()
connectionInfo.features = arrayOf(Feature(PoTokenConstants.PO_TOKENS, 1))
Log.d(TAG, "PoTokensApiService handleServiceRequest")
callback.onPostInitCompleteWithConnectionInfo(
CommonStatusCodes.SUCCESS, PoTokensApiServiceImpl(
applicationContext, request.packageName, lifecycleScope
), connectionInfo
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens.internal

import android.content.Context
import android.util.Log
import androidx.lifecycle.LifecycleCoroutineScope
import com.google.android.gms.common.api.Status
import com.google.android.gms.common.api.internal.IStatusCallback
import com.google.android.gms.potokens.PoToken
import com.google.android.gms.potokens.utils.PoTokenHelper
import org.microg.gms.profile.ProfileManager

class PoTokensApiServiceImpl(
private val context: Context,
private val packageName: String,
private val lifecycleCoroutineScope: LifecycleCoroutineScope
) : IPoTokensService.Stub() {

override fun responseStatus(call: IStatusCallback, code: Int) {
Log.e(TAG, "responseStatus success")
call.onResult(Status.SUCCESS)
}

override fun responseStatusToken(call: ITokenCallbacks, i: Int, bArr: ByteArray) {
Log.d(TAG, "responseStatusToken packageName: $packageName")
ProfileManager.ensureInitialized(context)

lifecycleCoroutineScope.launchWhenCreated {
Log.d(TAG, "responseStatusToken start")
val bytes = PoTokenHelper.get(context).callPoToken(context, packageName, bArr)
Log.d(TAG, "responseStatusToken result: ${bytes.size}")
call.responseToken(Status.SUCCESS, PoToken(bytes))
Log.d(TAG, "responseStatusToken end")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.potokens.utils

object PoTokenConstants {
const val PO_TOKENS = "PO_TOKENS"
const val TOKEN_URL =
"https://deviceintegritytokens-pa.googleapis.com/v1/getPoIntegrityToken?alt=proto&key=AIzaSyBtL0AK6Hzgr69rQyeyhi-V1lmtsPGZd1M"
const val TYPE_URL = "type.googleapis.com/google.crypto.tink.AesGcmKey"
const val KEY_TOKEN = "po-token-fast"
const val KEY_FAST = "po-fast-key"
const val KEY_FALLBACK = "extraKeysRetainedInFallback"
const val KEY_DESC = "tokenDesc"
const val KEY_BACKUP = "tokenBackup"
const val KEY_SET_STR = "keySetStr"
}
Loading
Loading