1
2
3
4
5
6
7
|
OpenSSL:主要有三个部分组成
[root@stu2~]
# rpm -ql openssl
/usr/lib64/libcrypto
.so.10
#libcrypto主要实现加密解密的工具
/usr/lib64/libssl
.so.10
#主要实现ssl功能的
/usr/bin/openssl
#多用途的命令行程序
[root@stu2~]
# openssl version #查看openssl的版本号
OpenSSL1.0.0-fips 29 Mar 2010
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@stu2~]
# cp /etc/fstab ./ #复制文件到当前目录下
[root@stu2~]
# ls
anaconda-ks.cfg boot fstab
install
.log
install
.log.syslog ks.cfg
[root@stu2~]
# openssl enc -des3 -in fstab -e -out fstab.des3 #对文件进行加密测试输出到fstab.des3
enterdes-ede3-cbc encryption password:
#输入密码
Verifying- enter des-ede3-cbc encryption password:
#再次输入相同密码
[root@stu2~]
# ls #查看
anaconda-ks.cfg fstab
install
.log ks.cfg
boot fstab.des3
install
.log.syslog
[root@stu2~]
# cat fstab.des3
Salted__)申.2t~?..??
#后面的省略掉了
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@stu2~]
# ls
anaconda-ks.cfg fstab
install
.log ks.cfg
boot fstab.des3
install
.log.syslog
[root@stu2~]
# rm -f fstab #删除原文件
[root@stu2~]
# ls
anaconda-ks.cfg boot fstab.des3
install
.log
install
.log.syslog ks.cfg
[root@stu2~]
# openssl enc -des3 -in fstab.des3 -d -out fstab
enterdes-ede3-cbc decryption password:
#输入加密时的密码
[root@stu2~]
# ls
anaconda-ks.cfg fstab
install
.log ks.cfg
boot fstab.des3
install
.log.syslog
[root@stu2~]
# cat fstab #查看文件明文的列出了一部分
#
#/etc/fstab
#Created by anaconda on Sat Aug 10 08:33:02 2013
|
1
2
3
4
5
6
7
8
9
10
|
[root@stu2~]
# rm -f fstab.des3
[root@stu2~]
# ls
anaconda-ks.cfg boot fstab
install
.log
install
.log.syslog ks.cfg
[root@stu2~]
# openssl dgst -md5 fstab #用md5单向加密算法获取文件的特征码
MD5(fstab)=70adea925c86b2fa91e6a4900b31508a
[root@stu2~]
# openssl dgst -md5 -hex fstab #获取16进制的特征码,默认就是16进制的可以省略
MD5(fstab)=70adea925c86b2fa91e6a4900b31508a
[root@stu2~]
# vim fstab #在文件第一行添加一个#
[root@stu2~]
# openssl dgst -md5 -hex fstab #重新获取文件的特征码
MD5(fstab)=f8bd8f3c19697c85d4d683b0c4f0169b
#和之前的特征码几乎完全不同,这就是所谓的雪崩效应
|
1
2
3
4
|
[root@stu2~]
# openssl dgst -md5 -hex fstab
MD5(fstab)=f8bd8f3c19697c85d4d683b0c4f0169b
[root@stu2~]
# md5sum fstab
f8bd8f3c19697c85d4d683b0c4f0169b fstab
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@stu2~]
# openssl speed des-ede3
Doingdes ede3
for
3s on 16 size blocks: 3298403 des ede3's
in
2.99s
Doingdes ede3
for
3s on 64 size blocks: 828631 des ede3's
in
2.99s
Doingdes ede3
for
3s on 256 size blocks: 209735 des ede3's
in
2.99s
Doingdes ede3
for
3s on 1024 size blocks: 52521 des ede3's
in
3.00s
Doingdes ede3
for
3s on 8192 size blocks: 6691 des ede3's
in
2.98s
OpenSSL1.0.0-fips 29 Mar 2010
builton: Thu Feb 21 23:42:57 UTC 2013
options:bn(64,64)md2(int) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler:gcc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN-DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector--param=ssp-buffer-size=4 -m64 -mtune=generic -Wa,--noexecstack-DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DSHA1_ASM-DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DWHIRLPOOL_ASM
The
'numbers'
are
in
1000s of bytes per second processed.
type
16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
desede3 17650.32k 17736.58k 17957.24k 17927.17k 18393.51
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@stu2~]
# openssl passwd -1 -salt 12345678
Password:
$1$12345678$85L2ohc0YJ4r
/l1LAa6co1
说明:其中-1表示基于md5的加密算法,-salt添加一些额外数(一般为8位),当前最好使用无规律的随机数,通过帮助文档可以进行查看
man
sslpasswd
[root@stu2~]
# openssl rand -hex 4 #随机生产8位随机数
2c58639e
[root@stu2~]
# openssl passwd -1 -salt `openssl rand -hex 4`#通过salt后加密计算密码值
Password:
#输入密码
$1$ca64684d$tQyI7a.yLwbQRMulUBMCI/
#生成的密码值
# man sslpasswd
# openssl passwd -1 -salt
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@stu2~]
# openssl genrsa;
GeneratingRSA private key, 512 bit long modulus
.++++++++++++
................++++++++++++
eis 65537 (0x10001)
-----BEGINRSA PRIVATE KEY-----
MIIBOQIBAAJBAJnZzY3oIvGIG8CJFoXp0QHd1VvyFGmSvIvDMAfFgmuzfL8E3uk0
joZDq6HEnNxiAl+KFdheZeB2qluD2lZy9dUCAwEAAQJAEjnvVCRwH1UUlJapCGxO
yn3RTPc829T6aURSaFlJviByWdgKLnOsr
/HpBaF4/LGJXKcRdCRLC33CGBrSNFmc
8QIhAMskRtZ0xls0fjmCo8EnYOJBjmGjT5e8in19Ekc0KSy3AiEAweIl9k25q53J
XuFz
/rf0ZWtjkH2sC72MgI7iIiGAvdMCIDz9Gzdvv83KKMtjaX6oL/I99F1kBpVr
ybh7QG2YP3RpAiAGRA7CBQUJHNJTNKoRA1TsqinPk6ApyPhvdy6rt7V3bQIgDqQ7
ZquRPTo8QGCGrevqZBUowjeqczOzQaWup9nMlNg=
-----ENDRSA PRIVATE KEY-----
[root@stu2~]
# openssl genrsa 2048 > lian.key #可以指定生成私钥的位数,并重定向文件中
GeneratingRSA private key, 2048 bit long modulus
.............................................+++
.....+++
eis 65537 (0x10001)
[root@stu2~]
# cat lian.key #可以进行查看
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@stu2~]
# openssl genrsa -des3 2048 > lian.key #对生成的私钥文件进行单向加密
GeneratingRSA private key, 2048 bit long modulus
......................................................................................................................................+++
............................................+++
eis 65537 (0x10001)
Enterpass phrase:
Verifying- Enter pass phrase:
[root@stu2~]
# cat lian.key #查看加密后的私钥文件
-----BEGINRSA PRIVATE KEY-----
Proc-Type:4,ENCRYPTED
#表示该私钥已经被加密
DEK-Info:DES-EDE3-CBC,3E3043F0CDBAA02E
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@stu2~]
# (umask 077;openssl genrsa -out lian2.key 2048)
GeneratingRSA private key, 2048 bit long modulus
..........................................................+++
..+++
eis 65537 (0x10001)
[root@stu2~]
# ll
total84
-rw-------.1 root root 2801 Aug 10 08:44anaconda-ks.cfg
drwxr-xr-x 3 root root 4096 Aug 11 12:32 boot
-rw-r--r-- 1 root root 1051 Aug 21 15:34 fstab
-rw-r--r--.1 root root 43809 Aug 10 08:44
install
.log
-rw-r--r--.1 root root 9963 Aug 10 08:41install.log.syslog
-rw-r--r-- 1 root root 1388 Aug 11 12:32 ks.cfg
-rw------- 1 root root 1679 Aug 21 16:14 lian2.key
-rw-r--r-- 1 root root 1743 Aug 21 16:06 lian.key
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@stu2~]
# openssl rsa -in lian2.key -pubout
writingRSA key
-----BEGINPUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuRr
/Yy9xPDYowj2Cf
+vS
apaSvOHmj33tpm80NAzB7IOvkC8oiulj6oUoowWT1xHEuGbyOJILQEBwN4
/Jgm
+S
IN6
/r8gLssY4UBUj34T9ZHnAD0jEgPxRrQTiWSe1SlCStwkCR3RPlBUNXUAySa7X
St70Fg9gKIlz4HNMZRrXFgxgFSVE0i4sWFCwrDeIbAzTx2
/cGJVtQcYSMrdaKDAH
NdgcqKNI0aQSwX9HvTxRtX4sfl7XbqXiyUUJVyuZ4jIxI7yKyii68y
/Pk3mIz6mL
g5XOa15Jw9ggKHY5gd7g+nr4iioHMQQ
/WI8Bargs1ftwESw5lKddQBnLgn2aTpxe
1QIDAQAB
-----ENDPUBLIC KEY-----
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@stu2~]
# openssl req -new -key lan.key -out lan.csr
Youare about to be asked to enter information that will be incorporated
intoyour certificate request.
Whatyou are about to enter is what is called a Distinguished Name or a DN.
Thereare quite a few fields but you can leave some blank
Forsome fields there will be a default value,
Ifyou enter
'.'
, the field will be left blank.
-----
CountryName (2 letter code) [XX]:CN
#国家名
Stateor Province Name (full name) []:henan
#省份名称
LocalityName (eg, city) [Default City]:Zhengzhou
#城市名称
OrganizationName (eg, company) [Default Company Ltd]:lanlian
#公司名称
OrganizationalUnit Name (eg, section) []:tech
#部分名称
CommonName (eg, your name or your server's
hostname
) []:www.lanlian.com
#证书拥有者的名称,若使用域名访问这里使用域名,如用ip地址访问这里一定是Ip地址
EmailAddress []:
#邮箱地址,可以省略不写
Pleaseenter the following
'extra'
attributes
tobe sent with your certificate request
Achallenge password []:
#将请求加密起来输入密码,不想直接回车即可
Anoptional company name []:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
####################################################################
[ca ]
default_ca = CA_default
# The default ca section
####################################################################
[CA_default ]
#默认CA的配置
dir
=
/etc/pki/CA
# Where everything is kept自建CA的工作目录
certs = $
dir
/certs
# Where the issued certs are kept指定当前CA的证书存放位置
crl_dir = $
dir
/crl
# Where the issued crl are kept指定证书撤销列表所在的工作目录
database = $
dir
/index
.txt
# database index file.将签署的证书制作成索引保存下来也就是数据库文件
#unique_subject= no # Set to 'no' toallow creation of
#several ctificates with same subject.
new_certs_dir = $
dir
/newcerts
# default place for new certs.新签证书的位置
certificate = $
dir
/cacert
.pem
# The CA certificate CA自己证书位置
serial = $
dir
/serial
# The current serial number已签署的证书,序列号
crlnumber = $
dir
/crlnumber
# the current crl number已吊销证书的个数
# mustbe commented out to leave a V1 CRL
crl = $
dir
/crl
.pem
# The current CRL当前的证书吊销文件
private_key = $
dir
/private/cakey
.pem
# The private key证书颁发机构自己的私钥文件
RANDFILE = $
dir
/private/
.rand
# private random number file
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@stu2CA]
# (umask 077;openssl genrsa -out private/cakey.pem 2048) #为CA生成一个私钥
[root@stu2CA]
# ls private/
cakey.pem
[root@stu2 CA]
# openssl req -new -x509 -keyprivate/cakey.pem -out cacert.pem -days 3656
Youare about to be asked to enter information that will be incorporated
intoyour certificate request.
Whatyou are about to enter is what is called a Distinguished Name or a DN.
Thereare quite a few fields but you can leave some blank
Forsome fields there will be a default value,
Ifyou enter
'.'
, the field will be left blank.
-----
CountryName (2 letter code) [XX]:CN
Stateor Province Name (full name) []:henan
LocalityName (eg, city) [Default City]:zhengzhou
OrganizationName (eg, company) [Default Company Ltd]:lanlian
OrganizationalUnit Name (eg, section) []:tech
CommonName (eg, your name or your server's
hostname
) []:www.magedu.com
EmailAddress []:
[root@stu2CA]
# ls
cacert.pem certs crl newcerts private
[root@stu2CA]
# touch serial index.txt
[root@stu2CA]
# echo 01 > serial
[root@stu2CA]
# ls
cacert.pem certs crl index.txt newcerts private serial
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
[root@stu2~]
# openssl ca -in lan.csr -out lan.crt -days 3656
Usingconfiguration from
/etc/pki/tls/openssl
.cnf
Checkthat the request matches the signature
Signatureok
CertificateDetails:
Serial Number: 1 (0x1)
Validity
Not Before: Aug 21 09:20:01 2013GMT
Not After : Aug 25 09:20:01 2023GMT
Subject:
countryName = CN
stateOrProvinceName = henan
organizationName = lanlian
organizationalUnitName = tech
commonName = www.lanlian.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
6C:0F:54:43:9A:73:B2:74:FF:2E:59:16:E6:FD:D7:EE:C3:7D:0A:0B
X509v3 Authority Key Identifier:
keyid:59:56:89:9D:46:10:65:8B:F0:B4:EB:ED:C2:21:A0:CC:E4:9F:F4:FE
Certificateis to be certified
until
Aug 25 09:20:01 2023 GMT (3656 days)
Signthe certificate? [y
/n
]:y
1out of 1 certificate requests certified, commit? [y
/n
]y
Writeout database with 1 new entries
DataBase Updated
|