OpenSSL

0
2745

Cài đặt SSL

Thông tin cần có

Website certificate website.crt
Website privatekey website.key
Intermediate certificate inter.crt
Root CA certificate rootca.crt

Một số certificate cần cho quá trình cài đặt

  • GlobalSign Intermediate AlphaSSL
  • GlobalSign Intermediate DVSSL
  • GlobalSign Intermediate OVSSL
  • GlobalSign Intermediate EVSSL
  • GlobalSign Root AlphaSSL/DV/OV
  • GlobalSign Root EV
  • LetsEncrypt Intermediate
  • LetsEncrypt Root X3

Trong một số trường hợp cần cấu hình thêm dhparam.pem ⇒ Tạo ra bằng command sau

openssl dhparam -out dhparam.pem 2048

1.cPanel hosting

  • Đăng nhập vào trang quản trị web hosting
https://<domain>:2083/
  • Chuyển tới mục Security > SSL/TLS
  • Trong mục “Install and Manage SSL for your site (HTTPS)”, click vào “Manage SSL sites.”
  • Tại màn hình “Install an SSL Website”, chọn domain cần cài đặt SSL từ combo box, điền thông tin tương ứng vào 3 text box bên dưới rồi click “Install Certificate”
    • Certificate của website (CRT)
    • Private của website (KEY)
    • Certificate Authority Bundle (CABUNDLE)

2.Plesk hosting

  • Đăng nhập vào trang quản trị hosting
https://<domain>:8443/
  • Trong mục Websites & Domains, chuyển tới website cần cài đặt SSL và chọn “SSL/TLS Certificates”
  • Click nút “Add SSL/TLS Certificate”
  • Cung cấp thông tin về certificate cần cài đặt (upload file hoặc paste nội dung), bao gồm:
    • Private key của website
    • Certificate của website
    • CA Certificate
  • Click “Upload Certificate” để xác nhận và cài đặt SSL

3.Web server Apache

Cấu hình như sau vào virtualhost https

<IfModule mod_ssl.c>
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/website.crt
        SSLCertificateKeyFile /etc/ssl/certs/website.key
        SSLCertificateChainFile /etc/ssl/certs/chain.crt
        SSLCipherSuite AES256+EECDH:AES256+EDH:AES128+EECDH:AES128+EDH
        #SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SSLv3:!SSLv2
        SSLProtocol ALL -SSLv2 -SSLv3 +TLSv1 +TLSv1.1 +TLSv1.2
        SSLHonorCipherOrder on
</IfModule>

Cấu hình HSTS

Header always set Strict-Transport-Security "max-age=63072000;"

Cấu hình HPKP Header

Header set Public-Key-Pins "pin-sha256=\"cUPcTAZWKaASuYWhhneDttWpY3oBAkE3h2+soZS7sWs=\"; pin-sha256=\"M8HztCzM3elUxkcjR2S5P4hhyBNf6lHkmjAHKhpGPWE=\"; max-age=5184000; includeSubDomains; report-uri=\"https://www.example.org/hpkp-report\""

4.Web server Nginx

Cấu hình như sau vào virtualhost https

ssl_certificate /etc/ssl/certs/website_inter.crt;
ssl_certificate_key /etc/ssl/certs/website.key;

# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
ssl_dhparam /etc/ssl/certs/dhparam.pem;

# enables server-side protection from BEAST attacks ## http://blog.ivanristic.com/2013/09/is-beast-still-a-threat.html
ssl_prefer_server_ciphers on;
# disable SSLv3(enabled by default since nginx 0.8.19) since it's less secure then TLS http://en.wikipedia.org/wiki/Secure_Sockets_Layer#SSL_3.0
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ciphers chosen for forward secrecy and compatibility ## http://blog.ivanristic.com/2013/08/configuring-apache-nginx-and-openssl-for-forward-secrecy.html
ssl_ciphers HIGH:!aNULL:!MD5; # avoid weak ciphersuite

# enable session resumption to improve https performance ## http://vincent.bernat.im/en/blog/2011-ssl-session-reuse-rfc5077.html
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;

# enable ocsp stapling (mechanism by which a site can convey certificate revocation information to visitors in a privacy-preserving, scalable manner)
# http://blog.mozilla.org/security/2013/07/29/ocsp-stapling-in-firefox/
resolver 8.8.8.8 8.8.4.4;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/ssl/website_inter.crt;

# config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
# to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
# also https://hstspreload.org/
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";

5.Ứng dụng nền tảng Java

Tham khảo Hướng dẫn cài đặt SSL cho server Java (keystore)

Windows IIS

Tạo certificate PFX

openssl pkcs12 -export -in website.crt -inkey website.key -chain -CAfile chain.crt -name "domain" -out website.pfx

Hoặc

openssl pkcs12 -export -out name.pfx -inkey key.key -in key.crt -certfile ev.crt -passout pass:tenten

Chú ý:

  • -inkey: Đường dẫn Private Key
  • -in: Đường dẫn Certificate file
  • -certfile: Đường dẫn Intermediate theo từng gói
  • -passout: Password bảo vệ. Mặc định: tenten.

Chuyển đổi từ *.PEM (khi sử dụng SSL Let’s Enscypt) sang PFX

openssl pkcs12 -export -out certificate-full.pfx -inkey privkey1.pem -in cert1.pem -certfile fullchain1.pem

Script tự động gen PFX: (Với GlobalSign)

wget https://gist.githubusercontent.com/hoangdh/a0e45577f9a4531707d2f649ce5d585d/raw/b605cd6fb872a6a23f406e7d504efb4b15092e60/gen-pfx.sh
chmod +x gen-pfx.sh

Chú ý:

  • Tạo 1 file chứa Cert. và PK vào file có phần mở rộng là txt
  • Chọn Intermediate tương ứng: alpha, dv, ov, ev

Import vào server

  • Vào giao diện quản trị IIS
  • Chọn WebServer trong khung bên trái
  • Chọn mục Server Certificates trong khung bên phải
  • Click Import… và trỏ tới file .pfx đã chuẩn bị, nhập password bảo vệ, nhớ tick chọn mục Allow export

Cấu hình website https

  • Vào giao diện quản trị IIS
  • Chọn website cần thiết lập https từ khung bên trái
  • Click Bindings… và thiết lập port 443 cho tên miền và certificate tương ứng (chọn từ list các certificate đã import vào server)

6.Zimbra

Tham khảo Cấu hình SSL certificate cho Zimbra

OpenSSL help

Xem thông tin certificate

openssl x509 -text -noout -in certificate.crt

Xem thông tin CSR

openssl req -text -noout -verify -in CSR.csr

Generate private key kèm theo CSR

openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key

Generate key kèm theo self-signed certificate

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

Generate CSR từ private đã có

openssl req -out CSR.csr -key privateKey.key -new

Bỏ mật khẩu của private key

openssl rsa -in privateKey.pem -out newPrivateKey.pem

Convert PKCS7 ⇒ PEM

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.crt

Convert PFX ⇒ PEM

openssl pkcs12 -in certificate.pfx -out certificate.crt -nodes

Kiểm tra hash MD5 của certificate, CSR hoặc private key

openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in privateKey.key | openssl md5
openssl req -noout -modulus -in CSR.csr | openssl md5

Lấy encode Base64 của pubkey

Dùng cho cấu hình HPKP Header (Public-Key-Pins)

Sử dụng một trong 4 lệnh sau, tùy thuộc thông tin input là pubkey, CSR, hay privatekey (ECC hoặc RSA)

openssl x509 -in my-certificate.crt -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
openssl req -in my-signing-request.csr -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
openssl ec -in my-ecc-key-file.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64
openssl rsa -in my-rsa-key-file.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64

Hoặc extract từ một web HTTPS đang hoạt động

openssl s_client -servername www.example.com -connect www.example.com:443 | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

Kiểm tra certificate qua kết nối HTTPS

openssl s_client -connect www.paypal.com:443

Leave a Reply

avatar
  Subscribe  
Notify of