做面包有哪些網(wǎng)站知乎快速優(yōu)化系統(tǒng)
Linux系統(tǒng)常用的加解密工具:OpenSSL,gpg(是pgp的實(shí)現(xiàn))
加密算法和協(xié)議:
? ? 對(duì)稱加密:加解密使用同一個(gè)秘鑰;
? ? ? ? DES:Data Encryption Standard,數(shù)據(jù)加密標(biāo)準(zhǔn);? ==>? ? ? ? 3DES:
? ? ? ? AES:Advanced Encryption Standard(128、192、256、384、512)
? ? ? ? Blowfish、Twofish、IDEA、RC6、CAST
? ? 特性:
? ? ? ? 1、加密、解密使用同一個(gè)密鑰;
? ? ? ? 2、將原始數(shù)據(jù)分割成固定大小的塊,逐個(gè)進(jìn)行加密;
? ? 缺陷:
? ? ? ? 1、秘鑰過(guò)多;2、密鑰分發(fā);
? ? 公鑰加密:密鑰是成對(duì)出現(xiàn)
? ? ? ? 公鑰:公開(kāi)給所有人;pubkey
? ? ? ? 密鑰:自己留存,必須保證其私密性;secret key
? ? ? ? 特點(diǎn):公鑰加密的數(shù)據(jù),只能使用與之配對(duì)的私鑰解密;反之亦然;
? ? ? ? 數(shù)字簽名:讓接收方確認(rèn)發(fā)送方身份,發(fā)送發(fā)用私鑰加密簽名,接收方用公鑰解密確認(rèn)
????????秘鑰交換:發(fā)送方用對(duì)方公鑰加密對(duì)稱密鑰,發(fā)給對(duì)方
????????數(shù)據(jù)加密
? ? ? ? 算法:RSA、DSA、ELGamal
公鑰交換使用數(shù)字證書(shū),需要PKI支持。
單向加密:只能加密,不能解密:提取數(shù)據(jù)指紋;
? ? 特性:定長(zhǎng)輸出、雪崩效應(yīng);
? ? 算法:MD5(128bits)、sha1(160bits)、sha224、sha256、sha384、sha512
? ? 功能:完整性
密鑰交換:IKE
? ? 公鑰加密:
? ? DH(Deffie-Hellman):
PKI:Public Key Infrastructure,公鑰基礎(chǔ)設(shè)施
? ? 簽證機(jī)構(gòu):CA
? ? 注冊(cè)機(jī)構(gòu):RA
? ? 證書(shū)吊銷列表:CRL
? ? 證書(shū)存取庫(kù):
? ??X.509:定義了證書(shū)的結(jié)構(gòu)以及認(rèn)證協(xié)議標(biāo)準(zhǔn)
? ? ? ? 版本號(hào):
? ? ? ? 序列號(hào):
? ? ? ? 簽名算法ID:
? ? ? ? 發(fā)行者名稱:
? ? ? ? 有效期限:
? ? ? ? 主體名稱:
? ? ? ? 主體公鑰:
? ? ? ? 發(fā)行者唯一標(biāo)識(shí):
? ? ? ? 主體的唯一標(biāo)識(shí):
? ? ? ? 擴(kuò)展信息:
? ? ? ? 發(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分層設(shè)計(jì):
? ? 1、最底層:基礎(chǔ)算法原語(yǔ)的實(shí)現(xiàn),aes,rsa,md5
? ? 2、向上一層:各種算法的實(shí)現(xiàn)
? ? 3、再向上一層:組合算法實(shí)現(xiàn)的半成品
? ? 4、用各種組件拼裝而成的種種成品密碼學(xué)協(xié)議/軟件:tls,ssh
OpenSSL:開(kāi)源項(xiàng)目
? ? 三個(gè)組件:
? ? ? ? openssl:多用途的命令行工具;
? ? ? ? libcrypto:公共加密庫(kù);
? ? ? ? libssl:庫(kù),實(shí)現(xiàn)了ssl及tls;
openssl命令:
? ? openssl version:程序版本號(hào)
openssl命令分類:標(biāo)準(zhǔn)命令、消息摘要命令、加密命令
標(biāo)準(zhǔn)命令:enc、ca、req
對(duì)稱加密:
? ? 工具: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,單向加密的一種延伸應(yīng)用,用于實(shí)現(xiàn)在網(wǎng)絡(luò)通信中保證所傳輸?shù)臄?shù)據(jù)的完整性;
? ? 機(jī)制:CBC-MAC、HMAC:使用md5或sha1算法
生成用戶密碼:
? ? openssl passwd -1 -salt 123456789
生成隨機(jī)數(shù):
? ? openssl rand -base64|-hex? num? ??
公鑰加密:
? ? 加密:
????????算法:RSA,ELGamal
? ? ? ? 工具:gpg,openssl rsautl
? ? 數(shù)字簽名:
? ? ? ? 算法:RSA,DSA,ELGamal
? ? 密鑰交換:
? ? ? ? 算法:dh
? ? 生成密鑰(私鑰):
? ? ? ? openssl genrsa -out /PATH/TO/PRIVATEKEY.FILE numbits
? ? 隨機(jī)數(shù)生成器:熵池,用于存儲(chǔ)隨機(jī)數(shù),隨機(jī)數(shù)是由隨機(jī)事件產(chǎn)生的,如敲擊鍵盤、磁盤I/o等,兩個(gè)偽設(shè)備,用于生成隨機(jī)數(shù)。在/dev下的random和urandom
? ? ? ? /dev/random:僅從熵池中返回隨機(jī)數(shù),隨機(jī)數(shù)用盡,阻塞
? ? ? ? /dev/urandom:從熵池中返回隨機(jī)數(shù),隨機(jī)數(shù)用盡,會(huì)利用軟件生成偽隨機(jī)數(shù),非阻塞為了保證生成的私鑰文件的安全,設(shè)置其讀寫權(quán)限:
? ??(umask 077;openssl genrsa -out key.pri 2048)
使用小括號(hào),運(yùn)行的命令在子shell中運(yùn)行,不會(huì)對(duì)當(dāng)前的shell環(huán)境造成影響。
可以對(duì)私鑰文件進(jìn)行加密:
公鑰的生成,是從私鑰文件中提取的,需要私鑰文件:
? ? openssl rsa -in /PATH/FROM/PRIVATEKEY.FILE -pubout -out /PATH/TO/PUB.FILE
默認(rèn)輸出到屏幕。輸出到文件使用-out選項(xiàng),如果是加密的私鑰文件,需要輸入密碼
openssl實(shí)現(xiàn)私有CA:
? ? 1、生成一對(duì)密鑰
? ? 2、生成自簽署證書(shū)
? ? openssl genrsa -out /PATH/TO/KEYPRIVATE.FILE NUMBITS
? ? openssl rsa -in? /PATH/TO/KEYPRIVATE.FILE -pubout
生成自簽署證書(shū)和查看證書(shū),用到req命令:
? ? openssl req -new -x509 -key server1024.key -out server.crt -days 365
? ? openssl x509 -text -in server.crt
實(shí)現(xiàn)私有CA,需要在特定目錄下,有特定配置文件:
? ? 在/etc/pki/tls目錄下,有openssl.cnf配置文件,對(duì)于自建CA,主要關(guān)注配置文件如下ca區(qū)域的配置和申請(qǐng)信息的配置[req]的配置:
####################################################################
[ ca ]
default_ca = CA_default # The default ca section####################################################################
[ CA_default ]dir = /etc/pki/CA # 相當(dāng)于CA的根目錄,Where everything is kept
certs = $dir/certs # 簽發(fā)證書(shū)的保存目錄,Where the issued certs are kept
crl_dir = $dir/crl # 證書(shū)吊銷列表所在目錄,Where the issued crl are kept
database = $dir/index.txt # 簽發(fā)證書(shū)信息數(shù)據(jù)庫(kù),database index file.
#unique_subject = no # Set to 'no' to allow creation of# several ctificates with same subject.
new_certs_dir = $dir/newcerts # 新生成的證書(shū)保存位置,default place for new certs.certificate = $dir/cacert.pem # CA自己的證書(shū),The CA certificate
serial = $dir/serial # 保存下一個(gè)證書(shū)序列號(hào),The current serial number
crlnumber = $dir/crlnumber # 下一個(gè)吊銷證書(shū)號(hào)碼,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 # 隨機(jī)數(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 # 默認(rèn)證書(shū)有效期,how long to certify for
default_crl_days= 30 # 吊銷列表中保存時(shí)間,how long before next CRL
default_md = sha256 # 默認(rèn)的加密算法,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 # 默認(rèn)的國(guó)家代碼名字,原配置是XX,這里改為自己的
countryName_min = 2
countryName_max = 2stateOrProvinceName = State or Province Name (full name)
#stateOrProvinceName_default = ShanDong # 默認(rèn)省名字Default Province,改為自己的localityName = Locality Name (eg, city)
localityName_default = JiNan # 默認(rèn)城市(市縣)名字,Default City0.organizationName = Organization Name (eg, company)
0.organizationName_default = MyComp # 默認(rèn)公司名字,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 # 默認(rèn)組織名稱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
實(shí)操過(guò)程:
1、進(jìn)入CA根目錄,生成CA的私鑰,按照上面的配置CA根目錄是/etc/pki/CA,CA自己的私鑰為/etc/pki/CA/private/cakey.pem
2、生成自簽證書(shū):按照上面配置文件,CA自己的證書(shū)位置和名稱是/etc/pki/CA/cacert.pem。
3、創(chuàng)建目錄架構(gòu),主要是CA下要有certs、crl、newcerts子目錄,現(xiàn)在已經(jīng)有了,就不需要?jiǎng)?chuàng)建。
4、創(chuàng)建證書(shū)索引文件index.txt和序列號(hào)文件serial,并要給serial一個(gè)起始號(hào),因?yàn)闆](méi)有吊銷列表,吊銷列表號(hào)文件crlnumber不必創(chuàng)建。
5、至此,CA就搭建完成,可以簽發(fā)證書(shū)了
6、CA可以接收其他主機(jī)的證書(shū)簽發(fā)申請(qǐng)文件,簽發(fā)證書(shū)。這個(gè)證書(shū)簽發(fā)申請(qǐng)文件,是RA機(jī)構(gòu),即注冊(cè)機(jī)構(gòu)主要工作的結(jié)果文件;
? ? 證書(shū)簽發(fā)申請(qǐng)文件的生成,可以在其他主機(jī)上生成:假設(shè)給http服務(wù)器生成證書(shū)
? ? 1)http證書(shū)的位置,一般是在/etc/httpd下,新建一個(gè)ssl子目錄
? ? ? ? 不同的服務(wù),不同的證書(shū),不同的密鑰,使用者先向RA申請(qǐng)生成密鑰。
? ? 2)生成證書(shū)簽發(fā)申請(qǐng)文件,生成這個(gè)文件的過(guò)程,就是輸入申請(qǐng)人信息的過(guò)程:
這個(gè)httpd.csr,就是一個(gè)待簽發(fā)的證書(shū),所謂簽發(fā),就相當(dāng)于CA用自己的印戳在這個(gè)文件上蓋上印,實(shí)際就是CA用自己的密鑰在這個(gè)文件上數(shù)字簽名。
? ? 3)這個(gè)httpd.csr發(fā)給CA,CA進(jìn)行簽發(fā)
?查看CA的索引文件:
至此,私有CA創(chuàng)建完畢,并簽發(fā)了一個(gè)證書(shū)。在往后就是對(duì)證書(shū)的具體應(yīng)用了。
????????