Subject: Add GnuTLS support for SMTP, IMAP, POP, and NNTP Author: Hiroki Sato Origin: https://github.com/hrs-allbsd/Mew/commit/eefffb63ed0e1c0a8381fa639c07677bf2284600 Origin: https://github.com/tats/Mew/tree/feature/gnutls cf. https://groups.google.com/g/mew-ja/c/sSfEPKD_CSM diff --git a/00copyright b/00copyright index b049ccf..d7163e4 100644 --- a/00copyright +++ b/00copyright @@ -1,4 +1,4 @@ -Copyright (C) 1994-2015 Mew developing team. +Copyright (C) 1994-2020 Mew developing team. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/00copyright.ja b/00copyright.ja index 7df21de..d577401 100644 --- a/00copyright.ja +++ b/00copyright.ja @@ -1,7 +1,7 @@ (注) 以下は日本語の方が分かりやすい人のために、英語の著作権表示を訳し た文章である。正式な著作権は、英語の原本に従う。 -Copyright (C) 1994-2015 Mew developing team. +Copyright (C) 1994-2020 Mew developing team. All rights reserved. 変更の有無にかかわらず、ソースおよびバイナリ形式の再配布および利用は、 diff --git a/00diff b/00diff index 907e6aa..0383646 100644 --- a/00diff +++ b/00diff @@ -4,6 +4,10 @@ +* Mew now supports GnuTLS library for TLS connections when the Emacs + is built with it. To enable it, set mew-{imap,nntp,pop,smtp}-ssl to + 'native. + * mew-smtp-port now supports Unix domain socket. If it is set to an absolute pathname such as "/var/run/msp.sock", Mew will use it as a Unix domain socket which supports SOCK_STREAM and understands SMTP. diff --git a/info/mew.texi b/info/mew.texi index a463f17..d323e3f 100644 --- a/info/mew.texi +++ b/info/mew.texi @@ -136,13 +136,13 @@ home page (http://www.Mew.org/). @ifset ja Mew とは、テキスト・メールやマルチメディア・メール(MIME)、ニュース、セ -キュリティ機能(PGP、S/MIME、SSH、SSL)を便利に利用するためのユーザインター +キュリティ機能(PGP、S/MIME、SSH、TLS)を便利に利用するためのユーザインター フェイスです。最新の検索サービスとも連動します。 @end ifset @ifset en Mew is a user interface for text messages, multimedia messages (MIME), news articles and security functionality including PGP, S/MIME, SSH, -and SSL. Also, Mew can work with the recent search services. +and TLS. Also, Mew can work with the recent search services. @end ifset @ifset ja @@ -734,6 +734,7 @@ To read and/or write articles of NetNews, the followings are necessary. @end ifset @vindex mew-use-cached-passwd @vindex mew-use-master-passwd +@vindex mew-master-passwd-type @ifset ja メッセージを送受信したり、PGP や S/MIME を使ったりする場合には、パスワー @@ -899,6 +900,90 @@ touch your Emacs. If you leave your PC and an Emacs expert happens to check your configuration, your passwords could be stolen. @end ifset +@ifset ja +Mew のマスターパスワード機能は Mew 独自のものですが、Emacs には +auth-source と呼ばれるパスワードマネージャが含まれています。 +auth-source は .netrc 形式のテキストファイル、GNOME Keyring, macOS +Keychain といった、プラットフォームが提供するパスワード保存機能にも対 +応しています。 +@end ifset +@ifset en +While the master password feature is one of the feature of Mew, Emacs +supports ``auth-source'' password manager. Auth-source is similar to +Mew's master password but supports variety of platform-dependent +password stores including .netrc-style plain text, GNOME Keyring, and +macOS Keychain. +@end ifset + +@ifset ja +Mew の auth-source 対応は、まだ実験的なものです。 +auth-source を試すには、マスターパスワードを使用する +設定に加えて、次のように設定します。 +@end ifset +@ifset en +Note that support for auth-source is still experimental. +To try auth-source, configure the following variable: +@end ifset + +@lisp +(setq mew-master-passwd-type 'auth-source) +(setq auth-sources '("~/.authinfo.gpg" "~/.authinfo" "~/.netrc")) +@end lisp + +@ifset ja +どのパスワード保存機能を使用するかは、@samp{auth-sources} 変数で設定で +きます。上記設定では 3 個のファイルを探し、一番最初に見つかったものを +使用します。@samp{auth-sources} を指定しなかった場合、 +デフォルトでは .netrc 形式のテキストファイルとして、~/.authinfoと +いうファイルが使われます。GnuPG を使って暗号化し、~/.authinfo.gpg とい +う名前で用意すれば、暗号化した状態で維持することも可能です。平文のファ +イルにパスワードを保存するのは危険ですので、暗号化しておくことを強くお +勧めします。詳しくは、@xref{(auth)Top} を参照してください。 +@end ifset +@ifset en +Which password store is used can be set by @samp{auth-sources} +variable. In this example, one of the three files which was found +first is used. By default .netrc-style text file named +``~/.authinfo'' is used. You can encrypt this file by using GnuPG and +put the encrypted file as ``~/.authinfo.gpg'' and remove the original +file. Mew will use the encrypted version seamlessly. It is strongly +recommended to use an encrypted file to store your passwords because +there is no protection in a plain text file. For more details, see +@xref{(auth)Top}. +@end ifset + +@ifset ja +.netrc 形式のテキストファイルを GnuPG で暗号化した場合、Mew は保存され +たパスワードの使用時に、復号用の鍵にアクセスするためのパスフレーズを尋 +ねます。この復号処理には、EasyPG Assistant と呼ばれる Emacs パッケージ +が使われます。このパッケージは GnuPG を呼び出して暗号の処理を行なうも +のです。多くの場合、デフォルトの設定で問題なく動作しますが、設定可能な +項目がいくつかあります。詳しくは、@xref{(epa)Top} を参照してください。 +@end ifset +@ifset en +If you use encrypted version of the .netrc-style text file as your +password store, Mew will ask you passphrase of the decryption key to +retrieve passwords from the file. For encryption and decryption, an +Emacs package named EasyPG Assistant, which calls GnuPG from Emacs, is +used. While it works with no specific configuration in most cases, +you can find several configuration knobs. For more details, see +@xref{(epa)Top}. +@end ifset + +@ifset ja +現在の auth-source には、記録したパスワードを上書き・消去できないとい +う大きな欠点があることに注意してください。サーバのパスワードを変更した +場合は、~/.authinfo.gpg ファイルを手動で編集してください。これは、将来の +Emacs で修正される見込みです。 +@end ifset +@ifset en +Note that the current version of auth-source has a big problem that it +cannot delete or update the password entry in the password store. If +you want to change or remove a password, you have to edit the +~/.authinfo file manually. This will be fixed in the future version +of Emacs. +@end ifset + @c %%%%%%%%%%%%%%%%% @node start, Viewing, password, Overview @@ -11427,9 +11512,11 @@ POP サーバの名前。 @item mew-pop-ssh-server POP を SSH 経由で取得する場合の SSH サーバの名前。 @item mew-pop-ssl -POP over SSL を使うか否か。 +POP over TLS を使うか否か。@samp{'native} は GnuTLS +を使った TLS 接続、@samp{'tunnel} は stunnel +を使った TLS トンネル接続を意味する。 @item mew-pop-ssl-port -POP over SSL のポート番号。 +POP over TLS のポート番号。 @item mew-pop-user POP のアカウント名。初期値はログイン名。 @item mew-pop-auth @@ -11461,9 +11548,11 @@ The name of your POP server. @item mew-pop-ssh-server The name of SSH server which forwards the POP3 port. @item mew-pop-ssl -If non-nil, POP connections are made over SSL. +If non-nil, POP connections are made over TLS. +@samp{'native} enables GnuTLS for native TLS connection +and @samp{'tunnel} uses stunnel to establish a TLS tunnel. @item mew-pop-ssl-port -The port for POP over SSL. +The port for POP over TLS. @item mew-pop-user The user name on your POP server. The default is your login name. @item mew-pop-auth @@ -11518,9 +11607,11 @@ IMAP サーバの名前。 @item mew-imap-ssh-server IMAP を SSH 経由で取得する場合の SSH サーバの名前。 @item mew-imap-ssl -IMAP over SSL を使うか否か。 +IMAP over TLS を使うか否か。@samp{'native} は GnuTLS +を使った TLS 接続、@samp{'tunnel} は stunnel +を使った TLS トンネル接続を意味する。 @item mew-imap-ssl-port -IMAP over SSL のポート番号。 +IMAP over TLS のポート番号。 @item mew-imap-user IMAP のアカウント名。初期値はログイン名。 @item mew-imap-auth @@ -11548,9 +11639,11 @@ The name of your IMAP server. @item mew-imap-ssh-server The name of SSH server which forwards the IMAP4 port. @item mew-imap-ssl -If non-nil, IMAP connections are made over SSL. +If non-nil, IMAP connections are made over TLS. +@samp{'native} enables GnuTLS for native TLS connection +and @samp{'tunnel} uses stunnel to establish a TLS tunnel. @item mew-imap-ssl-port -The port for IMAP over SSL. +The port for IMAP over TLS. @item mew-imap-user The user name on the IMAP server. The default is your login name. @item mew-imap-auth @@ -11601,9 +11694,11 @@ NNTP サーバの名前。 @item mew-nntp-ssh-server NNTP を SSH 経由で取得する場合の SSH サーバの名前。 @item mew-nntp-ssl -NNTP over SSL を使うか否か。 +NNTP over TLS を使うか否か。@samp{'native} は GnuTLS +を使った TLS 接続、@samp{'tunnel} は stunnel +を使った TLS トンネル接続を意味する。 @item mew-nntp-ssl-port -NNTP over SSL のポート番号。 +NNTP over TLS のポート番号。 @item mew-nntp-user NNTP のアカウント名。もし @samp{nil} でなければ、認証の手続きが実行され る。(mew-nntp-auth という変数はないことに注意。) @@ -11632,9 +11727,11 @@ The name of your NNTP server. @item mew-nntp-ssh-server The name of SSH server which forwards the NNTP port. @item mew-nntp-ssl -If non-nil, NNTP connections are made over SSL. +If non-nil, NNTP connections are made over TLS. +@samp{'native} enables GnuTLS for native TLS connection +and @samp{'tunnel} uses stunnel to establish a TLS tunnel. @item mew-nntp-ssl-port -The port for NNTP over SSL. +The port for NNTP over TLS. @item mew-nntp-user The user name on the NNTP server. If non-nil, authentication is used. (Note that mew-nntp-auth does not exist.) @@ -11699,9 +11796,11 @@ SMTP サーバと接続する際に用いるアドレスファミリ。初期値 @item mew-smtp-ssh-server SSH 経由でメッセージを送る際の SSH サーバの名前。 @item mew-smtp-ssl -SMTP over SSL を使うか否か。 +SMTP over TLS を使うか否か。@samp{'native} は GnuTLS +を使った TLS 接続、@samp{'tunnel} は stunnel +を使った TLS トンネル接続を意味する。 @item mew-smtp-ssl-port -SMTP over SSL のポート番号。 +SMTP over TLS のポート番号。 @item mew-smtp-user SMTP AUTH で利用されるアカウント名。設定されない場合は、自動的にメール アドレスに設定される。 @@ -11736,9 +11835,11 @@ The address family to be used for the SMTP server. The default value is 'ipv4. @item mew-smtp-ssh-server The name of SSH server which forwards the SMTP port. @item mew-smtp-ssl -If non-nil, SMTP connections are made over SSL. +If non-nil, SMTP connections are made over TLS. +@samp{'native} enables GnuTLS for native TLS connection +and @samp{'tunnel} uses stunnel to establish a TLS tunnel. @item mew-smtp-ssl-port -The port for SMTP over SSL. +The port for SMTP over TLS. @item mew-smtp-user The user name on your SMTP server. If not configured, your e-mail address is automatically set. @@ -11814,10 +11915,10 @@ configure as follows: @end lisp @ifset ja -SSL (@xref{SSL})や TLS (@xref{TLS}) の章も参考にして下さい。 +TLS/SSL (@xref{TLS/SSL}) の章も参考にして下さい。 @end ifset @ifset en -Please refer also to SSL (@pxref{SSL}) and TLS (@pxref{TLS}). +Please refer also to TLS/SSL (@pxref{TLS/SSL}). @end ifset @ifset ja @@ -12350,8 +12451,10 @@ configure as follows: * region:: リージョン * visiting:: 移動 * SSH:: Secure SHell -* SSL:: Secure Socket Layer -* TLS:: Transport Layer Security +* TLS/SSL:: Transport Layer Security / Secure Socket Layer +* Stunnel:: Stunnel を使った TLS 接続 +* GnuTLS:: GnuTLS ライブラリを使った TLS 接続 +* TLS/SSL2:: TLS 接続のための変数設定 * spam:: スパム * spam2:: スパム(2) * addr-warn:: アドレスの警告 @@ -12362,8 +12465,10 @@ configure as follows: * region:: Region * visiting:: Visiting another buffer * SSH:: Secure SHell -* SSL:: Secure Socket Layer -* TLS:: Transport Layer Security +* TLS/SSL:: Transport Layer Security / Secure Socket Layer +* Stunnel:: TLS by Stunnel +* GnuTLS:: TLS by GnuTLS library +* TLS/SSL2:: Configuration Variables for TLS * spam:: Spam messages * spam2:: Spam messages (2) * addr-warn:: Warning addresses @@ -12472,7 +12577,7 @@ name is the smallest number, type @samp{C-cC-o}. @end ifset @c %%%%%%%%%%%%%%%%% -@node SSH, SSL, visiting, Tips +@node SSH, TLS/SSL, visiting, Tips @ifset ja @section Secure SHell @end ifset @@ -12518,51 +12623,99 @@ in the mode line. @end ifset @ifset ja -Mew の実装では、SSH と SSL/TLS を同時には使えません。SSH トンネルの中で -SSL/TLS を使う必要がある場合、Mew では SSL/TLS だけを設定し、SSH トンネ +Mew の実装では、SSH と TLS を同時には使えません。SSH トンネルの中で +TLS を使う必要がある場合、Mew では TLS だけを設定し、SSH トンネ ルはコマンドラインから張るようにして下さい。 @end ifset @ifset en -The implementation of Mew does not allow to use both SSH and SSL/TLS -at the same time. If you need to use SSL/TLS over an SSH tunnel, -please configure SSL/TLS only with Mew and set up an SSH tunnel on a +The implementation of Mew does not allow to use both SSH and TLS +at the same time. If you need to use TLS over an SSH tunnel, +please configure TLS only with Mew and set up an SSH tunnel on a command line. @end ifset @c %%%%%%%%%%%%%%%%% -@node SSL, TLS, SSH, Tips +@node TLS/SSL, Stunnel, SSH, Tips @ifset ja -@section Secure Socket Layer +@section Transport Layer Security / Secure Socket Layer @end ifset @ifset en -@section Secure Socket Layer +@section Transport Layer Security / Secure Socket Layer @end ifset -@vindex mew-ssl-cert-directory -@vindex mew-ssl-verify-level -@vindex mew-pop-ssl -@vindex mew-pop-ssl-port -@vindex mew-smtp-ssl @ifset ja -SSL を使うには、認証局方式の信用モデルを理解している必要があります。現 -在、Mew は SSL のために "stunnel" バージョン 3、4、5 をサポートしていま -す。 +Mew は、通信の秘匿性と完全性を保証するために、TCP 通信路の暗号化を行な +う TLS (Transport Layer Security) に対応しています。 +この機能を使うには、Emacs に GnuTLS ライブラリが組み込まれているか、 +外部プログラムとして "stunnel" バージョン 3、4、5 のいずれかが必要です。 @end ifset @ifset en -Before you use SSL, you should understand the trust model of -certificate authorities (CA). Currently, Mew supports "stunnel" version -3, 4 and 5 for SSL. +Mew supports TLS (Transport Layer Security) for confidentiality and +integrity of TCP transport. To use this feature, Emacs built with +GnuTLS library or a ``stunnel'' program version 3, 4, or 5 is required. @end ifset @ifset ja -Mew で利用する前に、SSL サーバに対して "stunnel" で SSL のコネクション +TLS プロトコルは、Netscape Communications 社が 1990 年代に開発した SSL +(Secure Socket Layer) の後継として規格化されたものです。 +2 つのプロトコルには互換性があり、 +GnuTLS や ``stunnel'' プログラムは TLS と SSL の両方に対応しています。 +しかし、2020 年の時点で SSL には多数の脆弱性が発見されており、 +SSL の使用は避けて TLS のみを使用すべきだと考えられています。 +@end ifset +@ifset en +SSL (Secure Socket Layer) was developed by Netscape Communications, +Inc. back in 1990s and TLS has been developed as the successor. While +these two protocols are compatible with each other in some degree, and +GnuTLS and ``stunnel'' support the both, as of 2020, SSL is considered +as a ``should not use'' protocol because a lot of security flaws were +found in the protocol. +@end ifset + +@ifset ja +TLS 機能の設定に用いる Mew の設定変数や関数の名前には、 ``ssl'' が含ま +れているものがあります。混乱しやすいですが、このような歴史的な理由によ +るものです。 +@end ifset +@ifset en +For this histrical reason, there are still variables and functions for +TLS functionality with ``ssl'' keyword in Mew. +@end ifset + +@ifset ja +TLS を有効にするには、stunnel もしくは GnuTLS ライブラリのための変数設 +定を行ない、次に各プロトコルについて TLS を有効にするかどうかの設定を +行ないます。 +@end ifset +@ifset en +To enable TLS functionality, you have to configure variables for +``stunnel'' program or GnuTLS library, and then ones for enabling TLS +of each supported protocols. +@end ifset + +@c %%%%%%%%%%%%%%%%% +@node Stunnel, GnuTLS, TLS/SSL, Tips +@ifset ja +@section Stunnel を使った TLS 接続 +@end ifset +@ifset en +@section TLS by Stunnel +@end ifset +@vindex mew-ssl-cert-directory +@vindex mew-ssl-verify-level + +@ifset ja +Mew で利用する前に、TLS サーバに対して "stunnel" で TLS のコネクション が張れるか確かめて下さい。"stunnel" は、"openssl" のライブラリをリンク しているので、"openssl" の知識が必要です。 +また、TLS を使うには、認証局方式の信用モデルを理解している必要があります。 @end ifset @ifset en -Before you use Mew with SSL, you must be sure that an SSL connection -can be established to your SSL server. Since "stunnel" is linked to +Before you use Mew with TLS, you must be sure that an TLS connection +can be established to your TLS server. Since "stunnel" is linked to the "openssl" library, you should understand "openssl". +Before you use TLS, you should understand the trust model of +certificate authorities (CA). @end ifset @ifset ja @@ -12604,18 +12757,20 @@ To copy the certificate, do as follows: @ifset ja "openssl" に付いてくる証明書は、世の中で使われている CA すべてを網羅で きていません。あなたが利用するサーバの証明書が、他の CA から発行された -場合、その CA の証明書を同様にコピーしておく必要があります。以下のペー -ジに CA の証明書がたくさん置いてあります。 +場合、その CA の証明書を同様にコピーしておく必要があります。インターネッ +トにおいて信頼されている CA の証明書は、次の URLで管理・公開されていま +す。 @end ifset @ifset en The certificates in the source of "openssl" do not cover all CAs. If -the certificate of your SSL server is signed by another CA, you must -copy the certificate of the CA to the directory. You may be able to -find appropriate certificate from the following page: +the certificate of your TLS server is signed by another CA, you must +copy the certificate of the CA to the directory. You can find trusted +CA certificates on Internet from the following URLs: @end ifset @example -http://www.columbia.edu/~ariel/good-certs/ns45/ +https://www.ccadb.org +https://www.mozilla.org/en-US/about/governance/policies/security-group/certs/ @end example @ifset ja @@ -12638,11 +12793,11 @@ It's default to 1. The meanings of the values are as follows: @item 0 検証しない @item 1 -サーバの証明書があれば検証する。検証結果が失敗なら、SSL/TSL コネクショ -ンは作られない。証明書がなければ、SSL/TLS コネクションを作成する。 +サーバの証明書があれば検証する。検証結果が失敗なら、TLS コネクショ +ンは作られない。証明書がなければ、TLS コネクションを作成する。 @item 2 -サーバの証明書を検証する。検証結果が失敗なら、SSL/TSL コネクションは作 -られない。証明書がなければ、SSL/TLS コネクションを作成しない。 +サーバの証明書を検証する。検証結果が失敗なら、TLS コネクションは作 +られない。証明書がなければ、TLS コネクションを作成しない。 @item 3 サーバが送ってきたものではなく、ローカルにインストールされている証明書 で検証する。 @@ -12652,11 +12807,11 @@ It's default to 1. The meanings of the values are as follows: No verification. @item 1 Verify server's certificate if present. If verification failed, an -SSL/TLS connection is not created. If not present, an SSL/TLS +TLS connection is not created. If not present, a TLS connection is created. @item 2 -Verify server's certificate. If verification failed, an SSL/TLS -connection is not created. If not present, an SSL/TLS connection is +Verify server's certificate. If verification failed, a TLS +connection is not created. If not present, a TLS connection is not created. @item 3 Verify server's certificate which locally installed (not one from the @@ -12665,14 +12820,187 @@ server). @end table @ifset ja -後は各プロトコルの SSL に関する変数を設定して下しさい。たとえば、POP -over SSL を利用するには、@samp{mew-pop-ssl} を @samp{t} にします。また、 +変数を設定したら、stunnel を使う準備は完了です。 +@end ifset +@ifset en +You can get started with using stunnel after configuring the +variables. +@end ifset + +@c %%%%%%%%%%%%%%%%% +@node GnuTLS, TLS/SSL2, Stunnel, Tips +@ifset ja +@section GnuTLS ライブラリを使った TLS 接続 +@end ifset +@ifset en +@section TLS by GnuTLS Library +@end ifset +@vindex mew-ssl-trustfiles +@vindex mew-ssl-verify-level +@vindex gnutls-verify-error +@vindex network-security-level + +@ifset ja +GnuTLS が組み込まれた Emacs を使っている場合、TLS 機能を有効にするため +の特別な設定は不要です。次の変数を設定することで、証明書の検証レベルと +信頼するルート CA を変更することができます。 +@end ifset +@ifset en +Mew requires no specific configuration to support TLS if you are using +an Emacs built with GnuTLS library. You can configure the certificate +verification level and trusted root CAs by using the following +variables. +@end ifset + +@ifset ja +証明書の検証レベルは、Emacs の Network Security Manager によって管理さ +れているポリシーに従います。ポリシーを設定するには、 +@samp{network-security-level} という変数を使います。デフォルト値は +@samp{'medium} です。@samp{'low} の場合、証明書を検証しません。 +@samp{'medium} の場合、ルート CA の証明書リストを使って証明書を検証し +ます。検証ができなかった場合、もしくは自己署名証明書だった場合、その証 +明書を受け入れるかどうかのダイアログが表示されます。また、今まで証明書 +を使って暗号化通信が行なわれていたサーバに対して、暗号化なしでの接続が +行なわれようとした場合にも、警告を表示します。@samp{'high} とすると、 +@samp{'medium} のチェックに加えて、サーバ証明書の鍵の変更や弱い暗号ス +イートの使用に関して警告が表示されます。詳しくは、 +@xref{(emacs)Network Security} を参照して下さい。 +@end ifset +@ifset en +The policy for verification of the server certificates is handled by +Emacs Network Security Manager. It is configured by +@samp{network-security-level}, and the default value is +@samp{'medium}. If it is set to @samp{'low}, no verification is +performed. If @samp{'medium}, NSM will check whether the certificate +used to establish the identity of the server we're connecting to can +be verified by using the specified root CA list. A dialog for +choosing whether the certificate should be accepted or not will be +displayed if it is an invalid certificate including self-signed one. +Also, if the connection is unencrypted, but it was encrypted in +previous sessions, a similar dialog will be displayed. @samp{'high} +will perform additional checks such as a validated certificate which +changes the public key and weak cipher/protocols. +For more details, +see @xref{(emacs)Network Security}. +@end ifset + +@ifset ja +GnuTLS を使う場合は前述のとおり @samp{network-security-level} を設定す +ることが推奨されます。一方で Mew は、Stunnel を用いた TLS 接続について、 +@samp{mew-ssl-verify-level} という変数を用いて証明書の検証レベルを設定 +していました。この変数で設定した場合との後方互換性を保つため、Mew は +@samp{mew-ssl-verify-level} が @samp{0} の場合のみ、 +@samp{network-security-level} を @samp{'low} に自動設定します。 +この自動設定は、 Mew による接続のみに影響します。 +@samp{mew-ssl-verify-level} のデフォルト値は @samp{1} となっています。 +@samp{0} 以外の値の場合は、@samp{network-security-level} の設定に変更 +が加えられることはありません。 +@end ifset +@ifset en +It is recommended to use @samp{network-security-level} to specify the +verification level when using GnuTLS. However, Mew traditionally used +@samp{mew-ssl-verify-level} variable to specify the verification level +for Stunnel program. To keep backward compatibility with it, +@samp{network-security-level} will be temporarily set to @samp{'low} +if and only if @samp{mew-ssl-verify-level} is @samp{0}. Note that the +default value of @samp{mew-ssl-verify-level} is @samp{1} and there +will be no change with @samp{network-security-level} when +@samp{mew-ssl-verify-level} is not @samp{0}. +@end ifset + +@ifset ja +GnuTLS には、証明書の検証方法を制御するための +@samp{gnutls-verify-error} という変数もあります。GnuTLS は TCP 接続の +確立時に証明書の検証を行ないますが、この変数は、検証に失敗した時に切断 +するかどうかを制御します。デフォルトでは @samp{nil} に設定されており、 +検証に失敗してもすぐには切断しません。前述の Network Security Manager +が、TCP 接続の確立後にチェックを行ない、切断するかどうかを決定します。 +すぐに切断しない設定がデフォルトとなっていることは奇妙に思われるかも知 +れませんが、Emacs で GnuTLS が標準的に行なう検証よりも多くの項目をチェッ +クできるようにするため、TCP 接続と検証処理を分離しています。 +@end ifset +@ifset en +GnuTLS has own variable, @samp{gnutls-verify-error}, to configure the +verification level. This variable controls if the TCP connection must +be disconnected or not if verification of the server certificates +failed upon the connection established. The default value is +@samp{nil}, which means connection will not be closed immediately even +when the verification fails. In this case, NSM will perform the +verification and decides whether the connection should be disconnected +or not. You might think it is a bit odd that the default value of +this variable is set to @samp{nil}. This is because Emacs itself will +check more details of the certificates and the connection than GnuTLS +does. For this reason, establishing a TCP connection and decision on +disconnect are separated. +@end ifset + +@ifset ja +@samp{gnutls-verify-error} を手動で設定した場合、TCP 接続の確立時に証 +明書の検証に失敗すると、すぐに接続が切断されます。NSM による検証は行な +われません。この場合、@samp{network-security-level} や +@samp{mew-ssl-verify-level} による設定は無効になりますので注意して下さ +い。特別な理由がない限り、@samp{gnutls-verify-error} ではなく +@samp{network-security-level} を使って設定することをお勧めします。 +@end ifset +@ifset en +If you set @samp{gnutls-verify-error} manually, GnuTLS will terminate +the TCP session when the verification of the server certificates +fails. In this case, no further verification by NSM will be +performed. Note that configurations by using +@samp{network-security-level} or @samp{mew-ssl-verify-level} will be +ignored in this case. It is recommended to use +@samp{network-security-level} over @samp{gnutls-verify-error} unless +you have a specific reason. +@end ifset + +@ifset ja +信頼するルート CA は、@samp{mew-ssl-trustfiles} の設定に従います。ただし、 +GnuTLS には通常、デフォルトのルート CA リストが設定されており、Emacs +26.3 とそれより前のバージョンでは、それが常に先頭に追加されます。リス +トを空にしても、デフォルトのリストを無視できないことに注意してください。 +@end ifset +@ifset en +The trusted root CA list can be specified in +@samp{mew-ssl-trustfiles}. However, GnuTLS has the default list of +the trusted files and they are always used first on Emacs version 26.3 +and prior. Note that you cannot disable them even if you set an empty +list to the variable. +@end ifset + +@c %%%%%%%%%%%%%%%%% +@node TLS/SSL2, spam, GnuTLS, Tips +@ifset ja +@section TLS 接続のための変数設定 +@end ifset +@ifset en +@section Configuration Variables for TLS +@end ifset +@vindex mew-ssl-default +@vindex mew-pop-ssl +@vindex mew-pop-ssl-port +@vindex mew-smtp-ssl +@vindex mew-smtp-ssl-port +@vindex mew-nntp-ssl +@vindex mew-nntp-ssl-port + +@ifset ja +次に各プロトコルの TLS に関する変数を設定して下さい。たとえば、POP +over TLS を利用するには、@samp{mew-pop-ssl} を @samp{t} にします。 +TLS の実装として stunnel もしくは GnuTLS を明示的に指定したい場合は、 +それぞれ @samp{'tunnel}, @samp{'native} を指定します。 +@samp{t} を設定したプロトコルについては、 +@samp{mew-ssl-default} を使って使用する実装を選択することが可能です。 +また、 ポート番号が標準と異なる場合には、@samp{mew-pop-ssl-port} を設定して下 さい。 @end ifset @ifset en -Then configure SSL-related variables of each protocol. For example, if -you want to use POP over SSL, set @samp{mew-pop-ssl} to @samp{t}. +Then configure TLS-related variables of each protocol. For example, if +you want to use POP over TLS, set @samp{mew-pop-ssl} to @samp{t}. +To specify the TLS implementation, @samp{'tunnel} or @samp{'native} +can be used instead of @samp{t} for stunnel or GnuTLS, respectively. +For protocols with @samp{t}, the value of @samp{mew-ssl-default} +is used as the default TLS implementation. Also, if its port is not a standard one, configure @samp{mew-pop-ssl-port}. @end ifset @@ -12682,10 +13010,10 @@ Also, if its port is not a standard one, configure @end lisp @ifset ja -SMTP で SSL を利用する場合は、以下のようにします。 +SMTP で TLS を利用する場合は、以下のようにします。 @end ifset @ifset en -To use SSL for SMTP, configure as follows: +To use TLS for SMTP, configure as follows: @end ifset @lisp @@ -12693,40 +13021,33 @@ To use SSL for SMTP, configure as follows: @end lisp @ifset ja -SSL で通信が保護されている場合、モードラインに錠前の絵が表示されます。 +TLS で通信が保護されている場合、モードラインに錠前の絵が表示されます。 @end ifset @ifset en -While a connection is protected by SSL, a picture of a lock is shown +While a connection is protected by TLS, a picture of a lock is shown in the mode line. @end ifset -@c %%%%%%%%%%%%%%%%% -@node TLS, spam, SSL, Tips -@ifset ja -@section Transport Layer Security -@end ifset -@ifset en -@section Transport Layer Security -@end ifset - @ifset ja -Mew では SSL の代りに TLS を利用することもできます。TLS の実現は、SSL -と同様 "stunnel" に頼っています。ですので、TLS を利用する際には、 -@xref{SSL} の説明に従って設定して下さい。 +Mew では、各プロトコルの STARTTLS 拡張を使い、TCP 接続の確立後に +TLS を有効にすることもできます。STARTTLS を利用したい場合、ますは +@xref{TLS/SSL} の説明に従って設定して下さい。 @end ifset @ifset en -Mew can use TLS instead of SSL. To enable TLS, Mew relies on -@w{"}stunnel", too. So, before using TLS, you should configure -according to the explanations in @ref{SSL}. +Mew can upgrade a plain TCP connection to a TLS connection by using +STARTTLS extension in each supported protocols. Before using this, +you have to configure variables according to @ref{TLS/SSL}. @end ifset @ifset ja -次に、SSL のポート番号を守りたいプロトコルと同じポート番号に設定します。 -たとえば、POP では以下のようにします。 +STARTTLS は、プロトコルの通常のポート番号と TLS 用のポート番号とを +一致するように設定することで有効になります。たとえば、POP では以下のよ +うにします。 @end ifset @ifset en -Then, set the SSL port to the same one of the protocol to be -protected. For instance, configure as follows for POP: +STARTTLS will be enabled when the port number for normal TCP +connections of the protocol is set to the same as the port number for +TLS connections. Configure as follows for POP, for instance: @end ifset @lisp @@ -12736,19 +13057,10 @@ protected. For instance, configure as follows for POP: @end lisp @ifset ja -すなわち、SSL のポート番号と保護したいプロトコルのポートが同じであれば -TLS、異なれば SSL が利用されます。 -@end ifset -@ifset en -That is, if the SSL port is the same as the port of the protocol to be -protected, TLS is used. Otherwise, SSL is used. -@end ifset - -@ifset ja -以下は、Message Submission を TLS で守るための設定例です。 +以下は、Message Submission で STARTTLS を有効にするための設定例です。 @end ifset @ifset en -The following is an example to protect Message Submission with TLS. +The following is an example to enable STARTTLS for Message Submission. @end ifset @lisp @@ -12758,7 +13070,7 @@ The following is an example to protect Message Submission with TLS. @end lisp @c %%%%%%%%%%%%%%%%% -@node spam, spam2, TLS, Tips +@node spam, spam2, TLS/SSL2, Tips @ifset ja @section スパム @end ifset diff --git a/mew-config.el b/mew-config.el index 7a80b4e..8c9214f 100644 --- a/mew-config.el +++ b/mew-config.el @@ -157,6 +157,17 @@ (defun mew-ssl-verify-level (&optional case) (mew-cfent-value case "ssl-verify-level" mew-ssl-verify-level)) +(defun mew-ssl-client-keycert-list (&optional case) + (mew-cfent-value case "ssl-client-keycert-list" + mew-ssl-client-keycert-list)) + +(defun mew-ssl-trustfiles (&optional case) + (mew-cfent-value case "ssl-trustfiles" mew-ssl-trustfiles)) + +(defun mew-ssl-algorithm-priority (&optional case) + (mew-cfent-value case "ssl-algorithm-priority" + mew-ssl-algorithm-priority)) + ;; (defun mew-smtp-server (&optional case) diff --git a/mew-imap.el b/mew-imap.el index c07dc93..eb0a5b8 100644 --- a/mew-imap.el +++ b/mew-imap.el @@ -1224,14 +1224,18 @@ ;;; Opening IMAP ;;; -(defun mew-imap-open (pnm server port no-msg) +(defun mew-imap-open (pnm case server port no-msg starttlsp) (let ((sprt (mew-*-to-port port)) + (sslnp (mew-ssl-native-p (mew-imap-ssl case))) pro tm) (condition-case emsg (progn (setq tm (run-at-time mew-imap-timeout-time nil 'mew-imap-timeout)) (or no-msg (message "Connecting to the IMAP server...")) - (setq pro (open-network-stream pnm nil server sprt)) + (setq pro (mew-open-network-stream pnm nil server sprt + 'imap sslnp starttlsp case)) + (setq pro (car pro)) + (when (not (processp pro)) (signal 'quit nil)) (mew-process-silent-exit pro) (mew-set-process-cs pro mew-cs-binary mew-cs-text-for-net) (or no-msg (message "Connecting to the IMAP server...done"))) @@ -1245,7 +1249,11 @@ pro)) (defun mew-imap-timeout () - (signal 'quit nil)) + ;; Do not timeout if the NSM query pane is active. + (unless (get-buffer "*Network Security Manager*") + (message "IMAP connection timed out (%d seconds)" + mew-imap-timeout-time) + (signal 'quit nil))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -1274,6 +1282,11 @@ (sshsrv (mew-imap-ssh-server case)) (sslp (mew-imap-ssl case)) (sslport (mew-imap-ssl-port case)) + (sslnp (mew-ssl-native-p (mew-imap-ssl case))) + (starttlsp + (mew-ssl-starttls-p (mew-imap-ssl case) + (mew-*-to-string (mew-imap-port case)) + (mew-imap-ssl-port case))) (proxysrv (mew-imap-proxy-server case)) (proxyport (mew-imap-proxy-port case)) ;; dirty but necessary for migration @@ -1288,25 +1301,28 @@ (if (mew-imap-get-process pnm) (message "Another IMAP process is running. Try later") (cond + (sslnp + (let ((serv (if starttlsp port sslport))) + (setq process (mew-imap-open pnm case server serv no-msg starttlsp)))) (sshsrv (setq sshpro (mew-open-ssh-stream case server port sshsrv)) (when sshpro (setq sshname (process-name sshpro)) (setq lport (mew-ssh-pnm-to-lport sshname)) (when lport - (setq process (mew-imap-open pnm "localhost" lport no-msg))))) + (setq process (mew-imap-open pnm case "localhost" lport no-msg nil))))) (sslp - (if (mew-port-equal port sslport) (setq tls mew-tls-imap)) + (when starttlsp (setq tls mew-tls-imap)) (setq sslpro (mew-open-ssl-stream case server sslport tls)) (when sslpro (setq sslname (process-name sslpro)) (setq lport (mew-ssl-pnm-to-lport sslname)) (when lport - (setq process (mew-imap-open pnm mew-ssl-localhost lport no-msg))))) + (setq process (mew-imap-open pnm case mew-ssl-localhost lport no-msg nil))))) (proxysrv - (setq process (mew-imap-open pnm proxysrv proxyport no-msg))) + (setq process (mew-imap-open pnm case proxysrv proxyport no-msg nil))) (t - (setq process (mew-imap-open pnm server port no-msg)))) + (setq process (mew-imap-open pnm case server port no-msg nil)))) (if (null process) (when (eq directive 'exec) (mew-imap-exec-recover bnm)) @@ -1403,7 +1419,15 @@ ;; (set-process-sentinel process 'mew-imap-sentinel) (set-process-filter process 'mew-imap-filter) - (set-process-buffer process buf))))) + (set-process-buffer process buf) + ;; + (when sslnp + ;; GnuTLS requires a client-initiated command after the + ;; session is established or upgraded to use TLS because + ;; no additional greeting from the server. + (mew-imap-set-status pnm "capability") + (mew-imap-command-capability process pnm)) + )))) (defun mew-imap-exec-recover (bnm) (mew-summary-visible-buffer bnm) @@ -1888,7 +1912,7 @@ ;;; Copyright Notice: -;; Copyright (C) 2002-2015 Mew developing team. +;; Copyright (C) 2002-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-imap2.el b/mew-imap2.el index 49b8231..3c46bd4 100644 --- a/mew-imap2.el +++ b/mew-imap2.el @@ -360,14 +360,18 @@ ;;; Opening IMAP ;;; -(defun mew-imap2-open (pnm server port) +(defun mew-imap2-open (pnm case server port starttlsp) (let ((sprt (mew-*-to-port port)) + (sslnp (mew-ssl-native-p (mew-imap-ssl case))) pro tm) (condition-case emsg (progn (setq tm (run-at-time mew-imap-timeout-time nil 'mew-imap2-timeout)) (message "Connecting to the IMAP server...") - (setq pro (open-network-stream pnm nil server sprt)) + (setq pro (mew-open-network-stream pnm nil server sprt + 'imap sslnp starttlsp case)) + (setq pro (car pro)) + (when (not (processp pro)) (signal 'quit nil)) (mew-process-silent-exit pro) (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net) (message "Connecting to the IMAP server...done")) @@ -381,7 +385,11 @@ pro)) (defun mew-imap2-timeout () - (signal 'quit nil)) + ;; Do not timeout if the NSM query pane is active. + (unless (get-buffer "*Network Security Manager*") + (message "IMAP connection timed out (%d seconds)" + mew-imap-timeout-time) + (signal 'quit nil))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -396,29 +404,37 @@ (sshsrv (mew-imap-ssh-server case)) (sslp (mew-imap-ssl case)) (sslport (mew-imap-ssl-port case)) + (sslnp (mew-ssl-native-p (mew-imap-ssl case))) + (starttlsp + (mew-ssl-starttls-p (mew-imap-ssl case) + (mew-*-to-string (mew-imap-port case)) + (mew-imap-ssl-port case))) (proxysrv (mew-imap-proxy-server case)) (proxyport (mew-imap-proxy-port case)) process sshname sshpro sslname sslpro lport tls) (cond + (sslnp + (let ((serv (if starttlsp port sslport))) + (setq process (mew-imap2-open pnm case server serv starttlsp)))) (sshsrv (setq sshpro (mew-open-ssh-stream case server port sshsrv)) (when sshpro (setq sshname (process-name sshpro)) (setq lport (mew-ssh-pnm-to-lport sshname)) (when lport - (setq process (mew-imap2-open pnm "localhost" lport))))) + (setq process (mew-imap2-open pnm case "localhost" lport nil))))) (sslp - (if (mew-port-equal port sslport) (setq tls mew-tls-imap)) + (when starttlsp (setq tls mew-tls-imap)) (setq sslpro (mew-open-ssl-stream case server sslport tls)) (when sslpro (setq sslname (process-name sslpro)) (setq lport (mew-ssl-pnm-to-lport sslname)) (when lport - (setq process (mew-imap2-open pnm mew-ssl-localhost lport))))) + (setq process (mew-imap2-open pnm case mew-ssl-localhost lport nil))))) (proxysrv - (setq process (mew-imap2-open pnm proxysrv proxyport))) + (setq process (mew-imap2-open pnm case proxysrv proxyport nil))) (t - (setq process (mew-imap2-open pnm server port)))) + (setq process (mew-imap2-open pnm case server port nil)))) (if (null process) (cond ((and sshsrv (null sshpro)) @@ -448,7 +464,14 @@ (set-process-buffer process nil) (set-process-sentinel process 'mew-imap2-sentinel) (set-process-filter process 'mew-imap2-filter) - (message "Copying in background...")))) + (message "Copying in background...") + (when sslnp + ;; GnuTLS requires a client-initiated command after the + ;; session is established or upgraded to use TLS because + ;; no additional greeting from the server. + (mew-imap2-set-status pnm "capability") + (mew-imap2-command-capability process pnm)) + ))) (defun mew-summary-from-local-to-imap () "Copy messages in local folders under specified folder prefix @@ -628,7 +651,7 @@ with '*' in the region are handled." ;;; Copyright Notice: -;; Copyright (C) 2003-2015 Mew developing team. +;; Copyright (C) 2003-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-net.el b/mew-net.el index 2206b28..ef78c51 100644 --- a/mew-net.el +++ b/mew-net.el @@ -14,9 +14,7 @@ (defvar mew-port-db '(("smtp" 25) - ;; This is officially assigned to another service (urd) by IANA. - ;; IESG will never assign a port number to SMTP over SSL... - ("smtps" 465) + ("smtps" 465) ; RFC 8314 ("pop3" 110) ("pop3s" 995) ("nntp" 119) @@ -881,7 +879,7 @@ The messages in the server side is always retained." ;;; Copyright Notice: -;; Copyright (C) 2002-2015 Mew developing team. +;; Copyright (C) 2002-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-nntp.el b/mew-nntp.el index e9c3352..bf3ddc7 100644 --- a/mew-nntp.el +++ b/mew-nntp.el @@ -388,14 +388,18 @@ ;;; Opening NNTP ;;; -(defun mew-nntp-open (pnm server port no-msg) +(defun mew-nntp-open (pnm case server port no-msg starttlsp) (let ((sprt (mew-*-to-port port)) + (sslnp (mew-ssl-native-p (mew-nntp-ssl case))) pro tm) (condition-case emsg (progn (setq tm (run-at-time mew-nntp-timeout-time nil 'mew-nntp-timeout)) (or no-msg (message "Connecting to the NNTP server...")) - (setq pro (open-network-stream pnm nil server sprt)) + (setq pro (mew-open-network-stream pnm nil server sprt + 'nntp sslnp starttlsp case)) + (setq pro (car pro)) + (when (not (processp pro)) (signal 'quit nil)) (mew-process-silent-exit pro) (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net) (or no-msg (message "Connecting to the NNTP server...done"))) @@ -409,7 +413,11 @@ pro)) (defun mew-nntp-timeout () - (signal 'quit nil)) + ;; Do not timeout if the NSM query pane is active. + (unless (get-buffer "*Network Security Manager*") + (message "NNTP connection timed out (%d seconds)" + mew-nntp-timeout-time) + (signal 'quit nil))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -423,6 +431,11 @@ (sshsrv (mew-nntp-ssh-server case)) (sslp (mew-nntp-ssl case)) (sslport (mew-nntp-ssl-port case)) + (sslnp (mew-ssl-native-p (mew-nntp-ssl case))) + (starttlsp + (mew-ssl-starttls-p (mew-nntp-ssl case) + (mew-*-to-string (mew-nntp-port case)) + (mew-nntp-ssl-port case))) (newsgroup (mew-bnm-to-newsgroup bnm)) (pnm (mew-nntp-info-name case newsgroup)) (buf (get-buffer-create (mew-nntp-buffer-name pnm))) @@ -432,23 +445,26 @@ (if (mew-nntp-get-process pnm) (message "Another NNTP process is running. Try later") (cond + (sslnp + (let ((serv (if starttlsp port sslport))) + (setq process (mew-nntp-open pnm case server serv no-msg starttlsp)))) (sshsrv (setq sshpro (mew-open-ssh-stream case server port sshsrv)) (when sshpro (setq sshname (process-name sshpro)) (setq lport (mew-ssh-pnm-to-lport sshname)) (when lport - (setq process (mew-nntp-open pnm "localhost" lport no-msg))))) + (setq process (mew-nntp-open pnm case "localhost" lport no-msg nil))))) (sslp - (if (mew-port-equal port sslport) (setq tls mew-tls-nntp)) + (when starttlsp (setq tls mew-tls-nntp)) (setq sslpro (mew-open-ssl-stream case server sslport tls)) (when sslpro (setq sslname (process-name sslpro)) (setq lport (mew-ssl-pnm-to-lport sslname)) (when lport - (setq process (mew-nntp-open pnm mew-ssl-localhost lport no-msg))))) + (setq process (mew-nntp-open pnm case mew-ssl-localhost lport no-msg nil))))) (t - (setq process (mew-nntp-open pnm server port no-msg)))) + (setq process (mew-nntp-open pnm case server port no-msg nil)))) (when process (mew-summary-lock process "NNTPing" (or sshpro sslpro)) (mew-sinfo-set-summary-form (mew-get-summary-form bnm)) @@ -502,7 +518,13 @@ (mew-sinfo-set-start-point (point)) ;; after erase-buffer (set-process-sentinel process 'mew-nntp-sentinel) (set-process-filter process 'mew-nntp-filter) - (set-process-buffer process buf))))) + (set-process-buffer process buf) + (when sslnp + ;; GnuTLS requires a client-initiated command after the + ;; session is established or upgraded to use TLS because + ;; no additional greeting from the server. + (mew-nntp-command-mode-reader process pnm)) + )))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -713,7 +735,7 @@ ;;; Copyright Notice: -;; Copyright (C) 1999-2015 Mew developing team. +;; Copyright (C) 1999-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-nntp2.el b/mew-nntp2.el index 4c12458..1f314f2 100644 --- a/mew-nntp2.el +++ b/mew-nntp2.el @@ -177,14 +177,18 @@ ;;; Opening NNTP ;;; -(defun mew-nntp2-open (pnm server port) +(defun mew-nntp2-open (pnm case server port starttlsp) (let ((sprt (mew-*-to-port port)) + (sslnp (mew-ssl-native-p (mew-nntp-ssl case))) pro tm) (condition-case emsg (progn (setq tm (run-at-time mew-nntp-timeout-time nil 'mew-nntp2-timeout)) (message "Connecting to the NNTP server...") - (setq pro (open-network-stream pnm nil server sprt)) + (setq pro (mew-open-network-stream pnm nil server sprt + 'nntp sslnp starttlsp case)) + (setq pro (car pro)) + (when (not (processp pro)) (signal 'quit nil)) (mew-process-silent-exit pro) (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net) (message "Connecting to the NNTP server...done")) @@ -198,7 +202,11 @@ pro)) (defun mew-nntp2-timeout () - (signal 'quit nil)) + ;; Do not timeout if the NSM query pane is active. + (unless (get-buffer "*Network Security Manager*") + (message "NNTP connection timed out (%d seconds)" + mew-nntp-timeout-time) + (signal 'quit nil))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -213,25 +221,33 @@ (sshsrv (mew-nntp-ssh-server case)) (sslp (mew-nntp-ssl case)) (sslport (mew-nntp-ssl-port case)) + (sslnp (mew-ssl-native-p (mew-nntp-ssl case))) + (starttlsp + (mew-ssl-starttls-p (mew-nntp-ssl case) + (mew-*-to-string (mew-nntp-port case)) + (mew-nntp-ssl-port case))) process sshname sshpro sslname sslpro lport tls) (cond + (sslnp + (let ((serv (if starttlsp port sslport))) + (setq process (mew-nntp2-open pnm case server serv starttlsp)))) (sshsrv (setq sshpro (mew-open-ssh-stream case server port sshsrv)) (when sshpro (setq sshname (process-name sshpro)) (setq lport (mew-ssh-pnm-to-lport sshname)) (when lport - (setq process (mew-nntp2-open pnm "localhost" lport))))) + (setq process (mew-nntp2-open pnm case "localhost" lport nil))))) (sslp - (if (mew-port-equal port sslport) (setq tls mew-tls-nntp)) + (when starttlsp (setq tls mew-tls-nntp)) (setq sslpro (mew-open-ssl-stream case server sslport tls)) (when sslpro (setq sslname (process-name sslpro)) (setq lport (mew-ssl-pnm-to-lport sslname)) (when lport - (setq process (mew-nntp2-open pnm mew-ssl-localhost lport))))) + (setq process (mew-nntp2-open pnm case mew-ssl-localhost lport nil))))) (t - (setq process (mew-nntp2-open pnm server port)))) + (setq process (mew-nntp2-open pnm case server port nil)))) (if (null process) (cond ((and sshsrv (null sshpro)) @@ -256,8 +272,13 @@ (set-process-buffer process nil) (set-process-sentinel process 'mew-nntp2-sentinel) (set-process-filter process 'mew-nntp2-filter) - (message "Posting in background...")))) - + (message "Posting in background...") + (when sslnp + ;; GnuTLS requires a client-initiated command after the + ;; session is established or upgraded to use TLS because + ;; no additional greeting from the server. + (mew-nntp-command-mode-reader process pnm)) + ))) (defun mew-nntp2-flush-queue (case &optional qfld) (let (msgs) (unless qfld (setq qfld (mew-postq-folder case))) @@ -417,7 +438,7 @@ ;;; Copyright Notice: -;; Copyright (C) 1999-2015 Mew developing team. +;; Copyright (C) 1999-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-passwd.el b/mew-passwd.el index 9604901..838257b 100644 --- a/mew-passwd.el +++ b/mew-passwd.el @@ -35,12 +35,100 @@ ;;; (defun mew-passwd-get-passwd (key) - (nth 1 (assoc key mew-passwd-alist))) + (cond + ((mew-passwd-use-auth-source-p) + (mew-passwd-auth-source-get-passwd key)) + (t (nth 1 (assoc key mew-passwd-alist))))) (defun mew-passwd-set-passwd (key val) - (if (assoc key mew-passwd-alist) - (setcar (nthcdr 1 (assoc key mew-passwd-alist)) val) - (setq mew-passwd-alist (cons (list key val 0) mew-passwd-alist)))) + (cond + ((mew-passwd-use-auth-source-p) + (mew-passwd-auth-source-set-passwd key val)) + (t (if (assoc key mew-passwd-alist) + (setcar (nthcdr 1 (assoc key mew-passwd-alist)) val) + (setq mew-passwd-alist (cons (list key val 0) mew-passwd-alist)))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; Functions for auth-source backend +;;; + +(autoload 'auth-source-search "auth-source") + +(defun mew-passwd-use-auth-source-p () + (eq mew-master-passwd-type 'auth-source)) + +(defun mew-passwd-auth-source-parse-key (key) + (let ((st (split-string key "[@:]"))) + (list :user (nth 0 st) + :host (nth 1 st) + :port (nth 2 st)))) + +;;; XXX will be revisited. +(defun mew-passwd-auth-source-parse-key-x (key) + (if (string-match "\\([^@]+\\)@\\([^:]+\\):\\(.+\\)" key) + (list :user (match-string 1 key) + :host (match-string 2 key) + :port (match-string 3 key)) + (list :key key + :user nil + :host nil + :port nil))) + +;;; XXX epa-pinentry-mode is set to 'loopback to avoid GUI pinentry +;;; window. This might not be a recommended way but it works. +;;; +;;; XXX when the backend is an encrypted file and an wrong passphrase +;;; is provided, a password prompt will be displayed. This may be +;;; confusing. +(defun mew-passwd-auth-source-get-passwd (key) + (let* ((epa-pinentry-mode 'loopback) + (slist (mew-passwd-auth-source-parse-key key)) + found) + (cond + ((member key mew-pgp-list) + ;; Never get GnuPG passphrase. Rely on gpg-agent for caching. + (setq found nil)) + (t + (condition-case error + (setq found (apply #'auth-source-search (nconc slist))) + (error + (setq found nil))))) + (if found + (let ((secret (plist-get (nth 0 found) :secret))) + (if (functionp secret) + (funcall secret) + secret)) + nil))) + +(defun mew-passwd-auth-source-set-passwd (key val) + (cond + ((member key mew-pgp-list) + ;; Never store GnuPG passphrase. Rely on gpg-agent for caching. + ) + (val + ;; Authenticated successfully. + (let* ((epa-pinentry-mode 'loopback) + (slist (mew-passwd-auth-source-parse-key key)) + (entry (apply #'auth-source-search + (append slist (list + :secret val :create t)))) + (save-function (plist-get (nth 0 entry) :save-function))) + (when (functionp save-function) + (funcall save-function)))) + (t + ;; Authentication failed. + ;; + ;; XXX: removal of the wrong password is not supported by any + ;; backends (i.e. auth-source-delete is noop). + (let* ((epa-pinentry-mode 'loopback) + (slist (mew-passwd-auth-source-parse-key key)) + (num (apply #'auth-source-forget+ (nconc slist))) + (entry (apply #'auth-source-delete (nconc slist))) + (save-function (plist-get (nth 0 entry) :save-function))) + (when (functionp save-function) + (funcall save-function)) + (message "Wrong password is stored. Please remove it manually."))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -95,14 +183,19 @@ (mew-timer (* mew-passwd-timer-unit 60) 'mew-passwd-timer)))) (defun mew-passwd-setup-master () - (when (and (not mew-passwd-master) mew-use-master-passwd) + (cond + ((mew-passwd-use-auth-source-p) + ;;; do nothing + ) + (t + (when (and (not mew-passwd-master) mew-use-master-passwd) (setq mew-passwd-agent-hack (mew-passwd-check-agent-hack)) (let ((file (expand-file-name mew-passwd-file mew-conf-path))) (if (file-exists-p file) (setq mew-passwd-alist (mew-passwd-load)) ;; save nil and ask master twice (mew-passwd-save))) - (add-hook 'kill-emacs-hook 'mew-passwd-clean-up))) + (add-hook 'kill-emacs-hook 'mew-passwd-clean-up))))) (defun mew-passwd-clean-up () (remove-hook 'kill-emacs-hook 'mew-passwd-clean-up) diff --git a/mew-pop.el b/mew-pop.el index 9e2db7c..5ff3783 100644 --- a/mew-pop.el +++ b/mew-pop.el @@ -610,14 +610,18 @@ ;;; Opening POP ;;; -(defun mew-pop-open (pnm server port no-msg) +(defun mew-pop-open (pnm case server port no-msg starttlsp) (let ((sprt (mew-*-to-port port)) + (sslnp (mew-ssl-native-p (mew-pop-ssl case))) pro tm) (condition-case emsg (progn (setq tm (run-at-time mew-pop-timeout-time nil 'mew-pop-timeout)) (or no-msg (message "Connecting to the POP server...")) - (setq pro (open-network-stream pnm nil server sprt)) + (setq pro (mew-open-network-stream pnm nil server sprt + 'pop sslnp starttlsp case)) + (setq pro (car pro)) + (when (not (processp pro)) (signal 'quit nil)) (mew-process-silent-exit pro) (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net) (or no-msg (message "Connecting to the POP server...done"))) @@ -631,7 +635,11 @@ pro)) (defun mew-pop-timeout () - (signal 'quit nil)) + ;; Do not timeout if the NSM query pane is active. + (unless (get-buffer "*Network Security Manager*") + (message "POP connection timed out (%d seconds)" + mew-pop-timeout-time) + (signal 'quit nil))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -646,6 +654,11 @@ (sshsrv (mew-pop-ssh-server case)) (sslp (mew-pop-ssl case)) (sslport (mew-pop-ssl-port case)) + (sslnp (mew-ssl-native-p (mew-pop-ssl case))) + (starttlsp + (mew-ssl-starttls-p (mew-pop-ssl case) + (mew-*-to-string (mew-pop-port case)) + (mew-pop-ssl-port case))) (proxysrv (mew-pop-proxy-server case)) (proxyport (mew-pop-proxy-port case)) (pnm (mew-pop-info-name case)) @@ -656,25 +669,28 @@ (if (mew-pop-get-process pnm) (message "Another POP process is running. Try later") (cond + (sslnp + (let ((serv (if starttlsp port sslport))) + (setq process (mew-pop-open pnm case server serv no-msg starttlsp)))) (sshsrv (setq sshpro (mew-open-ssh-stream case server port sshsrv)) (when sshpro (setq sshname (process-name sshpro)) (setq lport (mew-ssh-pnm-to-lport sshname)) (when lport - (setq process (mew-pop-open pnm "localhost" lport no-msg))))) + (setq process (mew-pop-open pnm case "localhost" lport no-msg nil))))) (sslp - (if (mew-port-equal port sslport) (setq tls mew-tls-pop)) + (when starttlsp (setq tls mew-tls-pop)) (setq sslpro (mew-open-ssl-stream case server sslport tls)) (when sslpro (setq sslname (process-name sslpro)) (setq lport (mew-ssl-pnm-to-lport sslname)) (when lport - (setq process (mew-pop-open pnm mew-ssl-localhost lport no-msg))))) + (setq process (mew-pop-open pnm case mew-ssl-localhost lport no-msg nil))))) (proxysrv - (setq process (mew-pop-open pnm proxysrv proxyport no-msg))) + (setq process (mew-pop-open pnm case proxysrv proxyport no-msg nil))) (t - (setq process (mew-pop-open pnm server port no-msg)))) + (setq process (mew-pop-open pnm case server port no-msg nil)))) (if (null process) (if (eq directive 'exec) (mew-summary-visible-buffer bnm)) @@ -743,7 +759,13 @@ ;; (set-process-sentinel process 'mew-pop-sentinel) (set-process-filter process 'mew-pop-filter) - (set-process-buffer process buf))))) + (set-process-buffer process buf) + (when sslnp + ;; GnuTLS requires a client-initiated command after the + ;; session is established or upgraded to use TLS because + ;; no additional greeting from the server. + (mew-pop-command-capa process pnm)) + )))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -960,7 +982,7 @@ ;;; Copyright Notice: -;; Copyright (C) 1999-2015 Mew developing team. +;; Copyright (C) 1999-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-smtp.el b/mew-smtp.el index e3dbbdc..16ae8ef 100644 --- a/mew-smtp.el +++ b/mew-smtp.el @@ -6,6 +6,11 @@ ;;; Code: (require 'mew) +(autoload 'puny-encode-domain "puny") +(when (and (fboundp 'gnutls-available-p) + (gnutls-available-p)) + (require 'gnutls) + (require 'nsm)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -386,25 +391,237 @@ (defvar mew-smtp-submission-family 'ipv4) +;;; XXX: (mew-open-network-stream) always returns a list +;; and is also used for non-SMTP protocols. +;;; XXX: port must be resolved by using mew-serv-to-port +;; because some service names are not in /etc/services. +;; mew-serv-to-port uses mew-port-db. +(setq mew--advice-tls-parameters-plist nil) +(defun mew--advice-filter-args-gnutls-negotiate (&rest args) + (nconc (car args) mew--advice-tls-parameters-plist)) +;;; +;;; Functions to handle tunneling by an external program. The +;;; external program must be capable of bidirectional communications +;;; via stdin and stdout and forward the data stream from/to the final +;;; destination. TLS and STARTTLS will be handled by GnuTLS. +;;; +(defun mew--tun-type (tun-plist) + (plist-get tun-plist :type)) +(setq mew--advice-tun-command nil) +(defun mew--advice-tun-command (case host port tun-plist) + (cond + ((eq (mew--tun-type tun-plist) 'ssh) + (format "%s -W %s:%s -oPort=%s %s" + (mew-ssh-prog case) + (plist-get tun-plist :host) + (plist-get tun-plist :port) + port host)) + (t nil))) +;; Override function for TLS connection over tunnel. +(defun mew--advice-override-open-gnutls-stream + (name buffer host service &optional nowait) + ;; Must be equivalent to + ;; (open-gnutls-stream name buffer host service &optional nowait) + (make-process args + :command mew--advice-tun-command + :coding 'utf-8-unix + :connection-type 'pipe + :noquery t + :stderr nil) + ;; Do gnutls-negotiate here + ) +;; Override function for PLAIN or STARTTLS connection over tunnel. +(defun mew--advice-override-make-network-process (&rest args) + ;; PLAIN: make-network-process + ;; STARTTLS: make-network-process -> gnutls-negotiate + (make-process args + :command mew--advice-tun-command + :coding 'utf-8-unix + :connection-type 'pipe + :noquery t + :stderr nil)) +;;; +;;; XXX: This conditional can be removed safely. (if (fboundp 'make-network-process) - (defun mew-open-network-stream (name buf server port) - (let (family nowait pro) - (when mew-inherit-submission + (defun mew-open-network-stream (name buf server port proto sslnp + starttlsp case &optional tun-plist) + (let* ((tun-type (mew--tun-type tun-plist)) + (mew--advice-tun-command (mew--advice-tun-command + case server port tun-plist)) + (status-msg (format "Opening a %s connection %s%s%s..." + (if sslnp "TLS" "TCP") + (if sslnp "(GnuTLS" "") + (if sslnp + (if starttlsp ", STARTTLS)" ")") + "") + (if (eq tun-type 'ssh) " over SSH" + ""))) + family nowait pro tlsparams) + ;; SMTP-specific + (when (and (eq proto 'smtp) mew-inherit-submission) (setq family mew-smtp-submission-family) (setq nowait t)) - (when (and (stringp port) (string-match "^/" port)) + ;; TLS does not work for Unix-domain socket for now. + (when (and (not sslnp) + (stringp port) (string-match "^/" port)) (setq family 'local) (setq server 'local)) - (setq pro (make-network-process :name name :buffer buf - :host server :service port - :family family :nowait nowait)) - (if nowait + (cond + ;; Both GnuTLS and NSM are mandatory for 'native. + ((and sslnp (or (not (fboundp 'gnutls-available-p)) + (not (gnutls-available-p)) + (not (fboundp 'gnutls-boot-parameters)) + (not (fboundp 'nsm-level)))) + (setq pro + (list nil + :error t + :status-msg + (concat status-msg + "FAILED (GnuTLS or NSM not available)")))) + ((and sslnp) + (let ((hostname (puny-encode-domain server)) + ;; Note: on Emacs 26.3 and prior GnuTLS always uses + ;; the system-wide default path first even if + ;; trustfiles is specified. + (trustfiles (mew-ssl-trustfiles case)) + (nsm-noninteractive nil) + (network-security-level network-security-level)) + (when (eq (mew-ssl-verify-level case) 0) + ;; Forcibly disable verification. + (setq network-security-level 'low)) + (setq tlsparams + (cons 'gnutls-x509pki + ;; XXX: (gnutls-boot-parameters) returns + ;; :priority key instead of :priority-string + ;; while (gnutls-negotiate) accepts + ;; :priority-string. To handle this odd + ;; mismatch, create :priority-string in the + ;; result of (gnutls-boot-parameters) here. + (let ((boot-params + (gnutls-boot-parameters + :type 'gnutls-x509pki + :keylist (mew-ssl-client-keycert-list case) + :trustfiles (mew-ssl-trustfiles case) + :priority-string (mew-ssl-algorithm-priority case) + :min-prime-bits mew-ssl-min-prime-bits + ;; + ;; mew-ssl-verify-error should be nil + ;; to defer verification to NSM. Note + ;; that gnutls-verify-error overrides + ;; verify-error when it is nil. + ;; Setting gnutls-verify-error to t is + ;; also discouraged. + ;; + :verify-error mew-ssl-verify-error + :hostname hostname))) + (plist-put boot-params + :priority-string + (plist-get boot-params :priority))))) + ;; debug output: TLS params + (funcall (intern (concat "mew-" (symbol-name proto) "-debug")) + (format "TLS proto=%s, server=%s:%s, starttlsp=%s" + proto hostname port starttlsp) + (format "verify-level=%s, network-security-level=%s, nowait=%s, tlsparams=%s" + (mew-ssl-verify-level case) network-security-level + nowait + (apply #'concat (mapcar (lambda (a) (format "%s " a)) tlsparams)))) + (let ((type (if starttlsp 'starttls 'tls))) + (with-temp-message status-msg + ;; XXX: (open-network-stream) does not pass tlsparams + ;; to (gnutls-negotiate) to start STARTTLS. As a + ;; workaround, add an advice to forcibly append the + ;; parameters. This should be fixed in + ;; (open-network-stream). + (setq mew--advice-tls-parameters-plist (cdr tlsparams)) + (advice-add 'gnutls-negotiate + :filter-args #'mew--advice-filter-args-gnutls-negotiate) + ;; + ;; Override key functions when using a tunnel. + (cond + ((and mew--advice-tun-command (eq type 'tls)) + (advice-add 'open-gnutls-stream + :override #'mew--advice-override-open-gnutls-stream)) + (mew--advice-tun-command + (advice-add 'make-network-process + :override #'mew--advice-override-make-network-process))) + (setq pro (open-network-stream + name buf server port + :type type + :return-list t + :nowait nowait + :always-query-capabilities + (mew-starttls-get-param proto :always-query-capabilities nil) + :capability-command + (mew-starttls-get-param proto :capability-command t) + :end-of-capability + (mew-starttls-get-param proto :end-of-capability t) + :end-of-command + (mew-starttls-get-param proto :end-of-command t) + :success + (mew-starttls-get-param proto :success t) + :starttls-function + (mew-starttls-get-param proto :starttls-function nil))) + (cond + ((and mew--advice-tun-command (eq type 'tls)) + (advice-remove 'open-gnutls-stream + #'mew--advice-override-open-gnutls-stream)) + (mew--advice-tun-command + (advice-remove 'make-network-process + #'mew--advice-override-make-network-process))) + (advice-remove 'gnutls-negotiate + #'mew--advice-filter-args-gnutls-negotiate) + ;; + ;; When a validation error occurs, (car pro) will be nil. + ;; + (let ((plainp (eq 'plain (plist-get (cdr pro) :type))) + (openp (and (car pro) + (eq 'open (process-status (car pro))))) + ;; Falling back to a plain connection is allowed + ;; only when verify-level < 2. + (needtlsp (and starttlsp + (> (mew-ssl-verify-level case) 1)))) + (cond + ((not openp) + (let ((msg (plist-get (cdr pro) :error))) + (setq pro (list nil + :error t + :status-msg + (concat status-msg "FAILED: " msg))))) + ((and plainp needtlsp) + (delete-process (car pro)) + (setq pro (list nil + :error t + :status-msg + (concat status-msg "FAILED")))) + (t + (setq pro (list + (car pro) + :error nil))))))))) + (t + (with-temp-message status-msg + (let ((params (list :name name :buffer buf + :service port :family family + :nowait nowait)) + ;; :host will be ignored when family is 'local. + (host (if (not (eq family 'local)) + (list :host server)))) + (setq pro (list + (apply #'make-network-process (nconc params host)) + :greeting nil + :capabilities nil + :type 'plain + :error nil)))))) + (if (and (eq proto 'smtp) nowait) (run-at-time mew-smtp-submission-timeout nil 'mew-smtp-submission-timeout pro)) + (when (plist-get (cdr pro) :error) + (message (plist-get (cdr pro) :status-msg))) pro)) - (defalias 'mew-open-network-stream 'open-network-stream)) + (defun mew-open-network-stream (name buf server port proto sslnp starttlsp case) + (open-network-stream name buf server port :return-list t))) -(defun mew-smtp-open (pnm server port) +(defun mew-smtp-open (pnm case server port starttlsp) (let ((sprt (mew-*-to-port port)) + (sslnp (mew-ssl-native-p (mew-smtp-ssl case))) pro tm) ;; xxx some OSes do not define "submission", sigh. (when (and (stringp sprt) (string= sprt "submission")) @@ -413,7 +630,15 @@ (progn (setq tm (run-at-time mew-smtp-timeout-time nil 'mew-smtp-timeout)) (message "Connecting to the SMTP server...") - (setq pro (mew-open-network-stream pnm nil server sprt)) + (setq pro (mew-open-network-stream pnm nil server sprt + 'smtp sslnp starttlsp case)) + (when (and sslnp starttlsp) + (mew-smtp-debug "*GREETING*" + (plist-get (cdr pro) :greeting)) + (mew-smtp-debug "*CAPABILITIES*" + (plist-get (cdr pro) :capabilities))) + (setq pro (car pro)) + (when (not (processp pro)) (signal 'quit nil)) (mew-process-silent-exit pro) (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net) (message "Connecting to the SMTP server...done")) @@ -427,7 +652,11 @@ pro)) (defun mew-smtp-timeout () - (signal 'quit nil)) + ;; Do not timeout if the NSM query pane is active. + (unless (get-buffer "*Network Security Manager*") + (message "SMTP connection timed out (%d seconds)" + mew-smtp-timeout-time) + (signal 'quit nil))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -442,51 +671,64 @@ (sshsrv (mew-smtp-ssh-server case)) (sslp (mew-smtp-ssl case)) (sslport (mew-*-to-string (mew-smtp-ssl-port case))) + (sslnp (mew-ssl-native-p (mew-smtp-ssl case))) + (starttlsp + (mew-ssl-starttls-p (mew-smtp-ssl case) + (mew-*-to-string (mew-smtp-port case)) + (mew-smtp-ssl-port case))) mew-inherit-submission process sshname sshpro sslname sslpro lport tlsp tls fallback) - (when (and sslp (mew-port-equal port sslport)) + (cond + ((and (not sslnp) sslp starttlsp) (setq tlsp t) ;; let stunnel know that a wrapper protocol is SMTP - (setq tls mew-tls-smtp)) + (setq tls mew-tls-smtp))) ;; a fallback: "submission" -> "smtp" ;; mew-smtp-port is "smtp" and mew-use-submission is t on Emacs 22 - (when (and (or (not sslp) tlsp) + (when (and (or (not sslp) starttlsp tlsp) (not fallbacked) mew-use-submission (fboundp 'make-network-process) ;; Emacs 22 or later (mew-port-equal port "smtp")) (setq port "submission") (setq fallback t) - (unless tlsp + (when (and sslp (not sslnp) (not tlsp)) ;; TLS uses stunnel. So, we should not use non-blocking connect. ;; Timeout should be carried out by stunnel. (setq mew-inherit-submission t)) - (if (mew-port-equal sslport "smtp") (setq sslport "submission"))) + (if (mew-port-equal sslport "smtp") + (setq sslport "submission"))) (cond + (sslnp + (let ((serv (if starttlsp port sslport))) + (setq process (mew-smtp-open pnm case server serv starttlsp)))) (sshsrv (setq sshpro (mew-open-ssh-stream case server port sshsrv)) (when sshpro (setq sshname (process-name sshpro)) (setq lport (mew-ssh-pnm-to-lport sshname)) (when lport - (setq process (mew-smtp-open pnm "localhost" lport))))) + (setq process (mew-smtp-open pnm case "localhost" lport nil))))) (sslp (setq sslpro (mew-open-ssl-stream case server sslport tls)) (when sslpro (setq sslname (process-name sslpro)) (setq lport (mew-ssl-pnm-to-lport sslname)) (when lport - (setq process (mew-smtp-open pnm mew-ssl-localhost lport))))) + (setq process (mew-smtp-open pnm case mew-ssl-localhost lport nil))))) (t - (setq process (mew-smtp-open pnm server port)))) + (setq process (mew-smtp-open pnm case server port nil)))) (if (null process) (cond ((and sshsrv (null sshpro)) (message "Cannot create to the SSH connection")) + (sslnp + (message "Cannot open an SSL/TLS (GnuTLS) connection")) ((and sslp (null sslpro)) (message "Cannot create to the SSL/TLS connection")) (t - (if (and (or (not sslp) tlsp) + (if (and (not (eq server 'local)) + (or (not sslp) tlsp) (not fallbacked) mew-use-submission (fboundp 'make-network-process) @@ -520,7 +762,15 @@ (set-process-buffer process nil) (set-process-sentinel process 'mew-smtp-sentinel) (set-process-filter process 'mew-smtp-filter) - (message "Sending in background...")))) + (message "Sending in background...") + ;; + (when sslnp + ;; GnuTLS requires a client-initiated command after the + ;; session is established or upgraded to use TLS because + ;; no additional greeting from the server. + (mew-smtp-set-status pnm "ehlo") + (mew-smtp-command-ehlo process pnm)) + ))) (defun mew-smtp-flush-queue (case &optional qfld) (let (msgs) @@ -762,7 +1012,7 @@ ;;; Copyright Notice: -;; Copyright (C) 1999-2015 Mew developing team. +;; Copyright (C) 1999-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-ssl.el b/mew-ssl.el index 608ab79..e9c1c6a 100644 --- a/mew-ssl.el +++ b/mew-ssl.el @@ -7,6 +7,81 @@ (require 'mew) +(defun mew-ssl-native-p (type) + "Return if the type is native or not" + (or (eq type 'native) + (and (eq type t) (eq mew-ssl-default 'native)))) +(defun mew-ssl-starttls-p (type port sslport) + "Return if STARTTLS should be used or not" + (and type (mew-port-equal port sslport))) +(defvar mew-ssl-min-prime-bits 2048 + "Default prime bits for GnuTLS connection.") +(defvar mew-ssl-verify-error nil + "verify-error parameter passed to GnuTLS. You might want to +keep this as nil.") +(defvar mew-ssl-native-starttls-plist + '( + ;; RFC 3207 + (smtp . (:capability-command + (format "EHLO %s\r\n" (mew-smtp-helo-domain case)) + :always-query-capabilities t + :end-of-command + (format "^[0-9]+ .*\r?\n") + :end-of-capability + (format "^[0-9]+ .*\r?\n") + :success (format "^2.*\r?\n") + :starttls-function + (lambda (capabilities) + (and (string-match "[ -]STARTTLS" capabilities) + "STARTTLS\r\n")))) + ;; RFC 2595 + (imap . (:capability-command + (format "1 CAPABILITY\r\n") + :always-query-capabilities t + :end-of-capability + (format "\r?\n") + :end-of-command + (format "\r?\n") + :success + (format "^1 OK ") + :starttls-function + (lambda (capabilities) + (when (string-match-p "STARTTLS" capabilities) + "1 STARTTLS\r\n")))) + ;; RFC 2595 + (pop . (:capability-command + (format "CAPA\r\n") + :always-query-capabilities nil + :end-of-capability + (format "^\\.\r?\n\\|^-ERR") + :end-of-command + (format "^\\(-ERR\\|+OK\\).*\r?\n") + :success + (format "^\\+OK.*\n") + :starttls-function + (lambda (capabilities) + (and (string-match "\\bSTLS\\b" capabilities) + "STLS\r\n")))) + ;; RFC 4642 + (nntp . (:capability-command + (format "CAPABILITIES\r?\n") + :always-query-capabilities t + :end-of-capability + (format "^\\.\r?\n") + :end-of-command + (format "^\\.\r?\n") + :success + (format "^2.+ \r?\n") + :starttls-function + (lambda (capabilities) + (when (string-match-p "STARTTLS" capabilities) + "STARTTLS\r\n")))) + )) +(defun mew-starttls-get-param (proto key evalp) + "Get parameter from mew-ssl-native-starttls-plist" + (let ((p (plist-get (cdr (assq proto mew-ssl-native-starttls-plist)) key))) + (if evalp (eval p) p))) + (defvar mew-prog-ssl "stunnel") (defvar mew-ssl-cert-directory "~/.certs" "The directory where certificates of root servers are stored. @@ -294,7 +369,7 @@ A local port number can be obtained the process name after ':'. " ;;; Copyright Notice: -;; Copyright (C) 2002-2018 Mew developing team. +;; Copyright (C) 2002-2020 Mew developing team. ;; All rights reserved. ;; Redistribution and use in source and binary forms, with or without diff --git a/mew-vars.el b/mew-vars.el index 3fa1af3..43104e5 100644 --- a/mew-vars.el +++ b/mew-vars.el @@ -578,6 +578,35 @@ is kept for further connections. This must be 't' for IMAP and NNTP." :group 'mew-net :type 'boolean) +(defcustom mew-ssl-default 'tunnel + "*Default SSL/TLS type when mew-{imap,nntp,pop,smtp}-ssl is 't'." + :group 'mew-net + :type '(choice (const :tag "Native (GnuTLS)" native) + (const :tag "External (stunnel)" tunnel))) + +;; XXX: the default value of gnutls-trustfiles can +;; be different from the compile-time list. +(defcustom mew-ssl-trustfiles nil + "List of CA buldle location filenames used by GnuTLS. +nil - use the default list specified at compile time of the Emacs." + :group 'mew-net + :type '(choice (const :tag "System Default" nil) + (repeat string))) + +(defcustom mew-ssl-algorithm-priority nil + "TLS priority string used by GnuTLS. +nil - use the default specified by Emacs Network Security Manager." + :group 'mew-net + :type '(choice (const :tag "System Default" nil) + (string :tag "Priority string"))) + +(defcustom mew-ssl-client-keycert-list nil + "The client-side certificate used for TLS connection. +'((\"keyfile\" \"certfile\")) - A list of key/cert pairs." + :group 'mew-net + :type '(choice (const :tag "None" nil) + (repeat string))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; SMTP @@ -601,11 +630,19 @@ server, set an appropriate value." (string :tag "Ssh server"))) (defcustom mew-smtp-ssl nil - "*If non-nil, SMTP connections are made over SSL/TLS." + "*If non-nil, SMTP connections are made over SSL/TLS. +native - Use GnuTLS (this requires Emacs compiled with GnuTLS + library). When mew-smtp-ssl-port is equal to + mew-smtp-port, a plain connection will be opened and + upgraded by STARTTLS. +tunnel - Use an external program to establish a TLS tunnel. + stunnel(1) utility is used by default." :group 'mew-smtp - :type 'boolean) + :type '(choice (const :tag "No TLS/SSL" nil) + (const :tag "Native (GnuTLS)" native) + (const :tag "External (stunnel)" tunnel))) -(defcustom mew-smtp-ssl-port 465 ;; no universal consensus +(defcustom mew-smtp-ssl-port 465 ;; RFC 8314 "*The port for SMTP over SSL/TLS. Set this to \"smtp\" if you want to use TLS." :group 'mew-smtp @@ -712,9 +749,17 @@ server, set an appropriate value." :type '(choice string (const nil))) (defcustom mew-pop-ssl nil - "*If non-nil, POP connections are made over SSL/TLS." + "*If non-nil, POP connections are made over SSL/TLS. +native - Use GnuTLS (this requires Emacs compiled with GnuTLS + library). When mew-pop-ssl-port is equal to + mew-pop-port, a plain connection will be opened and + upgraded by STARTTLS. +tunnel - Use an external program to establish a TLS tunnel. + stunnel(1) utility is used by default." :group 'mew-pop - :type 'boolean) + :type '(choice (const :tag "No TLS/SSL" nil) + (const :tag "Native (GnuTLS)" native) + (const :tag "External (stunnel)" tunnel))) (defcustom mew-pop-ssl-port "pop3s" "*The port for POP over SSL/TLS." @@ -805,9 +850,17 @@ server, set an appropriate value." :type '(choice string (const nil))) (defcustom mew-imap-ssl nil - "*If non-nil, IMAP connections are made over SSL/TLS." + "*If non-nil, IMAP connections are made over SSL/TLS. +native - Use GnuTLS (this requires Emacs compiled with GnuTLS + library). When mew-imap-ssl-port is equal to + mew-imap-port, a plain connection will be opened and + upgraded by STARTTLS. +tunnel - Use an external program to establish a TLS tunnel. + stunnel(1) utility is used by default." :group 'mew-imap - :type 'boolean) + :type '(choice (const :tag "No TLS/SSL" nil) + (const :tag "Native (GnuTLS)" native) + (const :tag "External (stunnel)" tunnel))) (defcustom mew-imap-ssl-port "imaps" "*The port for IMAP over SSL/TLS." @@ -922,9 +975,17 @@ server, set an appropriate value." :type '(choice string (const nil))) (defcustom mew-nntp-ssl nil - "*If non-nil, NNTP connections are made over SSL/TLS." + "*If non-nil, NNTP connections are made over SSL/TLS. +native - Use GnuTLS (this requires Emacs compiled with GnuTLS + library). When mew-nntp-ssl-port is equal to + mew-nntp-port, a plain connection will be opened and + upgraded by STARTTLS. +tunnel - Use an external program to establish a TLS tunnel. + stunnel(1) utility is used by default." :group 'mew-nntp - :type 'boolean) + :type '(choice (const :tag "No TLS/SSL" nil) + (const :tag "Native (GnuTLS)" native) + (const :tag "External (stunnel)" tunnel))) (defcustom mew-nntp-ssl-port "nntps" "*The port for NNTP over SSL/TLS." @@ -1674,6 +1735,13 @@ created (if the feature is provided)." :group 'mew-privacy :type 'boolean) +(defcustom mew-master-passwd-type 'master + "*Type of the password manager when mew-use-master-passwd is non-nil." + :group 'mew-privacy + :type '(choice + (const :tag "Master Password" 'master) + (const :tag "auth-source" 'auth-source))) + (defcustom mew-use-8bit nil "*If non-nil, the 8bit-clean charset mechanism is used for 8bit charsets, such as ISO-8859-1, in Draft mode. If nil, an appropriate diff --git a/mew-vars2.el b/mew-vars2.el index c7d629e..ddb3d12 100644 --- a/mew-vars2.el +++ b/mew-vars2.el @@ -940,7 +940,8 @@ imap-proxy-server, imap-proxy-port, nntp-server, nntp-port, nntp-ssh-server, nntp-ssl, nntp-ssl-port, nntp-user, nntp-size, nntp-header-only, nntp-msgid-user, nntp-msgid-domain, -ssl-cert-directory, ssl-verify-level, +ssl-cert-directory, ssl-verify-level, ssl-algorithm-priority, +ssl-client-keycert-list, ssl-trustfiles, inbox-folder, queue-folder, postq-folder, mailbox-type, mbox-command, mbox-command-arg, signature-file, content-type, refile-guess-alist,