I have a Java truststore foo.p12 which contains multiple public certificates such as RootCA certificates, Intermediate RootCA certificates signed by its RootCA, end entity server certificates issued by Intermediate RootCA (For example foo.p12 contains RootCA_1, IntermediateCA_1, EndEntity_1, RootCA_2, IntermediateCA_2, EndEntity_2).
I have a requirement, given the rootca_1 or EndEntity_1 as input, I need to read foo.p12 and retrieve all the certificate chain corresponding to rootca_1 or EndEntity_1.
I checked this link which has similar question, but the answers are not updated and also it does not give the solution to my problem. There is another link, but this again returns all the certificates under foo.p12 but not the certificate chains as I require.
Is there any Java solutions (JCE API's or Bouncy Castle API's etc) which could return the certificate chain given the rootCA or end entity certificate?