@Override public void setValue(Object value) { setCharArrayValue((char[]) value); }
private static String toString(final CharArrayAttribute charArrayAttr) { String labelStr = ""; if (charArrayAttr != null) { char[] chars = charArrayAttr.getCharArrayValue(); if (chars != null) { labelStr = new String(chars); } } return labelStr; }
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); application = new CharArrayAttribute(Attribute.APPLICATION); objectID = new ByteArrayAttribute(Attribute.OBJECT_ID); value = new ByteArrayAttribute(Attribute.VALUE); putAttributesInTable(this); }
template.getLabel().setCharArrayValue(labelChars); labelChars = key.getLabel().getCharArrayValue();
/** * Compares all member variables of this object with the other object. * Returns only true, if all are equal in both objects. * * @param otherObject * The other object to compare to. * @return True, if other is an instance of this class and all member * variables of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof Data)) { return false; } Data other = (Data) otherObject; return super.equals(other) && this.application.equals(other.application) && this.objectID.equals(other.objectID) && this.value.equals(other.value); }
/** * The overriding of this method should ensure that the objects of this * class work correctly in a hashtable. * * @return The hash code of this object. * @preconditions * @postconditions */ @Override public int hashCode() { return application.hashCode() ^ objectID.hashCode() ^ value.hashCode(); }
template.getLabel().setCharArrayValue(labelChars); labelChars = key.getLabel().getCharArrayValue();
/** * Compares all member variables of this object with the other object. * Returns only true, if all are equal in both objects. * * @param otherObject * The other object to compare to. * @return True, if other is an instance of this class and all member * variables of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof Storage)) { return false; } Storage other = (Storage) otherObject; return super.equals(other) && this.token.equals(other.token) && this.private_.equals(other.private_) && this.modifiable.equals(other.modifiable) && this.label.equals(other.label); }
/** * The overriding of this method should ensure that the objects of this * class work correctly in a hashtable. * * @return The hash code of this object. * @preconditions * @postconditions */ @Override public int hashCode() { return token.hashCode() ^ private_.hashCode() ^ modifiable.hashCode() ^ label.hashCode(); }
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 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); }
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); token = new BooleanAttribute(Attribute.TOKEN); private_ = new BooleanAttribute(Attribute.PRIVATE); modifiable = new BooleanAttribute(Attribute.MODIFIABLE); label = new CharArrayAttribute(Attribute.LABEL); putAttributesInTable(this); }
/** * Compares all member variables of this object with the other object. * Returns only true, if all are equal in both objects. * * @param otherObject * The other object to compare to. * @return True, if other is an instance of this class and all member * variables of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof WTLSCertificate)) { return false; } WTLSCertificate other = (WTLSCertificate) otherObject; return super.equals(other) && this.subject.equals(other.subject) && this.issuer.equals(other.issuer) && this.value.equals(other.value) && this.url.equals(other.url) && this.hashOfSubjectPublicKey.equals( other.hashOfSubjectPublicKey) && this.hashOfIssuerPublicKey.equals( other.hashOfIssuerPublicKey); }
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 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); }
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); subject = new ByteArrayAttribute(Attribute.SUBJECT); issuer = new ByteArrayAttribute(Attribute.ISSUER); value = new ByteArrayAttribute(Attribute.VALUE); url = new CharArrayAttribute(Attribute.URL); hashOfSubjectPublicKey = new ByteArrayAttribute(Attribute.HASH_OF_SUBJECT_PUBLIC_KEY); hashOfIssuerPublicKey = new ByteArrayAttribute(Attribute.HASH_OF_ISSUER_PUBLIC_KEY); putAttributesInTable(this); }
/** * Compares all member variables of this object with the other object. * Returns only true, if all are equal in both objects. * * @param otherObject * The other object to compare to. * @return True, if other is an instance of this class and all member * variables of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof X509PublicKeyCertificate)) { return false; } X509PublicKeyCertificate other = (X509PublicKeyCertificate) otherObject; return super.equals(other) && this.subject.equals(other.subject) && this.id.equals(other.id) && this.issuer.equals(other.issuer) && this.serialNumber.equals(other.serialNumber) && this.value.equals(other.value) && this.url.equals(other.url) && this.hashOfSubjectPublicKey.equals(other.hashOfSubjectPublicKey) && this.hashOfIssuerPublicKey.equals(other.hashOfIssuerPublicKey) && this.javaMidpSecurityDomain.equals(other.javaMidpSecurityDomain); }
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; }
@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); } }
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); subject = new ByteArrayAttribute(Attribute.SUBJECT); id = new ByteArrayAttribute(Attribute.ID); issuer = new ByteArrayAttribute(Attribute.ISSUER); serialNumber = new ByteArrayAttribute(Attribute.SERIAL_NUMBER); value = new ByteArrayAttribute(Attribute.VALUE); url = new CharArrayAttribute(Attribute.URL); hashOfSubjectPublicKey = new ByteArrayAttribute( Attribute.HASH_OF_SUBJECT_PUBLIC_KEY); hashOfIssuerPublicKey = new ByteArrayAttribute( Attribute.HASH_OF_ISSUER_PUBLIC_KEY); javaMidpSecurityDomain = new LongAttribute( Attribute.JAVA_MIDP_SECURITY_DOMAIN); putAttributesInTable(this); }