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

项目: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);
}