Cài đặt Client Certificate (.p12 / .pfx) trên Chrome / Windows / macOS
File `.p12` hoặc `.pfx` (PKCS#12) chứa **Private Key + Certificate + CA Chain** - dùng cho **Client Authentication (mTLS)**, VPN, WiFi 802.1X-EAP-TLS, Smart Card, Document Signing.
Cách 1: Cài đặt trực tiếp vào Windows Certificate Store (Khuyên dùng cho Chrome/Edge/IE)
Chrome/Edge trên Windows dùng **Windows Certificate Store** (System/Current User).
- Double-click file `.p12` / `.pfx` → Mở **Certificate Import Wizard**
- Store Location: **Current User** (chỉ user hiện tại) hoặc **Local Machine** (cần Admin, cho tất cả user)
- Next > File path: Đã điền > Next
- **Password:** Nhập mật khẩu bảo vệ file .p12 (do cấp cert cung cấp) > **Mark key as exportable** (nếu cần backup sau) > **Include all extended properties** > Next
- Certificate Store: **Automatically select** (hoặc chọn **Personal** > Next)
- Finish > "The import was successful"
- QUAN TRỌNG: Nếu CA không có trong Trusted Root > Cần import CA cert riêng:
- Double-click CA cert (.cer/.crt) > Current User > Place in: **Trusted Root Certification Authorities**
Cách 2: Quản lý qua Chrome Settings (Chỉ xem/import Personal store)
- Chrome > `chrome://settings/privacy` > Security > **Manage certificates**
- Tab **Personal** > **Import** > Wizard như Cách 1
- Tab **Trusted Root Certification Authorities** > Import CA cert nếu cần
Cách 3: PowerShell (Automation / Script)
$pfxPath = "C:\path\to\cert.p12"
$pwd = "mat_khau_pfx" | ConvertTo-SecureString -AsPlainText -Force
Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation Cert:\CurrentUser\My -Password $pwd -Exportable
# Import CA Root
$caPath = "C:\path\to\ca.cer"
Import-Certificate -FilePath $caPath -CertStoreLocation Cert:\CurrentUser\Root
Cách 4: Trên macOS (Keychain Access)
- Double-click `.p12` → Mở Keychain Access > Chọn **login** hoặc **System** keychain > Enter
- Nhập password file .p12 > Allow (Always Allow cho non-interactive)
- Tìm cert vừa import > Double-click > Trust > **When using this certificate: Always Trust**
- Import CA Root: Drag file `.cer` vào **System Roots** keychain > Always Trust
- Chrome/Edge/Safari trên macOS dùng System Keychain
Cách 5: Trên Android
- Settings > Security > Encryption & credentials > **Install a certificate** > **Wi-Fi certificate** (hoặc VPN & apps)
- Chọn file `.p12` / `.pfx` từ storage
- Nhập password file > Đặt tên cert > OK
- Dùng cho: WiFi 802.1X-EAP-TLS, VPN (StrongSwan, OpenVPN), App-specific
Cách 6: Trên iOS/iPadOS
- Gửi file `.p12` qua AirDrop / Email / MDM Profile
- Tap file > **Install** > Nhập passcode thiết bị > Nhập password .p12 > Install
- Settings > General > VPN & Device Management > Certificate Trust Settings > Bật trust cho cert
- Hoặc: Cài **Configuration Profile (.mobileconfig)** chứa cert + payload WiFi/VPN (MDM/Intune)
Chấp nhận Certificate cảnh báo trên Website (Server Cert - KHÔNG phải Client Cert)
Nếu truy cập site tự ký (self-signed) hoặc private CA:
- Chrome hiển thị "Not Secure" / "Your connection is not private" (NET::ERR_CERT_AUTHORITY_INVALID)
- Click **Not Secure** (góc trái address bar) > **Certificate is not valid** > **Certificate**
- Details > **Export** > Lưu `.cer` / `.pem`
- Import vào Trusted Root (Cách 1 hoặc 2) > Restart Chrome
- HOẶC: Chrome shortcut thêm flag: `--ignore-certificate-errors` (**CHỈ DEV/TEST, KHÔNG PROD**)
Bypass Chrome Certificate Error (Chỉ Dev/Test)
# Windows
Win+R > chrome.exe --ignore-certificate-errors --user-data-dir="C:\temp\chrome-dev"
# macOS
open -a "Google Chrome" --args --ignore-certificate-errors --user-data-dir="/tmp/chrome-dev"
# Linux
google-chrome --ignore-certificate-errors --user-data-dir="/tmp/chrome-dev"
Khôi phục Certificate trên Chrome
- Chrome > `chrome://flags/#show-cert-link` > **Enabled** > Relaunch
- Address bar > 🔒 > Certificate > Details > Export
Tại sao Chrome hỏi Client Certificate?
- Server cấu hình **mTLS (Mutual TLS)** - yêu cầu client trình bày cert
- Chrome hỏi OS: "User có cert nào match CA list của server không?"
- Android: OS quản lý cert store, Chrome không thể can thiệp. User phải chọn cert trong dialog hệ thống
- Enterprise: Deploy cert via MDM/Intune/SCEP để tự động, không user interaction
Client Certificate dùng làm gì?
- mTLS Authentication: Service-to-service (Zero Trust, Service Mesh: Istio, Linkerd), API Gateway
- VPN (IPsec/IKEv2, OpenVPN): Cert-based auth thay password
- WiFi 802.1X EAP-TLS: Mạnh nhất, không pass, dùng cert + private key
- Smart Card / PIV / CAC: Hardware token (YubiKey, Feitian, HID) lưu private key không export được
- Document Signing / Code Signing: Adobe Approved Trust List (AATL), Microsoft Trusted Root
Lưu ý bảo mật .p12/.pfx
- Chứa **Private Key** - ai có file + pass = thành bạn. **Bảo mật tuyệt đối**
- Không commit lên Git, không gửi email không mã hóa, không lưu cloud public
- Dùng Hardware Token (YubiKey, Nitrokey, TPM) lưu private key - **Không thể export**
- Rotate cert định kỳ (90-365 ngày), Revoke ngay khi compromise