openssl命令
一、date 命令時間戳
常用參數
date - 打印或設置系統日期和時間
根據指定格式顯示當前時間或設置系統時間.
-d, --date=STRING
顯示由 STRING 指定的時間, 而不是當前時間
-f, --file=DATEFILE
顯示 DATEFILE 中每一行指定的時間, 如同將 DATEFILE 中的每行作爲 --date 的參數一樣
-I, --iso-8601[=TIMESPEC] 按照 ISO-8601 的日期/時間格式輸出時間.
TIMESPEC=`date' (或者不指定時)僅輸出日期,等於 `hours', `minutes', 或`seconds' 時按照指定精度輸出日期及時間.
-r, --reference=FILE
顯示 FILE 的最後修改時間
-R, --rfc-822
根據 RFC-822 指定格式輸出日期
-s, --set=STRING
根據 STRING 設置時間
-u, --utc, --universal
顯示或設置全球時間(格林威治時間)
實用1:時間戳:
[root@localhost ~]# date #獲取當前時間
Sat Jan 18 10:18:19 CST 2020
##把當前時間轉時間戳
[root@localhost ~]# date -d "Sat Jan 18 10:18:19 CST 2020" '+%s'
1579313899
[root@localhost ~]# date -d '1970-01-01 UTC 1579313899 seconds' #時間戳轉時間
Sat Jan 18 10:18:19 CST 2020
#時間戳轉時間
[root@localhost ~]# date -d @1579313899
Sat Jan 18 10:18:19 CST 2020
根據要求,精確指定精度輸出:
# date -I #按照 ISO-8601 的日期/時間格式輸出時間
[root@localhost ~]# date -I
2020-01-18
# date -Ihours
[root@localhost ~]# date -Ihours #按小時精度輸出
2020-01-18T10+0800
# date -Iminutes #按分鐘精度輸出
[root@localhost ~]# date -Iminutes
2020-01-18T10:30+0800
# date -Iseconds #按秒精度輸出
[root@localhost ~]# date -Iseconds
2020-01-18T10:31:07+0800
根據要求做時間調整:
[root@localhost ~]# date -d "1 day ago" #一天前
Fri Jan 17 10:32:50 CST 2020
[root@localhost ~]# date -d "1 hour ago" 一個小時前
Sat Jan 18 09:33:01 CST 2020
[root@localhost ~]# date -d "1 minute ago" #一分鐘前
Sat Jan 18 10:32:10 CST 2020
[root@localhost ~]# date -d "-1 minute" #一分鐘前
Sat Jan 18 10:32:56 CST 2020
[root@localhost ~]# date -d "+1 minute" #一分鐘後
Sat Jan 18 10:35:04 CST 2020
[root@localhost ~]# date -d "+1 month" #一個月後
Tue Feb 18 10:34:16 CST 2020
[root@localhost ~]# date -d "+1 year" #一年後的
Mon Jan 18 10:34:27 CST 2021
[root@localhost ~]# date -d "+1 year" +%F_%T #格式化輸出
2021-01-18_10:37:06
二、Openssl 查看證書常用命令:
[root@localhost ~]# openssl crl -in file -inform der -noout ?
unknown option ?
usage: crl args
#輸入格式
-inform arg - input format - default PEM (DER or PEM)
#輸出格式
-outform arg - output format - default PEM
# 輸出加密內容
-text - print out a text format version
# 輸入文件
-in arg - input file - default stdin
# 輸出到指定文件或輸出到屏幕
-out arg - output file - default stdout
# 輸出hash值
-hash - print hash value
# 輸出指紋
-fingerprint - print the crl fingerprint
輸出DN
-issuer - print issuer DN
輸出上次生效時間
-lastupdate - lastUpdate field
輸出失效時間
-nextupdate - nextUpdate field
輸出CRL編號
-crlnumber - print CRL number
-noout - no CRL output
-CAfile name - verify CRL using certificates in file "name"
-CApath dir - verify CRL using certificates in "dir"
-nameopt arg - various certificate name options
示例一:查看證書註銷列表更新時間,主要是爲了驗證證書的有效性
[root@localhost ~]# openssl crl -in ctl.crl -inform der -noout -lastupdate -nextupdate -fingerprint -crlnumber
lastUpdate=Jan 15 05:32:28 2020 GMT # 生效時間
nextUpdate=Jan 16 05:32:28 2020 GMT # 失效時間
SHA1 Fingerprint=21:8D:05:2F:FC:E4:03:26:84:84:59:15:3E:A8:B8:12:A9:FE:28:92 #哈希指紋
crlNumber=00 #證書編號
# -in 查看的證書文件
# -inform 輸入證書的格式,默認是PEM
# -noout 不輸出證書內容到文件,默認輸出到屏幕
# -lastupdate 輸出生效時間
# -nextupdate 輸出失效時間
# -fingerprint 證書指紋
# -crlnumber 證書編號
注意,使用openssl 查看的證書時間爲標準的格林威治時間,在當地(China)需要在查看的時間基礎上加上8個小時。
示例二:查看證書註銷列表證書內容
[root@localhost ~]# openssl crl -in ctl.crl -inform der -lastupdate -nextupdate -fingerprint -crlnumber -text -noout
lastUpdate=Jan 15 05:32:28 2020 GMT
nextUpdate=Jan 16 05:32:28 2020 GMT
SHA1 Fingerprint=21:8D:05:2F:FC:E4:03:26:84:84:59:15:3E:A8:B8:12:A9:FE:28:92
crlNumber=00
Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: sha1WithRSAEncryption
Issuer: /C=CN/O=COM/CN=COM CA
Last Update: Jan 15 05:32:28 2020 GMT
Next Update: Jan 16 05:32:28 2020 GMT
CRL extensions:
X509v3 Authority Key Identifier:
keyid:E8:57:D3:59:4F:BA:69:F4:33:BF:4C:35:2C:60:23:6B:D6:9E:B8:36
X509v3 CRL Number:
0
Revoked Certificates:
Serial Number: 10038BC709DD787H
Revocation Date: Jun 10 08:13:06 2019 GMT
CRL entry extensions:
X509v3 CRL Reason Code:
Superseded
Serial Number: 100F0D70180FE103
..........
總結:
OpenSSL簡介:
OpenSSL 是一個安全套接字層密碼庫,包括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協議,並提供豐富的應用程序供測試或其它目的使用。
常見的證書、密鑰的編碼格式:
PEM - Privacy Enhanced Mail (x509)
打開看文本格式,以"-----BEGIN-----"開頭, "-----END-----"結尾,內容是Base64編碼,查看PEM格式的信息可以用命令
openssl rsa -in my.pem -text -noout
Unix服務器偏向於使用這種編碼格式.
DER - Distinguished Encoding Rules
打開看是二進制格式,不可讀,查看DER格式的信息可以用命令
openssl rsa -in my.der -inform der -text -noout
Java和Windows服務器偏向於使用這種編碼格式.