I am working on a distributed application with several unique subordinate processes that will interact with the main application through SSL-compatible sockets. The application is written in java.
I need help understanding SSLSockets, or rather, the certificates that they use.
What I'm looking for is someone who can tell me if I understood correctly the basic actions of certificate chains, but I would not say no as an example code.
I need a setting in which the server itself has a certificate with a CA certificate, and each subordinate will receive their own certificate created by the main application.
CA->Main server cert->Master SSL cert CA->Main server cert->Slave SSL cert 1 CA->Main server cert->Slave SSL cert 2 CA->Main server cert->Slave SSL cert 3
First question: is this certificate chain the right way to solve this problem? I think this is the easiest way to reach the master, and the slaves all have a unique identity, without forcing the CA to sign each certificate.
Second question: How am I going to programmatically create an SSL certificate in java? I am trying to create the last certificate in the chain here, assuming that I already have a "Master Server Certificate". So far I have received the key for the certificate (where is the RSA type):
public KeyPair generateKeypair(String type, int bytes) throws NoSuchAlgorithmException{ KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(type); keyPairGenerator.initialize(bytes); return keyPairGenerator.generateKeyPair(); } X509Principal issuer = PrincipalUtil.getSubjectX509Principal(serverCert); SubjectPublicKeyInfo key = SubjectPublicKeyInfo.getInstance(kpair.getPublic().getEncoded()); X509v3CertificateBuilder certGen = new X509v3CertificateBuilder( issuer, BigInteger.valueOf(new SecureRandom().nextInt()), before, after, subject, key ); AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA"); AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
I do not assume that setting serverCert as an issuer is enough to sign a certificate? As I understand it, I need to somehow sign a new certificate with the next certificate in the chain, but how to do it? I sign the certificate using the serverCert private key, for example:
AsymmetricKeyParameter akp = PrivateKeyFactory.createKey(serverPrivateKey.getEncoded()); AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA"); AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId); ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(akp);
Are there any other steps that I skipped?