use of com.android.tools.build.bundletool.model.SignerConfig in project bundletool by google.
the class BuildSdkApksCommand method populateSigningConfigurationFromFlags.
private static void populateSigningConfigurationFromFlags(Builder buildSdkApksCommand, ParsedFlags flags, PrintStream out, SystemEnvironmentProvider provider) {
// Signing-related arguments.
Optional<Path> keystorePath = KEYSTORE_FLAG.getValue(flags);
Optional<String> keyAlias = KEY_ALIAS_FLAG.getValue(flags);
Optional<Password> keystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
Optional<Password> keyPassword = KEY_PASSWORD_FLAG.getValue(flags);
if (keystorePath.isPresent() && keyAlias.isPresent()) {
SignerConfig signerConfig = SignerConfig.extractFromKeystore(keystorePath.get(), keyAlias.get(), keystorePassword, keyPassword);
SigningConfiguration.Builder builder = SigningConfiguration.builder().setSignerConfig(signerConfig);
buildSdkApksCommand.setSigningConfiguration(builder.build());
} else if (keystorePath.isPresent() && !keyAlias.isPresent()) {
throw InvalidCommandException.builder().withInternalMessage("Flag --ks-key-alias is required when --ks is set.").build();
} else if (!keystorePath.isPresent() && keyAlias.isPresent()) {
throw InvalidCommandException.builder().withInternalMessage("Flag --ks is required when --ks-key-alias is set.").build();
} else {
// Try to use debug keystore if present.
Optional<SigningConfiguration> debugConfig = DebugKeystoreUtils.getDebugSigningConfiguration(provider);
if (debugConfig.isPresent()) {
out.printf("INFO: The APKs will be signed with the debug keystore found at '%s'.%n", DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.getUnchecked(provider).get());
buildSdkApksCommand.setSigningConfiguration(debugConfig.get());
} else {
out.println("WARNING: The APKs won't be signed and thus not installable unless you also pass a " + "keystore via the flag --ks. See the command help for more information.");
}
}
}
use of com.android.tools.build.bundletool.model.SignerConfig in project bundletool by google.
the class BuildApksCommandTest method populateLineage_apkFile.
@Test
public void populateLineage_apkFile() throws Exception {
SigningCertificateLineage.SignerConfig signerConfig = new SigningCertificateLineage.SignerConfig.Builder(privateKey, certificate).build();
SigningCertificateLineage.SignerConfig oldestSignerConfig = new SigningCertificateLineage.SignerConfig.Builder(oldestSignerPrivateKey, oldestSignerCertificate).build();
SigningCertificateLineage lineage = new SigningCertificateLineage.Builder(oldestSignerConfig, signerConfig).build();
com.android.tools.build.bundletool.model.SignerConfig oldestSigner = com.android.tools.build.bundletool.model.SignerConfig.builder().setPrivateKey(oldestSignerPrivateKey).setCertificates(ImmutableList.of(oldestSignerCertificate)).build();
TestComponent.useTestModule(this, TestModule.builder().withSigningConfig(SigningConfiguration.builder().setSignerConfig(privateKey, certificate).setSigningCertificateLineage(lineage).setOldestSigner(oldestSigner).build()).build());
File lineageFile = createMinimalistSignedApkFile().toFile();
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--lineage=" + lineageFile, "--oldest-signer=" + oldestSignerPropertiesPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
assertThat(signingConfiguration.getSigningCertificateLineage().get().getCertificatesInLineage()).containsExactly(oldestSignerCertificate, certificate);
assertThat(signingConfiguration.getOldestSigner().get().getPrivateKey()).isEqualTo(oldestSignerConfig.getPrivateKey());
assertThat(signingConfiguration.getOldestSigner().get().getCertificates()).containsExactly(oldestSignerConfig.getCertificate());
}
use of com.android.tools.build.bundletool.model.SignerConfig in project bundletool by google.
the class BuildApksCommand method populateSigningConfigurationFromFlags.
private static void populateSigningConfigurationFromFlags(Builder buildApksCommand, ParsedFlags flags, PrintStream out, SystemEnvironmentProvider systemEnvironmentProvider) {
// Signing-related arguments.
Optional<Path> keystorePath = KEYSTORE_FLAG.getValue(flags);
Optional<String> keyAlias = KEY_ALIAS_FLAG.getValue(flags);
Optional<Password> keystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
Optional<Password> keyPassword = KEY_PASSWORD_FLAG.getValue(flags);
Optional<Integer> minV3RotationApi = MINIMUM_V3_ROTATION_API_VERSION_FLAG.getValue(flags);
Optional<Integer> rotationMinSdkVersion = ROTATION_MINIMUM_SDK_VERSION_FLAG.getValue(flags);
if (keystorePath.isPresent() && keyAlias.isPresent()) {
SignerConfig signerConfig = SignerConfig.extractFromKeystore(keystorePath.get(), keyAlias.get(), keystorePassword, keyPassword);
SigningConfiguration.Builder builder = SigningConfiguration.builder().setSignerConfig(signerConfig).setMinimumV3RotationApiVersion(minV3RotationApi).setRotationMinSdkVersion(rotationMinSdkVersion);
populateLineageFromFlags(builder, flags);
buildApksCommand.setSigningConfiguration(builder.build());
} else if (keystorePath.isPresent() && !keyAlias.isPresent()) {
throw InvalidCommandException.builder().withInternalMessage("Flag --ks-key-alias is required when --ks is set.").build();
} else if (!keystorePath.isPresent() && keyAlias.isPresent()) {
throw InvalidCommandException.builder().withInternalMessage("Flag --ks is required when --ks-key-alias is set.").build();
} else {
// Try to use debug keystore if present.
Optional<SigningConfiguration> debugConfig = DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider);
if (debugConfig.isPresent()) {
out.printf("INFO: The APKs will be signed with the debug keystore found at '%s'.%n", DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.getUnchecked(systemEnvironmentProvider).get());
buildApksCommand.setSigningConfiguration(debugConfig.get());
} else {
out.println("WARNING: The APKs won't be signed and thus not installable unless you also pass a " + "keystore via the flag --ks. See the command help for more information.");
}
}
}
use of com.android.tools.build.bundletool.model.SignerConfig in project bundletool by google.
the class AddTransparencyCommand method fromFlagsInDefaultMode.
private static AddTransparencyCommand fromFlagsInDefaultMode(ParsedFlags flags) {
Path keystorePath = KEYSTORE_FLAG.getRequiredValue(flags);
String keyAlias = KEY_ALIAS_FLAG.getRequiredValue(flags);
Optional<Password> keystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
Optional<Password> keyPassword = KEY_PASSWORD_FLAG.getValue(flags);
SignerConfig signerConfig = SignerConfig.extractFromKeystore(keystorePath, keyAlias, keystorePassword, keyPassword);
AddTransparencyCommand.Builder addTransparencyCommandBuilder = AddTransparencyCommand.builder().setMode(Mode.DEFAULT).setBundlePath(BUNDLE_LOCATION_FLAG.getRequiredValue(flags)).setOutputPath(OUTPUT_FLAG.getRequiredValue(flags)).setDexMergingChoice(DEX_MERGING_CHOICE_FLAG.getValue(flags).orElse(DexMergingChoice.ASK_IN_CONSOLE)).setSignerConfig(signerConfig);
flags.checkNoUnknownFlags();
return addTransparencyCommandBuilder.build();
}
use of com.android.tools.build.bundletool.model.SignerConfig in project bundletool by google.
the class BuildApksCommandTest method populateLineage_binaryFile.
@Test
public void populateLineage_binaryFile() throws Exception {
SigningCertificateLineage.SignerConfig signerConfig = new SigningCertificateLineage.SignerConfig.Builder(privateKey, certificate).build();
SigningCertificateLineage.SignerConfig oldestSignerConfig = new SigningCertificateLineage.SignerConfig.Builder(oldestSignerPrivateKey, oldestSignerCertificate).build();
SigningCertificateLineage lineage = new SigningCertificateLineage.Builder(oldestSignerConfig, signerConfig).build();
File lineageFile = tmpDir.resolve("lineage-file").toFile();
lineage.writeToFile(lineageFile);
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--lineage=" + lineageFile, "--oldest-signer=" + oldestSignerPropertiesPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
assertThat(signingConfiguration.getSigningCertificateLineage().get().getCertificatesInLineage()).containsExactly(oldestSignerCertificate, certificate);
assertThat(signingConfiguration.getOldestSigner().get().getPrivateKey()).isEqualTo(oldestSignerConfig.getPrivateKey());
assertThat(signingConfiguration.getOldestSigner().get().getCertificates()).containsExactly(oldestSignerConfig.getCertificate());
}
Aggregations