Apa itu Let’s Encrypt:
Let’s Encrypt adalah certificate authority yang didirikan pada 12 April 2016 yang menyediakan sertifikat X.509 gratis untuk Transport Layer Security (TLS) enkripsi melalui proses otomatisasi dan dirancang untuk menghilangkan proses yang kompleks saat melakukan pembuatan, validasi , penandatanganan, instalasi, dan pembaharuan sertifikat untuk situs web yang aman.

Prinsip utama dibalik didirikannya Let’s Encrypt adalah:
Gratis: Semua orang yang memiliki domain sendiri bisa menggunakan Let’s Encrypt untuk mendapatkan sertifikat yang terpercaya tanpa biaya.
Otomatis: Client software didalam web server bisa berinteraksi dengan Let’s Encrypt server untuk mendapatkan sertifikat dengan mudah, bisa di konfigurasikan dengan aman, dan secara otomatis memperbaharui sertifikat jika sudah hampir habis masa berlakunya.
Aman: Let’s Encrypt akan berfungsi sebagai platfom untuk TLS tingkat lanjut terbaik untuk Certificate Authority dengan membantu pengguna mengamankan server mereka.
Transparan: Semua sertifikat yang diterbitkan atau dicabut akan disimpan untuk umum dan tersedia bagi siapa saja untuk memeriksanya.
Terbuka: Penerbitan dan pembaharuan protokol otomatis akan dipublikasikan sebagai standar terbuka sehingga bisa di adopsi untuk keperluan lain.
Hasil kerjasama: Seperti yang mendasari protokol Internet itu sendiri, Let’s Encrypt adalah hasil kerjasama untuk kepentingan komunitas, Tanpa dikontrol oleh organisasi manapun juga.

Seperti sertifikat pada umumnya Let’s Encrypt dapat di install di hampir semua Operating system dan Platfom seperti Windows, Linux, BSD, dan lain sebagainya.
Untuk web server software kita bisa menggunakan apache atau nginx.
Dalam kali ini saya akan mencoba membuat sertifikat Let’s Encrypt dengan menggunakan nginx sebagai web server dengan OS freebsd 11 release.
Untuk mendapatkan dan membuat sertifikat Let’s Encrypt sudah banyak client software yang dibuat pengembang untuk list let’s encrypt clients bisa di lihat disini https://community.letsencrypt.org/t/list-of-client-implementations/2103

Saya mencoba salah satu dari pilihan di list tersebut yang mana ketentuannya adalah saya ingin yang simple, tidak banyak dependensi, support remote update (untuk web yang berbeda server).
Untuk itu saya pilih GetSSL https://github.com/srvrco/getssl.
Pastikan web server sudah berjalan dengan baik melalui protokol HTTP sebelum kita migrasikan ke protokol HTTPS.

Download software client GetSSL:

[[email protected]]# mkdir -p /root/bin
[[email protected]]# cd /root/bin
[[email protected]]# curl --silent https://raw.githubusercontent.com/srvrco/getssl/master/getssl > getssl ; chmod 700 getssl

Check getssl versi:

[[email protected]]# ./getssl -h
getssl ver. 1.83
Obtain SSL certificates from the letsencrypt.org ACME server

Usage: getssl [-h|--help] [-d|--debug] [-c|--create] [-f|--force] [-a|--all] [-q|--quiet] [-Q|--mute] [-u|--upgrade] [-U|--nocheck] [-r|--revoke cert key] [-w working_dir] domain

Options:
  -a, --all       Check all certificates
  -d, --debug     Outputs debug information
  -c, --create    Create default config files
  -f, --force     Force renewal of cert (overrides expiry checks)
  -h, --help      Display this help message and exit
  -q, --quiet     Quiet mode (only outputs on error, success of new cert, or getssl was upgraded)
  -Q, --mute      Like -q, but mutes notification about successful upgrade
  -r, --revoke cert key  [CA_server] Revoke a certificate (the cert and key are required)
  -u, --upgrade   Upgrade getssl if a more recent version is available
  -U, --nocheck   Do not check if a more recent version is available
  -w working_dir  Working directory

Buat konfigurasi standart sebagai dasar pembuatan sertifikat:

[[email protected]]# ./getssl -c agusprasetia.com

Maka akan terbentuk file ~/.getssl/agusprasetia.com/getssl.cfg, dan kita bisa mulai mengedit file ini sesuai keinginan kita.

PERINGATAN: Saat masih coba-coba setting pastikan pilih staging server yaitu CA=”https://acme-staging.api.letsencrypt.org” karena untuk trusted server CA=”https://acme-v01.api.letsencrypt.org” ada Rate Limit untuk melakukan transaksi create, validasi, dan update jika lebih dari 10 kali dalam 3 jam maka account kita akan di blokir sementara.

Dan ini default file yang sudah saya edit:

# Uncomment and modify any variables you need
# see https://github.com/srvrco/getssl/wiki/Config-variables for details
#
# The staging server is best for testing
#CA="https://acme-staging.api.letsencrypt.org"
# This server issues full certificates, however has rate limits
CA="https://acme-v01.api.letsencrypt.org"

AGREEMENT="https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf"

# Set an email address associated with your account - generally set at account level rather than domain.
ACCOUNT_EMAIL="[email protected]"
ACCOUNT_KEY_LENGTH=4096
ACCOUNT_KEY="/root/.getssl/agusprasetia_account.key"
PRIVATE_KEY_ALG="rsa"

# Additional domains - this could be multiple domains / subdomains in a comma separated list
# Note: this is Additional domains - so should not include the primary domain.
SANS=www.agusprasetia.com

# Acme Challenge Location. The first line for the domain, the following ones for each additional domain.
# If these start with ssh: then the next variable is assumed to be the hostname and the rest the location.
# An ssh key will be needed to provide you with access to the remote server.
# Optionally, you can specify a different userid for ssh/scp to use on the remote server before the @ sign.
# If left blank, the username on the local server will be used to authenticate against the remote server.
# If these start with ftp: then the next variables are ftpuserid:ftppassword:servername:ACL_location
# These should be of the form "/path/to/your/website/folder/.well-known/acme-challenge"
# where "/path/to/your/website/folder/" is the path, on your web server, to the web root for your domain.
ACL=('/usr/local/www/nginx-dist/agusprasetia/.well-known/acme-challenge' '/usr/local/www/nginx-dist/agusprasetia/.well-known/acme-challenge')
#     'ssh:server5:/var/www/agusprasetia.com/web/.well-known/acme-challenge'
#     'ssh:[email protected]:/var/www/agusprasetia.com/web/.well-known/acme-challenge'
#     'ftp:ftpuserid:ftppassword:agusprasetia.com:/web/.well-known/acme-challenge')

#Enable use of a single ACL for all checks
#USE_SINGLE_ACL="true"

# Location for all your certs, these can either be on the server (full path name)
# or using ssh /sftp as for the ACL
DOMAIN_CERT_LOCATION="/etc/ssl/agusprasetia.com/agusprasetia.com.crt"
DOMAIN_KEY_LOCATION="/etc/ssl/agusprasetia.com/agusprasetia.com.key"
CA_CERT_LOCATION="/etc/ssl/agusprasetia.com/chain.crt"
DOMAIN_CHAIN_LOCATION="/etc/ssl/agusprasetia.com/domain_chain.pem" # this is the domain cert and CA cert
DOMAIN_KEY_CERT_LOCATION="" # this is the domain_key and domain cert
DOMAIN_PEM_LOCATION="" # this is the domain_key. domain cert and CA cert

# The command needed to reload apache / nginx or whatever you use
RELOAD_CMD="service nginx restart"
# The time period within which you want to allow renewal of a certificate
# this prevents hitting some of the rate limits.
RENEW_ALLOW="30"

# Define the server type. This can be https, ftp, ftpi, imap, imaps, pop3, pop3s, smtp,
# smtps_deprecated, smtps, smtp_submission, xmpp, xmpps, ldaps or a port number which
# will be checked for certificate expiry and also will be checked after
# an update to confirm correct certificate is running (if CHECK_REMOTE) is set to true
SERVER_TYPE="https"
CHECK_REMOTE="true"

# Use the following 3 variables if you want to validate via DNS
VALIDATE_VIA_DNS="false"
#DNS_ADD_COMMAND=
#DNS_DEL_COMMAND=
#AUTH_DNS_SERVER=""
#DNS_WAIT=10
#DNS_EXTRA_WAIT=60

Proses pembuatan sertifikat:

[[email protected]]# ./getssl -d agusprasetia.com

Jika perintah diatas sukses maka akan ada file dalam folder /etc/ssl/agusprasetia.com/

[[email protected]]# ls /etc/ssl/agusprasetia.com/
            agusprasetia.com.crt    agusprasetia.com.key    chain.crt         domain_chain.pem

Buat 2048 bit Diffie-Hellman parameter:

[[email protected]]# mkdir -p /etc/ssl/DH
[[email protected]]# openssl dhparam -out /etc/ssl/DH/dhparam2048.pem 2048

Setting nginx web server untuk migrasi domain http ke mode https:

[[email protected]]# nano /usr/local/etc/nginx/vhosts/aghe-https.conf
server {
        listen       443;
        server_name  agusprasetia.com;
        server_name  www.agusprasetia.com;
        root /usr/local/www/nginx/agusprasetia;
        index index.php index.html index.htm;

        # SSL Certificate for https
        ssl on;
        ssl_certificate /etc/ssl/agusprasetia.com/domain_chain.pem;
        ssl_certificate_key /etc/ssl/agusprasetia.com/agusprasetia.com.key;

        # Hardening SSL
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/ssl/DH/dhparam2048.pem;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES1

Restart nginx server:
[[email protected]]# service nginx restart

Crontab update sertifikat secara berkala:

23  5 * * * /root/bin/getssl -u -q agusprasetia.com

;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
try_files $uri $uri/ /index.php?$args ;

root /usr/local/www/nginx;

index index.html index.htm;

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}
}

Restart nginx server:


Crontab update sertifikat secara berkala:



Leave a Reply

Your email address will not be published. Required fields are marked *