• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TlsClientProtocol类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
}
 
开发者ID:oberien,项目名称:Oberien,代码行数:13,代码来源:TlsClientTest.java


示例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();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:37,代码来源:TlsClientTest.java


示例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;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:8,代码来源:TlsClientTest.java


示例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));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:32,代码来源:TlsProtocolTest.java


示例5: createSSLSocket

import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入依赖的package包/类
private SSLSocket createSSLSocket(final String host, final TlsClientProtocol tlsClientProtocol) {
    return new BouncyCastleSSLSocket(host, tlsClientProtocol);
}
 
开发者ID:tobszarny,项目名称:ssl-provider-jvm16,代码行数:4,代码来源:TSLSocketConnectionFactory.java


示例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));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:61,代码来源:BasicTlsTest.java



注:本文中的org.bouncycastle.crypto.tls.TlsClientProtocol类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FlowExecutionStatus类代码示例发布时间:2022-05-22
下一篇:
Java IDialogFieldListener类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap