Linux九陰真經之九陰白骨爪殘卷1(加密和安全)
CA和證書
1、KPI :公共秘鑰體系
簽證機構:CA
註冊機構:RA
證書吊銷列表:CRL
證書存取庫
509:定義了證書的結構以及認證協議標準 版本號
序列號
簽名算法 主體公鑰
頒發者 CRL分發點
有效期限 擴展信息
主體名稱 發行者簽名
證書類型:
證書授權機構的證書
服務器
用戶證書
獲取證書兩種方法:
?使用證書授權機構
生成簽名請求(csr)
將csr發送給CA
從CA處接收簽名
?自簽名的證書
自已簽發自己的公鑰 安全協議
OpenSSL
三個組件:
openssl:加密模塊應用庫,實現了ssl及tls,包nss
libcrypto:加密算法庫,包openssl-libs
libssl:加密模塊應用庫,實現了ssl及tls,包nss
openssl命令
兩種運行模式:交互模式和批處理模式
標準命令:
enc, ca, req, ...
對稱加密
工具:oopenssl enc,
算法:3des, aes, blowfish, twofish
enc命令
幫助:man enc
加密: openssl enc -e -des3 -a -salt -in testfile -out testfile.cipher
enc(對稱加密)
-des3 (加密算法)
-a(以base64編碼,用可見字符表示,方便查看)
解密: openssl enc -d(解密) -des3 -a -salt -in testfile.cipher -out testfile
單向加密:
工具:md5sum, sha1sum, sha224sum,sha256sum…
openssl dgst
生成用戶密碼
passwd命令:
幫助:man sslpasswd
openssl passwd -1(以md5加密) -salt (加鹽,雜質,不容易破解)
生成隨機數
openssl rand -base64 | -hex NUM
NUM: 表示字節數;-hex時,每個字符為16進制,相當於4位二進制,出現的字符數為NUM*2
openssl rand -base64 9 (3的倍數 就不用添加=號) ,生成隨機數,適合當口令 openssl rand -base 64 12 | tr -dc ‘[:alnum:]‘ 生成一個12位隨機密碼,並且只留下數字和字母生成密鑰對兒
生成私鑰 (umask 066;openssl genrsa -out private.key 1024)
私鑰加密 (umask 066;openssl genrsa -out private.key -des 1024)
生成公鑰 (openssl rsa -in private.key -pubout -out public.key)將加密key解密 從私鑰中提取出公鑰
openssl rsa -in PRIVATEKEYFILE -pubout -out PUBLICKEYFILE
openssl rsa -in test.key -pubout -out test.key.pub
創建CA和申請證書
一、創建CA
1、ROOT CA 自己創建CA
生成私鑰
自簽名證書
二、用戶或服務器
1、生成私鑰
2、生成證書申請文件
3、將申請文件發給CA
三、CA頒發證書
證書簽名
四、證書發送給客戶端
五、應用軟件使用證書
例:向CA申請證書
1、建立Root CA ,生成私鑰
[root@laobai ~#cd /etc/pki/CA [root@laobai /etc/pki/CA#(umask 077;openssl genrsa -out private/cakey.pem 4096) Generating RSA private key, 4096 bit long modulus ...........++ .................................................................................................................++ e is 65537 (0x10001)
2、自簽名證書
[root@laobai /etc/pki/CA#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 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. -----
3、用戶服務器
(1)生成私鑰
[root@laobai /etc/pki/CA#(umask 077;openssl genrsa -out app.key 1024) Generating RSA private key, 1024 bit long modulus .......++++++ .................................................................................++++++ e is 65537 (0x10001)
(2)生成證書申請文件
[root@laobai /etc/pki/CA#openssl req -new -key app.key -out app.csr Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:beijing Locality Name (eg, city) [Default City]:beijing Organization Name (eg, company) [Default Company Ltd]:magedu Organizational Unit Name (eg, section) []:m30 Common Name (eg, your name or your server‘s hostname) []:www.magedu.com Email Address []: Please enter the following ‘extra‘ attributes to be sent with your certificate request A challenge password []: An optional company name []:
(3)將申請文件發給CA
[root@laobai /etc/pki/CA#sz certs/app.crt
此時在windows上的app.crt文件的後綴名改為cer,即可打開 證書
4、CA頒發證書
(1)
[root@laobai /etc/pki/CA#touch index.txt
(2)
[root@laobai /etc/pki/CA#echo 0F > serial
(3)
[root@laobai /etc/pki/CA#openssl ca -in app.csr -out certs/app.crt -days 100 Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok
Linux九陰真經之九陰白骨爪殘卷1(加密和安全)