Certificate Transparency คืออะไร?
เราคงปฏิเสธไม่ได้ว่าในปัจจุบัน ทุกคนต่างให้ความสำคัญกับเรื่องความมั่นคงและความเป็นส่วนตัวในเรื่องของข้อมูลที่อยู่บนอินเตอร์เน็ตเพิ่มมากขึ้น ผู้ให้บริการเว็บไซต์ต่างๆ จึงจำเป็นที่จะต้องให้ความสำคัญจึงได้นำเอาการเข้ารหัสแบบ TLS/SSL มาใช้ในการเข้ารหัสกันอย่างแพร่หลาย โดยการทำการซื้อ SSL Certificate จาก Certificate Authority ที่น่าเชื่อมาใช้งานกับเว็บไซต์ของตนเอง แต่ก็ยังมีผู้ไม่ประสงค์ดีทำการปลอมแปลง Certificate เหล่านั้นเพื่อนำไปใช้ให้เกิดความเสียหายกับผู้ที่มาใช้ระบบเป็นอย่างมาก ในหลายด้าน เช่น website spoofing, server impersonation และ man-in-the-middle attacks เป็นต้น
ซึ่งในปัจจุบันได้มีเทคนิคการป้องกันหลายวิธีแต่ก็ยังมีช่องโหว่และไม่มีประสิทธิภาพที่ดีพอ ดังข้อมูลที่เปรียบเทียบในตารางข้างล่าง

NSC (No side-channels): our experiments show that side-channel requests to third parties during the SSL handshake (e.g. OCSP checks) fail at least 1% of the time, often a great deal more, depending on what protocol they use. This level of failure makes it impossible to hard fail with protocols that use side channels.
IR (Instant recovery from loss of key): if the server loses its private key, can it immediately roll out a new certificate?
GA (Detects Global Attack): if the server is replaced by an evil server that everyone sees, does the protocol protect clients?
TA (Detects targeted attack): if the server is replaced by an evil server (or MitM) for one person or a small number of people, can the protocol protect those people?
NTTP (No trusted third parties): does the protocol avoid the need for the client to trust a third party?
IS (Instant startup): can a new server use a new certificate immediately and be trusted by clients?
US (Unmodified Servers): can it be used without server changes?
จะเห็นได้ว่า Certificate transparency มีความสามารถในการป้องกัน certificate ได้มีประสิทธิภาพมากขึ้น Certificate transparency TLS Extension จะเป็น open-source framework
โดยมีหลักการทำงานคร่าวๆ คือ ในภาพ Figure 3 จะมีส่วนเสริมการทำงาน 3 ส่วน ที่เป็นสีเขียวในูปคือ Monitor, Log Server และ Auditor ทำงานร่วมกัน เพื่อเป็นการทำงานในการร่วมตรวจสอบ SSL Certificate ที่น่าสงสัยร่วมกัน 3 ฝ่าย คือ Certificate Authority, Site Certificate และ Client(Browser)
ซึ่งเราสามารถตรวจสอบการตั้งค่า server certificate ปัจจุบันว่ารองรับ Certificate Transparency ได้ที่เว็บ https://www.ssllabs.com ซึ่งถ้ายังไม่ได้ตั้งค่าจะแสดงผลดังรูปข้างล่าง

ในบทความนี้ผมจะให้ความสำคัญในการ set up Certificate Transparency TLS Extension บนเว็บไซต์กับ nginx web server เท่านั้นครับ ผมเขียน shell script เพื่อใช้ในการ compile nginx ใน shell sctipt ดังนี้
#!/usr/bin/env bash # # nginx_ssl_transparency.sh # Script for compile nginx with nginx_ct and others. # By Thassanai Mhuansean # E-mail: thassanai.mh@gmail.com # # names of latest versions of each package export NGINX_VERSION=1.15.1 export VERSION_PCRE=pcre-8.42 export VERSION_NGINX=nginx-$NGINX_VERSION export HEADERMOD_VER=0.33 export OPENSSL_VER=1.0.2o export ZLIB=1.2.11 # URLs to the source directories export SOURCE_PCRE=https://ftp.pcre.org/pub/pcre/ export SOURCE_NGINX=http://nginx.org/download/ export SOURCE_NGINX_HEAD=https://github.com/openresty/headers-more-nginx-module/archive/v${HEADERMOD_VER}.tar.gz export SOURCE_OPENSSL=https://www.openssl.org/source/openssl-${OPENSSL_VER}.tar.gz export SOURCE_ZLIB=https://www.zlib.net/zlib-${ZLIB}.tar.gz # clean out any files from previous runs of this script rm -rf build mkdir build # proc for building faster NB_PROC=$(grep -c ^processor /proc/cpuinfo) # ensure that we have the required software to compile our own nginx sudo apt-get -y install curl wget build-essential libgd-dev libgeoip-dev checkinstall git sudo apt-get -y install golang cmake sudo apt-get -y install build-essential libpcre3 libpcre3-dev zlib1g-dev sudo apt-get -y install libtexluajit2 libtexluajit-dev # grab the source files echo "Download sources" wget -P ./build $SOURCE_PCRE$VERSION_PCRE.tar.gz wget -P ./build $SOURCE_NGINX$VERSION_NGINX.tar.gz wget -P ./build $SOURCE_NGINX_HEAD wget -P ./build $SOURCE_OPENSSL wget -P ./build $SOURCE_ZLIB # expand the source files echo "Extract Packages" cd build tar xzf $VERSION_NGINX.tar.gz tar xzf $VERSION_PCRE.tar.gz tar xzf v${HEADERMOD_VER}.tar.gz tar xzf openssl-${OPENSSL_VER}.tar.gz tar xzf zlib-${ZLIB}.tar.gz cd ../ # set where nginx will be built export BPATH=$(pwd)/build # Brotti, Better compression than gzip. cd $BPATH git clone https://github.com/google/ngx_brotli.git cd $BPATH/ngx_brotli git submodule update --init # NGINX_CT cd $BPATH git clone https://github.com/grahamedgecombe/nginx-ct --depth=1 cd $BPATH # build static OPENSSL echo "Configure & Build OPENSSL" cd $BPATH/openssl-${OPENSSL_VER} wget https://raw.githubusercontent.com/cloudflare/sslconfig/master/patches/openssl__chacha20_poly1305_draft_and_rfc_ossl102j.patch -O chacha.patch patch -p1 < chacha.patch ./config --prefix=/usr --openssldir=/usr/lib/ssl --libdir=/usr/lib/x86_64-linux-gnu enable-weak-ssl-ciphers make -j $NB_PROC make install # build nginx, with various modules included/excluded echo "Configure & Build Nginx" cd $BPATH/$VERSION_NGINX echo "Download and apply path" wget https://raw.githubusercontent.com/cloudflare/sslconfig/master/patches/nginx__1.13.0_http2_spdy.patch -O spdy.patch patch -p1 < spdy.patch ##echo "TLS patch" wget https://raw.githubusercontent.com/cloudflare/sslconfig/master/patches/nginx__1.11.5_dynamic_tls_records.patch -O tcp-tls.patch patch -p1 < tcp-tls.patch ./configure --prefix=/etc/nginx \ --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \ --with-cc-opt="-D FD_SETSIZE=2048" \ --with-ld-opt="-Wl,-rpath,/usr/local/lib" \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/lib/nginx/body \ --http-proxy-temp-path=/var/lib/nginx/proxy \ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \ --http-scgi-temp-path=/var/lib/nginx/scgi \ --user=nginx \ --group=nginx \ --with-cpu-opt=amd64 \ --with-ld-opt="-lrt" \ --with-openssl=/usr/src/build/openssl-${OPENSSL_VER} \ --with-openssl-opt=enable-weak-ssl-ciphers \ --with-openssl-opt=enable-ec_nistp_64_gcc_128 \ --with-pcre=$BPATH/$VERSION_PCRE \ --with-zlib=$BPATH/zlib-${ZLIB} \ --with-compat \ --with-http_ssl_module \ --with-http_spdy_module \ --with-http_v2_module \ --with-file-aio \ --with-google_perftools_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-http_image_filter_module=dynamic \ --without-mail_pop3_module \ --without-mail_smtp_module \ --without-mail_imap_module \ --with-stream \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-stream_geoip_module \ --with-threads \ --with-stream=dynamic \ --lock-path=/var/lock/nginx.lock \ --pid-path=/run/nginx.pid \ --http-client-body-temp-path=/var/lib/nginx/body \ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ --http-proxy-temp-path=/var/lib/nginx/proxy \ --http-scgi-temp-path=/var/lib/nginx/scgi \ --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \ --with-pcre-jit \ --with-http_stub_status_module \ --with-http_realip_module \ --with-http_auth_request_module \ --with-http_addition_module \ --with-http_geoip_module \ --add-module=$BPATH/headers-more-nginx-module-${HEADERMOD_VER} \ --add-module=$BPATH/ngx_brotli \ --add-dynamic-module=$BPATH/nginx-ct \ make -j $NB_PROC make install echo "All done.";
สามารถ download shell script ได้ที่ link นี้นะครับ https://raw.githubusercontent.com/thassanai/Machine-Learning/master/nginx_ssl_transparency.sh
หลังจากนั้นให้ไป config nginx.conf ที่ /etc/nginx
โดยเพิ่ม config ในส่วนการโหลด module ส่วนบนของ config
load_module modules/ngx_ssl_ct_module.so;
load_module modules/ngx_http_ssl_ct_module.so;
ต่อจากนั้นให้เพิ่ม config เกี่ยวกับ certificate tranparency TLS Extension ในส่วน server{ } ที่อยู่ใน http{ } ที่เราต้องการ config ดังนี้
#SSL Certificate transparent
ssl_ct on;
ssl_ct_static_scts /etc/ssl/sct;
ต่อจากนั้นให้ mkdir /etc/ssl/sct แล้วไปสร้าง SCT files โดย logs server จาก 3 server คือ Google server, Comodo, และ Digicert ครับ โดยใช้คำสั่งดังนี้
./ct-submit ct.googleapis.com/pilot < /path/to/certificate_with_intermediate.crt > /etc/ssl/sct/google-pilot.sct
./ct-submit ct2.digicert-ct.com/log < /path/to/certificate_with_intermediate.crt > /etc/ssl/sct/digicert2.sct
./ct-submit sabre.ct.comodo.com < /path/to/certificate_with_intermediate.crt > /etc/ssl/sct/comodo-sabre.sct
./ct-submit ct.googleapis.com/rocketeer < certificate_with_intermediate.crt > /etc/ssl/sct/google-rocketeer.sct
จะได้ไฟล์ดังรูป

ส่วนคำสั่ง ct-submit เราสามารถ clone ได้จาก github ได้ตามคำสั่งนี้ครับ
git clone https://github.com/grahamedgecombe/ct-submit.git
ซึ่ง ct-submit จะเขียนด้วยภาษา go ถ้าเครื่องจะต้องลง go-lang ก่อนครับ หลังจากนั้นเข้าไปใน directory ct-submit แล้วสั่ง go build ได้เลยครับ จะได้ ct-submit เป็น binary file พร้อมใช้งานได้เลยครับ
เมื่อเสร็จขั้นตอนให้สั่ง /etc/init.d/nginx reload อีกครั้งเพื่อให้ nginx โหลดค่า config ใหม่เข้าไป แล้วทำการตรวจสอบการทำงาน certificate transparency อีกครั้งที่เว็บ https://www.ssllabs.com ซึ่งถ้าทำงานได้ถูกต้องจะได้ประมาณนี้ครับ

หากมีข้อผิดพลาดหรือข้อติชมประการใด ส่งเมลล์มาได้ที่ thassanai.mh@gmail.com นะครับ
หมายเหตุ https://pookpui.com ยังไม่ได้ทำ certificate transparency นะครับ อิอิ เผื่อมีใครมาทดสอบ