本文整理汇总了Java中org.bouncycastle.crypto.tls.TlsClientProtocol类的典型用法代码示例。如果您正苦于以下问题:Java TlsClientProtocol类的具体用法?Java TlsClientProtocol怎么用?Java TlsClientProtocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TlsClientProtocol类属于org.bouncycastle.crypto.tls包,在下文中一共展示了TlsClientProtocol类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入依赖的package包/类
public static void main(String[] args)
throws Exception
{
InetAddress address = InetAddress.getLocalHost();
int port = 5556;
long time1 = System.currentTimeMillis();
MyTlsClient client = new MyTlsClient(null);
TlsClientProtocol protocol = openTlsConnection(address, port, client);
protocol.close();
long time2 = System.currentTimeMillis();
System.out.println("Elapsed 1: " + (time2 - time1) + "ms");
client = new MyTlsClient(client.getSessionToResume());
protocol = openTlsConnection(address, port, client);
long time3 = System.currentTimeMillis();
System.out.println("Elapsed 2: " + (time3 - time2) + "ms");
OutputStream output = protocol.getOutputStream();
output.write("GET / HTTP/1.1\r\n\r\n".getBytes("UTF-8"));
output.flush();
InputStream input = protocol.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(">>> " + line);
}
protocol.close();
}
示例3: 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;
}
示例4: 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));
}
示例5: createSSLSocket
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入依赖的package包/类
private SSLSocket createSSLSocket(final String host, final TlsClientProtocol tlsClientProtocol) {
return new BouncyCastleSSLSocket(host, tlsClientProtocol);
}
示例6: 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));
}