summaryrefslogtreecommitdiff
path: root/java/ssl/jdk1.5/IceSSL/ConnectorI.java
blob: 4b94a20aedd6193a34950c795522846ee4afd18b (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

package IceSSL;

final class ConnectorI implements IceInternal.Connector
{
    public IceInternal.Transceiver
    connect(int timeout)
    {
	//
	// The plugin may not be fully initialized.
	//
	if(!_instance.initialized())
	{
	    Ice.PluginInitializationException ex = new Ice.PluginInitializationException();
	    ex.reason = "IceSSL: plugin is not initialized";
	    throw ex;
	}

	if(_instance.networkTraceLevel() >= 2)
	{
	    String s = "trying to establish ssl connection to " + toString();
	    _logger.trace(_instance.networkTraceCategory(), s);
	}

	java.nio.channels.SocketChannel fd = IceInternal.Network.createTcpSocket();
	IceInternal.Network.setBlock(fd, false);
	IceInternal.Network.doConnect(fd, _addr, timeout);

	TransceiverI transceiver = null;
	try
	{
	    javax.net.ssl.SSLEngine engine = _instance.createSSLEngine(false);

	    transceiver = new TransceiverI(_instance, engine, fd, _host, false, "");
/*
	    transceiver.waitForHandshake(timeout);

	    //
	    // Check IceSSL.VerifyPeer.
	    //
	    int verifyPeer =
		_instance.communicator().getProperties().getPropertyAsIntWithDefault("IceSSL.VerifyPeer", 2);
	    if(verifyPeer > 0)
	    {
		try
		{
		    engine.getSession().getPeerCertificates();
		}
		catch(javax.net.ssl.SSLPeerUnverifiedException ex)
		{
		    Ice.SecurityException e = new Ice.SecurityException();
		    e.reason = "IceSSL: server did not supply a certificate";
		    e.initCause(ex);
		    throw e;
		}
	    }
*/

/*
	    if(!ctx.verifyPeer(fd, _host, false))
	    {
		Ice.SecurityException ex = new Ice.SecurityException();
		ex.reason = "IceSSL: outgoing connection rejected by certificate verifier";
		throw ex;
	    }
*/
	}
	catch(RuntimeException ex)
	{
	    try
	    {
		fd.close();
	    }
	    catch(java.io.IOException e)
	    {
		// Ignore.
	    }
	    throw ex;
	}

	if(_instance.networkTraceLevel() >= 1)
	{
	    String s = "ssl connection established\n" + IceInternal.Network.fdToString(fd);
	    _logger.trace(_instance.networkTraceCategory(), s);
	}

	return transceiver;
    }

    public String
    toString()
    {
	return IceInternal.Network.addrToString(_addr);
    }

    //
    // Only for use by EndpointI.
    //
    ConnectorI(Instance instance, String host, int port)
    {
	_instance = instance;
	_host = host;
	_logger = instance.communicator().getLogger();

	_addr = IceInternal.Network.getAddress(host, port);
    }

    private Instance _instance;
    private String _host;
    private Ice.Logger _logger;
    private java.net.InetSocketAddress _addr;
}