生成和交换预共享密钥

安全
本文详细的介绍了生成和交换预共享密钥的过程及步骤,主要是为了让读者能够更深入和容易的理解配置过程。希望此篇文章能够解决学习者的一些疑惑。

预共享密钥

 让我们以一个简单的认证工具开始:预共享密钥。为了使预共享密钥认证正常工作,每台主机上都定义了一个通用的密钥。这个密钥的定义将密钥与远程节点ISAKMP身份绑定在一起。从安全性方面而言,不好的做法是在每一对节点使用唯一的密钥。预共享密钥是通过使用全局配置命令<crypto isakmp key {0=unencrypted | 6=encrypted} {key string} {ip address or hostname}>配置的。

ISAKMP身份是远程路由器向本地节点发送ISAKMP信息的接口。如果路由器在多个接口上支持,那么主机名应该当作ISAKMP身份。使用全局命令<crypto isakmp identity {hostname | address}>可以配置路由器在它的ISAKMP节点协商中发送它的主机名。在默认情况下是使用路由器的ISAKMP接口IP地址。如果主机名选项被用于识别ISAKMP协商,那么远程节点主机需要有主机名到IP地址的映射,这是通过<ip host {hostname} {IP address1} {IP Address 2…IP Address 8}>实现的。

路由器也可以使用DNS来进行主机名解析,但是本地主机名定义速度更快而且不会因为DNS服务器的问题而中断。下面是一个两个路由器间的预共享key配置例子。本地路由器发送它的主机名,然后远程机器发送它的IP地址。首先就是本地节点路由器上的配置(IP地址和主机名密钥都已经定义了):  

  1. !   
  2. hostname outlan-rt01   
  3. !   
  4. !   
  5. crypto isakmp policy 10   
  6. encr 3des   
  7. hash md5   
  8. authentication pre-share   
  9. group 2   
  10. crypto isakmp key secretkey address 192.168.10.3   
  11. crypto isakmp identity hostname   
  12. !   
  13. interface FastEthernet0/0   
  14. ip address 172.30.80.17 255.255.255.252   
  15. !  

远程对等路由器的配置是这样的:

 

 

  1. !   
  2. hostname inlan-rt01   
  3. !   
  4. ip host outlan-rt01 172.30.80.17   
  5. !   
  6. !   
  7. crypto isakmp policy 10   
  8. encr 3des   
  9. hash md5   
  10. authentication pre-share   
  11. group 2   
  12. crypto isakmp key secretkey address outlan-rt01   
  13. !   
  14. interface FastEthernet1/0   
  15. ip address 192.168.10.3 255.255.255.252   
  16. !  

对于这个例子有两点需要注意。第一点要注意的是只有在本地路由器的配置中有一个ISAKMP身份定义。这是因为IP地址是默认发送的。第二点要注意的是,作为一个规则,你不应该混合使用ISAKMP的身份方法。或者全使用IP地址,或者全使用主机名,这样可以最小化配置错误。在以后的文章中,当我们探讨拓扑配置的内容时,我们将更进一步地研究如何使用主机名来进行ISAKMP身份验证。

RSA 现时标记 现在我们接着学习配置RSA现时标记来进行认证。这个ISAKMP策略例子是使用手动地RAS密钥认证交换。

 

  1. crypto isakmp policy 15   
  2. encr 3des   
  3. hash md5   
  4. authentication rsa-encr   
  5. group 5   
  6. lifetime 300  

 

如果说我们想要在outlan-rt01和inlan-rt01间应用上面的远程认证密钥例子。我们需要对ISAKMP政策做的唯一改变是增加认证参数(在这个例子中,两个主机使用其IP地址作为ISAKMP身份):

 

  1. !   
  2. hostname outlan-rt01   
  3. !   
  4. !   
  5. crypto isakmp policy 10   
  6. encr 3des   
  7. hash md5   
  8. authentication rsa-encr   
  9. group 2   
  10. !   
  11. interface FastEthernet0/0   
  12. ip address 172.30.80.17 255.255.255.252   
  13.  
  14. hostname inlan-rt01   
  15. !   
  16. !   
  17. crypto isakmp policy 10   
  18. encr 3des   
  19. hash md5   
  20. authentication rsa-encr   
  21. group 2   
  22. !   
  23. interface FastEthernet1/0   
  24. ip address 192.168.10.3 255.255.255.252  

 

为了对outlan-rt01和inlan-rt01进行认证,必须做两件事情。首先,每个路由器都必须生成一对RSA密钥(公开的和私有的)。然后,它们必须共享它们的公钥。这个基本过程在两个路由器上是一样的,因此我们可以看看outlan-rt01的过程。为了生成一对RAS密钥,路由器必须定义一个的主机名和IP域名。
 

  1. router(config)# hostname outlan-rt01   
  2. outlan-rt01(config)# ip domain-name outlan.net   

 

一旦配置了主机名和IP域名,下一步就是生成RSA 密钥。IOS支持可输出和不可输出的密钥,而且这两种密钥类型都支持RSA现时标记认证。然而,生成可输出密钥是个比较好的做法。这样如果你的环境部署了认证授权,你就可以使用相同的密钥,这使转变更容易些。

密钥的生成是通过使用全局配置命令完成的:对于不可输出密钥是<crypto key generate rsa label {label string},而对于可输出密钥则是<crypto key generate rsa exportable label {label string}>。标记(label)是可选择的;如果没有指定标记,那么密钥名称将是hostname.domain-name。对密钥进行标记是很好的做法,因为有时你会需要多个密钥。标记能够确保你能找到它们并且防止你不小心误写的。对于密钥的模数在大小,IOS支持512到2048位的密钥大小。而1024位的密钥就已经远远满足我们的要求了。
 

  1. outlan-rt01(config)#crypto key generate rsa exportable label outlan-rt01   
  2. The name for the keys will be: outlan-rt01   
  3. Choose the size of the key modulus in the range of 360 to 2048 for your   
  4. General Purpose Keys. Choosing a key modulus greater than 512 may take   
  5. a few minutes.   
  6. How many bits in the modulus [512]: 1024%   
  7. % Generating 1024 bit RSA keys, keys will be exportable...[OK]   
  8. outlan-rt01(config)#  

公共密钥 现在我们已经生成了RSA密钥,我们需要将我们的公钥放到inlan-rt01上。在开始这个步骤时,我们要看一下outlan-rt01的公钥。从EXEC中,我们使用命令<show crypto key mypubkey rsa {key label}>。如果在路由器上不存在密钥,那么输出就是这样的:  

 

  1. outlan-rt01#show crypto key mypubkey rsa   
  2. outlan-rt01#   

 

如果存在一个或者多个密钥,那么输出就是这样的:  

 

  1. outlan-rt01#show crypto key mypubkey rsa outlan-rt01   
  2. % Key pair was generated at: 01:03:58 UTC Apr 25 2002   
  3. Key name: outlan-rt01   
  4. Storage Device: not specified   
  5. Usage: General Purpose Key   
  6. Key is exportable.   
  7. Key Data:   
  8. 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 009F100B   
  9. 36665972 E97AD0B1 BC863579 66B67706 F9B009E9 39FF9C24 59D64250 5B45B2EF   
  10. 6F6EBA57 2635235A CCC2DEF7 11653C33 956E92BD 45ED2B4E CDEFB15F 40CCAE7C   
  11. F5E06445 17FEAF2B 75BD936C E75465A0 9F7EEB52 1D387EBB E78B553B 1E56957D   
  12. 4E607481 E3CF0482 8C672F6D F772170D 6B599060 BB96D7B2 9DEA29E7 CD020301 0001   
  13. outlan-rt01#   
  14.  

 

有时候,可能我们喜欢只有一个密钥,或者我们只想要一个密钥时却生成了两个。为了删除一个密钥,我们可以在全局配置模式中运行<crypto key zeroize rsa {key name}>。一旦key被删除,删除结果会马上生效且不能恢复。因此,在你决定要“化零”一个密钥时一定要小心。下面是一个删除一个名为outlan-rt01.outlan.net的密钥的例子:

 

 

 

  1. outlan-rt01#config t   
  2. Enter configuration commands, one per line. End with CNTL/Z.   
  3. outlan-rt01(config)#crypto key zeroize rsa outlan-rt01.outlan.net   
  4. % Keys to be removed are named named 'outlan-rt01.outlan.net'.   
  5. % All router certs issued using these keys will also be removed.   
  6. Do you really want to remove these keys? [yes/no]: yes   
  7. outlan-rt01(config)#   
  8. The RSA keys are stored in the private-config file on the nvram file system:   
  9. outlan-rt01#dir nvram:   
  10. Directory of nvram:/   
  11. 27 -rw- 751 startup-config   
  12. 28 ---- 24 private-config   
  13. 1 -rw- 0 ifIndex-table   
  14. 2 ---- 27 persistent-data   
  15. 29688 bytes total (26813 bytes free)   
  16. outlan-rt01#   

 

这样,我们知道如何创建和删除RAS密钥了,而且我们已经为outlan-rt01建立了一个密钥。我们还需要配置inlan-rt01来使用这个密钥。这是通过将outlan-rt01的RSA的公钥添加到inlan-rt01公共密钥链中实现的。

 

为了在outlan-rt01上查看这个公钥,我们这样运行:  

 

  1. outlan-rt01#sh crypto key mypubkey rsa outlan-rt01   
  2. % Key pair was generated at: 01:40:40 UTC Apr 25 2002   
  3. Key name: outlan-rt01   
  4. Storage Device: not specified   
  5. Usage: General Purpose Key   
  6. Key is exportable.   
  7. Key Data:   
  8. 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800   
  9. 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384   
  10. 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1   
  11. E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2   
  12. 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001   
  13. outlan-rt01#   
  14.  

 

在我们添加密钥到inlan-rt01公共的公钥链之前,让我们先看看这个密钥是否已经在inlan-rt01上定义了。(经常检查是个很好的方式,即使你知道它并不在那):

 

 

 

  1. inlan-rt01#sh crypto key pubkey-chain rsa   
  2. Codes: M - Manually configured, C - Extracted from certificate   
  3. inlan-rt01#   
  4.  

 

密钥并不在,因此我们需要手动定义和导入一个。在做这个步骤时,我们必须备份outlan-rt01的密钥或者在路由器上打开一个EXEC会话以便我们可以备份密钥。然后我们在inlan-rt01上打开EXEC会话,进入配置样式然后进入公钥链配置模式:

 

 

 

  1. inlan-rt01#config t   
  2. Enter configuration commands, one per line. End with CNTL/Z.   
  3. inlan-rt01(config)#   
  4. inlan-rt01(config)#crypto key pubkey-chain rsa   
  5. inlan-rt01(config-pubkey-chain)#   
  6. 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.   
  7. inlan-rt02(config-pubkey-chain)#addressed-key 172.30.80.18   
  8.  

 

一旦输入<addressed-key>命令,路由器就进入了配置公钥模式。把这个key粘贴到keychain上,我们先输入<key-string>指令。一旦这个指令输入,路由器就进入公钥配置模式,同时提示我们从其他路由器粘贴密钥数据。我们只需要拷贝密钥数据域(从outlan-rt01上开始的密钥数据):

 

 

 

  1. 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800   
  2. 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384   
  3. 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1   
  4. E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2   
  5. 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001   
  6. inlan-rt02(config-pubkey-key)#key-string   
  7. Enter a public key as a hexadecimal number ....   
  8. inlan-rt01(config-pubkey)#$0101 05000381 8D003081 89028181 00E45800   
  9. inlan-rt01(config-pubkey)#$B03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384   
  10. inlan-rt01(config-pubkey)#$C45E2B 340B458B 63DC16E7 AA9FE214 C35941F1   
  11. inlan-rt01(config-pubkey)#$A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2   
  12. inlan-rt01(config-pubkey)#quit   
  13. inlan-rt01(config-pubkey-key)#exit   
  14. inlan-rt01(config-pubkey-chain)#exit   
  15. inlan-rt01(config)#exit   
  16. inlan-rt01#   
  17.  

 

为了确保密钥已经正确输入,我们可以对比一下密钥。在inlan-rt01上,运行<show crypto key pubkey-chain rsa address xxx.xxx.xxx.xxx >命令:

 

 

 

  1. inlan-rt01#sh crypto key pubkey-chain rsa address 172.30.80.17   
  2. Key address: 172.30.80.17   
  3. Usage: General Purpose Key   
  4. Source: Manually entered   
  5. Data:   
  6. 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800   
  7. 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384   
  8. 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1   
  9. E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2   
  10. 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001   
  11. inlan-rt01#   
  12.  

 

然后,在outlan-rt01上运行<show crypto key mypubkey rsa [key label}>:  

 

  1. outlan-rt01#sh crypto key mypubkey rsa outlan-rt01   
  2. % Key pair was generated at: 01:40:40 UTC Apr 25 2002   
  3. Key name: outlan-rt01   
  4. Storage Device: not specified   
  5. Usage: General Purpose Key   
  6. Key is exportable.   
  7. Key Data:   
  8. 30819F30 0D06092A 864886F7 0D010101 05000381 8D003081 89028181 00E45800   
  9. 259A0BB9 D0D1E847 2D9E5045 6EB03D8B 1F03F1F3 C2B93EE6 35888B31 DF2E3384   
  10. 71C7C331 11D6308D E41511C5 ADC45E2B 340B458B 63DC16E7 AA9FE214 C35941F1   
  11. E3A5B136 752D963C 94B7892B B8A5B1F5 D13042D9 6754DDDB 40DAEFD6 D50A0AF2   
  12. 255499F6 448F7F59 E2823792 79696875 48649C7A 22838305 28622634 A3020301 0001   
  13. outlan-rt01#   
  14.  
  15.  

 

在outlan-rt01和inlan-rt01上的密钥互相匹配了。现在我们需要做的就是重复整个过程,这样inlan-rt01的公共RSA密钥就在outlan-rt01的RSA共公密钥链上了。我敢肯定到这个时候你就理解了涉及使用RSA现时标记的做法了。反复提醒自己“安全保证代价不匪——或者不容易”是没有坏处的。

 

【编辑推荐】

  1. 揭秘信息安全至尊利器
  2. 对抗网络钓鱼的关键是合作
  3. 恶意软件的收集与初步分析
责任编辑:佚名 来源: 中国网络
相关推荐

2012-09-26 09:51:11

电子政务数据交换

2009-09-10 11:11:07

pem密钥文件

2023-05-12 15:03:42

安全云平台加密

2018-03-30 15:12:00

安全密钥加密

2009-11-02 12:50:09

2018-03-16 10:57:06

Linux安全密钥

2009-03-02 10:13:00

VTP生成树交换技术

2018-02-09 09:00:00

2010-12-29 17:37:36

网络

2010-05-11 17:50:51

Kerberos认证协

2010-08-09 14:23:33

Flex正则表达式

2013-08-29 11:21:19

Firefox OSiOSAndroid

2012-02-16 08:27:14

安全漏洞RSA算法

2015-06-02 10:15:08

2023-06-08 00:14:57

2009-04-16 18:07:39

2010-01-08 16:11:45

SOHO网络交换机

2021-10-15 14:48:28

鸿蒙HarmonyOS应用

2022-01-09 08:17:52

量子计算机美国加密密钥服务

2012-12-31 10:01:20

点赞
收藏

51CTO技术栈公众号