FAQ.Security.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #!/bin/cat
  2. # $Id: FAQ.Security.txt,v 1.26 2021/07/11 12:11:38 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.Security.txt
  6. =======================================================================
  7. Imapsync tips about security. Issues and solutions.
  8. =======================================================================
  9. Questions answered in this FAQ are:
  10. Q. Is running this program a secure method of transferring emails?
  11. Are there any security concerns?
  12. Q. Does imapsync refer to SSL security protocols with --ssl1 and --ssl2
  13. and does it refer to TLS security protocols with the --tls1 and --tls2
  14. options?
  15. Short answer: No.
  16. Q. I noticed that the online UI has no option for TLS/SSL.
  17. Is this secure?
  18. Is this more secure than using the .bat file on my computer?
  19. Q. Are transferred emails/attachments stored on any other
  20. server/location aside from my originating/destination server(s)?
  21. Q. Other than changing passwords on the originating/destination email
  22. accounts once the relevant emails have been moved,
  23. are there any other security tips I should know?
  24. Q. I need to transfer mail from an imap server to another imap server.
  25. Which ports need to be open on the firewall to make this possible?
  26. Q. Does imapsync support the IMAP command STARTTLS?
  27. Q. Does imapsync support IMAP over SSL/TLS (IMAPS)?
  28. Q. How can I test an ssl/tls imap connection without imapsync?
  29. Q. How can I manually test login using --ssl?
  30. Q. Imapsync used to use SSL_VERIFY_PEER now it uses SSL_VERIFY_NONE.
  31. How can I change this back to the more secure SSL_VERIFY_PEER?
  32. Q: How can I have an imaps server?
  33. Now the questions again with their answers.
  34. =======================================================================
  35. Q. Is running this program a secure method of transferring emails?
  36. Are there any security concerns?
  37. R. Well, it depends. Use encryption and secure access to the host running
  38. imapsync then everything shall be safe.
  39. =======================================================================
  40. Q. Does imapsync refer to SSL security protocols with --ssl1 and --ssl2
  41. and does it refer to TLS security protocols with the --tls1 and --tls2
  42. options?
  43. Short answer: No.
  44. R. No.
  45. Imapsync behaviour:
  46. --ssl: Goes to encryption before the imap session start.
  47. The connection is on port 993.
  48. Can use the TLS or SSL security protocols.
  49. Fails if encryption cannot be established.
  50. --tls: Goes to encryption after the imap session start but before the
  51. credential are sent.
  52. The connection is on port 143.
  53. Can use the TLS or SSL securityprotocols.
  54. Fails if encryption cannot be established.
  55. Explanation:
  56. To force transferring emails over an encrypted connection, you can use
  57. the imapsync parameters --ssl1 and --ssl2 or the parameters --tls1 and
  58. --tls2, they all force the connection to be encrypted by the security
  59. protocols series SSL/TLS.
  60. In a security context, SSL refers to all deprecated Secure Sockets
  61. Layer protocols. TLS refers to the SSL successors, Transport Layer
  62. Security protocols. But TLS 1.0 and TLS 1.1 are also deprecated.
  63. Current endorsed versions of TLS are only TLS 1.2 and TLS 1.3 (July 2021).
  64. The whole story is detailed here:
  65. https://en.wikipedia.org/wiki/Transport_Layer_Security
  66. Options --ssl1 and --ssl2 are a little more paranoid than --tls1 and
  67. --tls2 because they verify that the hostname of the certificate is the
  68. same as the one used by imapsync. Other than that, the security
  69. behavior is the same.
  70. =======================================================================
  71. Q. I noticed that the online UI has no option for TLS/SSL.
  72. Is this secure?
  73. Is this more secure than using the .bat file on my computer?
  74. R1. The online UI does TLS/SSL imap connections if the imap servers
  75. support TLS/SSL.
  76. If you are concerned about security then using the .bat file or .sh on
  77. your computer should be more secure since you can examine and secure
  78. it by yourself, no matter high is your paranoid spirit compared to
  79. mine.
  80. The online UI security is mine, I am concerned by security, not to the
  81. utmost high level possible but I won't give you direct access to the
  82. host to discover my level. With a good guy spirit, feel free to try
  83. to break the online UI security and report me any security issue you
  84. encounter, I'll do my best to fix them as soon as possible. Drop me a
  85. note before starting because I may detect a sort of abuse and ban your
  86. IPs.
  87. =======================================================================
  88. Q. Are transferred emails/attachments stored on any other
  89. server/location aside from my originating/destination server(s)?
  90. R. No!
  91. =======================================================================
  92. Q. Other than changing passwords on the originating/destination email
  93. accounts once the relevant emails have been moved,
  94. are there any other security tips I should know?
  95. R. Yes. Secure the host where imapsync is running since credentials
  96. are on it.
  97. =======================================================================
  98. Q. I need to transfer mail from an imap server to another imap server.
  99. Which ports need to be open on the firewall to make this possible?
  100. R. It depends. Open either:
  101. * port 143 in basic (no special option) or tls mode (--tls1 or --tls2)
  102. * port 993 in ssl mode (--ssl1 or --ssl2)
  103. =======================================================================
  104. Q. Does imapsync support the IMAP command STARTTLS?
  105. R1. Yes.
  106. Use --tls1 and --tls2 options:
  107. --tls1 tells imapsync to use STARTTLS on host1.
  108. --tls2 tells imapsync to use STARTTLS on host2.
  109. R2. Since imapsync release 1.755 STARTTLS mode is activated
  110. automatically when the server announces that it supports it by
  111. listing STARTTLS inside the response to the CAPABILITY command.
  112. If either --notls or --ssl are explicitly mentioned on the
  113. command-line options then STARTTLS won't be done.
  114. =======================================================================
  115. Q. Does imapsync support IMAP over SSL/TLS (IMAPS)?
  116. R. Yes natively since release 1.161.
  117. Still, there are 2 ways, at least, to use ssl:
  118. a) Use native --ssl1 and/or --ssl2 options
  119. --ssl1 tells imapsync to use ssl/tls on host1.
  120. --ssl2 tells imapsync to use ssl/tls on host2.
  121. b) Use stunnel
  122. http://www.stunnel.org/
  123. Use stunnel3 command since stunnel now usually calls
  124. stunnel4 or stunnel5 and the command line options syntax
  125. has changed (option "-c" not recognized for example).
  126. Assuming there is an imaps (993) server on imap.foo.org,
  127. on your localhost machine (or bar machine), run:
  128. stunnel3 -c -d imap -r imap.foo.org:imaps -f
  129. or using numbers instead of names:
  130. stunnel3 -c -d 143 -r imap.foo.org:993 -f
  131. then use imapsync on localhost (or bar machine) imap (143) port.
  132. If the local port 143 is already taken then use a free one,
  133. like 10143 for example.
  134. c) Another example for accessing Gmail with no local root access
  135. to open port 143:
  136. stunnel3 -P '' -c -d 9993 -r imap.gmail.com:993 -f
  137. Then, to access Gmail as host2 use:
  138. imapsync ... --host2 localhost --port2 9993 --nossl2
  139. =======================================================================
  140. Q.How can I test an ssl/tls imap connection without imapsync?
  141. R1. Use either ncat or telnet-ssl or openssl commands like in the
  142. following examples with imap.gmail.com server:
  143. ncat --ssl -C imap.gmail.com 993
  144. telnet-ssl -z ssl imap.gmail.com 993
  145. openssl s_client -crlf -connect imap.gmail.com:993
  146. The previous commands are interactive, hit ctrl-c
  147. to finish them. If you want to finish automatically, then use:
  148. { sleep 2; echo "A LOGOUT"; sleep 1; } | ncat --ssl -C imap.gmail.com 993
  149. =======================================================================
  150. Q. How can I manually test login using --ssl?
  151. R. Use either ncat or telnet-ssl or openssl commands like in the
  152. following examples with imap.gmail.com server:
  153. ncat --ssl -C imap.gmail.com 993
  154. telnet-ssl -z ssl imap.gmail.com 993
  155. openssl s_client -crlf -connect imap.gmail.com:993
  156. Typical dialog for an imap LOGIN command:
  157. * OK Gimap ready for requests from 78.196.254.58 q1mb175739668wix
  158. A1 LOGIN "gilles.lamiral@gmail.com" "secret"
  159. * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE ... ESEARCH
  160. A1 OK gilles.lamiral@gmail.com Gilles Lamiral authenticated (Success)
  161. A2 LOGOUT
  162. * BYE LOGOUT Requested
  163. A2 OK 73 good day (Success)
  164. The client part you have to type is
  165. A1 LOGIN ...
  166. A2 LOGOUT
  167. while replacing ... by your credentials values,
  168. other lines are the server responses.
  169. =======================================================================
  170. Q. How can I test a STARTTLS imap connection without imapsync?
  171. R1. Use openssl command like the following example with
  172. an outlook.office365.com server:
  173. openssl s_client -crlf -starttls imap -connect outlook.office365.com:143
  174. The previous commands are interactive, hit ctrl-c
  175. to finish them. If you want to finish automatically, then use:
  176. { sleep 2; echo "a logout"; sleep 1; } | openssl s_client -crlf -starttls imap -connect outlook.office365.com:143
  177. Replace outlook.office365.com with your imap server name.
  178. ======================================================================
  179. Q. Imapsync used to use SSL_VERIFY_PEER now it uses SSL_VERIFY_NONE.
  180. How can I change this back to the more secure SSL_VERIFY_PEER?
  181. R. After imapsync 1.673,
  182. to set SSL_verify_mode to SSL_VERIFY_PEER on host1
  183. and SSL_verify_mode to SSL_VERIFY_NONE on host2
  184. imapsync ... --ssl1 --ssl2 \
  185. --sslargs1 SSL_verify_mode=1 \
  186. --sslargs2 SSL_verify_mode=0
  187. See "perldoc IO::Socket::SSL" for all possibilities, also at
  188. http://search.cpan.org/perldoc?IO%3A%3ASocket%3A%3ASSL
  189. It might be possible you need an extra option
  190. --sslargs1 SSL_ca_file=/etc/ssl/certs/ca-certificates.crt
  191. to help the ssl software verifying the server certificate.
  192. The file ca-certificates.crt may be elsewhere on your system, even
  193. named differently.
  194. The imap server certificates are not checked for authenticity
  195. by imapsync by default because too many imap servers are crappy
  196. configured regarding certified certificates.
  197. This default behavior is chosen like this because users
  198. want their emails transferred, instead of being not transferred
  199. because of an incompetent imap server sysadmin.
  200. I admit that this part, checking imap ssl/tls certificates,
  201. could be improved from my side by including well known
  202. certificates directly in imapsync.
  203. Drop me a note to encourage me, I'm lazy.
  204. =======================================================================
  205. Q: How can I have an imaps server?
  206. R. Three solutions.
  207. a) Install one
  208. b) or use stunnel :
  209. Assuming there is an imap (143) server on localhost
  210. stunnel -d 993 -r 143 -f
  211. c) or use stunnel on inetd
  212. imaps stream tcp nowait cyrus /usr/sbin/stunnel -s cyrus -p /etc/ssl/certs/imapd.pem -r localhost:imap2
  213. =======================================================================
  214. =======================================================================