1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.netty.handler.ssl;
18
19 import org.apache.tomcat.jni.Library;
20 import org.apache.tomcat.jni.SSL;
21 import org.jboss.netty.logging.InternalLogger;
22 import org.jboss.netty.logging.InternalLoggerFactory;
23 import org.jboss.netty.util.internal.NativeLibraryLoader;
24
25
26
27
28
29 public final class OpenSsl {
30
31 private static final InternalLogger logger = InternalLoggerFactory.getInstance(OpenSsl.class);
32 private static final Throwable UNAVAILABILITY_CAUSE;
33
34 static final String IGNORABLE_ERROR_PREFIX = "error:00000000:";
35
36 static {
37 Throwable cause = null;
38 try {
39 NativeLibraryLoader.load("netty-tcnative", SSL.class.getClassLoader());
40 Library.initialize("provided");
41 SSL.initialize(null);
42 } catch (Throwable t) {
43 cause = t;
44 logger.debug(
45 "Failed to load netty-tcnative; " +
46 OpenSslEngine.class.getSimpleName() + " will be unavailable.", t);
47 }
48 UNAVAILABILITY_CAUSE = cause;
49 }
50
51
52
53
54
55
56 public static boolean isAvailable() {
57 return UNAVAILABILITY_CAUSE == null;
58 }
59
60
61
62
63
64
65
66 public static void ensureAvailability() {
67 if (UNAVAILABILITY_CAUSE != null) {
68 throw (Error) new UnsatisfiedLinkError(
69 "failed to load the required native library").initCause(UNAVAILABILITY_CAUSE);
70 }
71 }
72
73
74
75
76
77
78
79 public static Throwable unavailabilityCause() {
80 return UNAVAILABILITY_CAUSE;
81 }
82
83 private OpenSsl() { }
84 }