use of ch.cyberduck.core.keychain.SecCertificateRef in project cyberduck by iterate-ch.
the class KeychainCertificateStore method toX509Certificate.
public static X509Certificate toX509Certificate(final SecIdentityRef identityRef) {
final PointerByReference reference = new PointerByReference();
int err;
err = SecurityFunctions.library.SecIdentityCopyCertificate(identityRef, reference);
if (0 != err) {
log.error(String.format("SecIdentityCopyCertificate returning error %d", err));
return null;
}
final SecCertificateRef certificateRef = new SecCertificateRef(reference.getValue());
try {
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
final NSData dataRef = SecurityFunctions.library.SecCertificateCopyData(certificateRef);
final X509Certificate selected = (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(dataRef.base64Encoding())));
if (log.isDebugEnabled()) {
log.info(String.format("Selected certificate %s", selected));
}
FoundationKitFunctions.library.CFRelease(certificateRef);
return selected;
} catch (CertificateException e) {
log.error(String.format("Error %s creating certificate from reference", e));
return null;
}
}
use of ch.cyberduck.core.keychain.SecCertificateRef in project cyberduck by iterate-ch.
the class KeychainCertificateStore method toDEREncodedCertificates.
public static NSArray toDEREncodedCertificates(final List<X509Certificate> certificates) {
// Prepare the certificate chain
try {
final Object[] encoded = new DEREncoder().encode(certificates);
} catch (CertificateException e) {
log.error(String.format("Failure %s DER encoding certificates %s", e, certificates));
return NSArray.array();
}
final NSMutableArray certs = NSMutableArray.arrayWithCapacity(new NSUInteger(certificates.size()));
for (X509Certificate certificate : certificates) {
try {
final SecCertificateRef certificateRef = SecurityFunctions.library.SecCertificateCreateWithData(null, NSData.dataWithBase64EncodedString(Base64.encodeBase64String(certificate.getEncoded())));
if (null == certificateRef) {
log.error(String.format("Error creating converting from ASN.1 DER encoded certificate %s", certificate));
continue;
}
certs.addObject(certificateRef);
} catch (CertificateEncodingException e) {
log.error(String.format("Failure %s retrieving encoded certificate", e));
}
}
return certs;
}
Aggregations