Product SiteDocumentation Site

10.2. setifikat X.509

Sertifikat adalah blok bangunan penting dari banyak layanan jaringan yang dibangun di atas protokol kriptografi, ketika mereka membutuhkan semacam otentikasi pusat.
Di antara protokol-protokol tersebut, SSL (Secure Socket Layer) diciptakan oleh Netscape untuk mengamankan koneksi ke server-server web. Itu kemudian distandarkan oleh IETF dengan singkatan TLS (Transport Layer Security). Sejak itu TLS terus berkembang dan saat ini SSL usang karena beberapa cacat desain yang telah ditemukan.
Protokol TLS bertujuan terutama untuk memberikan privasi dan integritas data antara dua atau lebih aplikasi komputer yang berkomunikasi. Kasus yang paling umum di Internet adalah komunikasi antara klien (misalnya peramban web) dan server.
Sepasang kunci diperlukan untuk pertukaran informasi, yang melibatkan kunci publik yang mencakup informasi tentang identitas pemilik dan cocok dengan sebuah kunci privat. Kunci privat harus dirahasiakan, jika tidak, keamanannya akan terkompromi. Namun, siapa pun dapat mencipta suatu pasangan kunci, menyimpan sebarang identitas padanya, dan menyaru menjadi identitas pilihan mereka. Satu solusi melibatkan konsep Certification Authority (CA), diformalkan oleh standar X.509. Istilah ini mencakup suatu entitas yang menyimpan suatu pasangan kunci terpercaya yang dikenal sebagai sertifikat root. Sertifikat ini hanya dipakai untuk menandatangani sertifikat lain (pasangan kunci), setelah langkah-langkah yang tepat dilaksanakan untuk memeriksa identitas yang disimpan dalam pasangan kunci. Aplikasi-aplikasi yang memakai X.509 kemudian dapat memeriksa sertifikat yang disajikan ke mereka, bila mereka tahu tentang sertifikat root yang terpercaya.
Anda dapat mengimplementasikan CA (seperti yang dijelaskan di Bagian 10.2.2, “Infrastruktur Kunci Publik: easy-rsa), tetapi jika Anda berniat untuk menggunakan sertifikat untuk situs web, Anda harus mengandalkan CA tepercaya. Harga bervariasi secara signifikan, tetapi dimungkinkan untuk menerapkan keamanan yang baik dengan mengeluarkan sedikit uang atau gratis.

10.2.1. Membuat sertifikat tepercaya yang gratis

Banyak program membuat dan menggunakan sertifikat snakeoil secara baku (lihat bilah sisi KEAMANAN Sertifikat SSL Snake oil). Untungnya paket certbot membawa semua yang kita butuhkan untuk membuat sertifikat tepercaya kita sendiri, yang disediakan oleh inisiatif "Lets Encrypt" (lihat bilah sisi KULTUR Inisiatif Let's Encrypt), yang juga dapat digunakan untuk agen transpor surat (Postfix) dan agen pengiriman surat (Dovecot, Cyrus, dll.), dan layanan jaringan lain.
Administrator Falcot hanya ingin membuat sertifikat untuk situs web mereka, yang berjalan di Apache. Ada plugin Apache yang nyaman untuk certbot yang secara otomatis menyunting konfigurasi Apache untuk menyajikan sertifikat yang diperoleh, jadi mereka memanfaatkannya:
# apt install python3-certbot-apache
[...]
# certbot --apache
aving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@falcot.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:  N

Account registered.

No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): falcot.com

Requesting a certificate for falcot.com
Performing the following challenges:
http-01 challenge for falcot.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://falcot.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=falcot.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/falcot.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/falcot.com/privkey.pem
   Your cert will expire on 2022-06-04. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
Jika Anda lebih suka server tetap berjalan selama pembuatan sertifikat, Anda dapat menggunakan plugin webroot untuk mendapatkan sertifikat dengan argumen certonly dan --webroot. Anda harus menentukan --webroot-path (disingkat -w), yang harus berisi berkas yang disajikan. Perintahnya terlihat sebagai berikut:
# certbot certonly --webroot -w /var/www/html -d www.DOMAIN.com -d DOMAIN.com
Anda perlu memulai ulang semua layanan menggunakan sertifikat yang telah Anda buat.
Sertifikat yang dibuat disebut sertifikat umur pendek, yang berlaku selama 90 hari dan harus diperpanjang sekali setiap tiga bulan menggunakan perintah certbot renew. Namun, kita sebaiknya tidak memperbarui setiap sertifikat secara manual, tetapi secara otomatis. Pekerjaan cron dasar disertakan oleh certbot dalam /etc/cron.d/certbot. Untuk memastikan bahwa sertifikat dapat diperpanjang secara otomatis, Anda dapat mengeksekusi pembaruan certbot --dry-run.

10.2.2. Infrastruktur Kunci Publik: easy-rsa

Juga mungkin untuk membuat CA kita sendiri, untuk itu kita akan memakai algoritme RSA, yang banyak dipakai dalam kriptografi kunci publik. Ini melibatkan suatu "pasangan kunci", yang terdiri dari sebuah kunci privat dan publik. Kedua kunci terkait dekat satu sama lain, dan properti matematisnya sedemikian sehingga sebuah pesan yang dienkripsi dengan kunci publik hanya dapat didekripsi oleh seseorang yang mengetahui kunci privatnya, yang memastikan kerahasiaan. Pada arah yang berlawanan, sebuah pesan yang dienkripsi dengan kunci privatnya dapat didekripsi oleh siapapun yang mengetahui kunci publiknya, yang mengizinkan otentikasi asal-usul dari suatu pesan karena hanya seseorang yang punya akses ke kunci privat yang dapat membuatnya. Ketika dihubungkan dengan sebuah fungsi hash digital (MD5, SHA1, atau varian yang lebih terkini), ini mengarah ke suatu mekanisme tanda tangan yang dapat diterapkan ke sebarang pesan.
Karena CA publik hanya mengeluarkan sertifikat dengan biaya (yang mahal), juga dimungkinkan untuk membuat otoritas sertifikasi pribadi dalam perusahaan. Paket easy-rsa menyediakan alat untuk melayani sebagai infrastruktur sertifikasi X.509, diimplementasikan sebagai satu set skrip menggunakan perintah openssl .
Para admin Falcot Corp memakai perkakas ini untuk membuat sertifikat-sertifikat yang diperlukan, untuk server dan klien. Ini memungkinkan konfigurasi semua klien serupa karena mereka hanya perlu menyiapkan agar mempercayai sertifkat yang datang dari CA lokal Falcot. CA ini adalah sertifikat pertama yang dibuat; sampai titik ini, para administrator menyiapkan sebuah direktori dengan berkas-berkas yang diperlukan bagi CA dalam suatu lokasi yang sesuai, lebih disukai pada sebuah mesin yang tidak tersambung ke jaringan untuk memitigasi risiko kunci privat CA dicuri.
$ make-cadir pki-falcot
$ cd pki-falcot
Mereka kemudian menyimpan parameter-parameter yang diperlukan ke dalam berkas vars, yang dapat disunting:
$ grep EASYRSA vars
if [ -z "$EASYRSA_CALLER" ]; then
# easyrsa.  More specific variables for specific files (e.g., EASYRSA_SSL_CONF)
#set_var EASYRSA	"${0%/*}"
#set_var EASYRSA_OPENSSL	"openssl"
#set_var EASYRSA_OPENSSL	"C:/Program Files/OpenSSL-Win32/bin/openssl.exe"
#set_var EASYRSA_PKI		"$PWD/pki"
#set_var EASYRSA_TEMP_DIR	"$EASYRSA_PKI"
#set_var EASYRSA_DN	"cn_only"
set_var EASYRSA_REQ_COUNTRY	"FR"
set_var EASYRSA_REQ_PROVINCE	"Loire"
set_var EASYRSA_REQ_CITY	"Saint-Étienne"
set_var EASYRSA_REQ_ORG	"Falcot Corp"
set_var EASYRSA_REQ_EMAIL	"admin@falcot.com"
set_var EASYRSA_REQ_OU		"Certificate authority"
#set_var EASYRSA_KEY_SIZE	2048
#set_var EASYRSA_ALGO		rsa
#set_var EASYRSA_CURVE		secp384r1
#set_var EASYRSA_CA_EXPIRE	3650
#set_var EASYRSA_CERT_EXPIRE	825
#set_var EASYRSA_CRL_DAYS	180
#set_var EASYRSA_CERT_RENEW	30
#set_var EASYRSA_RAND_SN	"yes"
#set_var EASYRSA_NS_SUPPORT	"no"
#set_var EASYRSA_NS_COMMENT	"Easy-RSA Generated Certificate"
#set_var EASYRSA_TEMP_FILE	"$EASYRSA_PKI/extensions.temp"
# when undefined here, default behaviour is to look in $EASYRSA_PKI first, then
# fallback to $EASYRSA for the 'x509-types' dir.  You may override this
#set_var EASYRSA_EXT_DIR	"$EASYRSA/x509-types"
#set_var EASYRSA_KDC_REALM      "CHANGEME.EXAMPLE.COM"
# EASYRSA_PKI or EASYRSA dir (in that order.) NOTE that this file is Easy-RSA
#set_var EASYRSA_SSL_CONF	"$EASYRSA/openssl-easyrsa.cnf"
#set_var EASYRSA_REQ_CN		"ChangeMe"
#set_var EASYRSA_DIGEST		"sha256"
#set_var EASYRSA_BATCH		""
$ vim vars
$ 
Sekarang kita siapkan direktori infrastruktur kunci publik dengan perintah berikut:
$ ./easyrsa init-pki


init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /home/debian/pki-falcot/pki

Langkah berikutnya adalah penciptaan pasangan kunci CA (dua bagian dari pasangan kunci akan disimpan di bawah pki/ca.crt dan pki/private/ca.key selama langkah ini). Kita dapat menambahkan opsi nopass untuk menghindari memasukkan sandi setiap kali kunci pribadi digunakan:
$ ./easyrsa build-ca nopass

Using SSL: openssl OpenSSL 1.1.1k  25 Mar 2021
Generating RSA private key, 2048 bit long modulus (2 primes)
..................+++++
...............................+++++
e is 65537 (0x010001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:

CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/home/debian/pki-falcot/pki/ca.crt

Sertifikat sekarang dapat dibuat, maupun parameter Diffie-Hellman yang diperlukan untuk koneksi SSL/TLS sisi server. Mereka ingin memakainya bagi Server VPN (lihat bagian Bagian 10.3, “Virtual Private Network”) yang diidentifikasi oleh nama DNS vpn.falcot.com; nama ini digunakan kembali untuk berkas-berkas kunci yang dihasilkan (keys/vpn.falcot.com.crt bagi sertifikat publik, keys/vpn.falcot.com.key untuk kunci privat):
$ ./easyrsa gen-req vpn.falcot.com nopass

Using SSL: openssl OpenSSL 1.1.1k  25 Mar 2021
Generating a RSA private key
......................................+++++
..........................................................................+++++
writing new private key to '/home/debian/pki-falcot/pki/easy-rsa-5515.0PwyXl/tmp.g1c6u6'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Common Name (eg: your user, host, or server name) [vpn.falcot.com]:

Keypair and certificate request completed. Your files are:
req: /home/debian/pki-falcot/pki/reqs/vpn.falcot.com.req
key: /home/debian/pki-falcot/pki/private/vpn.falcot.com.key


$ ./easyrsa sign-req server vpn.falcot.com

Using SSL: openssl OpenSSL 1.1.1k  25 Mar 2021


You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.

Request subject, to be signed as a server certificate for 825 days:

subject=
    commonName                = vpn.falcot.com


Type the word 'yes' to continue, or any other input to abort.
  Confirm request details: yes
Using configuration from /home/debian/pki-falcot/pki/easy-rsa-5603.87iCIa/tmp.u8r8Fj
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'vpn.falcot.com'
Certificate is to be certified until May 27 15:26:29 2024 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

Certificate created at: /home/debian/pki-falcot/pki/issued/vpn.falcot.com.crt


$ ./easyrsa gen-dh

Using SSL: openssl OpenSSL 1.1.1k  25 Mar 2021
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
[…]

DH parameters of size 2048 created at /home/debian/pki-falcot/pki/dh.pem

Langkah berikut menciptakan sertifikat untuk klien VPN; satu sertifikat diperlukan untuk setiap komputer atau orang yang diizinkan untuk menggunakan VPN:
$ ./easyrsa build-client-full JoeSmith nopass

Using SSL: openssl OpenSSL 1.1.1k  25 Mar 2021
Generating a RSA private key
...................................+++++
.........................................................................................+++++
writing new private key to '/home/debian/pki-falcot/pki/easy-rsa-5694.DOYwSn/tmp.RKlbOE'
-----
Using configuration from /home/debian/pki-falcot/pki/easy-rsa-5694.DOYwSn/tmp.d5QHAC
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'JoeSmith'
Certificate is to be certified until May 27 15:29:25 2024 GMT (825 days)

Write out database with 1 new entries
Data Base Updated