Example usage for io.netty.handler.ssl OpenSsl unavailabilityCause

List of usage examples for io.netty.handler.ssl OpenSsl unavailabilityCause

Introduction

In this page you can find the example usage for io.netty.handler.ssl OpenSsl unavailabilityCause.

Prototype

public static Throwable unavailabilityCause() 

Source Link

Document

Returns the cause of unavailability of <a href="https://netty.io/wiki/forked-tomcat-native.html"> netty-tcnative </a> and its OpenSSL support.

Usage

From source file:blazingcache.network.netty.NetworkUtils.java

License:Apache License

public static boolean isOpenSslAvailable() {
    if (openSslAvailable != null) {
        return openSslAvailable;
    }//from www. ja  va 2s  .c o  m
    if (ENABLE_OPENSSL && OpenSsl.isAvailable()) {
        OpenSsl.ensureAvailability();
        openSslAvailable = true;
    } else {
        Throwable cause = OpenSsl.unavailabilityCause();
        LOG.log(Level.INFO, "Native OpenSSL support is not available on this platform: " + cause);
        openSslAvailable = false;
    }
    return openSslAvailable;
}

From source file:co.elastic.tealess.cli.EnvironmentCommand.java

License:Apache License

private void showNettyDetails() {
    if (OpenSsl.isAvailable()) {
        System.out.printf("Netty OpenSSL support is available.\n");
    } else {/* w  w  w . jav a2  s  .c o  m*/
        Throwable e = OpenSsl.unavailabilityCause();
        System.out.printf("Netty's OpenSSL layer could not be loaded: %s\n", e.getMessage());
    }

    System.out.println("Netty details:");
    Map<String, Version> nettyComponents = Version.identify();
    Version.identify().forEach((k, v) -> {
        if (k.contains("tcnative")) {
            System.out.printf("  %s\n", v);
        }
    });

}

From source file:com.floragunn.searchguard.SGTests.java

License:Apache License

@Test
public void testEnsureOpenSSLAvailability() {

    if (allowOpenSSL) {
        Assert.assertTrue(String.valueOf(OpenSsl.unavailabilityCause()), OpenSsl.isAvailable());
    }
}

From source file:com.floragunn.searchguard.ssl.DefaultSearchGuardKeyStore.java

License:Apache License

private void logOpenSSLInfos() {
    if (OpenSsl.isAvailable()) {
        log.info("Open SSL " + OpenSsl.versionString() + " available");
        log.debug("Open SSL available ciphers " + OpenSsl.availableCipherSuites());
    } else {//  w  w w  . ja v a  2 s.c  om
        log.info(
                "Open SSL not available (this is not an error, we simply fallback to built-in JDK SSL) because of "
                        + OpenSsl.unavailabilityCause());
    }
}

From source file:com.floragunn.searchguard.ssl.OpenSSLTest.java

License:Apache License

@Test
public void testEnsureOpenSSLAvailability() {
    Assert.assertTrue("OpenSSL not available: " + String.valueOf(OpenSsl.unavailabilityCause()),
            OpenSsl.isAvailable());//from w ww.  jav  a  2s  .  co m

    /*String allowOpenSSLProperty = System.getenv("SG_ALLOW_OPENSSL");
    System.out.println("SG_ALLOW_OPENSSL "+allowOpenSSLProperty);
    if(Boolean.parseBoolean(allowOpenSSLProperty)) {
    System.out.println("OpenSSL must be available");
    Assert.assertTrue(String.valueOf(OpenSsl.unavailabilityCause()), OpenSsl.isAvailable());
    } else {
    System.out.println("OpenSSL can be available");
    }*/
}

From source file:com.floragunn.searchguard.ssl.rest.SearchGuardSSLInfoAction.java

License:Apache License

@Override
protected void handleRequest(final RestRequest request, final RestChannel channel, final Client client)
        throws Exception {

    BytesRestResponse response = null;/*from   w  w w. j  a va 2 s  .  c o m*/
    XContentBuilder builder = channel.newBuilder();

    try {

        final X509Certificate[] certs = request.getFromContext("_sg_ssl_peer_certificates");
        builder.startObject();

        builder.field("principal", (String) request.getFromContext("_sg_ssl_principal"));
        builder.field("peer_certificates", certs != null && certs.length > 0 ? certs.length + "" : "0");
        builder.field("ssl_protocol", (String) request.getFromContext("_sg_ssl_protocol"));
        builder.field("ssl_cipher", (String) request.getFromContext("_sg_ssl_cipher"));
        builder.field("ssl_openssl_available", OpenSsl.isAvailable());
        builder.field("ssl_openssl_version", OpenSsl.version());
        builder.field("ssl_openssl_version_string", OpenSsl.versionString());
        Throwable openSslUnavailCause = OpenSsl.unavailabilityCause();
        builder.field("ssl_openssl_non_available_cause",
                openSslUnavailCause == null ? "" : openSslUnavailCause.toString());
        builder.field("ssl_provider_http", sgks.getHTTPProviderName());
        builder.field("ssl_provider_transport_server", sgks.getTransportServerProviderName());
        builder.field("ssl_provider_transport_client", sgks.getTransportClientProviderName());
        builder.endObject();

        response = new BytesRestResponse(RestStatus.OK, builder);
    } catch (final Exception e1) {
        logger.error("Error handle request " + e1, e1);
        builder = channel.newBuilder();
        builder.startObject();
        builder.field("error", e1.toString());
        builder.endObject();
        response = new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, builder);
    }

    channel.sendResponse(response);
}

From source file:com.github.ibole.microservice.rpc.client.grpc.GrpcClientInitializer.java

License:Apache License

public GrpcClientInitializer(ClientOptions pClientOptions, List<ClientInterceptor> clientInterceptosr,
        int pInitialCapacity, int pMaximumSize) {
    LOG.info("Rpc client initializer with initial capacity {} and maximum size {} for channel pool.",
            pInitialCapacity, pInitialCapacity);
    LOG.info("Global client options: \n'{}'.", pClientOptions);

    if (!isAlpnProviderEnabled()) {
        LOG.error("Neither Jetty ALPN nor OpenSSL are available. " + "OpenSSL unavailability cause:\n{}",
                OpenSsl.unavailabilityCause().toString());
        throw new IllegalStateException(
                "Neither Jetty ALPN nor OpenSSL via " + "netty-tcnative were properly configured.");
    }//from   w w  w  .j ava 2  s .  co m

    Preconditions.checkState(!AbstractNameResolverProvider.providers().isEmpty(),
            "No NameResolverProviders found via ServiceLoader, including for DNS. "
                    + "This is probably due to a broken build. If using ProGuard, check your configuration");

    globalClientOptions = pClientOptions;

    channelPool = createChannelPool(globalClientOptions, clientInterceptosr, pInitialCapacity, pMaximumSize);

    ClientMetrics.counter(MetricLevel.Info, "Initializer.active").inc();
}

From source file:com.google.cloud.bigtable.grpc.BigtableSession.java

License:Open Source License

public BigtableSession(BigtableOptions options) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(options.getProjectId()), PROJECT_ID_EMPTY_OR_NULL);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(options.getZoneId()), ZONE_ID_EMPTY_OR_NULL);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(options.getClusterId()), CLUSTER_ID_EMPTY_OR_NULL);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(options.getUserAgent()), USER_AGENT_EMPTY_OR_NULL);
    LOG.info(/*  w w w  . j a  v  a2s  . c  om*/
            "Opening connection for projectId %s, zoneId %s, clusterId %s, "
                    + "on data host %s, table admin host %s.",
            options.getProjectId(), options.getZoneId(), options.getClusterId(), options.getDataHost(),
            options.getTableAdminHost());
    if (!isAlpnProviderEnabled()) {
        LOG.error("Neither Jetty ALPN nor OpenSSL are available. " + "OpenSSL unavailability cause:\n%s",
                OpenSsl.unavailabilityCause().toString());
        throw new IllegalStateException(
                "Neither Jetty ALPN nor OpenSSL via " + "netty-tcnative were properly configured.");
    }
    this.options = options;

    Builder<HeaderInterceptor> headerInterceptorBuilder = new ImmutableList.Builder<>();

    // Looking up Credentials takes time. Creating the retry executor and the EventLoopGroup don't
    // take as long, but still take time. Get the credentials on one thread, and start up the elg
    // and scheduledRetries thread pools on another thread.
    CredentialInterceptorCache credentialsCache = CredentialInterceptorCache.getInstance();
    RetryOptions retryOptions = options.getRetryOptions();
    CredentialOptions credentialOptions = options.getCredentialOptions();
    try {
        HeaderInterceptor headerInterceptor = credentialsCache.getCredentialsInterceptor(credentialOptions,
                retryOptions);
        if (headerInterceptor != null) {
            headerInterceptorBuilder.add(headerInterceptor);
        }
    } catch (GeneralSecurityException e) {
        throw new IOException("Could not initialize credentials.", e);
    }

    headerInterceptors = headerInterceptorBuilder.build();

    ChannelPool dataChannel = createChannelPool(options.getDataHost());

    BigtableSessionSharedThreadPools sharedPools = BigtableSessionSharedThreadPools.getInstance();

    // More often than not, users want the dataClient. Create a new one in the constructor.
    this.dataClient = new BigtableDataGrpcClient(dataChannel, sharedPools.getRetryExecutor(), options);

    // Defer the creation of both the tableAdminClient and clusterAdminClient until we need them.
}

From source file:com.google.cloud.compatchecker.GoogleCloudCompatChecker.java

License:Apache License

public static boolean check() {
    Properties osProperties = new Properties();
    new OsDetector().detect(osProperties, Lists.<String>newArrayList());

    String bitMode = System.getProperty("sun.arch.data.model");

    boolean openSslIsAvailable = OpenSsl.isAvailable();
    boolean openSslAlpnIsSupported = OpenSsl.isAlpnSupported();
    String javaVersion = Runtime.class.getPackage().getImplementationVersion();
    String javaSpecificationVersion = System.getProperty("java.specification.version");

    System.out.println("OS details:");
    System.out.println("  " + Detector.DETECTED_NAME + ": " + osProperties.get(Detector.DETECTED_NAME));
    System.out.println("  " + Detector.DETECTED_ARCH + ": " + osProperties.get(Detector.DETECTED_ARCH));
    System.out.println(// www .j a  v  a 2  s .  c om
            "  " + Detector.DETECTED_CLASSIFIER + ": " + osProperties.get(Detector.DETECTED_CLASSIFIER));
    System.out.println("  " + Detector.DETECTED_RELEASE + ": " + osProperties.get(Detector.DETECTED_RELEASE));
    System.out.println("  " + Detector.DETECTED_RELEASE_VERSION + ": "
            + osProperties.get(Detector.DETECTED_RELEASE_VERSION));
    System.out.println("JVM details:");
    System.out.println("  Java version: " + javaVersion);
    System.out.println("  Java specification version: " + javaSpecificationVersion);
    System.out.println("  JVM bit mode: " + bitMode);
    System.out.println("OpenSSL details:");
    System.out.println("  open ssl is available: " + openSslIsAvailable);
    System.out.println("  ALPN is supported: " + openSslAlpnIsSupported);

    String osClassifier = (String) osProperties.get(Detector.DETECTED_CLASSIFIER);

    boolean compatible = true;
    boolean warnings = false;
    System.out.println("Checking compatibility...");
    if (supportedClassifiers.contains(osClassifier)) {
        System.out.println("  [PASS] This OS + architecture is supported.");
    } else {
        System.out.println("  [FAIL] This OS + architecture is NOT supported.");
        compatible = false;
    }
    if (bitMode.equals("64")) {
        System.out.println("  [PASS] 64-bit JVM is supported.");
    } else {
        System.out.println("  [FAIL] " + bitMode + "-bit JVM is NOT supported.");
        compatible = false;
    }
    if (openSslIsAvailable) {
        System.out.println("  [PASS] Open SSL is available");
    } else {
        System.out.println("  [FAIL] Open SSL is NOT available");
        if (OpenSsl.unavailabilityCause() != null) {
            System.out.println("         Open SSL Unavailability cause:");
            OpenSsl.unavailabilityCause().printStackTrace(System.out);
        }
        compatible = false;
    }
    if (openSslAlpnIsSupported) {
        System.out.println("  [PASS] Open SSL ALPN is supported");
    } else {
        System.out.println("  [FAIL] Open SSL ALPN is NOT supported");
        compatible = false;
    }
    if (javaSpecificationVersion == null) {
        System.out.println("  [WARN] Couldn't detect java specification version.");
        warnings = true;
    } else if (javaSpecificationVersion.equals("1.7")) {
        System.out.println("  [WARN] gRPC doesn't work on Google App Engine Standard under Java 1.7");
        warnings = true;
    }
    if (!compatible) {
        System.out.println("Result: FAIL");
        System.out.println("  Your environment is not supported by Forked Tomcat Native.");
        System.out.println("  See http://netty.io/wiki/forked-tomcat-native.html for details.");
        System.out.println("  This means that you won't be able to use grpc-based APIs, but");
        System.out.println("  http1-based APIs should still work.");
    } else {
        System.out.println("Result: UNKNOWN (checker implementation not complete)");
        System.out.println("  Based on what was checked, nothing was identified that would");
        System.out.println("  prevent you from using grpc-based APIs.");
        if (warnings) {
            System.out.println("  However, there were some warnings to watch out for.");
        }
    }

    return compatible;
}

From source file:com.linecorp.armeria.common.util.NativeLibraries.java

License:Apache License

/**
 * Logs the availability of the native libraries used by Armeria. This method does nothing if it was
 * called once before.//from w  w  w . ja va  2s . c  o m
 */
public static void report() {
    if (!reported.compareAndSet(false, true)) {
        return;
    }

    if (USE_EPOLL) {
        logger.info("/dev/epoll: "
                + (Epoll.isAvailable() ? "yes" : "no (" + filterCause(Epoll.unavailabilityCause()) + ')'));
    } else {
        logger.info("/dev/epoll: disabled");
    }

    if (USE_OPENSSL) {
        logger.info("OpenSSL: "
                + (OpenSsl.isAvailable() ? "yes (" + OpenSsl.versionString() + ", " + OpenSsl.version() + ')'
                        : "no (" + filterCause(OpenSsl.unavailabilityCause()) + ')'));
    } else {
        logger.info("OpenSSL: disabled");
    }
}