Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

別ドメインのwandboxを利用したい #3

Closed
kosh04 opened this issue Dec 19, 2014 · 4 comments
Closed

別ドメインのwandboxを利用したい #3

kosh04 opened this issue Dec 19, 2014 · 4 comments

Comments

@kosh04
Copy link
Owner

kosh04 commented Dec 19, 2014

Wandbox for CodeIQ
のような別ドメインで運用されているWandboxでも利用できるようにしたい。

;; こんな感じ
(let ((wandbox-base-url "http://apex.cloudapp.net/wandbox"))
  (wandbox :lang "C++" :code "..."))

今の実装ではコンパイラ一覧を先読みしてキャッシュとして利用しているため、
動的にドメイン変更を可能にする場合はキャッシュを上書きするか別の方法を考える必要がある。

kosh04 added a commit that referenced this issue Mar 23, 2016
- Define server structure
- TODO: sandbox-profiles to be deprecated?
@kosh04
Copy link
Owner Author

kosh04 commented Apr 3, 2016

手元の環境では問題なく動作するのだが、Travis CIのログを見てみると (url-retrieve "https://wandbox.fetus.jp/api/list.json") の箇所が失敗している。なぜ?

https://travis-ci.org/kosh04/emacs-wandbox/jobs/119997969

Contacting host: wandbox.fetus.jp:443
gnutls.c: [0] (Emacs) fatal error: A TLS fatal alert has been received.
gnutls.c: [0] (Emacs) Received alert:  Handshake failed
gnutls.el: (err=[-12] A TLS fatal alert has been received.) boot: (:priority NORMAL :hostname wandbox.fetus.jp :loglevel 0 :min-prime-bits 256 :trustfiles (/etc/ssl/certs/ca-certificates.crt) :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :verify-hostname-error nil :callbacks nil)

@ryoh-miura
Copy link

マニュアルと外側から観察する限りemacsビルトインのSSL/TLS関数がネゴシエーションに失敗していました。

https://www.gnu.org/software/emacs/manual/html_node/elisp/Network.html

Emacs can create encrypted network connections, using either built-in or external
support. The built-in support uses the GnuTLS (“Transport Layer Security”) library;
see the GnuTLS project page. If your Emacs was compiled with GnuTLS support,
the function gnutls-available-p is defined and returns non-nil. For more details, see
Overview in The Emacs-GnuTLS manual. The external support uses the starttls.el
library, which requires a helper utility such as gnutls-cli to be installed on the system.
The open-network-stream function can transparently handle the details of creating
encrypted connections for you, using whatever support is available.

https://glyph.twistedmatrix.com/2015/11/editor-malware.html

Step 5: Configure the Other TLS Verifier
If GnuTLS is not linked in, it will use whatever TLS program you give it
(which might be gnutls-cli or openssl s_client,but since only the most recent
version of openssl s_client can even attempt to verify certificates, I’d recommend
against it).

読み違えていたのですが、gnutlsを明示的に使わなければ回避は出来たのでその備忘録となります。

(if (fboundp 'gnutls-available-p) (fmakunbound 'gnutls-available-p))

ただ名前空間全体が上書きされる気がするので、もしかするといやな事がおきるかもしれません。

↓は作業手順とその結果となります。ご参考までに。。。

再現手順 1. gnutlsのネゴシエーションとtsharkの結果

(url-retrieve-synchronously "https://wandbox.fetus.jp/api/list.json") 
Secure Sockets Layer
    SSL Record Layer: Handshake Protocol: Client Hello
        Content Type: Handshake (22)
        Version: SSL 3.0 (0x0300)
        Length: 112
        Handshake Protocol: Client Hello
            Handshake Type: Client Hello (1)
            Length: 108
            Version: TLS 1.2 (0x0303)
            Random
                gmt_unix_time: Apr  5, 2016 07:13:25.000000000 JST
                random_bytes: 1e9f44b5655766920a66dd6ea73c0c71a41fb436a1aa644f...
            Session ID Length: 0
            Cipher Suites Length: 48
            Cipher Suites (24 suites)
                Cipher Suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA (0x0033)
                Cipher Suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 (0x0067)
                ...
            Compression Methods Length: 1

handshake failed (40) <- だったはず。ログ失念...

再現手順 2. gnutlsを利用しないネゴシエーションとtsharkの結果

(if (fboundp 'gnutls-available-p) (fmakunbound 'gnutls-available-p))
(url-retrieve-synchronously "https://wandbox.fetus.jp/api/list.json") 
Secure Sockets Layer
    SSL Record Layer: Handshake Protocol: Client Hello
        Content Type: Handshake (22)
        Version: TLS 1.0 (0x0301)
        Length: 290
        Handshake Protocol: Client Hello
            Handshake Type: Client Hello (1)
            Length: 286
            Version: TLS 1.2 (0x0303)
            Random
                gmt_unix_time: Apr 12, 1977 13:17:42.000000000 JST
                random_bytes: 25f283374f227d2ed9f3a55218b9651a69d2c65b9fc137b9...
            Session ID Length: 0
            Cipher Suites Length: 136
                Cipher Suites (68 suites)
                Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)
...
            Compression Methods Length: 1
...
            Extension: ec_point_formats
                Type: ec_point_formats (0x000b)
                Length: 4
                EC point formats Length: 3
                Elliptic curves point formats (3)
                    EC point format: uncompressed (0)
            Extension: elliptic_curves
                Type: elliptic_curves (0x000a)
...
            Extension: SessionTicket TLS
                Type: SessionTicket TLS (0x0023)

--
Secure Sockets Layer
    TLSv1.2 Record Layer: Handshake Protocol: Server Hello
        Content Type: Handshake (22)
        Version: TLS 1.2 (0x0303)
        Length: 61
        Handshake Protocol: Server Hello
            Handshake Type: Server Hello (2)
            Length: 57
            Version: TLS 1.2 (0x0303)
            Random
                gmt_unix_time: Sep 27, 2044 10:45:49.000000000 JST
                random_bytes: 9d3312feec0f681c4ca6784c764ff438305c126c598b8f0e...
            Session ID Length: 0
            Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)

手元の再現環境

$ dpkg -l | grep -e emacs -e gnutls
ii  emacs24-bin-common                  24.3+1-2ubuntu1                         amd64        GNU Emacs editor's shared, architecture dependent files
ii  emacs24-common                      24.3+1-2ubuntu1                         all          GNU Emacs editor's shared, architecture independent infrastructure
ii  emacs24-common-non-dfsg             24.3+1-1                                all          GNU Emacs common non-DFSG items, including the core documentation
ii  emacs24-nox                         24.3+1-2ubuntu1                         amd64        GNU Emacs editor (without X support)
ii  emacsen-common                      2.0.7                                   all          Common facilities for all emacsen
ii  libcurl3-gnutls:amd64               7.35.0-1ubuntu2.5                       amd64        easy-to-use client-side URL transfer library (GnuTLS flavour)
ii  libgnutls-dev                       2.12.23-12ubuntu2.4                     amd64        GNU TLS library - development files
ii  libgnutls-openssl27:amd64           2.12.23-12ubuntu2.4                     amd64        GNU TLS library - OpenSSL wrapper
ii  libgnutls26:amd64                   2.12.23-12ubuntu2.4                     amd64        GNU TLS library - runtime library
ii  libgnutlsxx27:amd64                 2.12.23-12ubuntu2.4                     amd64        GNU TLS library - C++ runtime library

$ ldd /usr/bin/emacs | grep gnutls
        libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007f49214bf000)
(defun network-stream-open-tls (name buffer host service parameters)
   (use-builtin-gnutls (and (fboundp 'gnutls-available-p)
    (gnutls-available-p)))
   (stream<
    (funcall (if use-builtin-gnutls
      'open-gnutls-stream
      'open-tls-stream)

@ryoh-miura
Copy link

あああ、失敗している理由を書いていなかったでした。。。
ClientHelloのパケットを自前で作成すれば判断出来るかと思うのですが、二つの理由の可能性があるかと。1つ目は、レコードレイヤのSSLv3でチェックがはねられる。2つ目は、Cipher Suites (24 suites)の中にServer側では許容できるものがない。
要領を得ないコメントで混乱させてしまいましたら大変失礼いたしました。。。

@kosh04
Copy link
Owner Author

kosh04 commented Apr 6, 2016

ありがとうございます。

まだ実験途中ですが、組み込みのTLS関数を利用しなければ上記の問題を回避できることはわかったので、どうしても利用したい人はnadvice等で各自パッチを当てるように促すのが無難な解決方法かなと思ってます。

https://github.com/kosh04/emacs-wandbox/blob/develop/tls-patch.el

kosh04 added a commit that referenced this issue Apr 12, 2016
Available other wandbox server.
store server infomations to `wandbox-server` structure.

HTTP request use request library, and s.

Replace private functions to defsubst.

Apply and Test tls stream patch. (optional)

Update travis conf.
refer to nlamirault/emacs-travis
@kosh04 kosh04 closed this as completed Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants