Merge "Pull SecureBox.java out into its own library."

This commit is contained in:
Brian Lee
2023-01-25 17:23:03 +00:00
committed by Android (Google) Code Review
16 changed files with 145 additions and 10 deletions

View 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
View File

@@ -0,0 +1 @@
include /services/core/java/com/android/server/locksettings/recoverablekeystore/OWNERS

View File

@@ -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(

View 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",
],
}

View 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>

View 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>

View File

@@ -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;

View File

@@ -182,6 +182,7 @@ java_library_static {
"SurfaceFlingerProperties",
"com.android.sysprop.watchdog",
"ImmutabilityAnnotation",
"securebox",
],
javac_shard_size: 50,
javacflags: [

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -62,6 +62,7 @@ android_test {
"junit-params",
"ActivityContext",
"coretests-aidl",
"securebox",
],
libs: [

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;