-
Bug
-
Resolution: Fixed
-
P3
-
1.0.2
-
ventura
-
generic
-
generic
Name: krC82822 Date: 02/10/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
BufferedInputStream available() function always returns zero when attached to a
SSLSocket example of code (Server and Client):
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
import java.security.*;
public class SSLClient {
public static void main ( String [] args ) throws Exception {
System.setProperty("http.keepAlive", "false");
System.setProperty("javax.net.ssl.trustStore","/newCerts/client");
Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
System.out.println("Added provider...");
System.out.println("Getting default SSL Config...");
SSLSocketFactory fac = (SSLSocketFactory)
SSLSocketFactory.getDefault();
System.out.println("Connecting...");
SSLSocket soc = (SSLSocket)fac.createSocket("localhost", 2020);
System.out.println("Connected...");
InputStream is = soc.getInputStream();
OutputStream os = soc.getOutputStream();
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(os);
int num;
byte[] b=new byte[1024];
bos.write("Hello this is a test of an SSL Client\n".getBytes());
bos.flush();
System.out.println("Available: " + bis.available());
while ((num=bis.available()) != 0) {
bis.read(b, 0, 1023);
for (int i=0; i<num; i++) {
System.out.print((char)b[i]);
}
}
}
}
import java.io.*;
import java.net.*;
import java.security.KeyStore;
import javax.net.*;
import javax.net.ssl.*;
import javax.security.cert.X509Certificate;
import com.sun.net.ssl.*;
import java.security.*;
public class SSLServer {
private static Socket socket = null;
private static ServerSocket sSocket = null;
public static void main ( String [] args ) throws Exception {
if (args.length < 1) {
System.out.println("Usage: java SSLServer {auth|noauth}");
System.exit(0);
}
System.setProperty("http.keepAlive", "false");
Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
SSLServerSocketFactory ssf = null;
// set up key manager to do server authentication
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks;
char[] passphrase = "changeit".toCharArray();
ctx = SSLContext.getInstance("SSL");
kmf = KeyManagerFactory.getInstance("SunX509");
ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("/newCerts/server"), passphrase);
kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(), null, null);
ssf = ctx.getServerSocketFactory();
sSocket = ssf.createServerSocket(2020);
if (args[0].equals("auth")) {
((SSLServerSocket)sSocket).setNeedClientAuth(true);
}
while (true) {
System.out.println("Accepting Connections...");
socket = sSocket.accept();
Thread t = new Thread() {
public void run() {
try {
InputStream is = socket.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
OutputStream os = socket.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
byte[] read = new byte[1024];
int num;
while ((num=bis.available()) != 0) {
System.out.println("Reading loop: " + num);
for(int i=0; i<num; i++) {
System.out.print((char)read[i]);
}
}
byte[] out = "Hello this is an answer from SSL
Server\n".getBytes();
bos.write(out);
bos.flush();
} catch (IOException ioe) {
System.err.println(ioe);
}
}
};
t.start();
}
}
}
(Review ID: 111868)
======================================================================
Name: krC82822 Date: 02/28/2001
28 Feb 2001, eval1127@eng -- see also # 4414135.
java version "1.1.7B"
plus several several others
======================================================================