-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathProviderTest.java
More file actions
147 lines (131 loc) · 5.83 KB
/
Copy pathProviderTest.java
File metadata and controls
147 lines (131 loc) · 5.83 KB
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
/* ProviderTest.java
*
* Copyright (C) 2006-2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLContext;
import com.wolfssl.provider.jsse.WolfSSLProvider;
/**
* This class tests the wolfSSL provider installation. It lists all providers
* installed on the system, tries to look up the wolfSSL provider, and if
* found, prints out the information about the wolfSSL provider.
* Finally, it tests what provider is registered to provide TLS to Java.
*
* This app can be useful for testing if wolfJSSE has been installed
* correctly at the system level.
*/
public class ProviderTest {
/* Print out info about registered Security providers. Does not
* install wolfJSSE. If wolfJSSE has been installed at the system
* level, or application has installed wolfJSSE at runtime, it will
* show up. Otherwise will not. main() below calls this once without
* installing wolfJSSE explicitly, then calls again after installing
* wolfJSSE at runtime as the highest-level provider. */
public static void pollProviders()
{
/* Get all providers */
Provider [] providers = Security.getProviders();
System.out.println("\nAll Installed Java Security Providers:");
System.out.println("---------------------------------------");
for(Provider prov:providers)
{
System.out.println("\t" + prov);
}
Provider p = Security.getProvider("wolfJSSE");
if (p == null) {
System.out.println("No wolfJSSE provider registered in system");
} else {
/* Test if wolfSSL is a Provider */
System.out.println("\nInfo about wolfSSL Provider (wolfJSSE):");
System.out.println("----------------------------------------");
System.out.println("Provider: " + p);
System.out.println("Info: " + p.getInfo());
System.out.println("Services:");
System.out.println(p.getServices());
}
/* Test which Provider provides TLS versions */
System.out.println("\nWhat Provider is providing TLS?");
System.out.println("--------------------------------");
try {
/* TLS default */
SSLContext s = SSLContext.getInstance("TLS");
Provider prov = s.getProvider();
System.out.println("\tSSLContext TLS Provider = " + prov);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(ProviderTest.class.getName()).log(Level.SEVERE,
null, ex);
}
try {
/* TLS 1.0 - NOTE: compiled out by default in native wolfSSL */
SSLContext s = SSLContext.getInstance("TLSv1");
Provider prov = s.getProvider();
System.out.println("\tSSLContext TLSv1 Provider = " + prov);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(ProviderTest.class.getName()).log(Level.SEVERE,
null, ex);
}
try {
/* TLS 1.1 */
SSLContext s = SSLContext.getInstance("TLSv1.1");
Provider prov = s.getProvider();
System.out.println("\tSSLContext TLSv1.1 Provider = " + prov);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(ProviderTest.class.getName()).log(Level.SEVERE,
null, ex);
}
try {
/* TLS 1.2 */
SSLContext s = SSLContext.getInstance("TLSv1.2");
Provider prov = s.getProvider();
System.out.println("\tSSLContext TLSv1.2 Provider = " + prov);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(ProviderTest.class.getName()).log(Level.SEVERE,
null, ex);
}
try {
/* TLS 1.3 */
SSLContext s = SSLContext.getInstance("TLSv1.3");
Provider prov = s.getProvider();
System.out.println("\tSSLContext TLSv1.3 Provider = " + prov);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(ProviderTest.class.getName()).log(Level.SEVERE,
null, ex);
}
}
public static void main(String args [])
{
/* Print system providers before explicit wolfJSSE install */
System.out.println("=================================================");
System.out.println("| Before installing wolfJSSE at runtime |");
System.out.println("=================================================");
pollProviders();
/* Install wolfJSSE */
Security.insertProviderAt(new WolfSSLProvider(), 1);
/* Print system provider, after installing wolfJSSE */
System.out.println("");
System.out.println("=================================================");
System.out.println("| After installing wolfJSSE at runtime |");
System.out.println("=================================================");
pollProviders();
}
}