Dan Griffin's Blog
Comments on security, PKI, smart cards, cryptography, and entrepreneurship.
Testing & Debugging IPsec Security Associations
October 5, 2007
I was recently doing some IPsec debugging and found myself in a situation where I needed to know exactly which machine certificate was being used for the AuthIP authentication. That is, it wasn’t enough to know that the connection was established; I needed to ensure it was using right cert. Unfortunately, the IP Security Monitor MMC snap-in doesn’t help - it gives the source, destination, authentication method, and encryption algs, but it doesn’t give the identity of the cert.
Ditto fo netsh.exe, which gives roughly the same information:
>netsh ipsec dynamic show mmsas
IKE Main Mode SAs at 10/2/2007 9:51:31 AM
———————————————————————-
Cookie Par :clclb5a7f901784c:374d415ff84d7e99
Sec Methods :3DES/SHA 1/2/28800
Auth Mode :RSA Signature
Source :192.168.1.177 ,port 500
Destination :192.168.1.184 , port 500
But then it occurred to me that the IPsecPing.exe sample could probably be extended to provide this information. Sure enough! The IKEEXT_CERTIFICATE_CREDENTIAL0 structure is populated with a cert hash, and is included in the IKEEXT_CREDENTIAL0 structure when its IKEEXT_AUTHENTICATION_METHOD_TYPE is set to IKEEXT_CERTIFICATE (see iketypes.h in the SDK). Simple matter to dump that hash out to the console with everything else.
First delete the existing security associations:
>netsh ipsec dynamic delete sa
OK.
Then run the new and improved IPsecPing (noting the new cert hash displayed in the middle of the fourth line of output):
>IPSecPing.exe -v -4 jwsecure-v8
Create socket <AF_INET, SOCK_STREAM, IPPROTO_TCP>, return code=0
TCP over IPsec connect to dest: jwsecure-v8, addr 192.168.1.184:135…
TCP over IPSec WSAConnect: success, 0.09s from 192.168.1.177:49723 to 192.168.1.184:135
IKEMM: 3DES, SHA1, DH_2, Certificate [ D30D68BE5288FE2EDAEFF20E204E0F1BE2D0E3FE ], 28800s,
192.168.1.177, 192.168.1.184, icookie=0xa7b5c1c1, rcookie=0×5f414d37
IKEQM: transport, SHA1, 3DES, 100000kb, 3600s, 192.168.1.177, 192.168.1.184, idletime=300s
Disconnecting, IKE MM and QM deleted
Then feed that hash to certutil to verify it’s the one I’m expecting: >certutil.exe -store MY D30D68BE5288FE2EDAEFF20E204E0F1BE2D0E3FE MY ================ Certificate 0 ================ Serial Number: 19448d66000000000027
Issuer: CN=LHTest-CA1, DC=LHTest, DC=local NotBefore: 9/28/2007 5:45 PM NotAfter: 9/27/2008 5:45 PM Subject: EMPTY (DNS Name=jwsecure-v6.LHTest.local)
Non-root Certificate Template: Workstation, Workstation Authentication Cert Hash(sha1): d3 0d 68 be 52 88 fe 2e da ef f2 0e 20 4e 0f 1b e2 d0 e3 fe
Key Container = 52170cddeeaf13800cf207cbdf975d48_e0d1ac96-454a-4e9d-acd5-01f307e67f97 Provider = Microsoft RSA SChannel Cryptographic Provider Private key is NOT exportable Encryption test passed CertUtil: -store command completed successfully.
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL