Enrolling Cisco IOS for certificates via terminal


In this post we'll go over enrolling Cisco IOS routers for certificates using terminal.  


Generate keys


Firstly we need to generate key pair that we'll then use to create Certificate Signing Request (CSR) that will include our public key. Here we need to decide on the key length. Security wise - the longer the better. It's never that simple though. To this day there are applications that simply do not support anything longer than 2048. This should be taken into consideration. Do we need anything longer than that? We'd have to consider the threat vector. Longer key makes factorization harder. To my knowledge as of writing 1024 bit keys have not been factored. It would take very long time and a lot of very advanced infrastructure to do. This is not a valid threat for most organizations. Key length should be considered in terms of certificate lifetime. The longer the validity the longer they. There also is the CPU overhead we need to take into account. Yes, nowadays CPUs are fast. However, if we consider a large scale deployment with 100s of certificates and for example DMVPNs, using 1024 bit keys vs 2048 can mean significantly more VPNs on single box. 

For the purpose of my lab I'm using 1024 bit keys.


r1(config)#crypto key generate rsa general-keys modulus 1024

To view generated keys:

r1#sh crypto key mypubkey rsa

% Key pair was generated at: 16:46:47 GMT Mar 29 2013
Key name: r1.securesenses.net
 Usage: General Purpose Key
 Key is not exportable.
 Key Data:
--- omitted--- 
% Key pair was generated at: 13:46:55 GMT Mar 30 2013
Key name: r1.securesenses.net.server
 Usage: Encryption Key
 Key is not exportable.
 Key Data:
--- omitted--- 

Import Root CA cert

In order to enrol a router for certificate we need to install the whole trust chain - certifcates of all CA's starting with root CA up to the CA that will issue our certificate. Since we are using terminal enrolment we need certificates in text format so that we can paste them in. For that we will use PEM - "Privacy Enhanced Mail" -  standard. We can recognize PEM format from using 
---BEGIN CERTFICATE--- and ---END CERTIFICATE---- headers and trailers. Between them the certificate is actually represented using Distinguished Encoding Rules - DER - encoding. 


Convert CRT to PEM

Windows Certificate MMC does not allow for saving certificates in PEM format. We will need to convert the .CRT to .PEM. OpenSSL library is what we will use. 

At command prompt:

openssl x509 -in ROOT-CA.crt -inform der -out ROOT-CA.pem -outform pem


Install ROOT CA certificate:

Create a trustpoint for the CA root certificate.

R1(config)#crypto ca trustpoint ORCA1-CA
R1(ca-trustpoint)#enrollment terminal PEM
R1(ca-trustpoint)#crl optional 
R1(ca-trustpoint)#exit

Import the CA root certificate with copy and paste.

r1(config)#crypto ca authenticate ORCA1-CA

Enter the base 64 encoded CA certificate.
End with a blank line or the word "quit" on a line by itself

-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

Certificate has the following attributes:
       Fingerprint MD5: E9FD8A22 E82C13EF 5DB781A7 616AD113 
       Fingerprint SHA1: 6085A54F 1A6A67B1 7F8DC1A9 54F995AD
                         8DA49D21 

% Do you accept this certificate? [yes/no]: yes
Trustpoint CA certificate accepted.
% Certificate successfully imported

Confirm that hash matches the hash in the .CRT encoded cert we started with.



Install Sub-ordinate CA certificate:

We repeat above steps in order to install Subordinate CA certififcate. This is required so that we can validate full certificate chain. 
This time we should get the following message:

Certificate validated - Signed by existing trustpoint CA certificate.

Trustpoint CA certificate accepted.
% Certificate successfully imported


Verify certificates have been installed and associated to trustpoints:

r1#show crypto pki certificates
CA Certificate
  Status: Available
  Certificate Serial Number: 4D00000002924DEC093140270B000000000002
  Certificate Usage: Signature
  Issuer:
    cn=ORCA1-CA
  Subject:
    cn=IssuingCA-DC1
    dc=kp
    dc=local
  CRL Distribution Points:
    http://dc1.kp.local/ORCA1-CA.crl
  Validity Date:
    start date: 13:44:58 GMT Mar 14 2013
    end   date: 13:54:58 GMT Mar 14 2014
  Associated Trustpoints: SubCa

CA Certificate
  Status: Available
  Certificate Serial Number: 37A15821A55DD2864B62A67B6EFD5429
  Certificate Usage: Signature
  Issuer:
    cn=ORCA1-CA
  Subject:
    cn=ORCA1-CA
  Validity Date:
    start date: 16:03:12 GMT Mar 13 2013
    end   date: 16:13:12 GMT Mar 13 2023
  Associated Trustpoints: ORCA1-CA


Generate Certificate Signing Request (CSR)

r1(config)#crypto pki enroll SubCa
% Start certificate enrollment ..

% The subject name in the certificate will include: r1.securesenses.net
% Include the router serial number in the subject name? [yes/no]: yes
% The serial number in the certificate will be: FF1045C5
% Include an IP address in the subject name? [no]: no
Display Certificate Request to terminal? [yes/no]: yes
Certificate Request follows:

-----BEGIN CERTIFICATE REQUEST-----
-----END CERTIFICATE REQUEST-----

---End - This line is not part of the certificate request---

Redisplay enrolment request? [yes/no]: no

Copy everything between ---- BEGIN C..---- and ----END C..---- inclusive to a text file and save as .csr. Make sure you use a notepad so that no additional encoding is added.


Sign the request:

The request does not contain template information. Therefore we have supply in the request. For that we need to use certreq.exe utility.

C:\> certreq -submit -attrib CertificateTemplate:RouterCert .\r1.req r1.pem

Alternately we can omit the output file name and use GUI to save to CRT or CER format which we then convert to PEM using the following command:

openssl x509 -in r1.cer -out r1.pem -outform PEM



Import Router Certificate:

r1(config)#crypto pki import SubCa certificate

Enter the base 64 encoded certificate.
End with a blank line or the word "quit" on a line by itself

------BEGIN CERTIFICATE-----
------END CERTIFICATE-----


% Router Certificate successfully imported


Verify certificate import:

r1#show crypto pki certificates
Certificate
  Status: Available
  Certificate Serial Number: 6D00000017F99CF9DB55D020E5000000000017
  Certificate Usage: General Purpose
  Issuer:
    cn=IssuingCA-DC1
    dc=kp
    dc=local
  Subject:
    Name: r1.securesenses.net
    Serial Number: FF1045C5
    hostname=r1.securesenses.net
    serialNumber=FF1045C5
  CRL Distribution Points:
    http://dc1.kp.local/pki/IssuingCA-DC1.crl
  Validity Date:
    start date: 00:03:38 GMT Apr 1 2013
    end   date: 13:54:58 GMT Mar 14 2014
  Associated Trustpoints: SubCa


Cisco KB reference:

http://www.cisco.com/en/US/products/hw/modules/ps2706/products_configuration_example09186a008037d1c8.shtml

No comments:

Post a Comment