Skip to content

Commit

Permalink
Add PoToken service (#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 authored Jan 4, 2024
1 parent c104211 commit 3a8cdce
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 0 deletions.
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,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.internal.IStatusCallback;
import com.google.android.gms.potokens.internal.ITokenCallbacks;

interface IPoTokensService {
void responseStatus(IStatusCallback call, int code) = 1;
void responseStatusToken(ITokenCallbacks call, int i, in byte[] bArr) = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 {
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

0 comments on commit 3a8cdce

Please sign in to comment.