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
This commit is contained in:
8
libs/securebox/Android.bp
Normal file
8
libs/securebox/Android.bp
Normal file
@@ -0,0 +1,8 @@
|
||||
package {
|
||||
default_applicable_licenses: ["frameworks_base_license"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "securebox",
|
||||
srcs: ["src/**/*.java"],
|
||||
}
|
||||
1
libs/securebox/OWNERS
Normal file
1
libs/securebox/OWNERS
Normal file
@@ -0,0 +1 @@
|
||||
include /services/core/java/com/android/server/locksettings/recoverablekeystore/OWNERS
|
||||
@@ -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
libs/securebox/tests/Android.bp
Normal file
46
libs/securebox/tests/Android.bp
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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
libs/securebox/tests/AndroidManifest.xml
Normal file
33
libs/securebox/tests/AndroidManifest.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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>
|
||||
31
libs/securebox/tests/AndroidTest.xml
Normal file
31
libs/securebox/tests/AndroidTest.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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.
|
||||
-->
|
||||
<configuration description="Runs Tests for SecureBox">
|
||||
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||
<option name="cleanup-apks" value="true" />
|
||||
<option name="install-arg" value="-t" />
|
||||
<option name="test-file-name" value="SecureBoxTests.apk" />
|
||||
</target_preparer>
|
||||
|
||||
<option name="test-suite-tag" value="apct" />
|
||||
<option name="test-suite-tag" value="framework-base-presubmit" />
|
||||
<option name="test-tag" value="SecureBoxTests" />
|
||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
||||
<option name="package" value="com.android.security.tests" />
|
||||
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
||||
<option name="hidden-api-checks" value="false"/>
|
||||
</test>
|
||||
</configuration>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* Copyright (C) 2023 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.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.locksettings.recoverablekeystore;
|
||||
package com.android.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -24,11 +24,11 @@ import static org.testng.Assert.expectThrows;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
@@ -182,6 +182,7 @@ java_library_static {
|
||||
"SurfaceFlingerProperties",
|
||||
"com.android.sysprop.watchdog",
|
||||
"ImmutabilityAnnotation",
|
||||
"securebox",
|
||||
],
|
||||
javac_shard_size: 50,
|
||||
javacflags: [
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.util.Pair;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.security.SecureBox;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@@ -44,6 +44,7 @@ import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.HexDump;
|
||||
import com.android.security.SecureBox;
|
||||
import com.android.server.locksettings.recoverablekeystore.certificate.CertParsingException;
|
||||
import com.android.server.locksettings.recoverablekeystore.certificate.CertUtils;
|
||||
import com.android.server.locksettings.recoverablekeystore.certificate.CertValidationException;
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.server.locksettings.recoverablekeystore.SecureBox;
|
||||
import com.android.security.SecureBox;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@@ -62,6 +62,7 @@ android_test {
|
||||
"junit-params",
|
||||
"ActivityContext",
|
||||
"coretests-aidl",
|
||||
"securebox",
|
||||
],
|
||||
|
||||
libs: [
|
||||
|
||||
@@ -55,6 +55,7 @@ import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.security.SecureBox;
|
||||
import com.android.server.locksettings.recoverablekeystore.storage.RecoverableKeyStoreDb;
|
||||
import com.android.server.locksettings.recoverablekeystore.storage.RecoverySnapshotStorage;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.security.SecureBox;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -60,6 +60,7 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.security.SecureBox;
|
||||
import com.android.server.locksettings.recoverablekeystore.storage.ApplicationKeyStorage;
|
||||
import com.android.server.locksettings.recoverablekeystore.storage.CleanupManager;
|
||||
import com.android.server.locksettings.recoverablekeystore.storage.RecoverableKeyStoreDb;
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.SystemClock;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.server.locksettings.recoverablekeystore.SecureBox;
|
||||
import com.android.security.SecureBox;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user