public void setCertLabel(String certLabel) { if (certLabel != null) { this.certId = certLabel.equals(keyId.getLabel()) ? keyId : new P11ObjectIdentifier(keyId.getId(), certLabel); } else { this.certId = null; } }
private P11Identity saveP11Entity(final SecretKey key, final String label) throws P11TokenException { byte[] id = generateId(); savePkcs11SecretKey(id, label, key); P11EntityIdentifier identityId = new P11EntityIdentifier(slotId, new P11ObjectIdentifier(id, label)); try { return new EmulatorP11Identity(this,identityId, key, maxSessions, random); } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException ex) { throw new P11TokenException( "could not construct KeyStoreP11Identity: " + ex.getMessage(), ex); } }
private P11Identity saveP11Entity(final KeyPair keypair, final String label) throws P11TokenException { byte[] id = generateId(); savePkcs11PrivateKey(id, label, keypair.getPrivate()); savePkcs11PublicKey(id, label, keypair.getPublic()); P11EntityIdentifier identityId = new P11EntityIdentifier(slotId, new P11ObjectIdentifier(id, label)); try { return new EmulatorP11Identity(this,identityId, keypair.getPrivate(), keypair.getPublic(), null, maxSessions, random); } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException ex) { throw new P11TokenException( "could not construct KeyStoreP11Identity: " + ex.getMessage(), ex); } }
private ObjectIdentifier(ASN1Sequence seq) throws BadAsn1ObjectException { requireRange(seq, 2, 2); int idx = 0; byte[] id = getOctetStringBytes(seq.getObjectAt(idx++)); String label = getUtf8String(seq.getObjectAt(idx++)); this.value = new P11ObjectIdentifier(id, label); }
@Override public P11ObjectIdentifier addCert(final X509Certificate cert) throws P11TokenException, CertificateException { ParamUtil.requireNonNull("cert", cert); assertWritable("addCert"); byte[] encodedCert = cert.getEncoded(); for (P11ObjectIdentifier objectId : certificates.keySet()) { X509Cert tmpCert = certificates.get(objectId); if (Arrays.equals(encodedCert, tmpCert.encodedCert())) { return objectId; } } byte[] id = generateId(); String cn = X509Util.getCommonName(cert.getSubjectX500Principal()); String label = generateLabel(cn); P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, label); addCert(objectId, cert); return objectId; }
private P11Identity saveP11Entity(SecretKey key, P11NewObjectControl control) throws P11TokenException { byte[] id = control.getId(); if (id == null) { id = generateId(); } assertValidId(id); String label = control.getLabel(); savePkcs11SecretKey(id, label, key); P11IdentityId identityId = new P11IdentityId(slotId, new P11ObjectIdentifier(id, label), null, null); return new EmulatorP11Identity(this,identityId, key, maxSessions, random); }
/** * TODO. * @param slotId * Slot identifier. Must not be {@code null}. * @param keyId * Object identifier. Must not be {@code null}. * @param publicKeyLabel * Label of the public key * @param certLabel * Label of the certificate */ public P11IdentityId(P11SlotIdentifier slotId, P11ObjectIdentifier keyId, String publicKeyLabel, String certLabel) { this.slotId = ParamUtil.requireNonNull("slotId", slotId); this.keyId = ParamUtil.requireNonNull("keyId", keyId); if (publicKeyLabel != null) { this.publicKeyId = publicKeyLabel.equals(keyId.getLabel()) ? keyId : new P11ObjectIdentifier(keyId.getId(), publicKeyLabel); } else { this.publicKeyId = null; } if (certLabel != null) { this.certId = certLabel.equals(keyId.getLabel()) ? keyId : new P11ObjectIdentifier(keyId.getId(), certLabel); } else { this.certId = null; } }
/** * TODO. * @param slotId * Slot identifier. Must not be {@code null}. * @param keyId * Object identifier. Must not be {@code null}. * @param publicKeyLabel * Label of the public key * @param certLabel * Label of the certificate */ public P11IdentityId(P11SlotIdentifier slotId, P11ObjectIdentifier keyId, String publicKeyLabel, String certLabel) { this.slotId = Args.notNull(slotId, "slotId"); this.keyId = Args.notNull(keyId, "keyId"); if (publicKeyLabel != null) { this.publicKeyId = publicKeyLabel.equals(keyId.getLabel()) ? keyId : new P11ObjectIdentifier(keyId.getId(), publicKeyLabel); } else { this.publicKeyId = null; } if (certLabel != null) { this.certId = certLabel.equals(keyId.getLabel()) ? keyId : new P11ObjectIdentifier(keyId.getId(), certLabel); } else { this.certId = null; } }
@Override protected P11ObjectIdentifier addCert0(X509Certificate cert, P11NewObjectControl control) throws P11TokenException, CertificateException { byte[] id = control.getId(); if (id == null) { id = generateId(); } String label = control.getLabel(); savePkcs11Cert(id, label, cert); return new P11ObjectIdentifier(id, label); }
private void analyseSingleKey(SecretKey secretKey, P11SlotRefreshResult refreshResult) { byte[] id = secretKey.getId().getByteArrayValue(); char[] label = secretKey.getLabel().getCharArrayValue(); if (id == null || label == null) { return; } P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, new String(label)); IaikP11Identity identity = new IaikP11Identity(this, new P11IdentityId(slotId, objectId, null, null), secretKey); refreshResult.addIdentity(identity); }
private Asn1P11ObjectIdentifier(final ASN1Sequence seq) throws BadAsn1ObjectException { Asn1Util.requireRange(seq, 2, 2); int idx = 0; byte[] id = Asn1Util.getOctetStringBytes(seq.getObjectAt(idx++)); String label = Asn1Util.getUtf8String(seq.getObjectAt(idx++)); this.objectId = new P11ObjectIdentifier(id, label); }
private Asn1P11ObjectIdentifier(ASN1Sequence seq) throws BadAsn1ObjectException { Asn1Util.requireRange(seq, 2, 2); int idx = 0; byte[] id = Asn1Util.getOctetStringBytes(seq.getObjectAt(idx++)); String label = Asn1Util.getUtf8String(seq.getObjectAt(idx++)); this.value = new P11ObjectIdentifier(id, label); }
new P11ObjectIdentifier(id, keyLabel), pubKeyLabel, certLabel); try { return new EmulatorP11Identity(this,identityId, keypair.getPrivate(),
@Override protected P11ObjectIdentifier addCert0(X509Certificate cert, P11NewObjectControl control) throws P11TokenException { ConcurrentBagEntry<Session> bagEntry = borrowSession(); try { Session session = bagEntry.value(); X509PublicKeyCertificate newCertTemp = createPkcs11Template(session, new X509Cert(cert), control); X509PublicKeyCertificate newCert = (X509PublicKeyCertificate) session.createObject(newCertTemp); return new P11ObjectIdentifier(newCert.getId().getByteArrayValue(), new String(newCert.getLabel().getCharArrayValue())); } catch (TokenException ex) { throw new P11TokenException(ex.getMessage(), ex); } finally { sessions.requite(bagEntry); } }
private void analyseSingleKey(final SecretKey secretKey, final P11SlotRefreshResult refreshResult) { byte[] id = secretKey.getId().getByteArrayValue(); P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, toString(secretKey.getLabel())); IaikP11Identity identity = new IaikP11Identity(this, new P11EntityIdentifier(slotId, objectId), secretKey); refreshResult.addIdentity(identity); }
private void analyseSingleKey(Session session, PrivateKey privKey, P11SlotRefreshResult refreshResult) throws P11TokenException, XiSecurityException { byte[] id = privKey.getId().getByteArrayValue(); char[] label = privKey.getLabel().getCharArrayValue(); if (id == null || label == null) { return; } String pubKeyLabel = null; PublicKey p11PublicKey = getPublicKeyObject(session, id, null); if (p11PublicKey != null) { pubKeyLabel = new String(p11PublicKey.getLabel().getCharArrayValue()); } String certLabel = null; java.security.PublicKey pubKey = null; X509Cert cert = refreshResult.getCertForId(id); if (cert != null) { certLabel = refreshResult.getCertLabelForId(id); pubKey = cert.getCert().getPublicKey(); } else if (p11PublicKey != null) { pubKey = generatePublicKey(p11PublicKey); } else { LOG.info("neither certificate nor public key for the key (" + hex(id) + " is available"); return; } P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, new String(label)); X509Certificate[] certs = (cert == null) ? null : new X509Certificate[]{cert.getCert()}; IaikP11Identity identity = new IaikP11Identity(this, new P11IdentityId(slotId, objectId, pubKeyLabel, certLabel), privKey, pubKey, certs); refreshResult.addIdentity(identity); }
private void analyseSingleKey(final PrivateKey privKey, final P11SlotRefreshResult refreshResult) throws P11TokenException, XiSecurityException { byte[] id = privKey.getId().getByteArrayValue(); java.security.PublicKey pubKey = null; X509Cert cert = refreshResult.getCertForId(id); if (cert != null) { pubKey = cert.cert().getPublicKey(); } else { PublicKey p11PublicKey = getPublicKeyObject(id, null); if (p11PublicKey == null) { LOG.info("neither certificate nor public key for the key (" + Hex.toHexString(id) + " is available"); return; } pubKey = generatePublicKey(p11PublicKey); } P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, toString(privKey.getLabel())); X509Certificate[] certs = (cert == null) ? null : new X509Certificate[]{cert.cert()}; IaikP11Identity identity = new IaikP11Identity(this, new P11EntityIdentifier(slotId, objectId), privKey, pubKey, certs); refreshResult.addIdentity(identity); }
P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label); P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);
P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label); P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId); java.security.PublicKey jcePublicKey;
P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label); P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);