FAQ.SSL_errors.txt 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #!/bin/cat
  2. $Id: FAQ.SSL_errors.txt,v 1.18 2022/01/14 21:20:37 gilles Exp gilles $
  3. This document is also available online at
  4. https://imapsync.lamiral.info/FAQ.d/
  5. https://imapsync.lamiral.info/FAQ.d/FAQ.SSL_errors.txt
  6. ======================================================================
  7. Imapsync SSL errors
  8. ======================================================================
  9. Questions answered in this FAQ are:
  10. Q. What is the error
  11. DEBUG: .../IO/Socket/SSL.pm:1177: global error: Undefined SSL object
  12. Q. What are the errors
  13. DEBUG: .../IO/Socket/SSL.pm:1165: local error: SSL write error
  14. or
  15. DEBUG: .../IO/Socket/SSL.pm:1088: local error: SSL read error
  16. Q. What can I do to avoid those "SSL read/write errors"?
  17. Q. What are the errors
  18. SSL connect attempt failed SSL
  19. routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  20. or
  21. SSL connect attempt failed SSL
  22. SSL routines:ssl_choose_client_version:unsupported protocol
  23. Q. What is the error
  24. fatal SSL error: SSL connect attempt failed with unknown error
  25. SSL wants a read first
  26. Q. How to see the certificate and identify problems in it?
  27. Now the questions again with their answers.
  28. ======================================================================
  29. Q. What is the error
  30. DEBUG: .../IO/Socket/SSL.pm:1177: global error: Undefined SSL object
  31. R. It's a fake error from the Perl Module IO::Socket::SSL
  32. Imapsync works well despite this fake warning but it's disturbing
  33. when you encounter errors due to something else, you believe it's
  34. the issue but no, it's something else to deal with.
  35. This fake error is fixed in IO::Socket::SSL release 2.073
  36. https://metacpan.org/dist/IO-Socket-SSL/changes
  37. "fix #110 - prevent internal error warning in some cases"
  38. https://github.com/noxxi/p5-io-socket-ssl/issues/110
  39. imapsync.exe release 2.178 uses this fixed 2.073 IO::Socket::SSL
  40. ======================================================================
  41. Q. What are the errors
  42. DEBUG: .../IO/Socket/SSL.pm:1165: local error: SSL write error
  43. or
  44. DEBUG: .../IO/Socket/SSL.pm:1088: local error: SSL read error
  45. R1. As they claim, those errors are SSL errors. SSL is not directly
  46. done by imapsync but by an underlying Perl module called
  47. IO::Socket::SSL. Those errors arise sometimes and sometimes
  48. they form a series that ends with imapsync auto-abortion.
  49. Those errors happen with some hosts but not with others,
  50. it's often Exchange or Office365. I don't know what exactly happens.
  51. Those errors happen more often on Windows than on Linux.
  52. ======================================================================
  53. Q. What can I do to avoid those "SSL read/write errors"?
  54. R0. Windows users: upgrade to imapsync.exe release 1.836 (or next ones)
  55. Those errors appear less often with imapsync releases post 1.836
  56. R1. Remove all ssl/tls encryption
  57. imapsync ... --nossl1 --notls1 --nossl2 --notls2
  58. R2. If you don't want to quit encryption, rerun imapsync until the
  59. complete sync is over. Those errors are not at the same place
  60. each time, so imapsync will sync the remaining messages at each run
  61. until none remains.
  62. R3. Run imapsync on a Linux machine, a VM is ok, there are less
  63. SSL errors on Unix.
  64. R4. Use https://imapsync.lamiral.info/X/
  65. It's a Linux host so response R3 applies there.
  66. R5. Set up a ssltunnel proxy to the host.
  67. Read the file FAQ.Security.txt for an example to set up
  68. a ssltunnel proxy.
  69. ======================================================================
  70. Q. What are the errors
  71. SSL connect attempt failed SSL
  72. routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  73. or
  74. SSL connect attempt failed SSL
  75. SSL routines:ssl_choose_client_version:unsupported protocol
  76. R1. Use:
  77. imapsync ... --sslargs1 SSL_cipher_list=DEFAULT
  78. or
  79. imapsync ... --sslargs2 SSL_cipher_list=DEFAULT
  80. depending on where the error occurs, host1 or host2 or both.
  81. R2. If it doesn't work, I let you try other things,
  82. I quote the "SSL_version" section of
  83. https://metacpan.org/pod/IO::Socket::SSL (Module version: 2.066)
  84. imapsync ... --sslargs1 SSL_cipher_list=DEFAULT
  85. imapsync ... --sslargs1 SSL_version=SSLv2
  86. imapsync ... --sslargs1 SSL_version=SSLv23
  87. imapsync ... --sslargs1 SSL_version=SSLv3
  88. imapsync ... --sslargs1 SSL_version=TLSv1
  89. imapsync ... --sslargs1 SSL_version=TLSv1_1
  90. imapsync ... --sslargs1 SSL_version=TLSv1_2
  91. imapsync ... --sslargs1 SSL_version=TLSv1_3
  92. Those examples are for host1. For host2, use --sslargs2 instead.
  93. Feedback on what worked for you is welcome!
  94. A loop to check every version and print the good ones:
  95. for v in SSLv2 SSLv23 SSLv3 TLSv1 TLSv1_1 TLSv1_2 TLSv1_3; do
  96. imapsync ... --sslargs1 SSL_version=$v && GOOD="$GOOD $v"
  97. done
  98. echo "$GOOD"
  99. I reproduce below the documentation of the underlying Perl
  100. module IO::Socket::SSL used by imapsync:
  101. https://metacpan.org/pod/IO::Socket::SSL
  102. ...
  103. SSL_version
  104. Sets the version of the SSL protocol used to transmit data.
  105. 'SSLv23' uses a handshake compatible with SSL2.0, SSL3.0 and TLS1.x,
  106. while 'SSLv2', 'SSLv3', 'TLSv1', 'TLSv1_1', 'TLSv1_2', or 'TLSv1_3'
  107. restrict handshake and protocol to the specified version.
  108. All values are case-insensitive. Instead of 'TLSv1_1', 'TLSv1_2', and 'TLSv1_3'
  109. one can also use 'TLSv11', 'TLSv12', and 'TLSv13'.
  110. Support for 'TLSv1_1', 'TLSv1_2', and 'TLSv1_3'
  111. requires recent versions of Net::SSLeay and openssl.
  112. Independent from the handshake format you can limit to set of
  113. accepted SSL versions by adding !version separated by ':'.
  114. The default SSL_version is 'SSLv23:!SSLv3:!SSLv2' which means,
  115. that the handshake format is compatible to SSL2.0 and higher,
  116. but that the successful handshake is limited to TLS1.0 and higher,
  117. that is no SSL2.0 or SSL3.0 because both of these versions have
  118. serious security issues and should not be used anymore.
  119. You can also use !TLSv1_1 and !TLSv1_2 to
  120. disable TLS versions 1.1 and 1.2 while still allowing TLS version 1.0.
  121. Setting the version instead to 'TLSv1' might break interaction
  122. with older clients, which need and SSL2.0 compatible handshake.
  123. On the other side some clients just close the connection
  124. when they receive a TLS version 1.1 request.
  125. In this case setting the version
  126. to 'SSLv23:!SSLv2:!SSLv3:!TLSv1_1:!TLSv1_2' might help.
  127. ======================================================================
  128. Q. What is the error
  129. fatal SSL error: SSL connect attempt failed with unknown error
  130. SSL wants a read first
  131. R. If you're using --ssl1 or --ssl2, try instead --tls1 or --tls2
  132. ======================================================================
  133. Q. How to see the certificate and identify problems in it?
  134. R. Use the command openssl like this:
  135. echo | openssl s_client -crlf -connect imap.gmail.com:993
  136. echo | openssl s_client -crlf -connect test1.lamiral.info:993
  137. and examine carefully the content, the "verify return:" lines,
  138. the chain. Sometimes, the server certificate is ok but not the whole
  139. chain of certificates so the certification fails.
  140. Here is an example.
  141. One of the certificate is expired:
  142. echo | openssl s_client -crlf -connect test1.lamiral.info:993
  143. CONNECTED(00000003)
  144. depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
  145. verify return:1
  146. depth=1 C = US, O = Let's Encrypt, CN = R3
  147. verify return:1
  148. depth=0 CN = test1.lamiral.info
  149. verify error:num=10:certificate has expired
  150. notAfter=Apr 11 10:14:05 2021 GMT
  151. verify return:1
  152. depth=0 CN = test1.lamiral.info
  153. notAfter=Apr 11 10:14:05 2021 GMT
  154. verify return:1
  155. ---
  156. Certificate chain
  157. 0 s:/CN=test1.lamiral.info
  158. i:/C=US/O=Let's Encrypt/CN=R3
  159. 1 s:/C=US/O=Let's Encrypt/CN=R3
  160. i:/O=Digital Signature Trust Co./CN=DST Root CA X3
  161. ---
  162. Server certificate
  163. -----BEGIN CERTIFICATE-----
  164. MIIFKjCCBBKgAwIBAgISBHYZCE3qSTIlvq97HI5TpBeAMA0GCSqGSIb3DQEBCwUA
  165. MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
  166. EwJSMzAeFw0yMTAxMTExMDE0MDVaFw0yMTA0MTExMDE0MDVaMB0xGzAZBgNVBAMT
  167. EnRlc3QxLmxhbWlyYWwuaW5mbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
  168. ggEBAMUTJVdrTl86nDI2yO6Vz5l1qxMMPqJylQcgi9vDHpwsnUq5HGPv+qZNhM69
  169. ...
  170. After an complete server update ("apt update && apt upgrade && /etc/init.d/dovecot restart"):
  171. echo | openssl s_client -crlf -connect test1.lamiral.info:993
  172. CONNECTED(00000003)
  173. depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
  174. verify return:1
  175. depth=1 C = US, O = Let's Encrypt, CN = R3
  176. verify return:1
  177. depth=0 CN = test1.lamiral.info
  178. verify return:1
  179. ---
  180. Certificate chain
  181. 0 s:/CN=test1.lamiral.info
  182. i:/C=US/O=Let's Encrypt/CN=R3
  183. 1 s:/C=US/O=Let's Encrypt/CN=R3
  184. i:/O=Digital Signature Trust Co./CN=DST Root CA X3
  185. ---
  186. Server certificate
  187. -----BEGIN CERTIFICATE-----
  188. MIIFKTCCBBGgAwIBAgISBD4QN3cfB1JpTm75oVrkkAElMA0GCSqGSIb3DQEBCwUA
  189. MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
  190. EwJSMzAeFw0yMTAzMTIxODQxMTJaFw0yMTA2MTAxODQxMTJaMB0xGzAZBgNVBAMT
  191. EnRlc3QxLmxhbWlyYWwuaW5mbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
  192. ggEBANuPNbYLPMZ4vPa9NBoHAUdIXqpi0eqdXMXd2sT+qRmqxS5ihr999BHOROcr
  193. ...
  194. Champagne!
  195. ======================================================================
  196. ======================================================================