use of org.openecard.mdlw.sal.cryptoki.CK_ATTRIBUTE in project open-ecard by ecsec.
the class MwSession method getCertificates.
/**
* Returns all Certificates from the Token of the selected Session
*
* @return List of certificates.
* @throws CryptokiException
*/
public List<MwCertificate> getCertificates() throws CryptokiException {
NativeLongByReference temp = new NativeLongByReference(new NativeLong(CryptokiLibrary.CKO_CERTIFICATE, true));
CK_ATTRIBUTE pTemplate = new CK_ATTRIBUTE();
pTemplate.setType(CKA_CLASS);
pTemplate.setPValue(temp.getPointer());
pTemplate.setUlValueLen(new NativeLong(NativeLong.SIZE));
List<Long> res = findObjects(pTemplate);
List<MwCertificate> cerList = new ArrayList<>();
for (long l : res) {
try {
cerList.add(new MwCertificate(l, mw, this));
} catch (CryptokiException ex) {
LOG.warn("Skipping certificate due to error.", ex);
}
}
return cerList;
}
use of org.openecard.mdlw.sal.cryptoki.CK_ATTRIBUTE in project open-ecard by ecsec.
the class MwSession method getData.
/**
* Returns all Data Objects from the Token of the selected Session
*
* @return List of data objects.
* @throws CryptokiException
*/
public List<MwData> getData() throws CryptokiException {
NativeLongByReference temp = new NativeLongByReference(new NativeLong(CryptokiLibrary.CKO_DATA, true));
CK_ATTRIBUTE pTemplate = new CK_ATTRIBUTE();
pTemplate.setType(CKA_CLASS);
pTemplate.setPValue(temp.getPointer());
pTemplate.setUlValueLen(new NativeLong(NativeLong.SIZE));
List<Long> res = findObjects(pTemplate);
List<MwData> dataList = new ArrayList<>();
for (long l : res) {
try {
dataList.add(new MwData(l, mw, this));
} catch (CryptokiException ex) {
LOG.warn("Skipping data object due to error.", ex);
}
}
return dataList;
}
use of org.openecard.mdlw.sal.cryptoki.CK_ATTRIBUTE in project open-ecard by ecsec.
the class MwSession method getPublicKeys.
/**
* Returns all Public Keys from the Token of the selected Session
*
* @return List public keys.
* @throws CryptokiException
*/
public List<MwPublicKey> getPublicKeys() throws CryptokiException {
List<MwPublicKey> keyList = new ArrayList<>();
NativeLongByReference temp = new NativeLongByReference(new NativeLong(CryptokiLibrary.CKO_PUBLIC_KEY, true));
CK_ATTRIBUTE pTemplate = new CK_ATTRIBUTE();
pTemplate.setType(CKA_CLASS);
pTemplate.setPValue(temp.getPointer());
pTemplate.setUlValueLen(new NativeLong(NativeLong.SIZE));
List<Long> res = findObjects(pTemplate);
for (long l : res) {
try {
keyList.add(new MwPublicKey(l, mw, this));
} catch (CryptokiException ex) {
LOG.warn("Skipping public key due to error.", ex);
}
}
return keyList;
}
use of org.openecard.mdlw.sal.cryptoki.CK_ATTRIBUTE in project open-ecard by ecsec.
the class MwSession method getPrivateKeys.
/**
* Returns all Private Keys from the Token of the selected Session
*
* @return List of private keys.
* @throws CryptokiException
*/
public List<MwPrivateKey> getPrivateKeys() throws CryptokiException {
LOG.debug("Trying to get private key objects from middleware.");
NativeLong privkey = new NativeLong(CryptokiLibrary.CKO_PRIVATE_KEY, true);
NativeLongByReference temp = new NativeLongByReference(privkey);
CK_ATTRIBUTE pTemplate = new CK_ATTRIBUTE();
pTemplate.setType(CKA_CLASS);
pTemplate.setPValue(temp.getPointer());
pTemplate.setUlValueLen(new NativeLong(NativeLong.SIZE));
List<Long> res = findObjects(pTemplate);
List<MwPrivateKey> keyList = new ArrayList<>();
for (long l : res) {
try {
MwPrivateKey key = new MwPrivateKey(l, mw, this);
LOG.debug("Found private key {} (handle={}).", key, l);
keyList.add(key);
} catch (CryptokiException ex) {
LOG.warn("Skipping private key due to error.", ex);
}
}
return keyList;
}
use of org.openecard.mdlw.sal.cryptoki.CK_ATTRIBUTE 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.");
}
}
Aggregations