Skip to content

Commit

Permalink
Fix statusCode location for UI operations
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Feb 22, 2019
1 parent cc0eaa3 commit f2e7951
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/fidesmo/fdsm/ServiceDeliverySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static ServiceDeliverySession getInstance(FidesmoCard card, FidesmoApiCli
return new ServiceDeliverySession(card, client, formHandler);
}


public boolean deliver(String appId, String serviceId, PrintStream debug) throws CardException, IOException {
// Address #4
client.rpc(client.getURI(FidesmoApiClient.DEVICES_URL, HexUtils.bin2hex(card.getCIN()), new BigInteger(1, card.getBatchId()).toString()));
Expand Down Expand Up @@ -199,6 +198,7 @@ protected ObjectNode processTransmitOperation(JsonNode operationId, String sessi
}
}

// Send an empty fetch request when APDU-s are done
return emptyFetchRequest(sessionId);
}

Expand Down Expand Up @@ -279,6 +279,8 @@ protected ObjectNode processUIOperation(JsonNode operation, String sessionId, Js
values.put(v.getKey(), value);
}
operationResult.set("fields", values);
operationResult.put("statusCode", 200);

if (encrypted) {
operationResult.put("ephemeralKey", HexUtils.bin2hex(encryptSessionKey(spkey, sessionKey)));
}
Expand All @@ -288,6 +290,7 @@ protected ObjectNode processUIOperation(JsonNode operation, String sessionId, Js

ObjectNode fetchRequest = emptyFetchRequest(sessionId);
fetchRequest.set("operationResult", operationResult);

return fetchRequest;
}

Expand Down Expand Up @@ -315,7 +318,6 @@ protected ObjectNode processUserAction(JsonNode operation, String sessionId) thr
return fetchRequest;
}


private byte[] encrypt(String value, Key key) throws GeneralSecurityException {
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
c.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(new byte[16]));
Expand All @@ -336,10 +338,9 @@ private byte[] encryptSessionKey(PublicKey publicKey, Key key) throws GeneralSec
}

private ObjectNode emptyFetchRequest(String sessionId) {
ObjectNode operationResult = JsonNodeFactory.instance.objectNode();
operationResult.put("sessionId", sessionId);
operationResult.put("statusCode", sessionId);
return operationResult;
ObjectNode fetchRequest = JsonNodeFactory.instance.objectNode();
fetchRequest.put("sessionId", sessionId);
return fetchRequest;
}

private ObjectNode mapToJsonNode(Map<String, Field> map) {
Expand Down

0 comments on commit f2e7951

Please sign in to comment.