Create SSL Certificate¶
Overview¶
SSL/TLS Certificate digunakan untuk mengenkripsi komunikasi antara Client dan Server menggunakan protokol HTTPS.
Pada environment development, lab, maupun internal infrastructure, SSL/TLS Certificate dapat dibuat menggunakan OpenSSL.
Dokumen ini menggunakan pendekatan Private Certificate Authority (CA) untuk menerbitkan Server Certificate.
Prerequisites¶
Pastikan OpenSSL tersedia.
Contoh:
SSL/TLS Components¶
Dalam konfigurasi ini terdapat beberapa komponen:
| Component | Description |
|---|---|
ca.key |
Private Key Certificate Authority |
ca.crt |
Certificate Authority Certificate |
server.key |
Server Private Key |
server.csr |
Certificate Signing Request |
server.crt |
Server SSL/TLS Certificate |
server.ext |
Certificate Extension Configuration |
Certificate Architecture¶
Certificate Authority
β
βββββββββββ΄ββββββββββ
β β
ca.key ca.crt
Private Key CA Certificate
β β
β β
βββββββββββ¬ββββββββββ
β
β Sign
βΌ
Server Certificate
β
βββββββββββ΄ββββββββββ
β β
server.key server.crt
Private Key Server Certificate
Create SSL Directory¶
Buat directory untuk menyimpan CA dan Server Certificate.
Struktur directory:
Certificate Authority¶
Generate CA Private Key¶
Generate Private Key untuk Certificate Authority.
Verify:
Expected:
Protect CA Private Key¶
CA Private Key harus dilindungi.
Verify:
Expected:
Generate CA Certificate¶
Buat Certificate Authority Certificate:
openssl req \
-x509 \
-new \
-nodes \
-key ~/ssl/ca/ca.key \
-sha256 \
-days 3650 \
-out ~/ssl/ca/ca.crt \
-subj "/C=ID/O=Internal CA/CN=Internal Root CA"
Certificate berlaku selama:
atau sekitar 10 tahun.
Verify CA Certificate¶
Contoh:
subject=C = ID, O = Internal CA, CN = Internal Root CA
issuer=C = ID, O = Internal CA, CN = Internal Root CA
Karena ini merupakan Root CA:
CA Files¶
Setelah CA dibuat:
| File | Description |
|---|---|
ca.key |
CA Private Key |
ca.crt |
CA Certificate |
CA Security¶
ca.key merupakan Private Key Certificate Authority.
File tersebut sangat sensitif.
Tidak boleh:
- Dibagikan ke client.
- Disimpan pada web server.
- Dimasukkan ke repository Git.
- Dikirim melalui email.
- Diberikan kepada user yang tidak membutuhkan akses.
Apabila ca.key compromised, attacker dapat menerbitkan certificate baru yang dipercaya oleh seluruh client yang mempercayai CA tersebut.
Server Certificate¶
Generate Server Private Key¶
Generate Private Key untuk server.
Verify:
Protect Server Private Key¶
Verify:
Expected:
Create Certificate Extension File¶
Certificate modern membutuhkan Subject Alternative Name (SAN).
Buat file:
Isi:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage=digitalSignature,keyEncipherment
extendedKeyUsage=serverAuth
subjectAltName=@alt_names
[alt_names]
DNS.1=edkas-pc1
DNS.2=localhost
IP.1=127.0.0.1
Subject Alternative Name¶
SAN menentukan hostname dan IP Address yang valid untuk certificate.
Pada contoh di atas:
Certificate valid apabila server diakses menggunakan:
atau:
atau:
Certificate Extension¶
Penjelasan parameter:
| Parameter | Purpose |
|---|---|
basicConstraints=CA:FALSE |
Certificate bukan Certificate Authority |
keyUsage=digitalSignature,keyEncipherment |
Key digunakan untuk TLS |
extendedKeyUsage=serverAuth |
Certificate digunakan untuk Server Authentication |
subjectAltName |
Menentukan hostname/IP yang valid |
Generate Certificate Signing Request¶
Generate Certificate Signing Request (CSR):
openssl req \
-new \
-key ~/ssl/server/server.key \
-out ~/ssl/server/server.csr \
-subj "/C=ID/O=Internal/CN=edkas-pc1"
Verify CSR¶
Expected:
Sign Server Certificate¶
Sign CSR menggunakan Certificate Authority:
openssl x509 \
-req \
-in ~/ssl/server/server.csr \
-CA ~/ssl/ca/ca.crt \
-CAkey ~/ssl/ca/ca.key \
-CAcreateserial \
-out ~/ssl/server/server.crt \
-days 825 \
-sha256 \
-extfile ~/ssl/server/server.ext
Certificate berlaku selama:
Server Certificate Files¶
Setelah certificate berhasil dibuat:
Verify Server Certificate¶
openssl x509 \
-in ~/ssl/server/server.crt \
-noout \
-subject \
-issuer \
-dates \
-ext subjectAltName
Contoh:
subject=C = ID, O = Internal, CN = edkas-pc1
issuer=C = ID, O = Internal CA, CN = Internal Root CA
X509v3 Subject Alternative Name:
DNS:edkas-pc1
DNS:localhost
IP Address:127.0.0.1
Verify Certificate Chain¶
Verify Server Certificate menggunakan CA:
Expected:
Certificate Trust¶
Install CA Certificate on Client¶
Agar browser atau client mempercayai Server Certificate, client harus mempercayai:
Contoh:
CA Certificate Distribution¶
ca.crt dapat didistribusikan kepada client yang membutuhkan akses ke internal HTTPS service.
Contoh:
Jangan distribusikan:
Certificate Verification¶
Verify Certificate Subject¶
Verify Certificate Issuer¶
Expected:
Verify Certificate Validity¶
Example:
Verify SAN¶
Expected:
Verify Certificate Chain¶
Expected:
Verify Certificate From Running HTTPS Service¶
Apabila certificate telah digunakan oleh HTTPS service, certificate yang benar-benar disajikan oleh service dapat diperiksa menggunakan:
openssl s_client \
-connect edkas-pc1:8787 \
-servername edkas-pc1 \
</dev/null 2>/dev/null |
openssl x509 \
-noout \
-subject \
-issuer \
-dates \
-ext subjectAltName
Command ini berguna untuk memastikan certificate yang digunakan oleh service sesuai dengan certificate yang telah dibuat.
Common SSL/TLS Problems¶
Certificate Does Not Match Hostname¶
Misalnya certificate hanya memiliki:
tetapi service diakses menggunakan:
Certificate tidak valid untuk hostname tersebut.
Tambahkan hostname ke SAN:
Kemudian generate ulang certificate.
Certificate Authority Is Not Trusted¶
Error yang dapat muncul:
atau:
Pastikan client mempercayai:
Certificate Expired¶
Periksa:
Jika notAfter sudah melewati waktu saat ini, certificate harus diperbarui.
Wrong Certificate Is Being Served¶
Periksa certificate dari service:
openssl s_client \
-connect edkas-pc1:8787 \
-servername edkas-pc1 \
</dev/null 2>/dev/null |
openssl x509 \
-noout \
-subject \
-issuer \
-dates
Bandingkan dengan:
Security Consideration¶
Private Key¶
Private Key harus dilindungi.
Server:
Certificate Authority:
Permission:
Never Commit Private Keys¶
Jangan memasukkan private key ke Git repository.
Contoh .gitignore:
Certificate Authority Private Key¶
ca.key memiliki risiko paling tinggi.
Jika CA Private Key compromised, attacker dapat membuat certificate baru yang dipercaya oleh client yang mempercayai CA tersebut.
Oleh karena itu:
sebaiknya hanya tersedia pada sistem yang bertugas melakukan certificate signing.
Certificate Directory Structure¶
Contoh struktur final:
~/ssl/
β
βββ ca/
β βββ ca.key
β βββ ca.crt
β βββ ca.srl
β
βββ server/
βββ server.key
βββ server.csr
βββ server.crt
βββ server.ext
Certificate Lifecycle¶
Generate CA Private Key
β
βΌ
Generate CA Certificate
β
βΌ
Generate Server Private Key
β
βΌ
Create SAN Configuration
β
βΌ
Generate CSR
β
βΌ
Sign CSR with CA
β
βΌ
Generate Server Certificate
β
βΌ
Verify Certificate
β
βΌ
Install CA Certificate on Client
β
βΌ
Configure HTTPS Service
β
βΌ
Verify HTTPS