12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.*;
25 import java.net.*;
26 import java.util.*;
27 import java.security.*;
28 import javax.net.*;
29 import javax.net.ssl.*;
30 import java.lang.reflect.*;
31
32 import sun.security.util.KeyLength;
33
34 public class ShortRSAKeyWithinTLS {
35
36 /*
37 * =============================================================
38 * Set the various variables needed for the tests, then
39 * specify what tests to run on each side.
40 */
41
42 /*
43 * Should we run the client or server in a separate thread?
44 * Both sides can throw exceptions, but do you have a preference
45 * as to which side should be the main thread.
46 */
47 static boolean separateServerThread = false;
48
49 /*
50 * Is the server ready to serve?
51 */
52 volatile static boolean serverReady = false;
158
159 InputStream sslIS = sslSocket.getInputStream();
160 OutputStream sslOS = sslSocket.getOutputStream();
161
162 sslOS.write(280);
163 sslOS.flush();
164 sslIS.read();
165
166 sslSocket.close();
167 }
168
169 private void checkKeySize(KeyStore ks) throws Exception {
170 PrivateKey privateKey = null;
171 PublicKey publicKey = null;
172
173 if (ks.containsAlias(keyAlias)) {
174 System.out.println("Loaded entry: " + keyAlias);
175 privateKey = (PrivateKey)ks.getKey(keyAlias, null);
176 publicKey = (PublicKey)ks.getCertificate(keyAlias).getPublicKey();
177
178 int privateKeySize = KeyLength.getKeySize(privateKey);
179 if (privateKeySize != keySize) {
180 throw new Exception("Expected key size is " + keySize +
181 ", but the private key size is " + privateKeySize);
182 }
183
184 int publicKeySize = KeyLength.getKeySize(publicKey);
185 if (publicKeySize != keySize) {
186 throw new Exception("Expected key size is " + keySize +
187 ", but the public key size is " + publicKeySize);
188 }
189 }
190 }
191
192 /*
193 * =============================================================
194 * The remainder is just support stuff
195 */
196
197 // use any free port by default
198 volatile int serverPort = 0;
199
200 volatile Exception serverException = null;
201 volatile Exception clientException = null;
202
203 private static String keyAlias;
204 private static int keySize;
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.*;
25 import java.net.*;
26 import java.util.*;
27 import java.security.*;
28 import javax.net.*;
29 import javax.net.ssl.*;
30 import java.lang.reflect.*;
31
32 import sun.security.util.KeyUtil;
33
34 public class ShortRSAKeyWithinTLS {
35
36 /*
37 * =============================================================
38 * Set the various variables needed for the tests, then
39 * specify what tests to run on each side.
40 */
41
42 /*
43 * Should we run the client or server in a separate thread?
44 * Both sides can throw exceptions, but do you have a preference
45 * as to which side should be the main thread.
46 */
47 static boolean separateServerThread = false;
48
49 /*
50 * Is the server ready to serve?
51 */
52 volatile static boolean serverReady = false;
158
159 InputStream sslIS = sslSocket.getInputStream();
160 OutputStream sslOS = sslSocket.getOutputStream();
161
162 sslOS.write(280);
163 sslOS.flush();
164 sslIS.read();
165
166 sslSocket.close();
167 }
168
169 private void checkKeySize(KeyStore ks) throws Exception {
170 PrivateKey privateKey = null;
171 PublicKey publicKey = null;
172
173 if (ks.containsAlias(keyAlias)) {
174 System.out.println("Loaded entry: " + keyAlias);
175 privateKey = (PrivateKey)ks.getKey(keyAlias, null);
176 publicKey = (PublicKey)ks.getCertificate(keyAlias).getPublicKey();
177
178 int privateKeySize = KeyUtil.getKeySize(privateKey);
179 if (privateKeySize != keySize) {
180 throw new Exception("Expected key size is " + keySize +
181 ", but the private key size is " + privateKeySize);
182 }
183
184 int publicKeySize = KeyUtil.getKeySize(publicKey);
185 if (publicKeySize != keySize) {
186 throw new Exception("Expected key size is " + keySize +
187 ", but the public key size is " + publicKeySize);
188 }
189 }
190 }
191
192 /*
193 * =============================================================
194 * The remainder is just support stuff
195 */
196
197 // use any free port by default
198 volatile int serverPort = 0;
199
200 volatile Exception serverException = null;
201 volatile Exception clientException = null;
202
203 private static String keyAlias;
204 private static int keySize;
|