Java 类org.bouncycastle.crypto.tls.DatagramTransport 实例源码

项目:irma_future_id    文件:UnreliableDatagramTransport.java   
public UnreliableDatagramTransport(DatagramTransport transport, Random random,
                                   int percentPacketLossReceiving, int percentPacketLossSending)
{
    if (percentPacketLossReceiving < 0 || percentPacketLossReceiving > 100)
    {
        throw new IllegalArgumentException("'percentPacketLossReceiving' out of range");
    }
    if (percentPacketLossSending < 0 || percentPacketLossSending > 100)
    {
        throw new IllegalArgumentException("'percentPacketLossSending' out of range");
    }

    this.transport = transport;
    this.random = random;
    this.percentPacketLossReceiving = percentPacketLossReceiving;
    this.percentPacketLossSending = percentPacketLossSending;
}
项目:bc-java    文件:UnreliableDatagramTransport.java   
public UnreliableDatagramTransport(DatagramTransport transport, Random random,
                                   int percentPacketLossReceiving, int percentPacketLossSending)
{
    if (percentPacketLossReceiving < 0 || percentPacketLossReceiving > 100)
    {
        throw new IllegalArgumentException("'percentPacketLossReceiving' out of range");
    }
    if (percentPacketLossSending < 0 || percentPacketLossSending > 100)
    {
        throw new IllegalArgumentException("'percentPacketLossSending' out of range");
    }

    this.transport = transport;
    this.random = random;
    this.percentPacketLossReceiving = percentPacketLossReceiving;
    this.percentPacketLossSending = percentPacketLossSending;
}
项目:rtcdcjava    文件:DTLSTransportFactory.java   
static DTLSTransport createServerTransport(final RTCCertificate rtcCertificate,
                                           final DatagramTransport transport) throws IOException {

    final DefaultTlsServer defaultTlsServer = new DefaultTlsServer() {

        private final AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(rtcCertificate.getKeyPair()
                                                                                                                .getPrivate()
                                                                                                                .getEncoded());
        private final Certificate cCert = new Certificate(new org.bouncycastle.asn1.x509.Certificate[]{rtcCertificate.getCertificate().toASN1Structure()});

        @Override
        protected ProtocolVersion getMaximumVersion() {
            return ProtocolVersion.DTLSv10;
        }

        @Override
        protected ProtocolVersion getMinimumVersion() {
            return ProtocolVersion.DTLSv10;
        }

        @Override
        protected TlsSignerCredentials getRSASignerCredentials() throws IOException {
            return new DefaultTlsSignerCredentials(this.context,
                                                   this.cCert,
                                                   this.privateKeyAsymKeyParam);
        }
    };

    return new DTLSServerProtocol(SECURE_RANDOM).accept(defaultTlsServer,
                                                        transport);
}
项目:rtcdcjava    文件:DTLSTransportFactory.java   
static DTLSTransport createClientTransport(final DatagramTransport transport) throws IOException {

        final DefaultTlsClient defaultTlsClient = new DefaultTlsClient() {

            @Override
            public ProtocolVersion getClientVersion() {
                return ProtocolVersion.DTLSv10;
            }

            @Override
            public ProtocolVersion getMinimumVersion() {
                return ProtocolVersion.DTLSv10;
            }

            @Override
            public TlsAuthentication getAuthentication() throws IOException {

                return new ServerOnlyTlsAuthentication() {
                    @Override
                    public void notifyServerCertificate(final Certificate serverCertificate) throws IOException {
                        //TODO Check if certificate is signed by a trusted party.
                    }
                };
            }
        };

        return new DTLSClientProtocol(SECURE_RANDOM).connect(defaultTlsClient,
                                                             transport);
    }
项目:irma_future_id    文件:DTLSProtocolTest.java   
public void testClientServer()
    throws Exception
{
    SecureRandom secureRandom = new SecureRandom();

    DTLSClientProtocol clientProtocol = new DTLSClientProtocol(secureRandom);
    DTLSServerProtocol serverProtocol = new DTLSServerProtocol(secureRandom);

    MockDatagramAssociation network = new MockDatagramAssociation(1500);

    ServerThread serverThread = new ServerThread(serverProtocol, network.getServer());
    serverThread.start();

    DatagramTransport clientTransport = network.getClient();

    clientTransport = new UnreliableDatagramTransport(clientTransport, secureRandom, 0, 0);

    clientTransport = new LoggingDatagramTransport(clientTransport, System.out);

    MockDTLSClient client = new MockDTLSClient(null);
    DTLSTransport dtlsClient = clientProtocol.connect(client, clientTransport);

    for (int i = 1; i <= 10; ++i)
    {
        byte[] data = new byte[i];
        Arrays.fill(data, (byte)i);
        dtlsClient.send(data, 0, data.length);
    }

    byte[] buf = new byte[dtlsClient.getReceiveLimit()];
    while (dtlsClient.receive(buf, 0, buf.length, 1000) >= 0)
    {
        ;
    }

    dtlsClient.close();

    serverThread.shutdown();
}
项目:irma_future_id    文件:DTLSClientTest.java   
private static DTLSTransport openDTLSConnection(InetAddress address, int port, TlsClient client)
    throws IOException
{
    DatagramSocket socket = new DatagramSocket();
    socket.connect(address, port);

    int mtu = 1500;
    DatagramTransport transport = new UDPTransport(socket, mtu);
    transport = new UnreliableDatagramTransport(transport, secureRandom, 0, 0);
    transport = new LoggingDatagramTransport(transport, System.out);

    DTLSClientProtocol protocol = new DTLSClientProtocol(secureRandom);

    return protocol.connect(client, transport);
}
项目:bc-java    文件:DTLSProtocolTest.java   
public void testClientServer()
    throws Exception
{
    SecureRandom secureRandom = new SecureRandom();

    DTLSClientProtocol clientProtocol = new DTLSClientProtocol(secureRandom);
    DTLSServerProtocol serverProtocol = new DTLSServerProtocol(secureRandom);

    MockDatagramAssociation network = new MockDatagramAssociation(1500);

    ServerThread serverThread = new ServerThread(serverProtocol, network.getServer());
    serverThread.start();

    DatagramTransport clientTransport = network.getClient();

    clientTransport = new UnreliableDatagramTransport(clientTransport, secureRandom, 0, 0);

    clientTransport = new LoggingDatagramTransport(clientTransport, System.out);

    MockDTLSClient client = new MockDTLSClient(null);
    DTLSTransport dtlsClient = clientProtocol.connect(client, clientTransport);

    for (int i = 1; i <= 10; ++i)
    {
        byte[] data = new byte[i];
        Arrays.fill(data, (byte)i);
        dtlsClient.send(data, 0, data.length);
    }

    byte[] buf = new byte[dtlsClient.getReceiveLimit()];
    while (dtlsClient.receive(buf, 0, buf.length, 1000) >= 0)
    {
        ;
    }

    dtlsClient.close();

    serverThread.shutdown();
}
项目:bc-java    文件:DTLSClientTest.java   
private static DTLSTransport openDTLSConnection(InetAddress address, int port, TlsClient client)
    throws IOException
{
    DatagramSocket socket = new DatagramSocket();
    socket.connect(address, port);

    int mtu = 1500;
    DatagramTransport transport = new UDPTransport(socket, mtu);
    transport = new UnreliableDatagramTransport(transport, secureRandom, 0, 0);
    transport = new LoggingDatagramTransport(transport, System.out);

    DTLSClientProtocol protocol = new DTLSClientProtocol(secureRandom);

    return protocol.connect(client, transport);
}
项目:irma_future_id    文件:LoggingDatagramTransport.java   
public LoggingDatagramTransport(DatagramTransport transport, PrintStream output)
{
    this.transport = transport;
    this.output = output;
    this.launchTimestamp = System.currentTimeMillis();
}
项目:irma_future_id    文件:MockDatagramAssociation.java   
public DatagramTransport getClient()
{
    return client;
}
项目:irma_future_id    文件:MockDatagramAssociation.java   
public DatagramTransport getServer()
{
    return server;
}
项目:irma_future_id    文件:DTLSProtocolTest.java   
ServerThread(DTLSServerProtocol serverProtocol, DatagramTransport serverTransport)
{
    this.serverProtocol = serverProtocol;
    this.serverTransport = serverTransport;
}
项目:bc-java    文件:LoggingDatagramTransport.java   
public LoggingDatagramTransport(DatagramTransport transport, PrintStream output)
{
    this.transport = transport;
    this.output = output;
    this.launchTimestamp = System.currentTimeMillis();
}
项目:bc-java    文件:MockDatagramAssociation.java   
public DatagramTransport getClient()
{
    return client;
}
项目:bc-java    文件:MockDatagramAssociation.java   
public DatagramTransport getServer()
{
    return server;
}
项目:bc-java    文件:DTLSProtocolTest.java   
ServerThread(DTLSServerProtocol serverProtocol, DatagramTransport serverTransport)
{
    this.serverProtocol = serverProtocol;
    this.serverTransport = serverTransport;
}