This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Endpoint for the Service Delivery Request | |
put(new Route("/deliver") { | |
@Override | |
public Object handle(Request request, Response response) { | |
JSONObject jsonParameters = (JSONObject) JSONValue.parse(request.body()); | |
String serviceId = (String) jsonParameters.get("serviceId"); | |
// launch first operation for each of the two services or return 404 if serviceId unknown | |
if (serviceId.equals(Constants.invokeServiceId)){ | |
// first operation is GET CARD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read block 1 of sector 1 of the virtual MIFARE card | |
public int readBlock(String sessionId, HashMap<String, String> pendingOperations) { | |
String url = "https://api.fidesmo.com/mifare/read"; | |
String callbackUrl = Constants.rootUrl + Constants.readBlockCallbackUrl; | |
// Encode the JSON structure with the trailer data for one sector | |
JSONObject payload = new JSONObject(); | |
JSONArray blockData = new JSONArray(); | |
blockData.add(Utils.encodeBlockToRead(1, 1)); | |
payload.put("blocks", blockData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns JSON encoding of a block (inside a sector) to be read | |
public static JSONObject encodeBlockToRead(int numSector, int numBlock) { | |
JSONObject block = new JSONObject(); | |
block.put ("sector", numSector); | |
block.put ("block", numBlock); | |
return block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BufferedReader inputReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
String inputLine; | |
StringBuffer response = new StringBuffer(); | |
while ((inputLine = inputReader.readLine()) != null) { | |
response.append(inputLine); | |
} | |
inputReader.close(); | |
JSONObject jsonResponse = (JSONObject) JSONValue.parse(response.toString()); | |
String operationId = (String) jsonResponse.get("operationId"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// handles response from the Read MIFARE Data message | |
post(new Route(Constants.readBlockCallbackUrl) { | |
@Override | |
public Object handle(Request request, Response response) { | |
JSONObject jsonParameters = (JSONObject) JSONValue.parse(request.body()); | |
String operationId = (String) jsonParameters.get("operationId"); | |
String sessionId = pendingOperations.get(operationId); | |
pendingOperations.remove(operationId); | |
int statusCode = ((Long)jsonParameters.get("statusCode")).intValue(); | |
if (statusCode != HTTP_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// we are done - send the Service Delivery Completed message | |
cardClient.serviceDeliveryCompleted(true, sessionMap.get(sessionId).getCounter(), sessionId); | |
// Time to remove this session from the map - it is finished! | |
sessionMap.remove(sessionId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javacard.framework.*; | |
public class ExampleCardlet extends Applet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void install(byte[] bArray, short bOffset, byte bLength){ | |
new ExampleCardlet(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void process(APDU apdu){ | |
byte buffer[] = apdu.getBuffer(); | |
short length = (short) helloFidesmo.length; | |
Util.arrayCopyNonAtomic(helloFidesmo, (short)0, buffer, (short)0, (short)length); | |
apdu.setOutgoingAndSend((short)0, length); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import java.util.Arrays; | |
import java.lang.String; | |
import javax.smartcardio.*; | |
public class HelloFidesmoTest { | |
// don't forget to set the HELLO_FIDESMO_APPID environment variable with the AppID | |
// assigned by Fidesmo to your app in https://developer.fidesmo.com | |
public static String applicationId = System.getenv().get("HELLO_FIDESMO_APPID"); | |
final private static String aidPrefix = "A00000061700"; |
OlderNewer