-
Notifications
You must be signed in to change notification settings - Fork 0
/
0001-Remove-OpenSSL-parts-depending-on-tcnative.patch
8985 lines (8966 loc) · 380 KB
/
0001-Remove-OpenSSL-parts-depending-on-tcnative.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 39b320920d3473d8cbc94d4a35dad37fa236e278 Mon Sep 17 00:00:00 2001
From: Severin Gehwolf <[email protected]>
Date: Thu, 20 Oct 2016 15:54:52 +0200
Subject: [PATCH 1/3] Remove OpenSSL parts depending on tcnative.
---
handler/pom.xml | 6 -
.../main/java/io/netty/handler/ssl/OpenSsl.java | 503 -----
.../handler/ssl/OpenSslCertificateException.java | 79 -
.../io/netty/handler/ssl/OpenSslClientContext.java | 211 --
.../java/io/netty/handler/ssl/OpenSslContext.java | 58 -
.../java/io/netty/handler/ssl/OpenSslEngine.java | 40 -
.../io/netty/handler/ssl/OpenSslEngineMap.java | 35 -
.../ssl/OpenSslExtendedKeyMaterialManager.java | 40 -
.../handler/ssl/OpenSslKeyMaterialManager.java | 179 --
.../io/netty/handler/ssl/OpenSslServerContext.java | 373 ----
.../handler/ssl/OpenSslServerSessionContext.java | 124 --
.../netty/handler/ssl/OpenSslSessionContext.java | 137 --
.../io/netty/handler/ssl/OpenSslSessionStats.java | 253 ---
.../netty/handler/ssl/OpenSslSessionTicketKey.java | 78 -
.../ssl/ReferenceCountedOpenSslClientContext.java | 298 ---
.../ssl/ReferenceCountedOpenSslContext.java | 867 ---------
.../handler/ssl/ReferenceCountedOpenSslEngine.java | 2037 --------------------
.../ssl/ReferenceCountedOpenSslServerContext.java | 239 ---
.../main/java/io/netty/handler/ssl/SslContext.java | 30 +-
.../main/java/io/netty/handler/ssl/SslHandler.java | 47 +-
.../netty/handler/ssl/ocsp/OcspClientHandler.java | 65 -
.../io/netty/handler/ssl/ocsp/package-info.java | 23 -
.../handler/ssl/JdkOpenSslEngineInteroptTest.java | 108 --
.../ssl/OpenSslCertificateExceptionTest.java | 49 -
.../handler/ssl/OpenSslClientContextTest.java | 38 -
.../io/netty/handler/ssl/OpenSslEngineTest.java | 661 -------
.../ssl/OpenSslJdkSslEngineInteroptTest.java | 114 --
.../ssl/OpenSslRenegotiateSmallBIOTest.java | 23 -
.../netty/handler/ssl/OpenSslRenegotiateTest.java | 36 -
.../handler/ssl/OpenSslServerContextTest.java | 39 -
.../io/netty/handler/ssl/OpenSslTestUtils.java | 27 -
.../java/io/netty/handler/ssl/PemEncodedTest.java | 95 -
.../ssl/ReferenceCountedOpenSslEngineTest.java | 57 -
.../java/io/netty/handler/ssl/SniClientTest.java | 161 --
.../java/io/netty/handler/ssl/SniHandlerTest.java | 496 -----
.../netty/handler/ssl/SslContextBuilderTest.java | 132 --
.../java/io/netty/handler/ssl/SslErrorTest.java | 255 ---
.../java/io/netty/handler/ssl/SslHandlerTest.java | 58 +-
.../java/io/netty/handler/ssl/ocsp/OcspTest.java | 501 -----
39 files changed, 10 insertions(+), 8562 deletions(-)
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSsl.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslCertificateException.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslClientContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslEngine.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslEngineMap.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslExtendedKeyMaterialManager.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslKeyMaterialManager.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslServerContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslServerSessionContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslSessionContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslSessionStats.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/OpenSslSessionTicketKey.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslClientContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslServerContext.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/ocsp/OcspClientHandler.java
delete mode 100644 handler/src/main/java/io/netty/handler/ssl/ocsp/package-info.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/JdkOpenSslEngineInteroptTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslCertificateExceptionTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslClientContextTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslEngineTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslJdkSslEngineInteroptTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslRenegotiateSmallBIOTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslRenegotiateTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslServerContextTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/OpenSslTestUtils.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/PemEncodedTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngineTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/SniClientTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/SslContextBuilderTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java
delete mode 100644 handler/src/test/java/io/netty/handler/ssl/ocsp/OcspTest.java
diff --git a/handler/pom.xml b/handler/pom.xml
index 7535c45..d0ed1bc 100644
--- a/handler/pom.xml
+++ b/handler/pom.xml
@@ -50,12 +50,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>${tcnative.artifactId}</artifactId>
- <classifier>${tcnative.classifier}</classifier>
- <optional>true</optional>
- </dependency>
- <dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<optional>true</optional>
diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java b/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java
deleted file mode 100644
index d2f091a..0000000
--- a/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * Copyright 2014 The Netty Project
- *
- * The Netty Project licenses this file to you under the Apache License,
- * version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package io.netty.handler.ssl;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.handler.ssl.util.SelfSignedCertificate;
-import io.netty.util.ReferenceCountUtil;
-import io.netty.util.ReferenceCounted;
-import io.netty.util.internal.NativeLibraryLoader;
-import io.netty.util.internal.SystemPropertyUtil;
-import io.netty.util.internal.logging.InternalLogger;
-import io.netty.util.internal.logging.InternalLoggerFactory;
-import io.netty.internal.tcnative.Buffer;
-import io.netty.internal.tcnative.Library;
-import io.netty.internal.tcnative.SSL;
-import io.netty.internal.tcnative.SSLContext;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * Tells if <a href="http://netty.io/wiki/forked-tomcat-native.html">{@code netty-tcnative}</a> and its OpenSSL support
- * are available.
- */
-public final class OpenSsl {
-
- private static final InternalLogger logger = InternalLoggerFactory.getInstance(OpenSsl.class);
- private static final String LINUX = "linux";
- private static final String UNKNOWN = "unknown";
- private static final Throwable UNAVAILABILITY_CAUSE;
-
- static final Set<String> AVAILABLE_CIPHER_SUITES;
- private static final Set<String> AVAILABLE_OPENSSL_CIPHER_SUITES;
- private static final Set<String> AVAILABLE_JAVA_CIPHER_SUITES;
- private static final boolean SUPPORTS_KEYMANAGER_FACTORY;
- private static final boolean SUPPORTS_HOSTNAME_VALIDATION;
- private static final boolean USE_KEYMANAGER_FACTORY;
- private static final boolean SUPPORTS_OCSP;
-
- // Protocols
- static final String PROTOCOL_SSL_V2_HELLO = "SSLv2Hello";
- static final String PROTOCOL_SSL_V2 = "SSLv2";
- static final String PROTOCOL_SSL_V3 = "SSLv3";
- static final String PROTOCOL_TLS_V1 = "TLSv1";
- static final String PROTOCOL_TLS_V1_1 = "TLSv1.1";
- static final String PROTOCOL_TLS_V1_2 = "TLSv1.2";
-
- static final Set<String> SUPPORTED_PROTOCOLS_SET;
-
- static {
- Throwable cause = null;
-
- // Test if netty-tcnative is in the classpath first.
- try {
- Class.forName("io.netty.internal.tcnative.SSL", false, OpenSsl.class.getClassLoader());
- } catch (ClassNotFoundException t) {
- cause = t;
- logger.debug(
- "netty-tcnative not in the classpath; " +
- OpenSslEngine.class.getSimpleName() + " will be unavailable.");
- }
-
- // If in the classpath, try to load the native library and initialize netty-tcnative.
- if (cause == null) {
- try {
- // The JNI library was not already loaded. Load it now.
- loadTcNative();
- } catch (Throwable t) {
- cause = t;
- logger.debug(
- "Failed to load netty-tcnative; " +
- OpenSslEngine.class.getSimpleName() + " will be unavailable, unless the " +
- "application has already loaded the symbols by some other means. " +
- "See http://netty.io/wiki/forked-tomcat-native.html for more information.", t);
- }
-
- try {
- initializeTcNative();
-
- // The library was initialized successfully. If loading the library failed above,
- // reset the cause now since it appears that the library was loaded by some other
- // means.
- cause = null;
- } catch (Throwable t) {
- if (cause == null) {
- cause = t;
- }
- logger.debug(
- "Failed to initialize netty-tcnative; " +
- OpenSslEngine.class.getSimpleName() + " will be unavailable. " +
- "See http://netty.io/wiki/forked-tomcat-native.html for more information.", t);
- }
- }
-
- UNAVAILABILITY_CAUSE = cause;
-
- if (cause == null) {
- logger.debug("netty-tcnative using native library: {}", SSL.versionString());
-
- final Set<String> availableOpenSslCipherSuites = new LinkedHashSet<String>(128);
- boolean supportsKeyManagerFactory = false;
- boolean useKeyManagerFactory = false;
- boolean supportsHostNameValidation = false;
- try {
- final long sslCtx = SSLContext.make(SSL.SSL_PROTOCOL_ALL, SSL.SSL_MODE_SERVER);
- long certBio = 0;
- SelfSignedCertificate cert = null;
- try {
- SSLContext.setCipherSuite(sslCtx, "ALL");
- final long ssl = SSL.newSSL(sslCtx, true);
- try {
- for (String c: SSL.getCiphers(ssl)) {
- // Filter out bad input.
- if (c == null || c.isEmpty() || availableOpenSslCipherSuites.contains(c)) {
- continue;
- }
- availableOpenSslCipherSuites.add(c);
- }
- try {
- SSL.setHostNameValidation(ssl, 0, "netty.io");
- supportsHostNameValidation = true;
- } catch (Throwable ignore) {
- logger.debug("Hostname Verification not supported.");
- }
- try {
- cert = new SelfSignedCertificate();
- certBio = ReferenceCountedOpenSslContext.toBIO(cert.cert());
- SSL.setCertificateChainBio(ssl, certBio, false);
- supportsKeyManagerFactory = true;
- try {
- useKeyManagerFactory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
- @Override
- public Boolean run() {
- return SystemPropertyUtil.getBoolean(
- "io.netty.handler.ssl.openssl.useKeyManagerFactory", true);
- }
- });
- } catch (Throwable ignore) {
- logger.debug("Failed to get useKeyManagerFactory system property.");
- }
- } catch (Throwable ignore) {
- logger.debug("KeyManagerFactory not supported.");
- }
- } finally {
- SSL.freeSSL(ssl);
- if (certBio != 0) {
- SSL.freeBIO(certBio);
- }
- if (cert != null) {
- cert.delete();
- }
- }
- } finally {
- SSLContext.free(sslCtx);
- }
- } catch (Exception e) {
- logger.warn("Failed to get the list of available OpenSSL cipher suites.", e);
- }
- AVAILABLE_OPENSSL_CIPHER_SUITES = Collections.unmodifiableSet(availableOpenSslCipherSuites);
-
- final Set<String> availableJavaCipherSuites = new LinkedHashSet<String>(
- AVAILABLE_OPENSSL_CIPHER_SUITES.size() * 2);
- for (String cipher: AVAILABLE_OPENSSL_CIPHER_SUITES) {
- // Included converted but also openssl cipher name
- availableJavaCipherSuites.add(CipherSuiteConverter.toJava(cipher, "TLS"));
- availableJavaCipherSuites.add(CipherSuiteConverter.toJava(cipher, "SSL"));
- }
- AVAILABLE_JAVA_CIPHER_SUITES = Collections.unmodifiableSet(availableJavaCipherSuites);
-
- final Set<String> availableCipherSuites = new LinkedHashSet<String>(
- AVAILABLE_OPENSSL_CIPHER_SUITES.size() + AVAILABLE_JAVA_CIPHER_SUITES.size());
- availableCipherSuites.addAll(AVAILABLE_OPENSSL_CIPHER_SUITES);
- availableCipherSuites.addAll(AVAILABLE_JAVA_CIPHER_SUITES);
-
- AVAILABLE_CIPHER_SUITES = availableCipherSuites;
- SUPPORTS_KEYMANAGER_FACTORY = supportsKeyManagerFactory;
- SUPPORTS_HOSTNAME_VALIDATION = supportsHostNameValidation;
- USE_KEYMANAGER_FACTORY = useKeyManagerFactory;
-
- Set<String> protocols = new LinkedHashSet<String>(6);
- // Seems like there is no way to explicitly disable SSLv2Hello in openssl so it is always enabled
- protocols.add(PROTOCOL_SSL_V2_HELLO);
- if (doesSupportProtocol(SSL.SSL_PROTOCOL_SSLV2)) {
- protocols.add(PROTOCOL_SSL_V2);
- }
- if (doesSupportProtocol(SSL.SSL_PROTOCOL_SSLV3)) {
- protocols.add(PROTOCOL_SSL_V3);
- }
- if (doesSupportProtocol(SSL.SSL_PROTOCOL_TLSV1)) {
- protocols.add(PROTOCOL_TLS_V1);
- }
- if (doesSupportProtocol(SSL.SSL_PROTOCOL_TLSV1_1)) {
- protocols.add(PROTOCOL_TLS_V1_1);
- }
- if (doesSupportProtocol(SSL.SSL_PROTOCOL_TLSV1_2)) {
- protocols.add(PROTOCOL_TLS_V1_2);
- }
-
- SUPPORTED_PROTOCOLS_SET = Collections.unmodifiableSet(protocols);
- SUPPORTS_OCSP = doesSupportOcsp();
- } else {
- AVAILABLE_OPENSSL_CIPHER_SUITES = Collections.emptySet();
- AVAILABLE_JAVA_CIPHER_SUITES = Collections.emptySet();
- AVAILABLE_CIPHER_SUITES = Collections.emptySet();
- SUPPORTS_KEYMANAGER_FACTORY = false;
- SUPPORTS_HOSTNAME_VALIDATION = false;
- USE_KEYMANAGER_FACTORY = false;
- SUPPORTED_PROTOCOLS_SET = Collections.emptySet();
- SUPPORTS_OCSP = false;
- }
- }
-
- private static boolean doesSupportOcsp() {
- boolean supportsOcsp = false;
- if (version() >= 0x10002000L) {
- long sslCtx = -1;
- try {
- sslCtx = SSLContext.make(SSL.SSL_PROTOCOL_TLSV1_2, SSL.SSL_MODE_SERVER);
- SSLContext.enableOcsp(sslCtx, false);
- supportsOcsp = true;
- } catch (Exception ignore) {
- // ignore
- } finally {
- if (sslCtx != -1) {
- SSLContext.free(sslCtx);
- }
- }
- }
- return supportsOcsp;
- }
- private static boolean doesSupportProtocol(int protocol) {
- long sslCtx = -1;
- try {
- sslCtx = SSLContext.make(protocol, SSL.SSL_MODE_COMBINED);
- return true;
- } catch (Exception ignore) {
- return false;
- } finally {
- if (sslCtx != -1) {
- SSLContext.free(sslCtx);
- }
- }
- }
-
- /**
- * Returns {@code true} if and only if
- * <a href="http://netty.io/wiki/forked-tomcat-native.html">{@code netty-tcnative}</a> and its OpenSSL support
- * are available.
- */
- public static boolean isAvailable() {
- return UNAVAILABILITY_CAUSE == null;
- }
-
- /**
- * Returns {@code true} if the used version of openssl supports
- * <a href="https://tools.ietf.org/html/rfc7301">ALPN</a>.
- */
- public static boolean isAlpnSupported() {
- return version() >= 0x10002000L;
- }
-
- /**
- * Returns {@code true} if the used version of OpenSSL supports OCSP stapling.
- */
- public static boolean isOcspSupported() {
- return SUPPORTS_OCSP;
- }
-
- /**
- * Returns the version of the used available OpenSSL library or {@code -1} if {@link #isAvailable()}
- * returns {@code false}.
- */
- public static int version() {
- return isAvailable() ? SSL.version() : -1;
- }
-
- /**
- * Returns the version string of the used available OpenSSL library or {@code null} if {@link #isAvailable()}
- * returns {@code false}.
- */
- public static String versionString() {
- return isAvailable() ? SSL.versionString() : null;
- }
-
- /**
- * Ensure that <a href="http://netty.io/wiki/forked-tomcat-native.html">{@code netty-tcnative}</a> and
- * its OpenSSL support are available.
- *
- * @throws UnsatisfiedLinkError if unavailable
- */
- public static void ensureAvailability() {
- if (UNAVAILABILITY_CAUSE != null) {
- throw (Error) new UnsatisfiedLinkError(
- "failed to load the required native library").initCause(UNAVAILABILITY_CAUSE);
- }
- }
-
- /**
- * Returns the cause of unavailability of
- * <a href="http://netty.io/wiki/forked-tomcat-native.html">{@code netty-tcnative}</a> and its OpenSSL support.
- *
- * @return the cause if unavailable. {@code null} if available.
- */
- public static Throwable unavailabilityCause() {
- return UNAVAILABILITY_CAUSE;
- }
-
- /**
- * @deprecated use {@link #availableOpenSslCipherSuites()}
- */
- @Deprecated
- public static Set<String> availableCipherSuites() {
- return availableOpenSslCipherSuites();
- }
-
- /**
- * Returns all the available OpenSSL cipher suites.
- * Please note that the returned array may include the cipher suites that are insecure or non-functional.
- */
- public static Set<String> availableOpenSslCipherSuites() {
- return AVAILABLE_OPENSSL_CIPHER_SUITES;
- }
-
- /**
- * Returns all the available cipher suites (Java-style).
- * Please note that the returned array may include the cipher suites that are insecure or non-functional.
- */
- public static Set<String> availableJavaCipherSuites() {
- return AVAILABLE_JAVA_CIPHER_SUITES;
- }
-
- /**
- * Returns {@code true} if and only if the specified cipher suite is available in OpenSSL.
- * Both Java-style cipher suite and OpenSSL-style cipher suite are accepted.
- */
- public static boolean isCipherSuiteAvailable(String cipherSuite) {
- String converted = CipherSuiteConverter.toOpenSsl(cipherSuite);
- if (converted != null) {
- cipherSuite = converted;
- }
- return AVAILABLE_OPENSSL_CIPHER_SUITES.contains(cipherSuite);
- }
-
- /**
- * Returns {@code true} if {@link javax.net.ssl.KeyManagerFactory} is supported when using OpenSSL.
- */
- public static boolean supportsKeyManagerFactory() {
- return SUPPORTS_KEYMANAGER_FACTORY;
- }
-
- /**
- * Returns {@code true} if <a href="https://wiki.openssl.org/index.php/Hostname_validation">Hostname Validation</a>
- * is supported when using OpenSSL.
- */
- public static boolean supportsHostnameValidation() {
- return SUPPORTS_HOSTNAME_VALIDATION;
- }
-
- static boolean useKeyManagerFactory() {
- return USE_KEYMANAGER_FACTORY;
- }
-
- static long memoryAddress(ByteBuf buf) {
- assert buf.isDirect();
- return buf.hasMemoryAddress() ? buf.memoryAddress() : Buffer.address(buf.nioBuffer());
- }
-
- private OpenSsl() { }
-
- private static void loadTcNative() throws Exception {
- String os = normalizeOs(SystemPropertyUtil.get("os.name", ""));
- String arch = normalizeArch(SystemPropertyUtil.get("os.arch", ""));
-
- Set<String> libNames = new LinkedHashSet<String>(4);
- // First, try loading the platform-specific library. Platform-specific
- // libraries will be available if using a tcnative uber jar.
- libNames.add("netty-tcnative-" + os + '-' + arch);
- if (LINUX.equalsIgnoreCase(os)) {
- // Fedora SSL lib so naming (libssl.so.10 vs libssl.so.1.0.0)..
- libNames.add("netty-tcnative-" + os + '-' + arch + "-fedora");
- }
- // finally the default library.
- libNames.add("netty-tcnative");
- // in Java 8, statically compiled JNI code is namespaced
- libNames.add("netty_tcnative");
-
- NativeLibraryLoader.loadFirstAvailable(SSL.class.getClassLoader(),
- libNames.toArray(new String[libNames.size()]));
- }
-
- private static boolean initializeTcNative() throws Exception {
- return Library.initialize();
- }
-
- private static String normalizeOs(String value) {
- value = normalize(value);
- if (value.startsWith("aix")) {
- return "aix";
- }
- if (value.startsWith("hpux")) {
- return "hpux";
- }
- if (value.startsWith("os400")) {
- // Avoid the names such as os4000
- if (value.length() <= 5 || !Character.isDigit(value.charAt(5))) {
- return "os400";
- }
- }
- if (value.startsWith(LINUX)) {
- return LINUX;
- }
- if (value.startsWith("macosx") || value.startsWith("osx")) {
- return "osx";
- }
- if (value.startsWith("freebsd")) {
- return "freebsd";
- }
- if (value.startsWith("openbsd")) {
- return "openbsd";
- }
- if (value.startsWith("netbsd")) {
- return "netbsd";
- }
- if (value.startsWith("solaris") || value.startsWith("sunos")) {
- return "sunos";
- }
- if (value.startsWith("windows")) {
- return "windows";
- }
-
- return UNKNOWN;
- }
-
- private static String normalizeArch(String value) {
- value = normalize(value);
- if (value.matches("^(x8664|amd64|ia32e|em64t|x64)$")) {
- return "x86_64";
- }
- if (value.matches("^(x8632|x86|i[3-6]86|ia32|x32)$")) {
- return "x86_32";
- }
- if (value.matches("^(ia64|itanium64)$")) {
- return "itanium_64";
- }
- if (value.matches("^(sparc|sparc32)$")) {
- return "sparc_32";
- }
- if (value.matches("^(sparcv9|sparc64)$")) {
- return "sparc_64";
- }
- if (value.matches("^(arm|arm32)$")) {
- return "arm_32";
- }
- if ("aarch64".equals(value)) {
- return "aarch_64";
- }
- if (value.matches("^(ppc|ppc32)$")) {
- return "ppc_32";
- }
- if ("ppc64".equals(value)) {
- return "ppc_64";
- }
- if ("ppc64le".equals(value)) {
- return "ppcle_64";
- }
- if ("s390".equals(value)) {
- return "s390_32";
- }
- if ("s390x".equals(value)) {
- return "s390_64";
- }
-
- return UNKNOWN;
- }
-
- private static String normalize(String value) {
- return value.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
- }
-
- static void releaseIfNeeded(ReferenceCounted counted) {
- if (counted.refCnt() > 0) {
- ReferenceCountUtil.safeRelease(counted);
- }
- }
-}
diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslCertificateException.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslCertificateException.java
deleted file mode 100644
index 4672d00..0000000
--- a/handler/src/main/java/io/netty/handler/ssl/OpenSslCertificateException.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016 The Netty Project
- *
- * The Netty Project licenses this file to you under the Apache License,
- * version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-package io.netty.handler.ssl;
-
-import io.netty.internal.tcnative.CertificateVerifier;
-
-import java.security.cert.CertificateException;
-
-/**
- * A special {@link CertificateException} which allows to specify which error code is included in the
- * SSL Record. This only work when {@link SslProvider#OPENSSL} or {@link SslProvider#OPENSSL_REFCNT} is used.
- */
-public final class OpenSslCertificateException extends CertificateException {
- private static final long serialVersionUID = 5542675253797129798L;
-
- private final int errorCode;
-
- /**
- * Construct a new exception with the
- * <a href="https://www.openssl.org/docs/manmaster/apps/verify.html">error code</a>.
- */
- public OpenSslCertificateException(int errorCode) {
- this((String) null, errorCode);
- }
-
- /**
- * Construct a new exception with the msg and
- * <a href="https://www.openssl.org/docs/manmaster/apps/verify.html">error code</a> .
- */
- public OpenSslCertificateException(String msg, int errorCode) {
- super(msg);
- this.errorCode = checkErrorCode(errorCode);
- }
-
- /**
- * Construct a new exception with the msg, cause and
- * <a href="https://www.openssl.org/docs/manmaster/apps/verify.html">error code</a> .
- */
- public OpenSslCertificateException(String message, Throwable cause, int errorCode) {
- super(message, cause);
- this.errorCode = checkErrorCode(errorCode);
- }
-
- /**
- * Construct a new exception with the cause and
- * <a href="https://www.openssl.org/docs/manmaster/apps/verify.html">error code</a> .
- */
- public OpenSslCertificateException(Throwable cause, int errorCode) {
- this(null, cause, errorCode);
- }
-
- /**
- * Return the <a href="https://www.openssl.org/docs/man1.0.2/apps/verify.html">error code</a> to use.
- */
- public int errorCode() {
- return errorCode;
- }
-
- private static int checkErrorCode(int errorCode) {
- if (!CertificateVerifier.isValid(errorCode)) {
- throw new IllegalArgumentException("errorCode '" + errorCode +
- "' invalid, see https://www.openssl.org/docs/man1.0.2/apps/verify.html.");
- }
- return errorCode;
- }
-}
diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslClientContext.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslClientContext.java
deleted file mode 100644
index 46412e9..0000000
--- a/handler/src/main/java/io/netty/handler/ssl/OpenSslClientContext.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright 2014 The Netty Project
- *
- * The Netty Project licenses this file to you under the Apache License,
- * version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-package io.netty.handler.ssl;
-
-import io.netty.internal.tcnative.SSL;
-
-import java.io.File;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
-import static io.netty.handler.ssl.ReferenceCountedOpenSslClientContext.newSessionContext;
-
-/**
- * A client-side {@link SslContext} which uses OpenSSL's SSL/TLS implementation.
- * <p>This class will use a finalizer to ensure native resources are automatically cleaned up. To avoid finalizers
- * and manually release the native memory see {@link ReferenceCountedOpenSslClientContext}.
- */
-public final class OpenSslClientContext extends OpenSslContext {
- private final OpenSslSessionContext sessionContext;
-
- /**
- * Creates a new instance.
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext() throws SSLException {
- this((File) null, null, null, null, null, null, null, IdentityCipherSuiteFilter.INSTANCE, null, 0, 0);
- }
-
- /**
- * Creates a new instance.
- *
- * @param certChainFile an X.509 certificate chain file in PEM format.
- * {@code null} to use the system default
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext(File certChainFile) throws SSLException {
- this(certChainFile, null);
- }
-
- /**
- * Creates a new instance.
- *
- * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
- * that verifies the certificates sent from servers.
- * {@code null} to use the default.
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext(TrustManagerFactory trustManagerFactory) throws SSLException {
- this(null, trustManagerFactory);
- }
-
- /**
- * Creates a new instance.
- *
- * @param certChainFile an X.509 certificate chain file in PEM format.
- * {@code null} to use the system default
- * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
- * that verifies the certificates sent from servers.
- * {@code null} to use the default.
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext(File certChainFile, TrustManagerFactory trustManagerFactory) throws SSLException {
- this(certChainFile, trustManagerFactory, null, null, null, null, null,
- IdentityCipherSuiteFilter.INSTANCE, null, 0, 0);
- }
-
- /**
- * Creates a new instance.
- *
- * @param certChainFile an X.509 certificate chain file in PEM format
- * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
- * that verifies the certificates sent from servers.
- * {@code null} to use the default..
- * @param ciphers the cipher suites to enable, in the order of preference.
- * {@code null} to use the default cipher suites.
- * @param apn Provides a means to configure parameters related to application protocol negotiation.
- * @param sessionCacheSize the size of the cache used for storing SSL session objects.
- * {@code 0} to use the default value.
- * @param sessionTimeout the timeout for the cached SSL session objects, in seconds.
- * {@code 0} to use the default value.
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext(File certChainFile, TrustManagerFactory trustManagerFactory, Iterable<String> ciphers,
- ApplicationProtocolConfig apn, long sessionCacheSize, long sessionTimeout)
- throws SSLException {
- this(certChainFile, trustManagerFactory, null, null, null, null, ciphers, IdentityCipherSuiteFilter.INSTANCE,
- apn, sessionCacheSize, sessionTimeout);
- }
-
- /**
- * Creates a new instance.
- *
- * @param certChainFile an X.509 certificate chain file in PEM format
- * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
- * that verifies the certificates sent from servers.
- * {@code null} to use the default..
- * @param ciphers the cipher suites to enable, in the order of preference.
- * {@code null} to use the default cipher suites.
- * @param cipherFilter a filter to apply over the supplied list of ciphers
- * @param apn Provides a means to configure parameters related to application protocol negotiation.
- * @param sessionCacheSize the size of the cache used for storing SSL session objects.
- * {@code 0} to use the default value.
- * @param sessionTimeout the timeout for the cached SSL session objects, in seconds.
- * {@code 0} to use the default value.
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext(File certChainFile, TrustManagerFactory trustManagerFactory, Iterable<String> ciphers,
- CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn,
- long sessionCacheSize, long sessionTimeout) throws SSLException {
- this(certChainFile, trustManagerFactory, null, null, null, null,
- ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout);
- }
-
- /**
- * Creates a new instance.
- * @param trustCertCollectionFile an X.509 certificate collection file in PEM format.
- * {@code null} to use the system default
- * @param trustManagerFactory the {@link TrustManagerFactory} that provides the {@link TrustManager}s
- * that verifies the certificates sent from servers.
- * {@code null} to use the default or the results of parsing
- * {@code trustCertCollectionFile}
- * @param keyCertChainFile an X.509 certificate chain file in PEM format.
- * This provides the public key for mutual authentication.
- * {@code null} to use the system default
- * @param keyFile a PKCS#8 private key file in PEM format.
- * This provides the private key for mutual authentication.
- * {@code null} for no mutual authentication.
- * @param keyPassword the password of the {@code keyFile}.
- * {@code null} if it's not password-protected.
- * Ignored if {@code keyFile} is {@code null}.
- * @param keyManagerFactory the {@link KeyManagerFactory} that provides the {@link javax.net.ssl.KeyManager}s
- * that is used to encrypt data being sent to servers.
- * {@code null} to use the default or the results of parsing
- * {@code keyCertChainFile} and {@code keyFile}.
- * @param ciphers the cipher suites to enable, in the order of preference.
- * {@code null} to use the default cipher suites.
- * @param cipherFilter a filter to apply over the supplied list of ciphers
- * @param apn Application Protocol Negotiator object.
- * @param sessionCacheSize the size of the cache used for storing SSL session objects.
- * {@code 0} to use the default value.
- * @param sessionTimeout the timeout for the cached SSL session objects, in seconds.
- * {@code 0} to use the default value.
- * @deprecated use {@link SslContextBuilder}
- */
- @Deprecated
- public OpenSslClientContext(File trustCertCollectionFile, TrustManagerFactory trustManagerFactory,
- File keyCertChainFile, File keyFile, String keyPassword,
- KeyManagerFactory keyManagerFactory, Iterable<String> ciphers,
- CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn,
- long sessionCacheSize, long sessionTimeout)
- throws SSLException {
- this(toX509CertificatesInternal(trustCertCollectionFile), trustManagerFactory,
- toX509CertificatesInternal(keyCertChainFile), toPrivateKeyInternal(keyFile, keyPassword),
- keyPassword, keyManagerFactory, ciphers, cipherFilter, apn, null, sessionCacheSize,
- sessionTimeout, false);
- }
-
- OpenSslClientContext(X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory,
- X509Certificate[] keyCertChain, PrivateKey key, String keyPassword,
- KeyManagerFactory keyManagerFactory, Iterable<String> ciphers,
- CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn, String[] protocols,
- long sessionCacheSize, long sessionTimeout, boolean enableOcsp)
- throws SSLException {
- super(ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout, SSL.SSL_MODE_CLIENT, keyCertChain,
- ClientAuth.NONE, protocols, false, enableOcsp);
- boolean success = false;
- try {
- sessionContext = newSessionContext(this, ctx, engineMap, trustCertCollection, trustManagerFactory,
- keyCertChain, key, keyPassword, keyManagerFactory);
- success = true;
- } finally {
- if (!success) {
- release();
- }
- }
- }
-
- @Override
- public OpenSslSessionContext sessionContext() {
- return sessionContext;
- }
-
- @Override
- OpenSslKeyMaterialManager keyMaterialManager() {
- return null;
- }
-}
diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslContext.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslContext.java
deleted file mode 100644
index c4ca6b5..0000000
--- a/handler/src/main/java/io/netty/handler/ssl/OpenSslContext.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2014 The Netty Project
- *
- * The Netty Project licenses this file to you under the Apache License,
- * version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-package io.netty.handler.ssl;
-
-import io.netty.buffer.ByteBufAllocator;
-
-import java.security.cert.Certificate;
-
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLException;
-
-/**
- * This class will use a finalizer to ensure native resources are automatically cleaned up. To avoid finalizers
- * and manually release the native memory see {@link ReferenceCountedOpenSslContext}.
- */
-public abstract class OpenSslContext extends ReferenceCountedOpenSslContext {
- OpenSslContext(Iterable<String> ciphers, CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apnCfg,
- long sessionCacheSize, long sessionTimeout, int mode, Certificate[] keyCertChain,
- ClientAuth clientAuth, String[] protocols, boolean startTls, boolean enableOcsp)
- throws SSLException {
- super(ciphers, cipherFilter, apnCfg, sessionCacheSize, sessionTimeout, mode, keyCertChain,
- clientAuth, protocols, startTls, enableOcsp, false);
- }
-
- OpenSslContext(Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
- OpenSslApplicationProtocolNegotiator apn, long sessionCacheSize,
- long sessionTimeout, int mode, Certificate[] keyCertChain,
- ClientAuth clientAuth, String[] protocols, boolean startTls,
- boolean enableOcsp) throws SSLException {
- super(ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout, mode, keyCertChain, clientAuth, protocols,
- startTls, enableOcsp, false);
- }
-
- @Override
- final SSLEngine newEngine0(ByteBufAllocator alloc, String peerHost, int peerPort) {
- return new OpenSslEngine(this, alloc, peerHost, peerPort);
- }
-
- @Override
- @SuppressWarnings("FinalizeDeclaration")
- protected final void finalize() throws Throwable {
- super.finalize();
- OpenSsl.releaseIfNeeded(this);
- }
-}
diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslEngine.java
deleted file mode 100644
index cbc7ee4..0000000
--- a/handler/src/main/java/io/netty/handler/ssl/OpenSslEngine.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2014 The Netty Project
- *
- * The Netty Project licenses this file to you under the Apache License,
- * version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-package io.netty.handler.ssl;
-
-import io.netty.buffer.ByteBufAllocator;
-
-import javax.net.ssl.SSLEngine;