尝试在客户端和服务器之间进行TLS握手。但是,它未通过更改密码指定步骤。同样在客户端上,我将收到如下所述的异常:我无法理解为什么我收到了如下异常的异常。

这是什么意思?有关如何解决此问题的任何想法?

我正在Java 7下运行它。


  java.security.NoSuchAlgorithmException:PBES2 AlgorithmParameters not
  可在
  sun.security.jca.GetInstance.getInstance(GetInstance.java:159)在
  java.security.Security.getImpl(Security.java:695)在
  java.security.AlgorithmParameters.getInstance(AlgorithmParameters.java:146)
    在com.certicom.security.pkcs.pkcs5.g。(来源未知)
  com.certicom.security.pkcs.pkcs5.i.a(来源未知)
  com.certicom.security.sslplus.b.a(来源未知)
  com.certicom.security.cert.internal.x509.PKCS8.decrypt(未知来源)
    在
  com.certicom.security.cert.internal.x509.SSLPlusSupport.getLocalIdentity(未知
  来源)com.certicom.tls.cert.CertLoader.loadLocalIdentity(未知
  来源)com.certicom.tls.interfaceimpl.i.a(来源不明)
  com.certicom.tls.TLSContext.loadLocalIdentity(未知来源)位于
  com.onstar.emxp.util.TLSClient.loadCert(TLSClient.java:66)在
  com.onstar.adc.pd.connection.TLSContextLoader.getTLSContext(TLSContextLoader.java:27)
    在com.onstar.adc.pd.PacketClient.run(PacketClient.java:74)
  
  java.security.InvalidKeyException:PBES2算法参数不正确
  可从com.certicom.security.pkcs.pkcs5.g。获得(未知
  来源)com.certicom.security.pkcs.pkcs5.i.a(来源不明)
  com.certicom.security.sslplus.b.a(来源未知)
  com.certicom.security.cert.internal.x509.PKCS8.decrypt(未知来源)
    在
  com.certicom.security.cert.internal.x509.SSLPlusSupport.getLocalIdentity(未知
  来源)com.certicom.tls.cert.CertLoader.loadLocalIdentity(未知
  来源)com.certicom.tls.interfaceimpl.i.a(来源不明)
  com.certicom.tls.TLSContext.loadLocalIdentity(未知来源)位于
  com.onstar.emxp.util.TLSClient.loadCert(TLSClient.java:66)在
  com.onstar.adc.pd.connection.TLSContextLoader.getTLSContext(TLSContextLoader.java:27)
    在com.onstar.adc.pd.PacketClient.run(PacketClient.java:74)
  
  java.security.KeyManagementException在
  com.certicom.security.cert.internal.x509.SSLPlusSupport.getLocalIdentity(未知
  来源)com.certicom.tls.cert.CertLoader.loadLocalIdentity(未知
  来源)com.certicom.tls.interfaceimpl.i.a(来源不明)
  com.certicom.tls.TLSContext.loadLocalIdentity(未知来源)位于
  com.onstar.emxp.util.TLSClient.loadCert(TLSClient.java:66)在
  com.onstar.adc.pd.connection.TLSContextLoader.getTLSContext(TLSContextLoader.java:27)
    在com.onstar.adc.pd.PacketClient.run(PacketClient.java:74)上警告:
  无法加载证书数据包服务器
  java.security.KeyManagementException


客户端代码进行tls握手:


    socket = new Socket(host, port);
    InputSSLIOStream inputStream = new InputSSLIOStream(
    socket.getInputStream());
    OutputSSLIOStream outputStream = new OutputSSLIOStream(
    socket.getOutputStream());
    TLSConnection tlsConnection = tlsContextLoader.getTLSContext()
                    .getClientConnection(inputStream, outputStream, "server");
    tlsConnection.startHandshake();
    socket.setSoTimeout(30000);
    OutputStream tlsOutputStream = tlsConnection.getOutputStream();
    InputStream tlsInputStream = tlsConnection.getInputStream();



我的TLS上下文加载器:

public class TLSContextLoader
{
    public TLSContext getTLSContext()
            throws Exception
    {
        TLSContext localTLSContext = new TLSContext();
        localTLSContext.setIsStrongCipherSuiteLimited(false);
        localTLSContext.setHelloProtocol("TLS1-ONLY");
        localTLSContext.setEllipticCurves(new String[] { "secp256r1" });
        localTLSContext.setClientAuthModes(new String[] { "ECDSA_SIGN" });
        localTLSContext.setDebugFlag();
        localTLSContext.setEccDraftCompatibility(-1);
        localTLSContext.setX509BasicConstraintBug(true);
        TLSClient.loadCert(localTLSContext, "packetserver");
        localTLSContext.setPSKParam(new byte[] { 49 });
        localTLSContext.loadTrustedCertificates(KeyLoader.getTrustedStream("rootca"));

        localTLSContext.setRNG(new SecureRandom(generateSeed()));
        LocalTrustManager localLocalTrustManager = new LocalTrustManager();
        localTLSContext.setTrustManager(localLocalTrustManager);
        localTLSContext.setEnabledCipherSuites(EMXPArrays.csvToArray("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA"));

        localTLSContext.setNeedClientAuth(false);
        return localTLSContext;
    }

    private byte[] generateSeed() {
        String str = new String();
        str = str + "IDH" + System.identityHashCode(str);
        Runtime localRuntime = Runtime.getRuntime();
        str = str + "FM" + localRuntime.freeMemory();
        str = str + "CT" + System.currentTimeMillis();
        Properties localProperties = System.getProperties();
        Enumeration localEnumeration = localProperties.elements();
        while (localEnumeration.hasMoreElements()) {
            str = str + localEnumeration.nextElement();
        }
        str = str + "VHC" + str.hashCode();
        return str.getBytes();
    }
}

最佳答案

解决了以上问题。为了确保安全性,正在客户端使用certicom库,而在服务器端则使用JDK 7。当客户端和服务器都基于JDK 7安全库时,客户端就可以与服务器进行对话并协商握手。

10-07 22:23