安全和加密需要注意的事項
講到安全機制,我們信息安全防護的首要目標應該是保密性、完整性、可用性、可控制性、不可否認性。而在安全防護環節,物理安全(各種設備/主機、機房環境)、系統安全(主機或設備的操作系統)、應用安全(各種網絡服務、應用程序)、網絡安全(對網絡訪問的控制、防火牆規則)、數據安全(信息的備份與恢復、加密解密)等環節是尤其需要注意的。
受到***常出現的狀況是:
假冒
篡改
否認
信息泄漏
拒絕服務
提升權限
設計安全機制的基本原則是:
使用成熟的安全系統
嚴格把控輸入數據
外部系統是不安全的
最小授權
減少外部接口
缺省使用安全模式
安全不是似是而非
從STRIDE思考
在入口處檢查
從管理上保護好你的系統
不安全的傳統協議:
Telnet、FTP、POP3等待;不這全密碼
http、smtp、NFS等等;不安全信息
Ldop、NIS、rsh等等;不安全驗證
密碼算法和協議:
對稱加密:加密和解密都使用一個同一個密鑰
屬於對稱加密的有:DES(56位), AES, Blowfish, Twofish, IDEA, RC6, CAST5
特性:加密、解密使用同一個密鑰,效率高
將原始數據分割成固定大小的塊,逐個進行加密
缺陷:密鑰過多
密鑰分發
數據來源無法確定
公鑰加密:密鑰是成對出現
公鑰:公開給所有人;public key
私鑰:自己留存,必須保證其私密性;secret key
特點:用公鑰加密數據,從能使用與之配對的私鑰解密;反之亦然;
功能:
數字簽名:主要在於讓接收方確認發送方身份
對稱密鑰交換:發送方用對方的公鑰加密一個對稱密鑰後以給對方
數據加密:適合加密較小數據
缺點:密鑰長,加密解密效率低下
算法:
RSA(加密,數字簽名),DSA(數字簽名),ELGamal
單向加密:hash算法的工作原理是將任意數據縮小成固定大小的“指紋”
任意長度輸入
固定長度輸出
若修改數據,指紋也會改變(“不會產生衝突”)
無法從指紋中重新生成數據(“單向”)
功能:數據完整性
常見算式:
md5: 128bits、sha1:160bit、sha224、sha256、sha384、sha512
常用工具:
md5sum|sha1sum [ --check ] file
openssl, gpg
rpm -V
由上圖可知:要想知道一個程序是否被改變,可以比對二者的sha1sum值
查看文件完整性的兩種實施方式:
(1)被安裝過的文件:
MD5單向加密
rpm --verify package_name (or -V)
(2)發行的軟件包文件
GPG公鑰簽名
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat*
Rpm --checksig pakage_file_name (or -K)
使用gpg實現對稱加密:
(1)對稱加密file文件
gpg -c file
ls file.gpg
(2)在另一臺主機上解密file
gpg -o file -d file.gpg
使用gpg工具實現公鑰加密:
在hostB主機上用公鑰加密,在hostA主機上解密
在hostA主機上生成公鑰/私鑰對
gpg --gen-key
在hostA主機上查看公鑰
gpg --list-keys
在hostA主機上導出公鑰到wang.pubkey
gpg -a --export -o wang.pubkey
從hostA主機上覆制公鑰文件到需要加密的B主機上
scp wang.pubkey hostb
在需要加密數據的hostB主機上生成公鑰/私鑰對
gpg --list-keys
gpg --gen-key
在hostB主機上導入公鑰
gpg --import wang.pubkey
gpg --list-keys
用從hostA主機導入的公鑰,加密hostB主機的文件file,生成file.gpg
gpg -e -r xiaochun file
file file.gpg
複製加密文件到hostA主機
scp fstab.gpg hostA
在hostA主機解密文件
gpg -d file.gpg
gpg -o file -d file.gpg
刪除公鑰和私鑰
gpg --delete-keys xiaochun
gpg --delete-secret-keys xiaochun
Eg:
[root@localhost bin]# gpg --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 1024
Requested keysize is 1024 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 1
Key expires at Wed 20 Sep 2017 03:00:47 PM CST
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: xiaohong
Email address:
Comment:
You selected this USER-ID:
"xiaohong"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
can't connect to `/root/.gnupg/S.gpg-agent': No such file or directory
gpg-agent[5795]: directory `/root/.gnupg/private-keys-v1.d' created
┌─────────────────────────────────────────────────────┐
│ Enter passphrase │
│ │
│ │
│ Passphrase **********______________________________ │
│ │
│ <OK> <Cancel> │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ Please re-enter this passphrase │
│ │
│ Passphrase **********______________________________ │
│ │
│ <OK> <Cancel> │
└─────────────────────────────────────────────────────┘
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
在上面文字下方界面,你可以一直敲擊鍵盤或移動鼠標,就可以了,
下面是在/root/.gnupg/下面生成了以下文件
用下面命令查看公鑰
以同樣的方法在另一臺主機上生成公鑰私鑰對
導出公鑰到xiaohong.pubkey
查看公鑰內容
從主機A複製到主機B
然後,將從主機A導入的公鑰也導入,由圖可知,主機B有了兩把公鑰
爲/boot/bin/for6.15.sh加密
認證協議