use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_transparencyVerified_codeTransparencyVersionNotSet.
@Test
public void bundleMode_transparencyVerified_codeTransparencyVersionNotSet() throws Exception {
String serializedJws = createJwsToken(CodeTransparency.getDefaultInstance(), transparencyKeyCertificate, transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).setTransparencyKeyCertificate(transparencyKeyCertificate).build().checkTransparency(new PrintStream(outputStream));
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).contains("No APK present. APK signature was not checked.");
assertThat(output).contains("Code transparency signature verified for the provided code transparency key" + " certificate.");
assertThat(output).contains("Code transparency verified: code related file contents match the code transparency" + " file.");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_unsupportedCodeTransparencyVersion.
@Test
public void bundleMode_unsupportedCodeTransparencyVersion() throws Exception {
String serializedJws = createJwsToken(CodeTransparency.newBuilder().setVersion(CodeTransparencyVersion.getCurrentVersion() + 1).build(), transparencyKeyCertificate, transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Throwable e = assertThrows(IllegalStateException.class, () -> CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).setTransparencyKeyCertificate(transparencyKeyCertificate).build().checkTransparency(new PrintStream(outputStream)));
assertThat(e).hasMessageThat().contains("Code transparency file has unsupported version.");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_transparencyVerified_transparencyKeyCertificateProvidedByUser.
@Test
public void bundleMode_transparencyVerified_transparencyKeyCertificateProvidedByUser() throws Exception {
String serializedJws = createJwsToken(CodeTransparency.newBuilder().setVersion(CodeTransparencyVersion.getCurrentVersion()).build(), transparencyKeyCertificate, transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).setTransparencyKeyCertificate(transparencyKeyCertificate).build().checkTransparency(new PrintStream(outputStream));
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).contains("No APK present. APK signature was not checked.");
assertThat(output).contains("Code transparency signature verified for the provided code transparency key" + " certificate.");
assertThat(output).contains("Code transparency verified: code related file contents match the code transparency" + " file.");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_verificationFailed_badCertificateProvidedByUser.
@Test
public void bundleMode_verificationFailed_badCertificateProvidedByUser() throws Exception {
String serializedJws = createJwsToken(CodeTransparency.newBuilder().setVersion(CodeTransparencyVersion.getCurrentVersion()).build(), transparencyKeyCertificate, transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
X509Certificate badCertificate = CertificateFactory.buildSelfSignedCertificate(kpg.generateKeyPair(), "CN=CheckTransparencyCommandTest_BadCertificate");
CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).setTransparencyKeyCertificate(badCertificate).build().checkTransparency(new PrintStream(outputStream));
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).contains("No APK present. APK signature was not checked.");
assertThat(output).contains("Code transparency verification failed because the provided public key certificate does" + " not match the code transparency file.");
assertThat(output).contains("SHA-256 fingerprint of the certificate that was used to sign code" + " transparency file: " + CodeTransparencyCryptoUtils.getCertificateFingerprint(transparencyKeyCertificate));
assertThat(output).contains("SHA-256 fingerprint of the certificate that was provided: " + CodeTransparencyCryptoUtils.getCertificateFingerprint(badCertificate));
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksPreprocessingTest method renderscript32Bit_warningMessageDisplayed.
@Test
public void renderscript32Bit_warningMessageDisplayed() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("assets/script.bc").setManifest(androidManifest("com.test.app"))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setOutputPrintStream(new PrintStream(output)).build();
command.execute();
assertThat(new String(output.toByteArray(), UTF_8)).contains("WARNING: App Bundle contains 32-bit RenderScript bitcode file (.bc)");
}
Aggregations