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

Commit a2f766f3 authored by Brian Lee's avatar Brian Lee
Browse files

Pull SecureBox.java out into its own library.

SecureBox is needed by Settings for encrypting device credential and
was inaccessible from services/core/java/com/android/server.
Create a new SecureBox library to resolve.

Test: atest com.android.server.locksettings.recoverablekeystore
SecureBoxTests
Bug: 258505917

Change-Id: I65484edf12b04dfe1642cd0c97bc999d26430395
parent 2b9edf63
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
package {
    default_applicable_licenses: ["frameworks_base_license"],
}

java_library {
    name: "securebox",
    srcs: ["src/**/*.java"],
}

libs/securebox/OWNERS

0 → 100644
+1 −0
Original line number Diff line number Diff line
include /services/core/java/com/android/server/locksettings/recoverablekeystore/OWNERS
+12 −4
Original line number Diff line number Diff line
@@ -14,11 +14,13 @@
 * limitations under the License.
 */

package com.android.server.locksettings.recoverablekeystore;
package com.android.security;

import android.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;

import java.math.BigInteger;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
@@ -41,6 +43,7 @@ import java.security.spec.ECPublicKeySpec;
import java.security.spec.EllipticCurve;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;

import javax.crypto.AEADBadTagException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@@ -380,7 +383,7 @@ public class SecureBox {
     * @param publicKey The public key.
     * @return The key packed into a 65-byte array.
     */
    static byte[] encodePublicKey(PublicKey publicKey) {
    public static byte[] encodePublicKey(PublicKey publicKey) {
        ECPoint point = ((ECPublicKey) publicKey).getW();
        byte[] x = point.getAffineX().toByteArray();
        byte[] y = point.getAffineY().toByteArray();
@@ -394,8 +397,13 @@ public class SecureBox {
        return output;
    }

    @VisibleForTesting
    static PublicKey decodePublicKey(byte[] keyBytes)
    /**
     * Decodes byte[] encoded public key.
     *
     * @param keyBytes encoded public key
     * @return the public key
     */
    public static PublicKey decodePublicKey(byte[] keyBytes)
            throws NoSuchAlgorithmException, InvalidKeyException {
        BigInteger x =
                new BigInteger(
+46 −0
Original line number 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 {
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test {
    name: "SecureBoxTests",
    srcs: [
        "**/*.java",
    ],
    static_libs: [
        "securebox",
        "androidx.test.runner",
        "androidx.test.rules",
        "androidx.test.ext.junit",
        "frameworks-base-testutils",
        "junit",
        "mockito-target-extended-minus-junit4",
        "platform-test-annotations",
        "testables",
        "testng",
        "truth-prebuilt",
    ],
    libs: [
        "android.test.mock",
        "android.test.base",
        "android.test.runner",
    ],
    jni_libs: [
        "libdexmakerjvmtiagent",
        "libstaticjvmtiagent",
    ],
}
+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.android.security.tests">

    <application android:debuggable="true" android:largeHeap="true">
        <uses-library android:name="android.test.mock" />
        <uses-library android:name="android.test.runner" />
    </application>

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:label="Tests for SecureBox"
        android:targetPackage="com.android.security.tests">
    </instrumentation>

</manifest>
Loading