Search in sources :

Example 1 with MongoKeyDecryptor

use of com.mongodb.crypt.capi.MongoKeyDecryptor in project mongo-java-driver by mongodb.

the class KeyManagementService method decryptKey.

Mono<Void> decryptKey(final MongoKeyDecryptor keyDecryptor) {
    SocketSettings socketSettings = SocketSettings.builder().connectTimeout(timeoutMillis, MILLISECONDS).readTimeout(timeoutMillis, MILLISECONDS).build();
    StreamFactory streamFactory = tlsChannelStreamFactoryFactory.create(socketSettings, SslSettings.builder().enabled(true).context(kmsProviderSslContextMap.get(keyDecryptor.getKmsProvider())).build());
    ServerAddress serverAddress = new ServerAddress(keyDecryptor.getHostName());
    LOGGER.info("Connecting to KMS server at " + serverAddress);
    return Mono.<Void>create(sink -> {
        Stream stream = streamFactory.create(serverAddress);
        stream.openAsync(new AsyncCompletionHandler<Void>() {

            @Override
            public void completed(final Void ignored) {
                streamWrite(stream, keyDecryptor, sink);
            }

            @Override
            public void failed(final Throwable t) {
                stream.close();
                sink.error(t);
            }
        });
    }).onErrorMap(this::unWrapException);
}
Also used : ServerAddress(com.mongodb.ServerAddress) SslSettings(com.mongodb.connection.SslSettings) StreamFactory(com.mongodb.connection.StreamFactory) ByteBuf(org.bson.ByteBuf) SSLContext(javax.net.ssl.SSLContext) MongoKeyDecryptor(com.mongodb.crypt.capi.MongoKeyDecryptor) CompletionHandler(java.nio.channels.CompletionHandler) Mono(reactor.core.publisher.Mono) MonoSink(reactor.core.publisher.MonoSink) MongoSocketException(com.mongodb.MongoSocketException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) AsynchronousChannelStream(com.mongodb.internal.connection.AsynchronousChannelStream) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) SocketSettings(com.mongodb.connection.SocketSettings) Loggers(com.mongodb.diagnostics.logging.Loggers) Closeable(java.io.Closeable) Map(java.util.Map) Stream(com.mongodb.connection.Stream) ByteBufNIO(org.bson.ByteBufNIO) AsyncCompletionHandler(com.mongodb.connection.AsyncCompletionHandler) Logger(com.mongodb.diagnostics.logging.Logger) TlsChannelStreamFactoryFactory(com.mongodb.connection.TlsChannelStreamFactoryFactory) AsyncCompletionHandler(com.mongodb.connection.AsyncCompletionHandler) StreamFactory(com.mongodb.connection.StreamFactory) ServerAddress(com.mongodb.ServerAddress) AsynchronousChannelStream(com.mongodb.internal.connection.AsynchronousChannelStream) Stream(com.mongodb.connection.Stream) SocketSettings(com.mongodb.connection.SocketSettings)

Example 2 with MongoKeyDecryptor

use of com.mongodb.crypt.capi.MongoKeyDecryptor in project mongo-java-driver by mongodb.

the class Crypt method decryptKeys.

private void decryptKeys(final MongoCryptContext cryptContext) {
    try {
        MongoKeyDecryptor keyDecryptor = cryptContext.nextKeyDecryptor();
        while (keyDecryptor != null) {
            decryptKey(keyDecryptor);
            keyDecryptor = cryptContext.nextKeyDecryptor();
        }
        cryptContext.completeKeyDecryptors();
    } catch (Throwable t) {
        throw wrapInClientException(t);
    }
}
Also used : MongoKeyDecryptor(com.mongodb.crypt.capi.MongoKeyDecryptor)

Aggregations

MongoKeyDecryptor (com.mongodb.crypt.capi.MongoKeyDecryptor)2 MongoSocketException (com.mongodb.MongoSocketException)1 ServerAddress (com.mongodb.ServerAddress)1 AsyncCompletionHandler (com.mongodb.connection.AsyncCompletionHandler)1 SocketSettings (com.mongodb.connection.SocketSettings)1 SslSettings (com.mongodb.connection.SslSettings)1 Stream (com.mongodb.connection.Stream)1 StreamFactory (com.mongodb.connection.StreamFactory)1 TlsChannelStreamFactoryFactory (com.mongodb.connection.TlsChannelStreamFactoryFactory)1 Logger (com.mongodb.diagnostics.logging.Logger)1 Loggers (com.mongodb.diagnostics.logging.Loggers)1 AsynchronousChannelStream (com.mongodb.internal.connection.AsynchronousChannelStream)1 Closeable (java.io.Closeable)1 CompletionHandler (java.nio.channels.CompletionHandler)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 SSLContext (javax.net.ssl.SSLContext)1 ByteBuf (org.bson.ByteBuf)1