Skip to content

Auth: Support Google 2-step verification #2866

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -73,6 +73,8 @@ public class AuthResponse {
public String auths;
@ResponseField("capabilities")
public String capabilities;
@ResponseField("ExpiresInDurationSec")
public int expiresInDurationSec;

public static AuthResponse parse(String result) {
AuthResponse response = new AuthResponse();
Expand Down Expand Up @@ -129,6 +131,7 @@ public String toString() {
if (itMetadata != null) sb.append(", itMetadata='").append(itMetadata).append('\'');
if (resolutionDataBase64 != null) sb.append(", resolutionDataBase64='").append(resolutionDataBase64).append('\'');
if (capabilities != null) sb.append(", capabilitites='").append(capabilities).append('\'');
if (expiresInDurationSec != 0) sb.append(", expiresInDurationSec='").append(expiresInDurationSec).append('\'');
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ object AuthPrefs {
}
}

@JvmStatic
fun shouldReceiveTwoStepVerification(context: Context): Boolean {
return SettingsContract.getSettings(context, Auth.getContentUri(context), arrayOf(Auth.TWO_STEP_VERIFICATION)) { c ->
c.getInt(0) != 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ object SettingsContract {
const val VISIBLE = "auth_manager_visible"
const val INCLUDE_ANDROID_ID = "auth_include_android_id"
const val STRIP_DEVICE_NAME = "auth_strip_device_name"
const val TWO_STEP_VERIFICATION = "auth_two_step_verification"

val PROJECTION = arrayOf(
TRUST_GOOGLE,
VISIBLE,
INCLUDE_ANDROID_ID,
STRIP_DEVICE_NAME,
TWO_STEP_VERIFICATION,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class SettingsProvider : ContentProvider() {
Auth.VISIBLE -> getSettingsBoolean(key, false)
Auth.INCLUDE_ANDROID_ID -> getSettingsBoolean(key, true)
Auth.STRIP_DEVICE_NAME -> getSettingsBoolean(key, false)
Auth.TWO_STEP_VERIFICATION -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand All @@ -222,6 +223,7 @@ class SettingsProvider : ContentProvider() {
Auth.VISIBLE -> editor.putBoolean(key, value as Boolean)
Auth.INCLUDE_ANDROID_ID -> editor.putBoolean(key, value as Boolean)
Auth.STRIP_DEVICE_NAME -> editor.putBoolean(key, value as Boolean)
Auth.TWO_STEP_VERIFICATION -> editor.putBoolean(key, value as Boolean)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public final class GcmConstants {
public static final String EXTRA_TOPIC = "gcm.topic";
public static final String EXTRA_TTL = "google.ttl";
public static final String EXTRA_UNREGISTERED = "unregistered";
public static final String EXTRA_ACCOUNT_NAME = "a";
public static final String EXTRA_REG_ID = "id";
public static final String EXTRA_AUTHS_TOKEN = "t";
public static final String EXTRA_GCM_BODY = "gcmb";
public static final String EXTRA_GMS_GNOTS_PAYLOAD = "gms.gnots.payload";

public static final String MESSAGE_TYPE_GCM = "gcm";
public static final String MESSAGE_TYPE_DELETED_MESSAGE = "deleted_message";
Expand Down
36 changes: 36 additions & 0 deletions play-services-core-proto/src/main/proto/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,39 @@ message Cookie {
optional string discard = 10;
optional string comment = 12;
}

message ItAuthData {
optional bytes auth = 1;
repeated bytes tokens = 2;
optional bytes signature = 3;
}

message ItMetadataData {
message ScopeEntry {
repeated string name = 1;
optional int32 id = 2;
}
repeated ScopeEntry entries = 1;
optional TokenField field = 3;
optional int32 liveTime = 4;
}

message TokenField {
enum FieldType {
UNKNOWN = 0;
SCOPE = 1;
EXPIRATION = 2;
}
repeated FieldType types = 1 [packed = true];
}

message OAuthAuthorization {
repeated int32 scopeIds = 1 [packed = true];
optional int32 effectiveDurationSeconds = 2;
}

message OAuthTokenData {
optional int32 fieldType = 1;
optional bytes authorization = 2;
optional int32 durationMillis = 3;
}
183 changes: 183 additions & 0 deletions play-services-core-proto/src/main/proto/gnots.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package social.boq.notifications.gmscoreapi;

option java_outer_classname = "GunsGmscoreApiService";
option java_package = "org.microg.gms.gcm";

service GunsGmscoreApiService {
rpc GmsGnotsFetchByIdentifier(FetchByIdentifierRequest) returns (FetchByIdentifierResponse);
rpc GmsGnotsSetReadStates(GmsGnotsSetReadStatesRequest) returns (GmsGnotsSetReadStatesResponse);
}

message FetchByIdentifierRequest {
optional GmsConfig config = 1;
optional NotificationIdentifierList identifiers = 2;
}

message GmsConfig {
message GmsVersionInfo {
optional int32 version = 10;
}
optional GmsVersionInfo versionInfo = 3;
}

message NotificationIdentifierList {
repeated NotificationIdentifier notifications = 1;
optional DeviceInfo deviceInfo = 2;
}

message FetchByIdentifierResponse {
optional NotificationList notifications = 2;
}

message NotificationList {
repeated NotificationData notifications = 1;
optional uint64 serverTime = 3;
}

message NotificationData {
optional UserInfo userInfo = 1;
optional NotificationIdentifier identifier = 2;
optional bool isActive = 3;
optional NotificationContent content = 4;
optional NotificationAction action = 5;
optional DeviceInfo deviceInfo = 6;
optional uint64 createTime = 7;
optional IntentActions intentActions = 8;
optional uint64 expiryTime = 9;
optional BinaryPayload binaryPayload = 10;
}

message IntentActions {
optional IntentPayload primaryPayload = 1;
optional IntentPayload secondaryPayload = 2;
}

message UserInfo {
optional string userId = 1;
}

message NotificationIdentifier {
optional string type = 1;
optional string uniqueId = 2;
optional uint64 timestamp = 3;
optional string source = 4;
optional string registrationId = 5;
optional int64 receivedTime = 6;
optional bytes payload = 7;
}

message NotificationContent {
optional int32 priority = 1;
optional IconInfo icon = 2;
optional string title = 3;
optional string accountName = 4;
optional string email = 5;
optional string description = 6;
optional string additionalText = 7;
optional string eventType = 8;
optional string errorMessage = 9;
optional bool isDismissible = 10;
optional bool requiresAuth = 11;
optional bool isUserVisible = 12;
optional bool isAutoCancel = 13;
optional ActionButtons buttons = 14;
optional bool isPersistent = 15;
optional string tickerText = 16;
repeated NotificationButton actionButtons = 17;
optional NotificationChannelInfo channelInfo = 18;
optional string groupKey = 19;
optional string sortKey = 20;
}

message NotificationChannelInfo {
optional string id = 1;
optional string description = 2;
optional string groupId = 3;
optional string groupName = 4;
optional int32 importance = 5;
optional string name = 6;
}

message IconInfo {
optional string iconUrl = 1;
}

message ActionButtons {
optional string primaryText = 1;
optional string secondaryText = 2;
}

message NotificationButton {
optional string text = 1;
optional NotificationAction action = 2;
optional string icon = 3;
optional bool isEnabled = 4;
optional int32 buttonType = 6;
}

message NotificationAction {
optional ActionMetadata metadata = 1;
optional ActionIntent intent = 2;
}

message ActionMetadata {
optional string actionUrl = 1;
optional bool value = 2;
}

message ActionIntent {
optional IntentPayload intentPayload = 4;
}

message IntentPayload {
optional string className = 1;
optional string action = 2;
optional int32 launchType = 3;
repeated IntentExtra extras = 4;
optional int32 flags = 5;
}

message IntentExtra {
optional string key = 1;
optional string value = 2;
}

message GmsGnotsSetReadStatesRequest {
optional GmsConfig config = 1;
optional ReadStateList readStates = 2;
}

message ReadStateList {
repeated ReadStateItem items = 1;
}

message ReadStateItem {
optional NotificationIdentifier notification = 1;
optional string state = 3;
optional int32 status = 4;
}

message GmsGnotsSetReadStatesResponse {
}

message DeviceInfo {
optional DensityQualifier densityQualifier = 1;
enum DensityQualifier {
MDPI = 0;
TVDPI = 1;
XHDPI = 2;
XXHDPI = 3;
HDPI = 4;
XXXHDPI = 5;
}
optional string localeTag = 2;
optional int32 sdkVersion = 3;
optional float density = 4;
optional string timeZoneId = 5;
repeated NotificationChannelInfo notificationChannels = 6;
}

message BinaryPayload {
required string type = 1;
required bytes data = 2;
}
3 changes: 3 additions & 0 deletions play-services-core/src/huawei/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<meta-data
android:name="org.microg.gms.settings.auth_strip_device_name"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.auth_two_step_verification"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.droidguard_enabled"
android:value="true" />
Expand Down
3 changes: 3 additions & 0 deletions play-services-core/src/huaweilh/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<meta-data
android:name="org.microg.gms.settings.auth_strip_device_name"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.auth_two_step_verification"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.droidguard_enabled"
android:value="true" />
Expand Down
18 changes: 18 additions & 0 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@
android:name="org.microg.gms.gcm.McsService"
android:process=":persistent" />

<service
android:name="org.microg.gms.gcm.GcmInGmsService"
android:exported="false"
android:process=":persistent"/>

<receiver
android:name="org.microg.gms.gcm.GcmRegistrationReceiver"
android:exported="false"
android:process=":persistent">
<intent-filter>
<action android:name="org.microg.gms.gcm.REGISTERED" />
<action android:name="org.microg.gms.gcm.REGISTER_ACCOUNT" />
<action android:name="org.microg.gms.gcm.NOTIFY_COMPLETE" />

<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>

<receiver
android:name="org.microg.gms.gcm.SendReceiver"
android:process=":persistent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.microg.gms.auth.AuthResponse;
import org.microg.gms.checkin.CheckinManager;
import org.microg.gms.checkin.LastCheckinInfo;
import org.microg.gms.common.Constants;
import org.microg.gms.common.HttpFormClient;
import org.microg.gms.common.Utils;
import org.microg.gms.people.PeopleManager;
Expand All @@ -79,6 +80,8 @@
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;
import static org.microg.gms.common.Constants.VENDING_PACKAGE_NAME;
import static org.microg.gms.gcm.GcmInGmsServiceKt.ACTION_GCM_REGISTER_ACCOUNT;
import static org.microg.gms.gcm.GcmInGmsServiceKt.KEY_GCM_REGISTER_ACCOUNT_NAME;

public class LoginActivity extends AssistantActivity {
public static final String TMPL_NEW_ACCOUNT = "new_account";
Expand Down Expand Up @@ -392,6 +395,7 @@ public void onResponse(AuthResponse response) {
}
checkin(true);
returnSuccessResponse(account);
notifyGcmGroupUpdate(account.name);
if (SDK_INT >= LOLLIPOP) { finishAndRemoveTask(); } else finish();
}

Expand All @@ -407,6 +411,13 @@ public void onException(Exception exception) {
});
}

private void notifyGcmGroupUpdate(String accountName) {
Intent intent = new Intent(ACTION_GCM_REGISTER_ACCOUNT);
intent.setPackage(Constants.GMS_PACKAGE_NAME);
intent.putExtra(KEY_GCM_REGISTER_ACCOUNT_NAME, accountName);
sendBroadcast(intent);
}

private boolean checkin(boolean force) {
try {
CheckinManager.checkin(LoginActivity.this, force);
Expand Down
Loading