+ private static PKCS7 toP7Chain(Certificate c) throws IOException, GeneralSecurityException {
+ LinkedList<X509Certificate> ll = getChain(c);
+ PKCS7 p7 = new PKCS7(new AlgorithmId[0], new ContentInfo(ContentInfo.DATA_OID, null), ll.toArray(new X509Certificate[ll.size()]), new SignerInfo[0]);
+ return p7;
+ }
+
+ private static LinkedList<X509Certificate> getChain(Certificate c) throws IOException, GeneralSecurityException {
+ LinkedList<X509Certificate> ll = new LinkedList<>();
+ ll.add(c.cert());
+ CACertificate ca = c.getParent();
+ while ( !ca.isSelfsigned()) {
+ ll.add(ca.getCertificate());
+ ca = ca.getParent();
+ }
+ ll.add(ca.getCertificate());
+ return ll;
+ }
+