本文整理汇总了Java中org.bouncycastle.crypto.tls.TlsClientProtocol.connect方法的典型用法代码示例。如果您正苦于以下问题:Java TlsClientProtocol.connect方法的具体用法?Java TlsClientProtocol.connect怎么用?Java TlsClientProtocol.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.tls.TlsClientProtocol
的用法示例。
在下文中一共展示了TlsClientProtocol.connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, CertificateException, NoSuchProviderException {
Security.addProvider(new BouncyCastleProvider());
final X509Certificate clientCertX509 = CertificateClientManagement.loadCertificate("secure/cert/test.crt");
final Certificate clientCert = new Certificate(new org.bouncycastle.asn1.x509.Certificate[] {org.bouncycastle.asn1.x509.Certificate.getInstance(clientCertX509.getEncoded())});
final KeyPair clientKeyPair = CertificateClientManagement.loadKey("secure/cert/test.key", clientCertX509.getPublicKey());
Socket socket = new Socket("localhost", 4444);
TlsClientProtocol tlsClientProtocol = new CustomTlsClientProtocol(socket.getInputStream(), socket.getOutputStream());
tlsClientProtocol.connect(new CustomTlsClient(clientKeyPair, clientCert));
System.out.println("auth finished");
while (true);
}
示例2: openTlsConnection
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入方法依赖的package包/类
static TlsClientProtocol openTlsConnection(InetAddress address, int port, TlsClient client) throws IOException
{
Socket s = new Socket(address, port);
TlsClientProtocol protocol = new TlsClientProtocol(s.getInputStream(), s.getOutputStream(), secureRandom);
protocol.connect(client);
return protocol;
}
示例3: testClientServer
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入方法依赖的package包/类
public void testClientServer()
throws Exception
{
SecureRandom secureRandom = new SecureRandom();
PipedInputStream clientRead = new PipedInputStream();
PipedInputStream serverRead = new PipedInputStream();
PipedOutputStream clientWrite = new PipedOutputStream(serverRead);
PipedOutputStream serverWrite = new PipedOutputStream(clientRead);
TlsClientProtocol clientProtocol = new TlsClientProtocol(clientRead, clientWrite, secureRandom);
TlsServerProtocol serverProtocol = new TlsServerProtocol(serverRead, serverWrite, secureRandom);
ServerThread serverThread = new ServerThread(serverProtocol);
serverThread.start();
MyTlsClient client = new MyTlsClient();
clientProtocol.connect(client);
// byte[] data = new byte[64];
// secureRandom.nextBytes(data);
//
// OutputStream output = clientProtocol.getOutputStream();
// output.write(data);
// output.close();
//
// byte[] echo = Streams.readAll(clientProtocol.getInputStream());
serverThread.join();
// assertTrue(Arrays.areEqual(data, echo));
}
示例4: testConnection
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入方法依赖的package包/类
public void testConnection()
throws Exception
{
Thread server = new HTTPSServerThread();
server.start();
Thread.yield();
AlwaysValidVerifyer verifyer = new AlwaysValidVerifyer();
Socket s = null;
for (int i = 0; s == null && i != 3; i++)
{
Thread.sleep(1000);
try
{
s = new Socket("localhost", PORT_NO);
}
catch (IOException e)
{
// ignore
}
}
if (s == null)
{
throw new IOException("unable to connect");
}
// long time = System.currentTimeMillis();
TlsClientProtocol protocol = new TlsClientProtocol(s.getInputStream(), s.getOutputStream());
protocol.connect(new LegacyTlsClient(verifyer));
InputStream is = protocol.getInputStream();
OutputStream os = protocol.getOutputStream();
os.write("GET / HTTP/1.1\r\n\r\n".getBytes());
// time = System.currentTimeMillis();
byte[] buf = new byte[4096];
int read = 0;
int total = 0;
while ((read = is.read(buf, total, buf.length - total)) > 0)
{
total += read;
}
is.close();
byte[] expected = Hex.decode("485454502f312e3120323030204f4b0d0a436f6e74656e742d547970653a20746578742f68"
+ "746d6c0d0a0d0a3c68746d6c3e0d0a3c626f64793e0d0a48656c6c6f20576f726c64210d0a3c2f626f64793e0d0a3c2f"
+ "68746d6c3e0d0a");
assertEquals(total, expected.length);
byte[] tmp = new byte[expected.length];
System.arraycopy(buf, 0, tmp, 0, total);
assertTrue(Arrays.areEqual(expected, tmp));
}