use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class AddTransparencyCommandTest method createBundle.
private static void createBundle(Path path, boolean hasSharedUserId, int minSdkVersion) throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule(BASE_MODULE, module -> addCodeFilesToBundleModule(module, hasSharedUserId, minSdkVersion)).addModule(FEATURE_MODULE1, module -> addCodeFilesToBundleModule(module, hasSharedUserId, minSdkVersion)).addModule(FEATURE_MODULE2, module -> addCodeFilesToBundleModule(module, hasSharedUserId, minSdkVersion)).build();
new AppBundleSerializer().writeToDisk(appBundle, path);
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class BuildApksCommandTest method createAppBundle.
private void createAppBundle(Path path, Optional<CodeTransparency> codeTransparency) throws Exception {
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app")).build());
if (codeTransparency.isPresent()) {
appBundle.addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(createJwsToken(JsonFormat.printer().print(codeTransparency.get()))).asByteSource(Charset.defaultCharset()));
}
new AppBundleSerializer().writeToDisk(appBundle.build(), path);
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer 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.io.AppBundleSerializer 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.io.AppBundleSerializer 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.");
}
Aggregations