/** * Adds the certificate to the PKCS#11 token under the given identifier {@code objectId}. * * @param cert * Certificate to be added. Must not be {@code null}. * @param control * Control of the object creation process. Must not be {@code null}. * @throws CertificateException * if process with certificate fails. * @throws P11TokenException * if PKCS#11 token exception occurs. */ public P11ObjectIdentifier addCert(X509Certificate cert, P11NewObjectControl control) throws P11TokenException, CertificateException { ParamUtil.requireNonNull("cert", cert); ParamUtil.requireNonNull("control", control); assertWritable("addCert"); if (control.getLabel() == null) { String cn = X509Util.getCommonName(cert.getSubjectX500Principal()); control = new P11NewObjectControl(control.getId(), generateLabel(cn)); } P11ObjectIdentifier objectId = addCert0(cert, control); certificates.put(objectId, new X509Cert(cert)); updateCaCertsOfIdentities(); LOG.info("added certificate {}", objectId); return objectId; }
/** * Adds the certificate to the PKCS#11 token under the given identifier {@code objectId}. * * @param cert * Certificate to be added. Must not be {@code null}. * @param control * Control of the object creation process. Must not be {@code null}. * @throws CertificateException * if process with certificate fails. * @throws P11TokenException * if PKCS#11 token exception occurs. */ public P11ObjectIdentifier addCert(X509Certificate cert, P11NewObjectControl control) throws P11TokenException, CertificateException { Args.notNull(cert, "cert"); Args.notNull(control, "control"); assertWritable("addCert"); if (control.getLabel() == null) { String cn = X509Util.getCommonName(cert.getSubjectX500Principal()); control = new P11NewObjectControl(control.getId(), generateLabel(cn)); } P11ObjectIdentifier objectId = addCert0(cert, control); certificates.put(objectId, new X509Cert(cert)); updateCaCertsOfIdentities(); LOG.info("added certificate {}", objectId); return objectId; }