javax无法将套接字转换为TLS; [英] javax Could not convert socket to TLS;

查看:62
本文介绍了javax无法将套接字转换为TLS;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Javax发送邮件时遇到问题。我们使用Gmail通过我们的Java软件发送邮件已有4年之久。现在我收到以下错误:

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not convert socket to TLS;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at SendEmail.sendMissingMailWeek(SendEmail.java:233)
    at main.negVerkaeufeMailenWeek(main.java:368)
    at main.main(main.java:79)
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1907)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:666)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at SendEmail.sendMissingMailWeek(SendEmail.java:226)
    ... 2 more
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
    at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
    at sun.security.ssl.TransportContext.kickstart(TransportContext.java:220)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:428)
    at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:549)
    at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:486)
    at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1902)
    ... 9 more

Process finished with exit code 1

以下是我的Gmail设置:

            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.port", "587");
            props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
            props.put("mail.smtp.debug", "true");

我还尝试了其他Mailserver(O365、Strato),但收到相同的错误。

TLS

该错误指示与与邮件服务器建立安全连接所需的推荐答案协议有关的某些问题。

正如您在问题注释中看到的,问题可能由许多不同的原因引起。在不了解您的操作系统、JDK和JavaMail库版本的情况下,我们只能提供真正的原因。

@g00se给您一个很好的建议:请通过提供以下选项尝试在启用SSL调试的情况下运行您的程序:

-Djavax.net.debug=all

此外,请尝试在您的配置属性中显式包含TLS协议,这可能会有所帮助:

props.put("mail.smtp.ssl.protocols", "TLSv1.2");

无论如何,对于您指出的症状,并且由于AFAIK Google最近没有更改任何相关配置,您的问题可能与JDK发行版中引入的a change有关,以便在默认情况下禁用不安全的TLS协议版本:

security-libs/javax.net.ssl
禁用TLS1.0和1.1

TLS 1.0和1.1是TLS协议的版本,不再 被认为是安全的,并已被更安全和更现代的 版本(TLS 1.2和1.3)。

这些版本现在默认情况下已禁用。如果你遇到 问题,您可以通过以下方式重新启用版本,风险自负:删除 jdk.tls.disabledAlgorithms中的&Quot;TLSv1&Quot;和/或&Quot;TLSv1.1&Quot; java.security配置文件中的安全属性。

正如您在bug description中看到的,更改已回传到不同的JDK版本。

可能是您升级了JDK,因此出现了问题。

如果是这种情况(如引号中所示),请尝试编辑java.security配置文件,并从jdk.tls.disabledAlgorithms安全属性中删除TLSv1和/或TLSv1.1

这篇关于javax无法将套接字转换为TLS;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆