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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
是否可以使用私钥解密我的XMPP服务器流量?_Xmpp_Rsa_Ssl_Encryption - Fatal编程技术网

是否可以使用私钥解密我的XMPP服务器流量?

是否可以使用私钥解密我的XMPP服务器流量?,xmpp,rsa,ssl,encryption,Xmpp,Rsa,Ssl,Encryption,如有必要,我可以提供更多细节,但我的问题基本上是: 如果我运行的openfire服务器使用我创建并拥有的RSA pub/priv key组合对流量进行加密,那么在Java中是否有更好的方法来嗅探网络上的数据包,然后使用我的私钥对其进行解密?目前,我可以使用以下方法对字符串进行加密/解密: public class TLSDecryptTest { Cipher Ecipher; Cipher Dcipher; public TLSDecryptTest(String pubpath, Str

如有必要,我可以提供更多细节,但我的问题基本上是:

如果我运行的openfire服务器使用我创建并拥有的RSA pub/priv key组合对流量进行加密,那么在Java中是否有更好的方法来嗅探网络上的数据包,然后使用我的私钥对其进行解密?目前,我可以使用以下方法对字符串进行加密/解密:

public class TLSDecryptTest {

Cipher Ecipher;
Cipher Dcipher;

public TLSDecryptTest(String pubpath, String privpath){
    byte[] publicKeyContentsAsByteArray;
    RSAPublicKey pubKey;
    try {
    this.Ecipher = Cipher.getInstance("RSA");
    String path1 = new String("C:\\Users\\peter.marino\\Desktop\\javapub.key");
    File pubFile = new File(path1);
    publicKeyContentsAsByteArray = new byte[(int)pubFile.length()];

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(pubFile));
        publicKeyContentsAsByteArray = new byte[(int)pubFile.length()];
        bis.read(publicKeyContentsAsByteArray);
        bis.close();

        CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
        Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(publicKeyContentsAsByteArray));
       pubKey = (RSAPublicKey) certificate.getPublicKey();
       this.Ecipher.init(Cipher.ENCRYPT_MODE, pubKey);
    } catch(Exception e) {
        System.out.println("Exception" + e);
    }

    try {
    this.Dcipher = Cipher.getInstance("RSA");
    String path2 = new String("C:\\Users\\peter.marino\\Desktop\\java.key");
    File privFile = new File(path2);
    byte[] privateKeyContentsAsByteArray = new byte[(int)privFile.length()];

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(privFile));
        privateKeyContentsAsByteArray = new byte[(int)privFile.length()];
        bis.read(privateKeyContentsAsByteArray);
        bis.close();

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");

        KeySpec ks = new PKCS8EncodedKeySpec(privateKeyContentsAsByteArray);
        RSAPrivateKey privKey = (RSAPrivateKey) keyFactory.generatePrivate(ks);
        System.out.println("PRIVATE KEY:::: " + new String(privKey.getEncoded()).equals(new String(privateKeyContentsAsByteArray)));
        this.Dcipher.init(Cipher.DECRYPT_MODE, privKey);
    } catch(Exception e) {
        System.out.println("Exception" + e);
    }

}

 public byte[] en(byte[] decryptedMessage) throws Exception {
     byte[] encryptedMessage = this.Ecipher.doFinal(decryptedMessage);
     //byte[] encryptedMessage = this.Ecipher.doFinal(decryptedMessage);
     return (encryptedMessage);

 }


 public byte[] de(byte[] encryptedMessage) throws Exception {
     byte[] decryptedMessage = this.Dcipher.doFinal(encryptedMessage);
     return (decryptedMessage);

 }

public static void main(String args[]) throws Exception{
    TLSDecryptTest t = new TLSDecryptTest(null,null);
    String s = ("Testing decryption.1Testing decryption.2Testing decryption.3Testing decryption.4");
    System.out.println("S: " + s);
    byte[] todo = s.getBytes();
    byte[] e = t.en(todo);
    String es = new String(e);
    System.out.println("E: " + es);
    byte[] d = t.de(e);
    String ds = new String(d);
    System.out.println("D: " + ds);
}
}

这很好用。然而,如果我嗅探到一些数据包,然后尝试解密,我就会出错。我甚至尝试只解密它的前256个字节,因为这是我的RSA密钥的限制,但它仍然会抛出错误。最值得注意的是,在doFinal行中出现了一个BadPaddingException

有什么想法吗


提前感谢。

否。使用公钥加密,您只能使用相反的密钥解密。e、 g

encrypted with private key => decrypt with public key
encryptd with public key => decrypt with private key
想想如果

encrypted with public key => decrypt with public key

这是可能的——因为公钥是公开的,每个人都可以看到,你基本上是在saran wrap中包装你的数据,因为每个人都已经有了解密它的密钥。这将彻底破坏整个SSL安全模型。

如果您谈论的是受SSL保护的会话,那么如果您拥有合法服务器的私钥,并且可以获得无论如何都是公共的证书,则中间人攻击是可能的。出于实际目的,您应该能够使用Wireshark监视您的流量


但是你不能按原样解密流量。部分原因是它没有使用公钥加密进行加密-数据使用每个会话生成的对称密钥进行加密

如果您拥有服务器的私钥,Wireshark将允许您解密。文档是

首先,转到Edit/Preferences/Protocols/SSL,单击RSA密钥旁边的Edit按钮:

接下来,单击新建。用描述何时应该使用密钥的信息填写表单。这应该是服务器的IP地址和端口:


您的密钥文件可能需要也可能不需要密码短语。点击OK三次。像往常一样抓拍。

那有什么意义呢?你是说我用错密钥解密了吗?我想我可以试着用公钥解密,但我的全部观点是我正试图用私钥解密。我想你不明白我的问题。用私钥加密=>用公钥解密:这实际上叫做用私钥签名并验证签名。即使对RSA的操作大致相同,但对DSA的操作却不同。更重要的是,使用私钥加密没有意义,因为任何人都可以读取加密的内容,因为公钥是公开的。在这种情况下没有PKI。SSL使用对称加密。是的,但是,假设我不能想象中间人使用这个客户端。他们只能给我他们的私钥/公钥对。你是说没有办法从中获得可用的数据吗?:/如果这是真的,那么感谢您的回复。还有,我将如何使用wireshark?如果你说的是真的,理论上也不可能做到……例如,有没有办法获得对称密钥?你应该研究一下对称密钥是如何从主密钥之前的密钥中派生出来的。您可能会找到更多的指针,但这可能需要相当多的工作。请注意,如果您使用的是短暂的Diffie-Hellman密码套件,则无法仅基于流量和私钥来执行此操作。@user1456637抱歉,我不明白您的意思。你的问题并不是说你有证书,也不是说你在使用WiRESHARK。@ USE1456637,你不能解密数据,但是你可以充当中间人,充当连接客户端的服务器,充当真实服务器的客户端。这是通过捕获到服务器的网络数据包,然后实现TLS客户机和服务器来完成的。当然,除了需要内核模式驱动程序的数据包捕获之外,您也可以这样做,这将是对wireshark的重写。听起来您正在尝试实现自己的SSL/TLS变体,这听起来是个坏主意。你为什么不使用SSL/TLS,因为它是由JSSE和其他实现提供的?因为它们提供了完美的前向保密性,你仍然会遇到困难。可能最好实现某种XMPP反向代理,这样您的服务就可以处理请求、监视请求并将它们转发到后面的实际服务器。这是毫无帮助的。我已经指出这是行不通的。此外,根据我的wireshark,xmpp不是有效的协议。xmpp在1.8.0rc1上工作。如果你不想重建,1.6.8将允许你选择一个像imap这样的协议,事情实际上会正常工作,只是在UI中被标记为错误。根据你为什么要这么做,你可能能够禁用DHE密码套件,提示如下:这是一个很好的链接,禁用DHE ci
我应该让你的建议起作用。我认为XMPP在wireshark中已经支持了很长一段时间了。XMPP已经支持了很长一段时间,但是要将一个协议连接到这个特定的对话框中,显然需要在解析器代码中付出额外的努力,直到最近才添加。