Search in sources :

Example 1 with BuildTreeDefinedKeys

use of org.gradle.api.internal.artifacts.verification.signatures.BuildTreeDefinedKeys in project gradle by gradle.

the class WriteDependencyVerificationFile method exportKeyRingCollection.

private void exportKeyRingCollection(PublicKeyService publicKeyService, BuildTreeDefinedKeys keyrings, Set<String> publicKeys) throws IOException {
    List<PGPPublicKeyRing> existingRings = loadExistingKeyRing(keyrings);
    PGPPublicKeyRingListBuilder builder = new PGPPublicKeyRingListBuilder();
    for (String publicKey : publicKeys) {
        if (publicKey.length() <= 16) {
            publicKeyService.findByLongId(new BigInteger(publicKey, 16).longValue(), builder);
        } else {
            publicKeyService.findByFingerprint(Fingerprint.fromString(publicKey).getBytes(), builder);
        }
    }
    List<PGPPublicKeyRing> keysSeenInVerifier = builder.build().stream().filter(WriteDependencyVerificationFile::hasAtLeastOnePublicKey).filter(e -> existingRings.stream().noneMatch(ring -> keyIds(ring).equals(keyIds(e)))).collect(Collectors.toList());
    ImmutableList<PGPPublicKeyRing> allKeyRings = ImmutableList.<PGPPublicKeyRing>builder().addAll(existingRings).addAll(keysSeenInVerifier).build();
    File keyringFile = keyrings.getBinaryKeyringsFile();
    writeBinaryKeyringFile(keyringFile, allKeyRings);
    File asciiArmoredFile = keyrings.getAsciiKeyringsFile();
    writeAsciiArmoredKeyRingFile(asciiArmoredFile, allKeyRings);
    LOGGER.lifecycle("Exported {} keys to {} and {}", allKeyRings.size(), keyringFile, asciiArmoredFile);
}
Also used : DependencyVerificationOverride(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride) SignatureVerificationResultBuilder(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationResultBuilder) ChecksumService(org.gradle.internal.hash.ChecksumService) UncheckedException(org.gradle.internal.UncheckedException) PublicKeyService(org.gradle.security.internal.PublicKeyService) ModuleComponentRepository(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ModuleComponentRepository) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) DependencyVerificationException(org.gradle.api.internal.artifacts.verification.DependencyVerificationException) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) BigInteger(java.math.BigInteger) ChecksumKind(org.gradle.api.internal.artifacts.verification.model.ChecksumKind) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.gradle.api.Project) Files.getNameWithoutExtension(com.google.common.io.Files.getNameWithoutExtension) DependencyVerificationsXmlReader(org.gradle.api.internal.artifacts.verification.serializer.DependencyVerificationsXmlReader) SignatureVerificationServiceFactory(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationServiceFactory) DependencyVerifier(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerifier) Set(java.util.Set) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) IgnoredKey(org.gradle.api.internal.artifacts.verification.model.IgnoredKey) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Gradle(org.gradle.api.invocation.Gradle) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) ArtifactView(org.gradle.api.artifacts.ArtifactView) List(java.util.List) Stream(java.util.stream.Stream) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) DefaultKeyServers(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DefaultKeyServers) Factory(org.gradle.internal.Factory) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) DependencyVerifyingModuleComponentRepository(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.DependencyVerifyingModuleComponentRepository) DependencyVerificationConfiguration(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerificationConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) UncheckedIOException(org.gradle.api.UncheckedIOException) Logger(org.gradle.api.logging.Logger) BuildOperationQueue(org.gradle.internal.operations.BuildOperationQueue) Configuration(org.gradle.api.artifacts.Configuration) ArtifactVerificationOperation(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.ArtifactVerificationOperation) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) ImmutableList(com.google.common.collect.ImmutableList) BuildTreeDefinedKeys(org.gradle.api.internal.artifacts.verification.signatures.BuildTreeDefinedKeys) DependencyVerificationsXmlWriter(org.gradle.api.internal.artifacts.verification.serializer.DependencyVerificationsXmlWriter) Fingerprint(org.gradle.security.internal.Fingerprint) OutputStream(java.io.OutputStream) PublicKeyResultBuilder(org.gradle.security.internal.PublicKeyResultBuilder) Action(org.gradle.api.Action) Iterator(java.util.Iterator) SignatureVerificationService(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationService) DependencyVerifierBuilder(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerifierBuilder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ResolutionStrategyInternal(org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal) ArmoredOutputStream(org.bouncycastle.bcpg.ArmoredOutputStream) Logging(org.gradle.api.logging.Logging) SecuritySupport(org.gradle.security.internal.SecuritySupport) ModuleComponentArtifactIdentifier(org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) PGPUtils(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.utils.PGPUtils) Collections(java.util.Collections) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) BigInteger(java.math.BigInteger) File(java.io.File)

Example 2 with BuildTreeDefinedKeys

use of org.gradle.api.internal.artifacts.verification.signatures.BuildTreeDefinedKeys in project gradle by gradle.

the class WriteDependencyVerificationFile method exportKeys.

private void exportKeys(SignatureVerificationService signatureVerificationService, DependencyVerifier verifier) throws IOException {
    BuildTreeDefinedKeys keys = isDryRun ? keyrings.dryRun() : keyrings;
    Set<String> keysToExport = Sets.newHashSet();
    verifier.getConfiguration().getTrustedKeys().stream().map(DependencyVerificationConfiguration.TrustedKey::getKeyId).forEach(keysToExport::add);
    verifier.getConfiguration().getIgnoredKeys().stream().map(IgnoredKey::getKeyId).forEach(keysToExport::add);
    verifier.getVerificationMetadata().stream().flatMap(md -> md.getArtifactVerifications().stream()).flatMap(avm -> Stream.concat(avm.getTrustedPgpKeys().stream(), avm.getIgnoredPgpKeys().stream().map(IgnoredKey::getKeyId))).forEach(keysToExport::add);
    exportKeyRingCollection(signatureVerificationService.getPublicKeyService(), keys, keysToExport);
}
Also used : DependencyVerificationOverride(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride) SignatureVerificationResultBuilder(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationResultBuilder) ChecksumService(org.gradle.internal.hash.ChecksumService) UncheckedException(org.gradle.internal.UncheckedException) PublicKeyService(org.gradle.security.internal.PublicKeyService) ModuleComponentRepository(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ModuleComponentRepository) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) DependencyVerificationException(org.gradle.api.internal.artifacts.verification.DependencyVerificationException) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) BigInteger(java.math.BigInteger) ChecksumKind(org.gradle.api.internal.artifacts.verification.model.ChecksumKind) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.gradle.api.Project) Files.getNameWithoutExtension(com.google.common.io.Files.getNameWithoutExtension) DependencyVerificationsXmlReader(org.gradle.api.internal.artifacts.verification.serializer.DependencyVerificationsXmlReader) SignatureVerificationServiceFactory(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationServiceFactory) DependencyVerifier(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerifier) Set(java.util.Set) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) IgnoredKey(org.gradle.api.internal.artifacts.verification.model.IgnoredKey) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Gradle(org.gradle.api.invocation.Gradle) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) ArtifactView(org.gradle.api.artifacts.ArtifactView) List(java.util.List) Stream(java.util.stream.Stream) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) DefaultKeyServers(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DefaultKeyServers) Factory(org.gradle.internal.Factory) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) DependencyVerifyingModuleComponentRepository(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.DependencyVerifyingModuleComponentRepository) DependencyVerificationConfiguration(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerificationConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) UncheckedIOException(org.gradle.api.UncheckedIOException) Logger(org.gradle.api.logging.Logger) BuildOperationQueue(org.gradle.internal.operations.BuildOperationQueue) Configuration(org.gradle.api.artifacts.Configuration) ArtifactVerificationOperation(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.ArtifactVerificationOperation) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) ImmutableList(com.google.common.collect.ImmutableList) BuildTreeDefinedKeys(org.gradle.api.internal.artifacts.verification.signatures.BuildTreeDefinedKeys) DependencyVerificationsXmlWriter(org.gradle.api.internal.artifacts.verification.serializer.DependencyVerificationsXmlWriter) Fingerprint(org.gradle.security.internal.Fingerprint) OutputStream(java.io.OutputStream) PublicKeyResultBuilder(org.gradle.security.internal.PublicKeyResultBuilder) Action(org.gradle.api.Action) Iterator(java.util.Iterator) SignatureVerificationService(org.gradle.api.internal.artifacts.verification.signatures.SignatureVerificationService) DependencyVerifierBuilder(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerifierBuilder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ResolutionStrategyInternal(org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal) ArmoredOutputStream(org.bouncycastle.bcpg.ArmoredOutputStream) Logging(org.gradle.api.logging.Logging) SecuritySupport(org.gradle.security.internal.SecuritySupport) ModuleComponentArtifactIdentifier(org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) PGPUtils(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.utils.PGPUtils) Collections(java.util.Collections) BuildTreeDefinedKeys(org.gradle.api.internal.artifacts.verification.signatures.BuildTreeDefinedKeys) DependencyVerificationConfiguration(org.gradle.api.internal.artifacts.verification.verifier.DependencyVerificationConfiguration)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Sets (com.google.common.collect.Sets)2 Files.getNameWithoutExtension (com.google.common.io.Files.getNameWithoutExtension)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 BigInteger (java.math.BigInteger)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ArmoredOutputStream (org.bouncycastle.bcpg.ArmoredOutputStream)2