use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildSdkApksManagerTest method sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged.
@Test
public void sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged() throws Exception {
SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withMinSdkVersion(SDK_SANDBOX_MIN_VERSION + 5), withSdkLibraryElement("20"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "12"))).build()).build();
execute(sdkBundle);
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
Variant variant = result.getVariant(0);
ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
assertThat(manifest.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION + 5);
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_unsupportedSignatureAlgorithm.
@Test
public void bundleMode_unsupportedSignatureAlgorithm() throws Exception {
String serializedJws = createJwsToken(CodeTransparency.getDefaultInstance(), transparencyKeyCertificate, transparencyPrivateKey, RSA_USING_SHA384);
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);
Throwable e = assertThrows(CommandExecutionException.class, () -> CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).build().checkTransparency(new PrintStream(new ByteArrayOutputStream())));
assertThat(e).hasMessageThat().contains("Exception while verifying code transparency signature.");
}
use of com.android.tools.build.bundletool.model.AndroidManifest 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.model.AndroidManifest 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.model.AndroidManifest 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.");
}
Aggregations