做面包有哪些網站知乎快速優(yōu)化系統(tǒng)
Linux系統(tǒng)常用的加解密工具:OpenSSL,gpg(是pgp的實現(xiàn))
加密算法和協(xié)議:
? ? 對稱加密:加解密使用同一個秘鑰;
? ? ? ? DES:Data Encryption Standard,數(shù)據加密標準;? ==>? ? ? ? 3DES:
? ? ? ? AES:Advanced Encryption Standard(128、192、256、384、512)
? ? ? ? Blowfish、Twofish、IDEA、RC6、CAST
? ? 特性:
? ? ? ? 1、加密、解密使用同一個密鑰;
? ? ? ? 2、將原始數(shù)據分割成固定大小的塊,逐個進行加密;
? ? 缺陷:
? ? ? ? 1、秘鑰過多;2、密鑰分發(fā);
? ? 公鑰加密:密鑰是成對出現(xiàn)
? ? ? ? 公鑰:公開給所有人;pubkey
? ? ? ? 密鑰:自己留存,必須保證其私密性;secret key
? ? ? ? 特點:公鑰加密的數(shù)據,只能使用與之配對的私鑰解密;反之亦然;
? ? ? ? 數(shù)字簽名:讓接收方確認發(fā)送方身份,發(fā)送發(fā)用私鑰加密簽名,接收方用公鑰解密確認
????????秘鑰交換:發(fā)送方用對方公鑰加密對稱密鑰,發(fā)給對方
????????數(shù)據加密
? ? ? ? 算法:RSA、DSA、ELGamal
公鑰交換使用數(shù)字證書,需要PKI支持。
單向加密:只能加密,不能解密:提取數(shù)據指紋;
? ? 特性:定長輸出、雪崩效應;
? ? 算法:MD5(128bits)、sha1(160bits)、sha224、sha256、sha384、sha512
? ? 功能:完整性
密鑰交換:IKE
? ? 公鑰加密:
? ? DH(Deffie-Hellman):
PKI:Public Key Infrastructure,公鑰基礎設施
? ? 簽證機構:CA
? ? 注冊機構:RA
? ? 證書吊銷列表:CRL
? ? 證書存取庫:
? ??X.509:定義了證書的結構以及認證協(xié)議標準
? ? ? ? 版本號:
? ? ? ? 序列號:
? ? ? ? 簽名算法ID:
? ? ? ? 發(fā)行者名稱:
? ? ? ? 有效期限:
? ? ? ? 主體名稱:
? ? ? ? 主體公鑰:
? ? ? ? 發(fā)行者唯一標識:
? ? ? ? 主體的唯一標識:
? ? ? ? 擴展信息:
? ? ? ? 發(fā)行者簽名:
SSL:Secure Socket Layer
? ? 1995:SSL?2.0,Netscape
? ? 1996:SSL 3.0
? ? 1999:TLS 1.0,ISOC
? ? 2006:TLS 1.1 RFC 4346
? ? 2008:TLS 1.2
? ? 2015:TLS 1.3
SSL/TLS分層設計:
? ? 1、最底層:基礎算法原語的實現(xiàn),aes,rsa,md5
? ? 2、向上一層:各種算法的實現(xiàn)
? ? 3、再向上一層:組合算法實現(xiàn)的半成品
? ? 4、用各種組件拼裝而成的種種成品密碼學協(xié)議/軟件:tls,ssh
OpenSSL:開源項目
? ? 三個組件:
? ? ? ? openssl:多用途的命令行工具;
? ? ? ? libcrypto:公共加密庫;
? ? ? ? libssl:庫,實現(xiàn)了ssl及tls;
openssl命令:
? ? openssl version:程序版本號
openssl命令分類:標準命令、消息摘要命令、加密命令
標準命令:enc、ca、req
對稱加密:
? ? 工具:openssl enc,gpg
? ? 算法:3des,aes,blowfish,twofish
? ? enc命令:
? ? ? ? openssl enc -e -des3 -a -salt -in ./fstab -out fstab.ciphertext
? ? ? ? openssl enc -d -des3 -a -salt -in fstab.ciphertext -out fstab1
單向加密:
? ? 工具:md5sum,sha1sum,sha224sum,sha256sum,...,openssl dgst
? ? dgst命令:openssl dgst -md5 -hex /PATH/TO/SOMEFILE
? ? MAC:Message Authentication Code,單向加密的一種延伸應用,用于實現(xiàn)在網絡通信中保證所傳輸?shù)臄?shù)據的完整性;
? ? 機制:CBC-MAC、HMAC:使用md5或sha1算法
生成用戶密碼:
? ? openssl passwd -1 -salt 123456789
生成隨機數(shù):
? ? openssl rand -base64|-hex? num? ??
公鑰加密:
? ? 加密:
????????算法:RSA,ELGamal
? ? ? ? 工具:gpg,openssl rsautl
? ? 數(shù)字簽名:
? ? ? ? 算法:RSA,DSA,ELGamal
? ? 密鑰交換:
? ? ? ? 算法:dh
? ? 生成密鑰(私鑰):
? ? ? ? openssl genrsa -out /PATH/TO/PRIVATEKEY.FILE numbits
? ? 隨機數(shù)生成器:熵池,用于存儲隨機數(shù),隨機數(shù)是由隨機事件產生的,如敲擊鍵盤、磁盤I/o等,兩個偽設備,用于生成隨機數(shù)。在/dev下的random和urandom
? ? ? ? /dev/random:僅從熵池中返回隨機數(shù),隨機數(shù)用盡,阻塞
? ? ? ? /dev/urandom:從熵池中返回隨機數(shù),隨機數(shù)用盡,會利用軟件生成偽隨機數(shù),非阻塞為了保證生成的私鑰文件的安全,設置其讀寫權限:
? ??(umask 077;openssl genrsa -out key.pri 2048)
使用小括號,運行的命令在子shell中運行,不會對當前的shell環(huán)境造成影響。
可以對私鑰文件進行加密:
公鑰的生成,是從私鑰文件中提取的,需要私鑰文件:
? ? openssl rsa -in /PATH/FROM/PRIVATEKEY.FILE -pubout -out /PATH/TO/PUB.FILE
默認輸出到屏幕。輸出到文件使用-out選項,如果是加密的私鑰文件,需要輸入密碼
openssl實現(xiàn)私有CA:
? ? 1、生成一對密鑰
? ? 2、生成自簽署證書
? ? openssl genrsa -out /PATH/TO/KEYPRIVATE.FILE NUMBITS
? ? openssl rsa -in? /PATH/TO/KEYPRIVATE.FILE -pubout
生成自簽署證書和查看證書,用到req命令:
? ? openssl req -new -x509 -key server1024.key -out server.crt -days 365
? ? openssl x509 -text -in server.crt
實現(xiàn)私有CA,需要在特定目錄下,有特定配置文件:
? ? 在/etc/pki/tls目錄下,有openssl.cnf配置文件,對于自建CA,主要關注配置文件如下ca區(qū)域的配置和申請信息的配置[req]的配置:
####################################################################
[ ca ]
default_ca = CA_default # The default ca section####################################################################
[ CA_default ]dir = /etc/pki/CA # 相當于CA的根目錄,Where everything is kept
certs = $dir/certs # 簽發(fā)證書的保存目錄,Where the issued certs are kept
crl_dir = $dir/crl # 證書吊銷列表所在目錄,Where the issued crl are kept
database = $dir/index.txt # 簽發(fā)證書信息數(shù)據庫,database index file.
#unique_subject = no # Set to 'no' to allow creation of# several ctificates with same subject.
new_certs_dir = $dir/newcerts # 新生成的證書保存位置,default place for new certs.certificate = $dir/cacert.pem # CA自己的證書,The CA certificate
serial = $dir/serial # 保存下一個證書序列號,The current serial number
crlnumber = $dir/crlnumber # 下一個吊銷證書號碼,the current crl number# must be commented out to leave a V1 CRL
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/cakey.pem # CA自己的私鑰,The private key
RANDFILE = $dir/private/.rand # 隨機數(shù)文件,private random number filex509_extensions = usr_cert # The extentions to add to the cert# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt = ca_default # Subject Name options
cert_opt = ca_default # Certificate field options# Extension copying option: use with caution.
# copy_extensions = copy# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions = crl_extdefault_days = 365 # 默認證書有效期,how long to certify for
default_crl_days= 30 # 吊銷列表中保存時間,how long before next CRL
default_md = sha256 # 默認的加密算法,use SHA-256 by default
preserve = no # keep passed DN ordering# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy = policy_match####################################################################
[ req ]
default_bits = 2048
default_md = sha256
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret# This sets a mask for permitted string types. There are several options.
# default: PrintableString, T61String, BMPString.
# pkix : PrintableString, BMPString (PKIX recommendation before 2004)
# utf8only: only UTF8Strings (PKIX recommendation after 2004).
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
string_mask = utf8only# req_extensions = v3_req # The extensions to add to a certificate request[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = CN # 默認的國家代碼名字,原配置是XX,這里改為自己的
countryName_min = 2
countryName_max = 2stateOrProvinceName = State or Province Name (full name)
#stateOrProvinceName_default = ShanDong # 默認省名字Default Province,改為自己的localityName = Locality Name (eg, city)
localityName_default = JiNan # 默認城市(市縣)名字,Default City0.organizationName = Organization Name (eg, company)
0.organizationName_default = MyComp # 默認公司名字,Default Company Ltd# we can do this but it is not needed normally :-)
#1.organizationName = Second Organization Name (eg, company)
#1.organizationName_default = World Wide Web Pty LtdorganizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = Tech # 默認組織名稱commonName = Common Name (eg, your name or your server\'s hostname) # 通用名稱
commonName_max = 64emailAddress = Email Address
emailAddress_max = 64# SET-ex3 = SET extension number 3[ req_attributes ]
challengePassword = A challenge password
challengePassword_min = 4
challengePassword_max = 20unstructuredName = An optional company name
實操過程:
1、進入CA根目錄,生成CA的私鑰,按照上面的配置CA根目錄是/etc/pki/CA,CA自己的私鑰為/etc/pki/CA/private/cakey.pem
2、生成自簽證書:按照上面配置文件,CA自己的證書位置和名稱是/etc/pki/CA/cacert.pem。
3、創(chuàng)建目錄架構,主要是CA下要有certs、crl、newcerts子目錄,現(xiàn)在已經有了,就不需要創(chuàng)建。
4、創(chuàng)建證書索引文件index.txt和序列號文件serial,并要給serial一個起始號,因為沒有吊銷列表,吊銷列表號文件crlnumber不必創(chuàng)建。
5、至此,CA就搭建完成,可以簽發(fā)證書了
6、CA可以接收其他主機的證書簽發(fā)申請文件,簽發(fā)證書。這個證書簽發(fā)申請文件,是RA機構,即注冊機構主要工作的結果文件;
? ? 證書簽發(fā)申請文件的生成,可以在其他主機上生成:假設給http服務器生成證書
? ? 1)http證書的位置,一般是在/etc/httpd下,新建一個ssl子目錄
? ? ? ? 不同的服務,不同的證書,不同的密鑰,使用者先向RA申請生成密鑰。
? ? 2)生成證書簽發(fā)申請文件,生成這個文件的過程,就是輸入申請人信息的過程:
這個httpd.csr,就是一個待簽發(fā)的證書,所謂簽發(fā),就相當于CA用自己的印戳在這個文件上蓋上印,實際就是CA用自己的密鑰在這個文件上數(shù)字簽名。
? ? 3)這個httpd.csr發(fā)給CA,CA進行簽發(fā)
?查看CA的索引文件:
至此,私有CA創(chuàng)建完畢,并簽發(fā)了一個證書。在往后就是對證書的具體應用了。
????????