@Override public void setValue(Object value) { setCharArrayValue((char[]) value); }
private Key getKeyObject(Session session, Key template, byte[] keyId, char[] keyLabel) throws P11TokenException { if (keyId != null) { template.getId().setByteArrayValue(keyId); } if (keyLabel != null) { template.getLabel().setCharArrayValue(keyLabel); } List<Storage> tmpObjects = getObjects(session, template, 2); if (CollectionUtil.isEmpty(tmpObjects)) { return null; } int size = tmpObjects.size(); if (size > 1) { LOG.warn("found {} public key identified by {}, use the first one", size, getDescription(keyId, keyLabel)); } return (Key) tmpObjects.get(0); }
private X509PublicKeyCertificate getCertificateObject(Session session, byte[] keyId, char[] keyLabel) throws P11TokenException { X509PublicKeyCertificate template = new X509PublicKeyCertificate(); if (keyId != null) { template.getId().setByteArrayValue(keyId); } if (keyLabel != null) { template.getLabel().setCharArrayValue(keyLabel); } List<Storage> tmpObjects = getObjects(session, template, 2); if (CollectionUtil.isEmpty(tmpObjects)) { LOG.info("found no certificate identified by {}", getDescription(keyId, keyLabel)); return null; } int size = tmpObjects.size(); if (size > 1) { LOG.warn("found {} public key identified by {}, use the first one", size, getDescription(keyId, keyLabel)); } return (X509PublicKeyCertificate) tmpObjects.get(0); }
private X509PublicKeyCertificate[] getCertificateObjects(Session session, byte[] keyId, char[] keyLabel) throws P11TokenException { X509PublicKeyCertificate template = new X509PublicKeyCertificate(); if (keyId != null) { template.getId().setByteArrayValue(keyId); } if (keyLabel != null) { template.getLabel().setCharArrayValue(keyLabel); } List<Storage> tmpObjects = getObjects(session, template); if (CollectionUtil.isEmpty(tmpObjects)) { LOG.info("found no certificate identified by {}", getDescription(keyId, keyLabel)); return null; } int size = tmpObjects.size(); X509PublicKeyCertificate[] certs = new X509PublicKeyCertificate[size]; for (int i = 0; i < size; i++) { certs[i] = (X509PublicKeyCertificate) tmpObjects.get(i); } return certs; }
private Key getKeyObject(final Key template, final byte[] keyId, final char[] keyLabel) throws P11TokenException { ConcurrentBagEntry<Session> session0 = borrowSession(); try { if (keyId != null) { template.getId().setByteArrayValue(keyId); } if (keyLabel != null) { template.getLabel().setCharArrayValue(keyLabel); } Session session = session0.value(); List<Storage> tmpObjects = getObjects(session, template, 2); if (CollectionUtil.isEmpty(tmpObjects)) { return null; } int size = tmpObjects.size(); if (size > 1) { LOG.warn("found {} public key identified by {}, use the first one", size, getDescription(keyId, keyLabel)); } return (Key) tmpObjects.get(0); } finally { sessions.requite(session0); } }
@Override public int removeObjects(final byte[] id, final String label) throws P11TokenException { if ((id == null || id.length == 0) && StringUtil.isBlank(label)) { throw new IllegalArgumentException("at least one of id and label must not be null"); } Key keyTemplate = new Key(); if (id != null && id.length > 0) { keyTemplate.getId().setByteArrayValue(id); } if (StringUtil.isNotBlank(label)) { keyTemplate.getLabel().setCharArrayValue(label.toCharArray()); } String objIdDesc = getDescription(id, label); int num = removeObjects(keyTemplate, "keys " + objIdDesc); X509PublicKeyCertificate certTemplate = new X509PublicKeyCertificate(); if (id != null && id.length > 0) { certTemplate.getId().setByteArrayValue(id); } if (StringUtil.isNotBlank(label)) { certTemplate.getLabel().setCharArrayValue(label.toCharArray()); } num += removeObjects(certTemplate, "certificates" + objIdDesc); return num; }
private X509PublicKeyCertificate[] getCertificateObjects(final byte[] keyId, final char[] keyLabel) throws P11TokenException { X509PublicKeyCertificate template = new X509PublicKeyCertificate(); if (keyId != null) { template.getId().setByteArrayValue(keyId); } if (keyLabel != null) { template.getLabel().setCharArrayValue(keyLabel); } List<Storage> tmpObjects; ConcurrentBagEntry<Session> session = borrowSession(); try { tmpObjects = getObjects(session.value(), template); } finally { sessions.requite(session); } if (CollectionUtil.isEmpty(tmpObjects)) { LOG.info("found no certificate identified by {}", getDescription(keyId, keyLabel)); return null; } int size = tmpObjects.size(); X509PublicKeyCertificate[] certs = new X509PublicKeyCertificate[size]; for (int i = 0; i < size; i++) { certs[i] = (X509PublicKeyCertificate) tmpObjects.get(i); } return certs; }
private static boolean labelExists(final Session session, final String keyLabel) throws P11TokenException { ParamUtil.requireNonBlank("keyLabel", keyLabel); Key key = new Key(); key.getLabel().setCharArrayValue(keyLabel.toCharArray()); Object[] objects; try { session.findObjectsInit(key); objects = session.findObjects(1); session.findObjectsFinal(); if (objects.length > 0) { return true; } X509PublicKeyCertificate cert = new X509PublicKeyCertificate(); cert.getLabel().setCharArrayValue(keyLabel.toCharArray()); session.findObjectsInit(cert); objects = session.findObjects(1); session.findObjectsFinal(); } catch (TokenException ex) { throw new P11TokenException(ex.getMessage(), ex); } return objects.length > 0; }
private int removeObjects(byte[] id, char[] label) throws P11TokenException { boolean labelNotBlank = (label != null && label.length != 0); if ((id == null || id.length == 0) && !labelNotBlank) { throw new IllegalArgumentException("at least one of id and label may not be null"); } Key keyTemplate = new Key(); if (id != null && id.length > 0) { keyTemplate.getId().setByteArrayValue(id); } if (labelNotBlank) { keyTemplate.getLabel().setCharArrayValue(label); } String objIdDesc = getDescription(id, label); int num = removeObjects(keyTemplate, "keys " + objIdDesc); X509PublicKeyCertificate certTemplate = new X509PublicKeyCertificate(); if (id != null && id.length > 0) { certTemplate.getId().setByteArrayValue(id); } if (labelNotBlank) { certTemplate.getLabel().setCharArrayValue(label); } num += removeObjects(certTemplate, "certificates" + objIdDesc); return num; }
newCertTemp.getLabel().setCharArrayValue(control.getLabel().toCharArray());
private static X509PublicKeyCertificate createPkcs11Template(final X509Cert cert, final byte[] keyId, final char[] label) { if (label == null || label.length == 0) { throw new IllegalArgumentException("label must not be null or empty"); } X509PublicKeyCertificate newCertTemp = new X509PublicKeyCertificate(); newCertTemp.getId().setByteArrayValue(keyId); newCertTemp.getLabel().setCharArrayValue(label); newCertTemp.getToken().setBooleanValue(true); newCertTemp.getCertificateType().setLongValue(CertificateType.X_509_PUBLIC_KEY); newCertTemp.getSubject().setByteArrayValue( cert.cert().getSubjectX500Principal().getEncoded()); newCertTemp.getIssuer().setByteArrayValue( cert.cert().getIssuerX500Principal().getEncoded()); newCertTemp.getSerialNumber().setByteArrayValue( cert.cert().getSerialNumber().toByteArray()); newCertTemp.getValue().setByteArrayValue(cert.encodedCert()); return newCertTemp; }
private static void setKeyAttributes(final String label, final long keyType, final P11NewKeyControl control, final PublicKey publicKey, final PrivateKey privateKey) { if (privateKey != null) { privateKey.getToken().setBooleanValue(true); privateKey.getLabel().setCharArrayValue(label.toCharArray()); privateKey.getKeyType().setLongValue(keyType); privateKey.getSign().setBooleanValue(true); privateKey.getPrivate().setBooleanValue(true); privateKey.getSensitive().setBooleanValue(true); privateKey.getExtractable().setBooleanValue(control.isExtractable()); } if (publicKey != null) { publicKey.getToken().setBooleanValue(true); publicKey.getLabel().setCharArrayValue(label.toCharArray()); publicKey.getKeyType().setLongValue(keyType); publicKey.getVerify().setBooleanValue(true); publicKey.getModifiable().setBooleanValue(Boolean.TRUE); } }
private static boolean labelExists(Session session, char[] keyLabel) throws P11TokenException { Args.notNull(keyLabel, "keyLabel"); Key key = new Key(); key.getLabel().setCharArrayValue(keyLabel); cert.getLabel().setCharArrayValue(keyLabel);
template.getLabel().setCharArrayValue(label.toCharArray()); template.getSign().setBooleanValue(true); template.getSensitive().setBooleanValue(true);
template.getLabel().setCharArrayValue(label.toCharArray()); template.getSign().setBooleanValue(true); template.getSensitive().setBooleanValue(true);
privateKey.getToken().setBooleanValue(true); if (!newObjectConf.isIgnoreLabel()) { privateKey.getLabel().setCharArrayValue(control.getLabel().toCharArray()); publicKey.getToken().setBooleanValue(true); if (!newObjectConf.isIgnoreLabel()) { publicKey.getLabel().setCharArrayValue(control.getLabel().toCharArray());
template.getLabel().setCharArrayValue(labelChars);
template.getLabel().setCharArrayValue(labelChars);