public P11Identity getIdentity(P11ObjectIdentifier keyId) throws P11UnknownEntityException { P11Identity ident = identities.get(keyId); if (ident == null) { throw new P11UnknownEntityException(slotId, keyId); } return ident; }
public P11SlotIdentifier getSlotIdForIndex(int index) throws P11UnknownEntityException { for (P11SlotIdentifier id : slotIds) { if (id.getIndex() == index) { return id; } } throw new P11UnknownEntityException("could not find slot with index " + index); }
public P11SlotIdentifier getSlotIdForId(long id) throws P11UnknownEntityException { for (P11SlotIdentifier slotId : slotIds) { if (slotId.getId() == id) { return slotId; } } throw new P11UnknownEntityException("could not find slot with id " + id); }
/** * Returns slot for the given {@code slotId}. * * @param slotId * slot identifier. Must not be {@code null}. * @return the slot * @throws P11TokenException * if PKCS#11 token error occurs */ public P11Slot getSlot(P11SlotIdentifier slotId) throws P11TokenException { Args.notNull(slotId, "slotId"); P11Slot slot = slots.get(slotId); if (slot == null) { throw new P11UnknownEntityException(slotId); } return slot; } // method gestSlot
/** * Exports the certificate of the given identifier {@code objectId}. * * @param objectId * Object identifier. Must not be {@code null}. * @return the exported certificate * @throws CertificateException * if process with certificate fails. * @throws P11TokenException * if PKCS#11 token exception occurs. */ public X509Certificate exportCert(P11ObjectIdentifier objectId) throws P11TokenException { Args.notNull(objectId, "objectId"); try { return getIdentity(objectId).getCertificate(); } catch (P11UnknownEntityException ex) { // CHECKSTYLE:SKIP } X509Cert cert = certificates.get(objectId); if (cert == null) { throw new P11UnknownEntityException(slotId, objectId); } return cert.getCert(); }
/** * TODO. * @param objectId * Object identifier. Must not be {@code null}. * @throws P11TokenException * if PKCS#11 token exception occurs. */ public void removeCerts(P11ObjectIdentifier objectId) throws P11TokenException { Args.notNull(objectId, "objectId"); assertWritable("removeCerts"); P11ObjectIdentifier keyId = null; for (P11ObjectIdentifier m : identities.keySet()) { P11Identity identity = identities.get(m); if (objectId.equals(identity.getId().getCertId())) { keyId = m; break; } } if (keyId != null) { certificates.remove(objectId); identities.get(keyId).setCertificates(null); } else if (certificates.containsKey(objectId)) { certificates.remove(objectId); } else { throw new P11UnknownEntityException(slotId, objectId); } updateCaCertsOfIdentities(); removeCerts0(objectId); }
throw new P11UnknownEntityException("could not find private key " + keyId);
@Override protected void removeIdentity0(P11IdentityId identityId) throws P11TokenException { P11ObjectIdentifier keyId = identityId.getKeyId(); boolean b1 = true; if (identityId.getCertId() != null) { removePkcs11Entry(certDir, identityId.getCertId()); } boolean b2 = removePkcs11Entry(privKeyDir, keyId); boolean b3 = true; if (identityId.getPublicKeyId() != null) { b3 = removePkcs11Entry(pubKeyDir, identityId.getPublicKeyId()); } boolean b4 = removePkcs11Entry(secKeyDir, keyId); if (! (b1 || b2 || b3 || b4)) { throw new P11UnknownEntityException(slotId, keyId); } }