home *** CD-ROM | disk | FTP | other *** search
- package netscape.net;
-
- import java.io.FileDescriptor;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.InetAddress;
- import java.net.ProtocolException;
- import java.net.SocketException;
- import java.net.SocketImpl;
- import java.net.UnknownHostException;
- import java.util.Enumeration;
- import java.util.Vector;
- import netscape.security.ForbiddenTargetException;
- import netscape.security.PrivilegeManager;
-
- class SSLSocketImpl extends SocketImpl {
- int timeout;
- private boolean requireClientAuth = false;
- private boolean useClientMode = false;
- private boolean clientModeInitialized = false;
- private boolean trustedForClientAuth = false;
- Vector handshakeListeners = new Vector();
- Thread callbackNotifier;
- SSLSocket socket;
-
- SSLSocketImpl() {
- this.socket = null;
-
- try {
- this.trustedForClientAuth = false;
-
- try {
- PrivilegeManager.checkPrivilegeEnabled("ClientAuth");
- } catch (NoClassDefFoundError var1) {
- }
-
- this.trustedForClientAuth = true;
- } catch (ForbiddenTargetException var2) {
- }
- }
-
- SSLSocketImpl(SSLSocket var1) {
- this.socket = var1;
-
- try {
- this.trustedForClientAuth = false;
-
- try {
- PrivilegeManager.checkPrivilegeEnabled("ClientAuth");
- } catch (NoClassDefFoundError var2) {
- }
-
- this.trustedForClientAuth = true;
- } catch (ForbiddenTargetException var3) {
- }
- }
-
- protected synchronized void create(boolean var1) throws IOException {
- if (!var1) {
- throw new IOException("UDP datagram sockets not supported in SSL.");
- } else {
- super.fd = new FileDescriptor();
- this.socketCreate(var1);
- }
- }
-
- protected void connect(String var1, int var2) throws UnknownHostException, IOException {
- Object var3 = null;
-
- try {
- InetAddress var4 = InetAddress.getByName(var1);
-
- try {
- this.connectToAddress(var4, var2);
- return;
- } catch (IOException var6) {
- var3 = var6;
- }
- } catch (UnknownHostException var7) {
- var3 = var7;
- }
-
- this.close();
- throw var3;
- }
-
- protected void connect(InetAddress var1, int var2) throws IOException {
- super.port = var2;
- super.address = var1;
-
- try {
- this.connectToAddress(var1, var2);
- } catch (IOException var4) {
- this.close();
- throw var4;
- }
- }
-
- private void connectToAddress(InetAddress var1, int var2) throws IOException {
- this.doConnect(var1, var2);
- }
-
- public void setNeedClientAuth(boolean var1) {
- this.requireClientAuth = var1;
- this.socketSetNeedClientAuth(var1);
- }
-
- public boolean getNeedClientAuth() {
- return this.requireClientAuth;
- }
-
- public void setUseClientMode(boolean var1) {
- this.clientModeInitialized = true;
- this.useClientMode = var1;
- }
-
- public boolean getUseClientMode() {
- return this.useClientMode;
- }
-
- boolean isClientModeInitialized() {
- return this.clientModeInitialized;
- }
-
- public void setOption(int var1, Object var2) throws SocketException {
- int var3 = 0;
- boolean var4 = true;
- switch (var1) {
- case 1:
- if (var2 == null || !(var2 instanceof Boolean)) {
- throw new SocketException("bad parameter for TCP_NODELAY");
- }
-
- var4 = (Boolean)var2;
- break;
- case 15:
- throw new SocketException("Cannot re-bind socket");
- case 128:
- if (var2 == null || !(var2 instanceof Integer) && !(var2 instanceof Boolean)) {
- throw new SocketException("Bad parameter for option");
- }
-
- if (var2 instanceof Boolean) {
- var4 = false;
- var3 = 0;
- } else {
- var3 = (Integer)var2;
- }
- break;
- case 4102:
- if (var2 != null && var2 instanceof Integer) {
- int var5 = (Integer)var2;
- if (var5 < 0) {
- throw new IllegalArgumentException("timeout < 0");
- }
-
- this.timeout = var5;
- return;
- }
-
- throw new SocketException("Bad parameter for SO_TIMEOUT");
- default:
- throw new SocketException("unrecognized TCP option: " + var1);
- }
-
- this.socketSetOptionIntVal(var1, var4, var3);
- }
-
- public Object getOption(int var1) throws SocketException {
- if (var1 == 4102) {
- return new Integer(this.timeout);
- } else {
- int var2 = this.socketGetOption(var1);
- switch (var1) {
- case 1:
- if (var2 == -1) {
- return new Boolean(false);
- }
-
- return new Boolean(true);
- case 15:
- InetAddress var3 = new InetAddress(var2);
- return var3;
- case 128:
- if (var2 == -1) {
- return new Boolean(false);
- }
-
- return new Integer(var2);
- default:
- return null;
- }
- }
- }
-
- private void doConnect(InetAddress var1, int var2) throws IOException {
- ProtocolException var3 = null;
- if (!this.isClientModeInitialized()) {
- this.setUseClientMode(true);
- }
-
- int var4 = 0;
-
- while(var4 < 3) {
- try {
- this.socketConnect(var1, var2);
- return;
- } catch (ProtocolException var6) {
- this.close();
- super.fd = new FileDescriptor();
- this.socketCreate(true);
- var3 = var6;
- ++var4;
- } catch (IOException var7) {
- this.close();
- throw var7;
- }
- }
-
- this.close();
- throw var3;
- }
-
- private boolean usingSocks() {
- return false;
- }
-
- protected synchronized void bind(InetAddress var1, int var2) throws IOException {
- this.socketBind(var1, var2);
- }
-
- protected synchronized void listen(int var1) throws IOException {
- this.socketListen(var1);
- }
-
- protected synchronized void accept(SocketImpl var1) throws IOException {
- this.socketAccept(var1);
- }
-
- protected synchronized InputStream getInputStream() throws IOException {
- return new SSLInputStream(this);
- }
-
- protected synchronized OutputStream getOutputStream() throws IOException {
- return new SSLOutputStream(this);
- }
-
- protected synchronized int available() throws IOException {
- return this.socketAvailable();
- }
-
- protected void close() throws IOException {
- if (super.fd != null && super.fd.valid()) {
- this.socketClose();
- super.fd = null;
- }
-
- }
-
- protected void finalize() throws IOException {
- this.close();
- }
-
- private native void socketCreate(boolean var1) throws IOException;
-
- private native void socketConnect(InetAddress var1, int var2) throws IOException;
-
- private native void socketBind(InetAddress var1, int var2) throws IOException;
-
- private native void socketListen(int var1) throws IOException;
-
- private native void socketAccept(SocketImpl var1) throws IOException;
-
- private native int socketAvailable() throws IOException;
-
- private native void socketClose() throws IOException;
-
- private native void socketSetNeedClientAuth(boolean var1);
-
- private native void socketSetOptionIntVal(int var1, boolean var2, int var3) throws SocketException;
-
- private native int socketGetOption(int var1) throws SocketException;
-
- protected FileDescriptor getFileDescriptor() {
- return super.fd;
- }
-
- protected InetAddress getInetAddress() {
- return super.address;
- }
-
- protected int getPort() {
- return super.port;
- }
-
- protected int getLocalPort() {
- return super.localport;
- }
-
- public void removeHandshakeCompletedListener(SSLHandshakeCompletedListener var1) {
- this.handshakeListeners.removeElement(var1);
- }
-
- public void addHandshakeCompletedListener(SSLHandshakeCompletedListener var1) {
- if (this.socket == null) {
- throw new RuntimeException("no socket in client-side SSLSocketImpl?");
- } else {
- if (this.callbackNotifier == null) {
- this.callbackNotifier = new SSLCallbackNotifier(this);
- this.callbackNotifier.start();
- }
-
- this.handshakeListeners.addElement(var1);
- }
- }
-
- void callHandshakeCompletedListeners() {
- try {
- Thread var1 = this.callbackNotifier;
- synchronized(var1){}
-
- try {
- this.callbackNotifier.notify();
- } catch (Throwable var4) {
- throw var4;
- }
-
- } catch (NullPointerException var5) {
- }
- }
-
- void doCallHandshakeCompletedListeners() {
- if (this.socket == null) {
- throw new RuntimeException("no socket in SSLSocketImpl?");
- } else {
- Vector var1 = this.handshakeListeners;
- synchronized(var1){}
-
- try {
- SSLHandshakeCompletedEvent var5 = new SSLHandshakeCompletedEvent(this.socket);
- Enumeration var3 = this.handshakeListeners.elements();
-
- while(var3.hasMoreElements()) {
- SSLHandshakeCompletedListener var4 = (SSLHandshakeCompletedListener)var3.nextElement();
- var4.handshakeCompleted(var5);
- }
- } catch (Throwable var7) {
- throw var7;
- }
-
- }
- }
-
- boolean allowClientAuth() {
- return this.trustedForClientAuth;
- }
-
- native SSLSecurityStatus getStatus();
-
- native void resetHandshake();
-
- native void forceHandshake();
-
- native void redoHandshake();
-
- static {
- SecurityManager.enablePrivilege("SuperUser");
- SecurityManager.enablePrivilege("UniversalPropertyRead");
- System.loadLibrary(System.getProperty("netscape.net.dll", "net"));
- }
- }
-