Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0eb56adc authored by Jonathan Klee's avatar Jonathan Klee Committed by Nishith Khanna
Browse files

Alter MODEL build property with an extra space

Indeed, adding this extra space at the end of the model name
prevent the enforcement of hardware-backend attestation.

This patch is based on kdrag0n's patch:
https://github.com/ProtonAOSP/android_frameworks_base/commit/f1d08fac5cc41c7d44961ca8ab554574864f5579
parent fea2215a
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -75,6 +75,8 @@ import java.util.Objects;
import java.util.StringJoiner;
import java.util.StringJoiner;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeoutException;


import com.android.internal.safetynet.SafetyNetHooks;

/**
/**
 * Base class for implementing application instrumentation code.  When running
 * Base class for implementing application instrumentation code.  When running
 * with instrumentation turned on, this class will be instantiated for you
 * with instrumentation turned on, this class will be instantiated for you
@@ -1356,6 +1358,7 @@ public class Instrumentation {
        Application app = getFactory(context.getPackageName())
        Application app = getFactory(context.getPackageName())
                .instantiateApplication(cl, className);
                .instantiateApplication(cl, className);
        app.attach(context);
        app.attach(context);
        SafetyNetHooks.init(app);
        return app;
        return app;
    }
    }
    
    
@@ -1373,6 +1376,7 @@ public class Instrumentation {
            ClassNotFoundException {
            ClassNotFoundException {
        Application app = (Application)clazz.newInstance();
        Application app = (Application)clazz.newInstance();
        app.attach(context);
        app.attach(context);
        SafetyNetHooks.init(app);
        return app;
        return app;
    }
    }


+47 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.safetynet;

import java.lang.reflect.Field;
import java.util.Arrays;

import android.app.Application;
import android.os.Build;
import android.util.Log;

public final class SafetyNetHooks {

    private static final String TAG = "SafetyNetHooks";
    private static final String GMS_PACKAGE_NAME = "com.google.android.gms";

    private static void setBuildField(String key, String value) {
        try {
            Field field = Build.class.getDeclaredField(key);
            field.setAccessible(true);
            field.set(null, value);
            field.setAccessible(false);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Log.e(TAG, "Failed to fake Build." + key, e);
        }
    }

    public static void init(Application app) {
        if (GMS_PACKAGE_NAME.equals(app.getPackageName())) {
            setBuildField("MODEL", Build.MODEL + " ");
        }
    }
}