GnuTLS PKI setup ================ NOTES: In this test: - We're testing with "CN=localhost" for the server certificate below. However, CN is deprecated, instead 'dnsName' ("Enter a dnsName of the subject of the certificate") is preferred (thanks Nikos Mavrogiannopoulos for this). Except the above, everything else in this setup is identical to the below setup which uses the 'dnsName' entry for the server certificate (instead of "CN" entry): https://kashyapc.fedorapeople.org/gnutls-pki-setup.txt (1) Create the private key for the CA: ----------------------------------------------------------------------- $ certtool --generate-privkey --outfile ca-key.pem Generating a 2048 bit RSA private key... ----------------------------------------------------------------------- (2) Generate the self-signed CA certificate using the above key: ----------------------------------------------------------------------- $ certtool --generate-self-signed --load-privkey ca-key.pem \ --outfile ca-cert.pem Generating a self signed certificate... Please enter the details of the certificate's distinguished name. Just press enter to ignore a field. Common name: UID: Organizational unit name: Organization name: Locality name: State or province name: Country name (2 chars): Enter the subject's domain component (DC): This field should not be used in new certificates. E-mail: Enter the certificate's serial number in decimal (default: 6145006154264725604): Activation/Expiration time. The certificate will expire in (days): 3650 Extensions. Does the certificate belong to an authority? (y/N): y Path length constraint (decimal, -1 for no constraint): Is this a TLS web client certificate? (y/N): Will the certificate be used for IPsec IKE operations? (y/N): Is this a TLS web server certificate? (y/N): Enter a dnsName of the subject of the certificate: Enter a URI of the subject of the certificate: Enter the IP address of the subject of the certificate: Enter the e-mail of the subject of the certificate: Will the certificate be used to sign other certificates? (y/N): y Will the certificate be used to sign CRLs? (y/N): Will the certificate be used to sign code? (y/N): Will the certificate be used to sign OCSP requests? (y/N): y Will the certificate be used for time stamping? (y/N): Enter the URI of the CRL distribution point: X.509 Certificate Information: [. . .] ----------------------------------------------------------------------- (3) Generate a private key for server certificate: ----------------------------------------------------------------------- $ certtool --generate-privkey --outfile server-key.pem Generating a 2048 bit RSA private key... ----------------------------------------------------------------------- (4) Generate the certificate request for the server: ----------------------------------------------------------------------- $ certtool --generate-request --load-privkey server-key.pem \ --outfile server-request.pem Generating a PKCS #10 certificate request... Common name: localhost Organizational unit name: Organization name: Locality name: State or province name: Country name (2 chars): Enter the subject's domain component (DC): UID: Enter a dnsName of the subject of the certificate: Enter a URI of the subject of the certificate: Enter the IP address of the subject of the certificate: Enter the e-mail of the subject of the certificate: Enter a challenge password: Does the certificate belong to an authority? (y/N): Will the certificate be used for signing (DHE and RSA-EXPORT ciphersuites)? (Y/n): Will the certificate be used for encryption (RSA ciphersuites)? (Y/n): Is this a TLS web client certificate? (y/N): Is this a TLS web server certificate? (y/N): ----------------------------------------------------------------------- (5) Generate a server sertificate using the key and request from steps (3) and (4): ----------------------------------------------------------------------- $ certtool --generate-certificate --load-request server-request.pem \ --outfile server-cert.pem --load-ca-certificate ca-cert.pem \ --load-ca-privkey ca-key.pem Enter the certificate's serial number in decimal (default: 6145007640219887502): Activation/Expiration time. The certificate will expire in (days): 3650 Extensions. Do you want to honour the extensions from the request? (y/N): y Does the certificate belong to an authority? (y/N): Is this a TLS web client certificate? (y/N): Will the certificate be used for IPsec IKE operations? (y/N): Is this a TLS web server certificate? (y/N): Enter a dnsName of the subject of the certificate: Enter a URI of the subject of the certificate: Enter the IP address of the subject of the certificate: Enter the e-mail of the subject of the certificate: Will the certificate be used for signing (required for TLS)? (Y/n): Will the certificate be used for encryption (not required for TLS)? (Y/n): X.509 Certificate Information: [. . .] ----------------------------------------------------------------------- (6) Run a GnuTLS server with the certificates created from above: ----------------------------------------------------------------------- $ gnutls-serv --priority=NORMAL -p 9000 \ --x509cafile=/export/security/2gnutls/ca-cert.pem \ --x509certfile=/export/security/2gnutls/server-cert.pem \ --x509keyfile=/export/security/2gnutls/server-key.pem Set static Diffie-Hellman parameters, consider --dhparams. Processed 1 CA certificate(s). HTTP Server listening on IPv4 0.0.0.0 port 9000...done HTTP Server listening on IPv6 :: port 9000...done * Accepted connection from IPv4 127.0.0.1 port 37232 on Mon May 4 15:29:30 2015 - Description: (TLS1.2)-(ECDHE-RSA-SECP256R1)-(AES-128-GCM) - Session ID: B4:86:24:42:0E:EB:24:91:E2:11:AB:6F:B6:35:AC:C4:DA:0E:FC:16:FA:B8:4B:BE:4E:E7:CB:7A:B6:19:BA:9C - Given server name[1]: localhost No certificates found! - Ephemeral EC Diffie-Hellman parameters - Using curve: SECP256R1 - Curve size: 256 bits - Version: TLS1.2 - Key Exchange: ECDHE-RSA - Server Signature: RSA-SHA256 - Cipher: AES-128-GCM - MAC: AEAD - Compression: NULL - Options: safe renegotiation, - Channel binding 'tls-unique': 3bbbbb3582bdcc97e9055c25 Scheduling inactive connection for close ----------------------------------------------------------------------- (7) Use the GnuTLS client to verify the connection: ----------------------------------------------------------------------- $ gnutls-cli --priority=NORMAL -p 9000 --x509cafile=/export/security/2gnutls/ca-cert.pem localhost Resolving 'localhost'... Connecting to '127.0.0.1:9000'... - Certificate type: X.509 - Got a certificate list of 1 certificates. - Certificate[0] info: - subject `CN=localhost', issuer `', RSA key 2048 bits, signed using RSA-SHA256, activated `2015-05-04 13:28:07 UTC', expires `2025-05-01 13:28:09 UTC', SHA-1 fingerprint `3da92ffc1510be660 3e391895a79839f87f01290' Public Key ID: d0e20aff363d98c99cd86820d4aec6f7d5f58f3a Public key's random art: +--[ RSA 2048]----+ | | | . | | . o . | | . . . o | |. o . S . | |. .+ . . . . | |....o* B . . | | + .+.% o E o | |. ...o.. . .o. . | +-----------------+ - Status: The certificate is trusted. - Successfully sent 0 certificate(s) to server. - Description: (TLS1.2)-(ECDHE-RSA-SECP256R1)-(AES-128-GCM) - Session ID: 97:0F:09:6E:9E:6C:A2:22:AA:9F:0B:88:7D:2A:7B:C1:62:09:8B:AF:1E:99:CE:BE:17:7D:EB:39:40:DC:CC:60 - Ephemeral EC Diffie-Hellman parameters - Using curve: SECP256R1 - Curve size: 256 bits - Version: TLS1.2 - Key Exchange: ECDHE-RSA - Server Signature: RSA-SHA256 - Cipher: AES-128-GCM - MAC: AEAD - Compression: NULL - Options: safe renegotiation, - Handshake was completed - Simple Client Mode: - Peer has closed the GnuTLS connection -----------------------------------------------------------------------