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

Verified Commit bfe649fc authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Add Google Certificates API

parent dc895b4e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
package com.google.android.gms.common.internal;

parcelable GoogleCertificatesQuery;
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
package com.google.android.gms.common.internal;

import com.google.android.gms.dynamic.IObjectWrapper;

interface ICertData {
    IObjectWrapper getWrappedBytes();
    int remoteHashCode();
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
package com.google.android.gms.common.internal;

import com.google.android.gms.common.internal.GoogleCertificatesQuery;
import com.google.android.gms.dynamic.IObjectWrapper;

interface IGoogleCertificatesApi {
    IObjectWrapper getGoogleCertficates();
    IObjectWrapper getGoogleReleaseCertificates();
    boolean isGoogleReleaseSigned(String packageName, IObjectWrapper certData);
    boolean isGoogleSigned(String packageName, IObjectWrapper certData);
    boolean isGoogleOrPlatformSigned(in GoogleCertificatesQuery query, IObjectWrapper packageManager);
}
 No newline at end of file
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 microG Project Team
 *
 * 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.google.android.gms.common.internal;

import android.os.RemoteException;

import com.google.android.gms.dynamic.IObjectWrapper;
import com.google.android.gms.dynamic.ObjectWrapper;

import java.util.Arrays;

public class CertData extends ICertData.Stub {
    private final byte[] bytes;
    private final int hashCode;

    public CertData(byte[] bytes) {
        this.bytes = bytes;
        if (bytes.length < 25) throw new RuntimeException("CertData to small");
        hashCode = Arrays.hashCode(Arrays.copyOfRange(bytes, 0, 25));
    }

    @Override
    public int hashCode() {
        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ICertData)) return false;
        ICertData cert = (ICertData) obj;
        try {
            if (cert.remoteHashCode() != hashCode()) return false;
            return Arrays.equals(ObjectWrapper.unwrapTyped(cert.getWrappedBytes(), byte[].class), getBytes());
        } catch (RemoteException e) {
            return false;
        }
    }

    public byte[] getBytes() {
        return bytes;
    }

    @Override
    public IObjectWrapper getWrappedBytes() throws RemoteException {
        return ObjectWrapper.wrap(getBytes());
    }

    @Override
    public int remoteHashCode() throws RemoteException {
        return hashCode();
    }
}
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 microG Project Team
 *
 * 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.google.android.gms.common.internal;

import android.os.IBinder;
import android.os.RemoteException;

import com.google.android.gms.dynamic.IObjectWrapper;
import com.google.android.gms.dynamic.ObjectWrapper;

import org.microg.safeparcel.AutoSafeParcelable;
import org.microg.safeparcel.SafeParceled;

public class GoogleCertificatesQuery extends AutoSafeParcelable {
    @SafeParceled(1)
    private String packageName;
    @SafeParceled(2)
    private IBinder certDataBinder;
    private CertData certData;
    @SafeParceled(3)
    private boolean allowNonRelease;

    public String getPackageName() {
        return packageName;
    }

    public CertData getCertData() {
        if (certData == null && certDataBinder != null) {
            ICertData iCertData = null;
            if (certDataBinder instanceof CertData) {
                certData = (CertData) certDataBinder;
            } else if (certDataBinder instanceof IObjectWrapper) {
                certData = ObjectWrapper.unwrapTyped((IObjectWrapper) certDataBinder, CertData.class);
                if (certData == null) {
                    byte[] bytes = ObjectWrapper.unwrapTyped((IObjectWrapper) certDataBinder, byte[].class);
                    if (bytes != null) {
                        certData = new CertData(bytes);
                    }
                }
                if (certData == null) {
                    iCertData = ObjectWrapper.unwrapTyped((IObjectWrapper) certDataBinder, ICertData.class);
                }
            } else if (certDataBinder instanceof ICertData) {
                iCertData = (ICertData) certDataBinder;
            }
            if (iCertData != null) {
                try {
                    byte[] bytes = ObjectWrapper.unwrapTyped(iCertData.getWrappedBytes(), byte[].class);
                    if (bytes != null) {
                        certData = new CertData(bytes);
                    }
                } catch (RemoteException e) {
                    // Ignore
                }
            }
        }
        return certData;
    }

    public static final Creator<GoogleCertificatesQuery> CREATOR = new AutoCreator<GoogleCertificatesQuery>(GoogleCertificatesQuery.class);
}