Search in sources :

Example 1 with SignerConfig

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.");
        }
    }
}
Also used : Path(java.nio.file.Path) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) Password(com.android.tools.build.bundletool.model.Password)

Example 2 with SignerConfig

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());
}
Also used : PrintStream(java.io.PrintStream) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) DeviceFactory.createDeviceSpecFile(com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile) File(java.io.File) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) Test(org.junit.Test)

Example 3 with SignerConfig

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.");
        }
    }
}
Also used : Path(java.nio.file.Path) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) Password(com.android.tools.build.bundletool.model.Password)

Example 4 with SignerConfig

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();
}
Also used : Path(java.nio.file.Path) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) Password(com.android.tools.build.bundletool.model.Password)

Example 5 with SignerConfig

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());
}
Also used : PrintStream(java.io.PrintStream) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) DeviceFactory.createDeviceSpecFile(com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile) File(java.io.File) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) Test(org.junit.Test)

Aggregations

SignerConfig (com.android.tools.build.bundletool.model.SignerConfig)5 SigningConfiguration (com.android.tools.build.bundletool.model.SigningConfiguration)4 Password (com.android.tools.build.bundletool.model.Password)3 Path (java.nio.file.Path)3 SigningCertificateLineage (com.android.apksig.SigningCertificateLineage)2 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)2 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)2 ApksigSigningConfiguration (com.android.tools.build.bundletool.model.ApksigSigningConfiguration)2 DeviceFactory.createDeviceSpecFile (com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Test (org.junit.Test)2