use of org.openecard.mdlw.sal.struct.CkAttribute in project open-ecard by ecsec.
the class MiddleWareWrapper method getAttributeValues.
public List<CkAttribute> getAttributeValues(long hSession, long hObject, long... types) throws CryptokiException {
CK_ATTRIBUTE baseAttr = new CK_ATTRIBUTE();
CK_ATTRIBUTE[] attrs = (CK_ATTRIBUTE[]) baseAttr.toArray(types.length);
for (int i = 0; i < types.length; i++) {
CK_ATTRIBUTE attr = attrs[i];
attr.setType(new NativeLong(types[i]));
attr.setPValue(Pointer.NULL);
attr.setUlValueLen(new NativeLong(0));
}
try (LockedObject lo = lockInternal()) {
// determine size of data to read and allocate space
check("C_GetAttributeValue", lib.C_GetAttributeValue(new NativeLong(hSession), new NativeLong(hObject), baseAttr, new NativeLong(attrs.length)));
for (CK_ATTRIBUTE next : attrs) {
long valueLen = next.getUlValueLen().longValue();
if (valueLen > 0) {
Memory newMem = new Memory(valueLen);
next.setPValue(newMem);
}
}
// read attributes
check("C_GetAttributeValue", lib.C_GetAttributeValue(new NativeLong(hSession), new NativeLong(hObject), baseAttr, new NativeLong(attrs.length)));
ArrayList<CkAttribute> result = new ArrayList<>();
for (CK_ATTRIBUTE next : attrs) {
CkAttribute resultAttr = new CkAttribute(next.getPValue(), next.getUlValueLen());
result.add(resultAttr);
}
return result;
} catch (InterruptedException ex) {
throw new IllegalStateException("Failed to release lock for middleware access.");
}
}
use of org.openecard.mdlw.sal.struct.CkAttribute in project open-ecard by ecsec.
the class MwCertificate method loadAttrValLabel.
/**
* Loading the Attribute Value for CKA_LABEL
*
* @return String
* @throws CryptokiException
*/
private String loadAttrValLabel() throws CryptokiException {
CkAttribute raw = mw.getAttributeValue(session.getSessionId(), objectHandle, CryptokiLibrary.CKA_LABEL);
String labelStr = AttributeUtils.getString(raw);
// find replacement if needed
if (labelStr == null && getSubject() != null) {
labelStr = new X500Principal(getSubject()).getName(X500Principal.RFC2253);
}
if (labelStr == null) {
try {
byte[] hash = MessageDigest.getInstance("SHA-1").digest(getValue());
labelStr = ByteUtils.toHexString(hash);
} catch (NoSuchAlgorithmException ex) {
// SHA-1 is a standard name and must be present
}
}
return labelStr;
}
Aggregations