Computer >> Hướng Dẫn Máy Tính >  >> Kết Nối Mạng >> An Ninh Mạng

Cách cài đặt chứng chỉ .p12 / PFX cho bảo mật mạng trên Chrome

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).

  1. Double-click file `.p12` / `.pfx` → Mở **Certificate Import Wizard**
  2. Store Location: **Current User** (chỉ user hiện tại) hoặc **Local Machine** (cần Admin, cho tất cả user)
  3. Next > File path: Đã điền > Next
  4. **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
  5. Certificate Store: **Automatically select** (hoặc chọn **Personal** > Next)
  6. Finish > "The import was successful"
  7. 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)

  1. Chrome > `chrome://settings/privacy` > Security > **Manage certificates**
  2. Tab **Personal** > **Import** > Wizard như Cách 1
  3. 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)

  1. Double-click `.p12` → Mở Keychain Access > Chọn **login** hoặc **System** keychain > Enter
  2. Nhập password file .p12 > Allow (Always Allow cho non-interactive)
  3. Tìm cert vừa import > Double-click > Trust > **When using this certificate: Always Trust**
  4. Import CA Root: Drag file `.cer` vào **System Roots** keychain > Always Trust
  5. Chrome/Edge/Safari trên macOS dùng System Keychain

Cách 5: Trên Android

  1. Settings > Security > Encryption & credentials > **Install a certificate** > **Wi-Fi certificate** (hoặc VPN & apps)
  2. Chọn file `.p12` / `.pfx` từ storage
  3. Nhập password file > Đặt tên cert > OK
  4. Dùng cho: WiFi 802.1X-EAP-TLS, VPN (StrongSwan, OpenVPN), App-specific

Cách 6: Trên iOS/iPadOS

  1. Gửi file `.p12` qua AirDrop / Email / MDM Profile
  2. Tap file > **Install** > Nhập passcode thiết bị > Nhập password .p12 > Install
  3. Settings > General > VPN & Device Management > Certificate Trust Settings > Bật trust cho cert
  4. 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:

  1. Chrome hiển thị "Not Secure" / "Your connection is not private" (NET::ERR_CERT_AUTHORITY_INVALID)
  2. Click **Not Secure** (góc trái address bar) > **Certificate is not valid** > **Certificate**
  3. Details > **Export** > Lưu `.cer` / `.pem`
  4. Import vào Trusted Root (Cách 1 hoặc 2) > Restart Chrome
  5. 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