use of iso.std.iso_iec._24727.tech.schema.Hash in project open-ecard by ecsec.
the class TinySALTest method testHash.
/**
* Test of hash method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testHash() {
System.out.println("hash");
Hash parameters = new Hash();
HashResponse result = instance.hash(parameters);
assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor());
}
use of iso.std.iso_iec._24727.tech.schema.Hash in project open-ecard by ecsec.
the class HashStep method perform.
@Override
public HashResponse perform(Hash request, Map<String, Object> internalData) {
HashResponse response = WSHelper.makeResponse(HashResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
String didName = SALUtils.getDIDName(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(internalData, connectionHandle);
DIDStructureType didStructure = SALUtils.getDIDStructure(request, didName, cardStateEntry, connectionHandle);
CryptoMarkerType cryptoMarker = new CryptoMarkerType(didStructure.getDIDMarker());
HashGenerationInfoType hashInfo = cryptoMarker.getHashGenerationInfo();
if (hashInfo != null) {
if (hashInfo == HashGenerationInfoType.NOT_ON_CARD) {
String algId = cryptoMarker.getAlgorithmInfo().getAlgorithmIdentifier().getAlgorithm();
SignatureAlgorithms alg = SignatureAlgorithms.fromAlgId(algId);
HashAlgorithms hashAlg = alg.getHashAlg();
if (hashAlg == null) {
String msg = String.format("Algorithm %s does not specify a Hash algorithm.", algId);
LOG.error(msg);
String minor = ECardConstants.Minor.App.INCORRECT_PARM;
response.setResult(WSHelper.makeResultError(minor, msg));
} else {
// calculate hash
MessageDigest md = MessageDigest.getInstance(hashAlg.getJcaAlg());
md.update(request.getMessage());
byte[] digest = md.digest();
response.setHash(digest);
}
} else {
// TODO: implement hashing on card
String msg = String.format("Unsupported Hash generation type (%s) requested.", hashInfo);
LOG.error(msg);
String minor = ECardConstants.Minor.SAL.INAPPROPRIATE_PROTOCOL_FOR_ACTION;
response.setResult(WSHelper.makeResultError(minor, msg));
}
} else {
// no hash alg specified, this is an error
String msg = String.format("No Hash generation type specified in CIF.");
LOG.error(msg);
String minor = ECardConstants.Minor.SAL.INAPPROPRIATE_PROTOCOL_FOR_ACTION;
response.setResult(WSHelper.makeResultError(minor, msg));
}
} catch (ECardException e) {
response.setResult(e.getResult());
} catch (UnsupportedAlgorithmException | NoSuchAlgorithmException ex) {
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
response.setResult(WSHelper.makeResult(e));
}
return response;
}
use of iso.std.iso_iec._24727.tech.schema.Hash in project open-ecard by ecsec.
the class GenericCryptographyProtocolTest method testHash.
@Test(enabled = TESTS_ENABLED)
public void testHash() {
// TODO write test as soon as implemented
HashResponse resp = instance.hash(new Hash());
assertEquals(resp.getResult().getResultMajor(), ECardConstants.Major.ERROR);
}
Aggregations