use of com.android.tools.build.bundletool.io.AppBundleSerializer 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.io.AppBundleSerializer 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.io.AppBundleSerializer in project bundletool by google.
the class BuildApksPreprocessingTest method localTestingMode_enabled_addsMetadata.
@Test
public void localTestingMode_enabled_addsMetadata() throws Exception {
AppBundle appBundle = createAppBundleWithBaseAndFeatureModules("feature");
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setLocalTestingMode(true).build();
command.execute();
try (ZipFile apkSet = new ZipFile(outputFilePath.toFile())) {
BuildApksResult result = extractTocFromApkSetFile(apkSet, outputDir);
assertThat(result.hasLocalTestingInfo()).isTrue();
assertThat(result.getLocalTestingInfo().getEnabled()).isTrue();
assertThat(result.getLocalTestingInfo().getLocalTestingPath()).isNotEmpty();
ImmutableList<ApkDescription> apkDescriptions = apkDescriptions(result.getVariantList());
assertThat(apkDescriptions).isNotEmpty();
assertThat(apkDescriptions.stream().map(ApkDescription::getPath)).contains("splits/base-master.apk");
for (ApkDescription apkDescription : apkDescriptions) {
File apk = extractFromApkSetFile(apkSet, apkDescription.getPath(), outputDir);
// The local testing metadata is set if and only if the apk is the base master.
assertThat((apkDescription.hasSplitApkMetadata() && apkDescription.getSplitApkMetadata().getSplitId().isEmpty() && apkDescription.getSplitApkMetadata().getIsMasterSplit()) || apkDescription.hasStandaloneApkMetadata()).isEqualTo(extractAndroidManifest(apk).getMetadataValue(LocalTestingPreprocessor.METADATA_NAME).isPresent());
}
}
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class BuildApksPreprocessingTest method localTestingMode_disabled_doesNotAddMetadata.
@Test
public void localTestingMode_disabled_doesNotAddMetadata() throws Exception {
AppBundle appBundle = createAppBundleWithBaseAndFeatureModules("feature");
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setLocalTestingMode(false).build();
command.execute();
try (ZipFile apkSet = new ZipFile(outputFilePath.toFile())) {
BuildApksResult result = extractTocFromApkSetFile(apkSet, outputDir);
assertThat(result.getLocalTestingInfo().getEnabled()).isFalse();
ImmutableList<ApkDescription> apkDescriptions = apkDescriptions(result.getVariantList());
assertThat(apkDescriptions).isNotEmpty();
for (ApkDescription apkDescription : apkDescriptions) {
File apk = extractFromApkSetFile(apkSet, apkDescription.getPath(), outputDir);
assertThat(extractAndroidManifest(apk).getMetadataValue(LocalTestingPreprocessor.METADATA_NAME)).isEmpty();
}
}
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer 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