do_su_0805's blog

dairyquestions は typo です。

雑に nginx 1.15.9 の変更差分を眺めた

という tweet を見かけ、 nginx 1.15.9 の CHANGES を見てきた

Changes with nginx 1.15.9 26 Feb 2019

*) Feature: variables support in the "ssl_certificate" and "ssl_certificate_key" directives.

*) Feature: the "poll" method is now available on Windows when using Windows Vista or newer.

*) Bugfix: if the "select" method was used on Windows and an error occurred while establishing a backend connection, nginx waited for the connection establishment timeout to expire.

*) Bugfix: the "proxy_upload_rate" and "proxy_download_rate" directives in the stream module worked incorrectly when proxying UDP datagrams

  • ssl_certificatessl_certificate_key が変数対応した
  • poll 関数が windows vista 以降なら使えるようになった
  • select メソッドのバグフィックス
  • proxy_upload_rate / proxy_download_rate が、UDP で不完全に動いていたのを直した。

なるほどなぁと思いつつ、proxy_*_ratessl_cerificate なんたらについて気になったので、ソースコードを見てみようと思って、いい感じの diff にたどり着くまでのお話です。

ソースコードのありか

nginx のソースコードは、公式ページからたどると https://trac.nginx.org/nginx/browser にあるらしい。

また、これを一時間に一回同期している、 https://github.com/nginx/nginx というリポジトリもある

いい感じに github で diff を見たい

  • 下記に掲載されているように、 compare/(from)...(to) という方法で差分が見れるということらしい。 kanonji.hatenadiary.com

今回は、 release-1.15.8release-1.15.9 の差分を見ることにする - https://github.com/nginx/nginx/compare/release-1.15.8...release-1.15.9

雑に見てみた感想

ちゃんとコードを追ったりはしてないけど、ここら辺中心に見たらssl関連はいろいろ面白そうという勘だけおいておく。どっかで気が向いたら見る

  • 新設関数 or ifdef による挙動新設があるものうち、関係がありそうなもの
    • int ngx_http_ssl_certificate(ngx_ssl_conn_t *ssl_conn, void *arg)
    • int ngx_stream_ssl_certificate(ngx_ssl_conn_t *ssl_conn, void *arg)
    • ngx_int_t ngx_ssl_connection_certificate(ngx_connection_t *c, ngx_pool_t *pool,ngx_str_t *cert, ngx_str_t *key, ngx_array_t *passwords)
    • ngx_int_t ngx_http_test_required_predicates(ngx_http_request_t *r,ngx_array_t *predicates)
    • static ngx_int_t ngx_http_ssl_compile_certificates(ngx_conf_t *cf,ngx_http_ssl_srv_conf_t *conf);
    • static ngx_int_t ngx_stream_ssl_compile_certificates(ngx_conf_t *cf,ngx_stream_ssl_conf_t *conf)
    • static X509 *ngx_ssl_load_certificate(ngx_pool_t *pool, char **err, ngx_str_t *cert, STACK_OF(X509) **chain)
    • static EVP_PKEY *ngx_ssl_load_certificate_key(ngx_pool_t *pool, char **err,ngx_str_t *key, ngx_array_t *passwords)
    • ngx_array_t *ngx_ssl_preserve_passwords(ngx_conf_t *cf, ngx_array_t *passwords)
  • ngx_ssl_certificate 関数の挙動
    • X509 の STACK_OF である *chain が表れて、 sk_X509_pop_free とかに突っ込まれている
  • nginx_ssl_session_* な関数の引数増加
    • ngx_ssl_session_cachengx_ssl_session_id_contexngx_array_t *certificates という今回の変更ど直球ぽい引数追加
  • ngx_http_request_t *ngx_http_create_request(ngx_connection_t *c) の挙動が新設され、以前の挙動が static ngx_http_request_t *ngx_http_alloc_request(ngx_connection_t *c) に一部移植されている
  • ngx_event_openssl.c まぁ名前的にしょうがないとはいえ、 #ifdef が広範囲に広がっており、読むのに注意がいる
  • 個人的に気になったのは、 ngx_freebsd_config.h に微妙な変更が入ってる。多分、ngx_file_aio_read.c の変更向け
    • FreeBSD_version < 700005 って、FreeBSD 7 か?