生成和交換預(yù)共享密鑰
預(yù)共享密鑰
讓我們以一個簡單的認證工具開始:預(yù)共享密鑰。為了使預(yù)共享密鑰認證正常工作,每臺主機上都定義了一個通用的密鑰。這個密鑰的定義將密鑰與遠程節(jié)點ISAKMP身份綁定在一起。從安全性方面而言,不好的做法是在每一對節(jié)點使用唯一的密鑰。預(yù)共享密鑰是通過使用全局配置命令<crypto isakmp key {0=unencrypted | 6=encrypted} {key string} {ip address or hostname}>配置的。
ISAKMP身份是遠程路由器向本地節(jié)點發(fā)送ISAKMP信息的接口。如果路由器在多個接口上支持,那么主機名應(yīng)該當作ISAKMP身份。使用全局命令<crypto isakmp identity {hostname | address}>可以配置路由器在它的ISAKMP節(jié)點協(xié)商中發(fā)送它的主機名。在默認情況下是使用路由器的ISAKMP接口IP地址。如果主機名選項被用于識別ISAKMP協(xié)商,那么遠程節(jié)點主機需要有主機名到IP地址的映射,這是通過<ip host {hostname} {IP address1} {IP Address 2…IP Address 8}>實現(xiàn)的。
路由器也可以使用DNS來進行主機名解析,但是本地主機名定義速度更快而且不會因為DNS服務(wù)器的問題而中斷。下面是一個兩個路由器間的預(yù)共享key配置例子。本地路由器發(fā)送它的主機名,然后遠程機器發(fā)送它的IP地址。首先就是本地節(jié)點路由器上的配置(IP地址和主機名密鑰都已經(jīng)定義了):
- !
- hostname outlan-rt01
- !
- !
- crypto isakmp policy 10
- encr 3des
- hash md5
- authentication pre-share
- group 2
- crypto isakmp key secretkey address 192.168.10.3
- crypto isakmp identity hostname
- !
- interface FastEthernet0/0
- ip address 172.30.80.17 255.255.255.252
- !
遠程對等路由器的配置是這樣的:
- !
- hostname inlan-rt01
- !
- ip host outlan-rt01 172.30.80.17
- !
- !
- crypto isakmp policy 10
- encr 3des
- hash md5
- authentication pre-share
- group 2
- crypto isakmp key secretkey address outlan-rt01
- !
- interface FastEthernet1/0
- ip address 192.168.10.3 255.255.255.252
- !
對于這個例子有兩點需要注意。第一點要注意的是只有在本地路由器的配置中有一個ISAKMP身份定義。這是因為IP地址是默認發(fā)送的。第二點要注意的是,作為一個規(guī)則,你不應(yīng)該混合使用ISAKMP的身份方法。或者全使用IP地址,或者全使用主機名,這樣可以最小化配置錯誤。在以后的文章中,當我們探討拓撲配置的內(nèi)容時,我們將更進一步地研究如何使用主機名來進行ISAKMP身份驗證。
RSA 現(xiàn)時標記 現(xiàn)在我們接著學(xué)習(xí)配置RSA現(xiàn)時標記來進行認證。這個ISAKMP策略例子是使用手動地RAS密鑰認證交換。
- crypto isakmp policy 15
- encr 3des
- hash md5
- authentication rsa-encr
- group 5
- lifetime 300
如果說我們想要在outlan-rt01和inlan-rt01間應(yīng)用上面的遠程認證密鑰例子。我們需要對ISAKMP政策做的唯一改變是增加認證參數(shù)(在這個例子中,兩個主機使用其IP地址作為ISAKMP身份):
- !
- hostname outlan-rt01
- !
- !
- crypto isakmp policy 10
- encr 3des
- hash md5
- authentication rsa-encr
- group 2
- !
- interface FastEthernet0/0
- ip address 172.30.80.17 255.255.255.252
- hostname inlan-rt01
- !
- !
- crypto isakmp policy 10
- encr 3des
- hash md5
- authentication rsa-encr
- group 2
- !
- interface FastEthernet1/0
- ip address 192.168.10.3 255.255.255.252
為了對outlan-rt01和inlan-rt01進行認證,必須做兩件事情。首先,每個路由器都必須生成一對RSA密鑰(公開的和私有的)。然后,它們必須共享它們的公鑰。這個基本過程在兩個路由器上是一樣的,因此我們可以看看outlan-rt01的過程。為了生成一對RAS密鑰,路由器必須定義一個的主機名和IP域名。
- router(config)# hostname outlan-rt01
- outlan-rt01(config)# ip domain-name outlan.net
一旦配置了主機名和IP域名,下一步就是生成RSA 密鑰。IOS支持可輸出和不可輸出的密鑰,而且這兩種密鑰類型都支持RSA現(xiàn)時標記認證。然而,生成可輸出密鑰是個比較好的做法。這樣如果你的環(huán)境部署了認證授權(quán),你就可以使用相同的密鑰,這使轉(zhuǎn)變更容易些。
密鑰的生成是通過使用全局配置命令完成的:對于不可輸出密鑰是<crypto key generate rsa label {label string},而對于可輸出密鑰則是<crypto key generate rsa exportable label {label string}>。標記(label)是可選擇的;如果沒有指定標記,那么密鑰名稱將是hostname.domain-name。對密鑰進行標記是很好的做法,因為有時你會需要多個密鑰。標記能夠確保你能找到它們并且防止你不小心誤寫的。對于密鑰的模數(shù)在大小,IOS支持512到2048位的密鑰大小。而1024位的密鑰就已經(jīng)遠遠滿足我們的要求了。
- outlan-rt01(config)#crypto key generate rsa exportable label outlan-rt01
- The name for the keys will be: outlan-rt01
- Choose the size of the key modulus in the range of 360 to 2048 for your
- General Purpose Keys. Choosing a key modulus greater than 512 may take
- a few minutes.
- How many bits in the modulus [512]: 1024%
- % Generating 1024 bit RSA keys, keys will be exportable...[OK]
- outlan-rt01(config)#
公共密鑰 現(xiàn)在我們已經(jīng)生成了RSA密鑰,我們需要將我們的公鑰放到inlan-rt01上。在開始這個步驟時,我們要看一下outlan-rt01的公鑰。從EXEC中,我們使用命令<show crypto key mypubkey rsa {key label}>。如果在路由器上不存在密鑰,那么輸出就是這樣的:
- outlan-rt01#show crypto key mypubkey rsa
- outlan-rt01#
如果存在一個或者多個密鑰,那么輸出就是這樣的:
- outlan-rt01#show crypto key mypubkey rsa outlan-rt01
- % Key pair was generated at: 01:03:58 UTC Apr 25 2002
- Key name: outlan-rt01
- Storage Device: not specified
- Usage: General Purpose Key
- Key is exportable.
- Key Data:
- 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 009F100B
- 36665972 E97AD0B1 BC863579 66B67706 F9B009E9 39FF9C24 59D64250 5B45B2EF
- 6F6EBA57 2635235A CCC2DEF7 11653C33 956E92BD 45ED2B4E CDEFB15F 40CCAE7C
- F5E06445 17FEAF2B 75BD936C E75465A0 9F7EEB52 1D387EBB E78B553B 1E56957D
- 4E607481 E3CF0482 8C672F6D F772170D 6B599060 BB96D7B2 9DEA29E7 CD020301 0001
- outlan-rt01#
有時候,可能我們喜歡只有一個密鑰,或者我們只想要一個密鑰時卻生成了兩個。為了刪除一個密鑰,我們可以在全局配置模式中運行<crypto key zeroize rsa {key name}>。一旦key被刪除,刪除結(jié)果會馬上生效且不能恢復(fù)。因此,在你決定要“化零”一個密鑰時一定要小心。下面是一個刪除一個名為outlan-rt01.outlan.net的密鑰的例子:
- outlan-rt01#config t
- Enter configuration commands, one per line. End with CNTL/Z.
- outlan-rt01(config)#crypto key zeroize rsa outlan-rt01.outlan.net
- % Keys to be removed are named named 'outlan-rt01.outlan.net'.
- % All router certs issued using these keys will also be removed.
- Do you really want to remove these keys? [yes/no]: yes
- outlan-rt01(config)#
- The RSA keys are stored in the private-config file on the nvram file system:
- outlan-rt01#dir nvram:
- Directory of nvram:/
- 27 -rw- 751 startup-config
- 28 ---- 24 private-config
- 1 -rw- 0 ifIndex-table
- 2 ---- 27 persistent-data
- 29688 bytes total (26813 bytes free)
- outlan-rt01#
這樣,我們知道如何創(chuàng)建和刪除RAS密鑰了,而且我們已經(jīng)為outlan-rt01建立了一個密鑰。我們還需要配置inlan-rt01來使用這個密鑰。這是通過將outlan-rt01的RSA的公鑰添加到inlan-rt01公共密鑰鏈中實現(xiàn)的。
為了在outlan-rt01上查看這個公鑰,我們這樣運行:
- outlan-rt01#sh crypto key mypubkey rsa outlan-rt01
- % Key pair was generated at: 01:40:40 UTC Apr 25 2002
- Key name: outlan-rt01
- Storage Device: not specified
- Usage: General Purpose Key
- Key is exportable.
- Key Data:
- 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800
- 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384
- 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1
- E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2
- 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001
- outlan-rt01#
在我們添加密鑰到inlan-rt01公共的公鑰鏈之前,讓我們先看看這個密鑰是否已經(jīng)在inlan-rt01上定義了。(經(jīng)常檢查是個很好的方式,即使你知道它并不在那):
- inlan-rt01#sh crypto key pubkey-chain rsa
- Codes: M - Manually configured, C - Extracted from certificate
- inlan-rt01#
密鑰并不在,因此我們需要手動定義和導(dǎo)入一個。在做這個步驟時,我們必須備份outlan-rt01的密鑰或者在路由器上打開一個EXEC會話以便我們可以備份密鑰。然后我們在inlan-rt01上打開EXEC會話,進入配置樣式然后進入公鑰鏈配置模式:
- inlan-rt01#config t
- Enter configuration commands, one per line. End with CNTL/Z.
- inlan-rt01(config)#
- inlan-rt01(config)#crypto key pubkey-chain rsa
- inlan-rt01(config-pubkey-chain)#
- Once in keychain mode, we need to first associate an IP address with the key. The router will be using its IP address as its ISAKMP identity.
- inlan-rt02(config-pubkey-chain)#addressed-key 172.30.80.18
一旦輸入<addressed-key>命令,路由器就進入了配置公鑰模式。把這個key粘貼到keychain上,我們先輸入<key-string>指令。一旦這個指令輸入,路由器就進入公鑰配置模式,同時提示我們從其他路由器粘貼密鑰數(shù)據(jù)。我們只需要拷貝密鑰數(shù)據(jù)域(從outlan-rt01上開始的密鑰數(shù)據(jù)):
- 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800
- 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384
- 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1
- E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2
- 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001
- inlan-rt02(config-pubkey-key)#key-string
- Enter a public key as a hexadecimal number ....
- inlan-rt01(config-pubkey)#$0101 05000381 8D003081 89028181 00E45800
- inlan-rt01(config-pubkey)#$B03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384
- inlan-rt01(config-pubkey)#$C45E2B 340B458B 63DC16E7 AA9FE214 C35941F1
- inlan-rt01(config-pubkey)#$A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2
- inlan-rt01(config-pubkey)#quit
- inlan-rt01(config-pubkey-key)#exit
- inlan-rt01(config-pubkey-chain)#exit
- inlan-rt01(config)#exit
- inlan-rt01#
為了確保密鑰已經(jīng)正確輸入,我們可以對比一下密鑰。在inlan-rt01上,運行<show crypto key pubkey-chain rsa address xxx.xxx.xxx.xxx >命令:
- inlan-rt01#sh crypto key pubkey-chain rsa address 172.30.80.17
- Key address: 172.30.80.17
- Usage: General Purpose Key
- Source: Manually entered
- Data:
- 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800
- 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384
- 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1
- E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2
- 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001
- inlan-rt01#
然后,在outlan-rt01上運行<show crypto key mypubkey rsa [key label}>:
- outlan-rt01#sh crypto key mypubkey rsa outlan-rt01
- % Key pair was generated at: 01:40:40 UTC Apr 25 2002
- Key name: outlan-rt01
- Storage Device: not specified
- Usage: General Purpose Key
- Key is exportable.
- Key Data:
- 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800
- 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384
- 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1
- E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2
- 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001
- outlan-rt01#
在outlan-rt01和inlan-rt01上的密鑰互相匹配了。現(xiàn)在我們需要做的就是重復(fù)整個過程,這樣inlan-rt01的公共RSA密鑰就在outlan-rt01的RSA共公密鑰鏈上了。我敢肯定到這個時候你就理解了涉及使用RSA現(xiàn)時標記的做法了。反復(fù)提醒自己“安全保證代價不匪——或者不容易”是沒有壞處的。
【編輯推薦】