I am having trouble getting a SSL connection to work. I did a lot of research on the web, but i am still missing some understanding it seems. I hope you can help me. I generate a development certificate chain: RootCA -> SubCA -> Server
I generate them like this
openssl req -batch -x509 -config ${ROOTCA_CONFIG} -newkey rsa:2048 -sha1 -nodes -out ${ROOTCA_CERT} -outform PEM -days 7300
openssl req -batch -config ${SUBCA_CONFIG} -newkey rsa:2048 -sha1 -nodes -out ${SUBCA_CSR} -outform PEM
openssl ca -batch -config ${ROOTCA_CONFIG} -policy signing_policy -extensions signing_req_CA -out ${SUBCA_CERT} -infiles ${SUBCA_CSR}
I then add the RootCA certificate to my Java trust store and the client certificate to the key store. That is the first thing that puzzles me: The SubCA Cert has the plaintext information i expect. The Root CA only has cryptographic information (the part between BEGIN and END CERTIFICATE. Is this to be exptected? My SubCA Cert looks like this, i truncated the crypto part:
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C=DE, O=Company, CN=Root CA 2016
Validity
Not Before: Oct 20 11:59:57 2016 GMT
Not After : Oct 18 11:59:57 2024 GMT
Subject: C=DE, O=Company, CN=SubCA 2016
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:ae:0b:94:36:76:7c:34:d8:37:61:44:5f:1c:68:
...
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
43:2E:0E:EB:66:C6:2F:AC:1B:24:C7:95:48:92:95:6E:E3:E0:83:1E
X509v3 Authority Key Identifier:
keyid:19:6B:27:27:F8:9F:56:E3:07:E7:AB:51:1E:15:DC:F8:F1:96:D5:35
X509v3 Basic Constraints: critical
CA:TRUE
X509v3 Key Usage:
Digital Signature, Certificate Sign, CRL Sign
X509v3 CRL Distribution Points:
Full Name:
URI:http://crl.url
Authority Information Access:
CA Issuers - URI:http://downloads.some.url
I then create a server certificate (variable names call it client, since it is used for generating both):
openssl req -batch -config ${CLIENT_CONFIG} -newkey rsa:2048 -sha256 -nodes -out ${CLIENT_CSR} -outform PEM -keyout $1.key
openssl ca -batch -config ${SUBCA_CONFIG} -policy signing_policy -extensions signing_req -out ${CLIENT_CERT} -infiles ${CLIENT_CSR}
The server cert looks like this:
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C=DE, O=Company, CN=SubCA 2016
Validity
Not Before: Oct 20 12:18:18 2016 GMT
Not After : Oct 20 12:18:18 2018 GMT
Subject: C=DE, ST=Bayern, L=Mytown, O=Company, OU=OU, CN=My Server
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
...
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
53:C6:01:AB:E4:AA:C4:A4:BC:8B:2D:45:9C:92:40:5D:59:B7:AD:A0
X509v3 Authority Key Identifier:
keyid:43:2E:0E:EB:66:C6:2F:AC:1B:24:C7:95:48:92:95:6E:E3:E0:83:1E
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 CRL Distribution Points:
Full Name:
URI:http://crl.url.de/some.crl
Authority Information Access:
CA Issuers - URI:http://some.url.de/rootcacert2016.cert
X509v3 Extended Key Usage:
TLS Web Client Authentication
X509v3 Subject Alternative Name:
DNS:localhost, DNS:127.0.0.1, DNS:some.url.de
Signature Algorithm: sha256WithRSAEncryption
...
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
Now i would like to verify the generated certificate. This fails with the message
error 2 at 1 depth lookup:unable to get issuer certificate
If verifies correctly if i concatenate SubCA and CA file into a single file. Is this also correct? I expected the certificate to be verifiable with each certificate?
And now to my problem: When i try to connect to my service, it provides its server certificate. I checked it with wireshark, to be sure. The client then fails authenticating with the message
“unable to find valid certification path to requested target"
I exported the server certificate as PKCS12 token and imported it into my java keystore. Im imported the ca/subca certificates into my truststore. This is presented by the server as expected. So i guess i messed up the certificate chain somehow. Since the concatenated certficate files worked so nicely with openssl, i tried to import that into my truststore. This leads to only have the subca certificate, so i guess this does now work. When i import both individually, the certificate list is fine. However, the certification path somehow is not right. Can you give me a hand? I am getting a bit frustrated...
Update: This is the root certificate:
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 13418448032209606381 (0xba37e7642ce496ed)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=DE, O=Company, CN=IDS Root CA 2016
Validity
Not Before: Oct 20 11:59:57 2016 GMT
Not After : Oct 15 11:59:57 2036 GMT
Subject: C=DE, O=Fraunhofer, CN=IDS Root CA 2016
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
...
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
19:6B:27:27:F8:9F:56:E3:07:E7:AB:51:1E:15:DC:F8:F1:96:D5:35
X509v3 Authority Key Identifier:
keyid:19:6B:27:27:F8:9F:56:E3:07:E7:AB:51:1E:15:DC:F8:F1:96:D5:35
X509v3 Basic Constraints: critical
CA:TRUE
X509v3 Key Usage:
Non Repudiation, Certificate Sign, CRL Sign
Signature Algorithm: sha1WithRSAEncryption
...
This is my config file to create the server cert:
HOME = .
RANDFILE = $ENV::HOME/.rnd
####################################################################
[ req ]
default_bits = 2048
#default_keyfile = connector.key
distinguished_name = connector_distinguished_name
req_extensions = connector_req_extensions
string_mask = utf8only
####################################################################
[ connector_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = DE
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = Bayern
localityName = Locality Name (eg, city)
localityName_default = Muenchen
organizationName = Organization Name (eg, company)
organizationName_default = Company
organizationalUnitName = Organizational Unit Name (department, division)
organizationalUnitName_default = OU
commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = Test Server
emailAddress = Email Address
emailAddress_default = [email protected]
####################################################################
[ connector_req_extensions ]
subjectKeyIdentifier = hash
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment, nonRepudiation
extendedKeyUsage = clientAuth
#securityProfile = ASN1:UTF8:IDS Security Profile Specification
#subjectAltName = URI:UUID:%%DEVICE_UUID%%
subjectAltName = @alternate_names
[ alternate_names ]
DNS.1 = localhost
DNS.2 = 127.0.0.1
DNS.3 = some.url.com
If verifies correctly if i concatenate SubCA and CA file into a single file. Is this also correct?
-- nope. this indicates that your AIA extension is incorrect and issuer certificate is not available at specified URL.Authority Information Access
extension with URLs to locate issuer certificate.