Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 由于SocketException,DTLS握手失败,尽管套接字从未按菜单关闭_Java_Sockets_Webrtc_Bouncycastle_Dtls - Fatal编程技术网

Java 由于SocketException,DTLS握手失败,尽管套接字从未按菜单关闭

Java 由于SocketException,DTLS握手失败,尽管套接字从未按菜单关闭,java,sockets,webrtc,bouncycastle,dtls,Java,Sockets,Webrtc,Bouncycastle,Dtls,道歉,因为这个问题可能有点模糊。 正在尝试建立与webrtc网关的webrtc连接。当使用accept或connect函数执行dtls握手时,它抛出SocketException 以下是错误: java.net.SocketException: Socket is closed at java.net.DatagramSocket.send(DatagramSocket.java:658) at org.bouncycastle.crypto.tls.UDPTranspor

道歉,因为这个问题可能有点模糊。 正在尝试建立与webrtc网关的webrtc连接。当使用accept或connect函数执行dtls握手时,它抛出SocketException

以下是错误:

   java.net.SocketException: Socket is closed
    at java.net.DatagramSocket.send(DatagramSocket.java:658)
    at org.bouncycastle.crypto.tls.UDPTransport.send(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSRecordLayer.sendRecord(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSRecordLayer.send(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSReliableHandshake$RecordLayerBuffer.sendToRecordLayer(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSReliableHandshake.writeHandshakeFragment(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSReliableHandshake.writeMessage(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSReliableHandshake.resendOutboundFlight(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSReliableHandshake.receiveMessage(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSServerProtocol.serverHandshake(Unknown Source)
    at org.bouncycastle.crypto.tls.DTLSServerProtocol.accept(Unknown Source)
    at callProcessor.DTLSManager.startDTLS(DTLSManager.java:421)
    at callProcessor.DTLSManager.processSTUNResponse(DTLSManager.java:554)
如果有任何其他线程正在关闭套接字但没有,则多次检查,如果关闭,则在传递套接字之前检查,结果为false。(SoTimeOut为60000)

代码段:

tlsServer = new DefaultTlsServer2() {
                    public void notifyClientCertificate(org.bouncycastle.crypto.tls.Certificate clientCertificate) throws IOException {
                        org.bouncycastle.asn1.x509.Certificate[] chain = clientCertificate.getCertificateList();
                        
                        logger.debug("notifyClientCertificate: " + chain[0].getSignature());

                        
                        /*// JFLog.log("Received client certificate chain of length " + chain.length);
                        for (int i = 0; i != chain.length; i++) {
                            org.bouncycastle.asn1.x509.Certificate entry = chain[i];
                            // JFLog.log("fingerprint:SHA-256 " + KeyMgmt.fingerprintSHA256(entry.getEncoded()) + " (" + entry.getSubject() + ")");
                            // JFLog.log("cert length=" + entry.getEncoded().length);
                        }*/
                    }

                    protected ProtocolVersion getMaximumVersion() {
                        logger.debug("getMaximumVersion: " + ProtocolVersion.DTLSv10);
                        return ProtocolVersion.DTLSv10;
                    }

                    protected ProtocolVersion getMinimumVersion() {
                        logger.debug("getMinimumVersion: " + ProtocolVersion.DTLSv10);
                        return ProtocolVersion.DTLSv10;
                    }

                    protected TlsEncryptionCredentials getRSAEncryptionCredentials() throws IOException {
                        logger.debug("getRSAEncryptionCredentials");
                        return new DefaultTlsEncryptionCredentials(context, dtlsInfo.getCertChain(), dtlsInfo.getPrivateKey());
                    }

                    @SuppressWarnings("rawtypes")
                    protected TlsSignerCredentials getRSASignerCredentials() throws IOException {
                        SignatureAndHashAlgorithm signatureAndHashAlgorithm = null;
                        Vector sigAlgs = supportedSignatureAlgorithms;
                        if (sigAlgs != null) {
                            for (int i = 0; i < sigAlgs.size(); ++i) {
                                SignatureAndHashAlgorithm sigAlg = (SignatureAndHashAlgorithm) sigAlgs.elementAt(i);
                                if (sigAlg.getSignature() == SignatureAlgorithm.rsa) {
                                    signatureAndHashAlgorithm = sigAlg;
                                    break;
                                }
                            }

                            if (signatureAndHashAlgorithm == null) {
                                return null;
                            }
                        }
                        
                        logger.debug("getRSASignerCredentials");
                        return new DefaultTlsSignerCredentials(context, dtlsInfo.getCertChain(), dtlsInfo.getPrivateKey(), signatureAndHashAlgorithm);
                    }

                    @SuppressWarnings("rawtypes")
                    public Hashtable getServerExtensions() throws IOException {
                        //see : http://bouncy-castle.1462172.n4.nabble.com/DTLS-SRTP-with-bouncycastle-1-49-td4656286.html
                        Hashtable table = super.getServerExtensions();
                        if (table == null) table = new Hashtable();
                        int[] protectionProfiles = {
                            // TODO : need to pick ONE that client offers
                            SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80  //this is the only one supported for now
                            // SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32
                            // SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_32
                            // SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_80
                        };
                        byte mki[] = new byte[0];  //should match client or use nothing
                        UseSRTPData srtpData = new UseSRTPData(protectionProfiles, mki);
                        TlsSRTPUtils.addUseSRTPExtension(table, srtpData);
                        
                        logger.debug("getServerExtensions: " + table.size());

                        return table;
                    }
                
                    public void notifyHandshakeComplete() throws IOException {
                        logger.debug("SRTPChannel:DTLS:Server:Handshake complete");
                        super.notifyHandshakeComplete();
                        getKeys();
                        remoteKey = tlsServer.getRemoteKey();
                        remoteSalt = tlsServer.getRemoteSalt();
                        localKey = tlsServer.getLocalKey();
                        localSalt = tlsServer.getLocalSalt();
                                
                        logger.debug("keys got here server");
                        isHandshakeComplete = 1;
                        logger.debug("isHandshakeComplete: " + isHandshakeComplete);

                    }
                };
                
                
                
                
                


                try {
                    logger.debug("SRTPChannel: accept dtlsCLient by DTLS server");
                    logger.debug("DTLS before accept:socket state:Socket is closed ?"+socket.isClosed()+socket.isConnected());
                    dtlsServer.accept(tlsServer, new UDPTransport(socket, 1500 - 20 - 8));      
                    udp_started = true;
               } catch (Exception e) {
                  logger.fatal("Exception:  ",e);     
               }
tlsServer=newdefaulttlsserver2(){
public void notifyClientCertificate(org.bouncycastle.crypto.tls.Certificate-clientCertificate)引发IOException异常{
org.bouncycastle.asn1.x509.Certificate[]chain=clientCertificate.getCertificateList();
debug(“notifyClientCertificate:+chain[0].getSignature());
/*//JFLog.log(“接收到的客户端证书链长度”+链长度);
for(int i=0;i!=chain.length;i++){
org.bouncycastle.asn1.x509.Certificate entry=chain[i];
//JFLog.log(“指纹:SHA-256”+keymmgmt.fingerprintSHA256(entry.getEncoded())+”(“+entry.getSubject()+”);
//JFLog.log(“cert length=“+entry.getEncoded().length”);
}*/
}
受保护的协议版本getMaximumVersion(){
debug(“getMaximumVersion:+ProtocolVersion.DTLSv10”);
返回ProtocolVersion.DTLSv10;
}
受保护的协议版本getMinimumVersion(){
调试(“getMinimumVersion:+ProtocolVersion.DTLSv10);
返回ProtocolVersion.DTLSv10;
}
受保护的TlsEncryptionCredentials getRSAEncryptionCredentials()引发IOException异常{
debug(“getRSAEncryptionCredentials”);
返回新的DefaultTlsEncryptionCredentials(上下文,dtlsInfo.getCertChain(),dtlsInfo.getPrivateKey());
}
@抑制警告(“原始类型”)
受保护的TlsSignerCredentials GetrsAssignerCredentials()引发IOException{
SignatureAndHashAlgorithm SignatureAndHashAlgorithm=null;
向量sigAlgs=支持的签名算法;
if(sigAlgs!=null){
对于(int i=0;i