Commit a0635f69 authored by Josh Ji's avatar Josh Ji

add vendor function (GET_COUNT 0x45)

return number of credentials
parent 7c2ff15c
newJavaCardApplet
\ No newline at end of file
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="delegatedBuild" value="false" />
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules"> <option name="modules">
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -35,6 +35,7 @@ import javacardx.apdu.ExtendedLength; ...@@ -35,6 +35,7 @@ import javacardx.apdu.ExtendedLength;
public class CTAP2 extends Applet implements ExtendedLength { public class CTAP2 extends Applet implements ExtendedLength {
private static final byte FIDO2_VENDOR_GET_COUNT = (byte)0x45;
private CBORDecoder cborDecoder; private CBORDecoder cborDecoder;
private CBOREncoder cborEncoder; private CBOREncoder cborEncoder;
...@@ -190,22 +191,25 @@ public class CTAP2 extends Applet implements ExtendedLength { ...@@ -190,22 +191,25 @@ public class CTAP2 extends Applet implements ExtendedLength {
case FIDO2_AUTHENTICATOR_GET_NEXT_ASSERTION: case FIDO2_AUTHENTICATOR_GET_NEXT_ASSERTION:
authGetNextAssertion(apdu, buffer); authGetNextAssertion(apdu, buffer);
break; break;
case FIDO2_VENDOR_ATTEST_SIGN: case FIDO2_VENDOR_ATTEST_SIGN: //0x41
attestSignRaw(apdu, vars[3]); attestSignRaw(apdu, vars[3]);
break; break;
case FIDO2_VENDOR_ATTEST_LOADCERT: case FIDO2_VENDOR_ATTEST_LOADCERT: //0x42
attestSetCert(apdu, vars[3]); attestSetCert(apdu, vars[3]);
break; break;
case FIDO2_VENDOR_PERSO_COMPLETE: case FIDO2_VENDOR_PERSO_COMPLETE: //0x43
persoComplete(apdu); persoComplete(apdu);
break; break;
case FIDO2_VENDOR_ATTEST_GETPUB: case FIDO2_VENDOR_ATTEST_GETPUB: //0x44
getAttestPublic(apdu); getAttestPublic(apdu);
break; break;
case FIDO2_VENDOR_ATTEST_GETCERT: case FIDO2_VENDOR_ATTEST_GETCERT: //0x4a
getCert(apdu); getCert(apdu);
break; break;
case FIDO2_AUTHENTICATOR_RESET: case FIDO2_VENDOR_GET_COUNT: //0x45
getCount(apdu);
break;
case FIDO2_AUTHENTICATOR_RESET: //0x07
// Need to finish doing this, we can, i mean, but I don't like it // Need to finish doing this, we can, i mean, but I don't like it
doReset(apdu); doReset(apdu);
break; break;
...@@ -244,6 +248,15 @@ public class CTAP2 extends Applet implements ExtendedLength { ...@@ -244,6 +248,15 @@ public class CTAP2 extends Applet implements ExtendedLength {
apdu.sendBytesLong(inBuf, (short) 0, vars[0]); apdu.sendBytesLong(inBuf, (short) 0, vars[0]);
} }
/** get counter's value */
public void getCount(APDU apdu){
short count = discoverableCreds.getCount();
apdu.setOutgoing();
apdu.setOutgoingLength((short)2);
Util.setShort(inBuf,(short)0, count);
apdu.sendBytesLong(inBuf,(short)0,(short)2);
}
/** /**
* Performs raw signatures, may only occur when personalisation is not complete. * Performs raw signatures, may only occur when personalisation is not complete.
* *
...@@ -1024,7 +1037,7 @@ public class CTAP2 extends Applet implements ExtendedLength { ...@@ -1024,7 +1037,7 @@ public class CTAP2 extends Applet implements ExtendedLength {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED); ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
} }
break; break;
case FIDO2_INS_NFCCTAP_MSG: case FIDO2_INS_NFCCTAP_MSG: // 0x10
handle(apdu); handle(apdu);
break; break;
case FIDO2_DESELECT: case FIDO2_DESELECT:
......
...@@ -27,6 +27,7 @@ public class CredentialArray { ...@@ -27,6 +27,7 @@ public class CredentialArray {
private boolean[] slotStatus; private boolean[] slotStatus;
private short size; private short size;
private short counter; private short counter;
private short count = 0;//the number of creds in the array
/** /**
* Constructor for a CredentialArray. * Constructor for a CredentialArray.
...@@ -46,6 +47,7 @@ public class CredentialArray { ...@@ -46,6 +47,7 @@ public class CredentialArray {
short slot = alreadyExists(in); short slot = alreadyExists(in);
creds[slot] = in; creds[slot] = in;
slotStatus[slot] = true; slotStatus[slot] = true;
count = (short)(slot + 1);
} catch (Exception e) { } catch (Exception e) {
UserException.throwIt(CTAP2.CTAP2_ERR_KEY_STORE_FULL); UserException.throwIt(CTAP2.CTAP2_ERR_KEY_STORE_FULL);
} }
...@@ -117,6 +119,10 @@ public class CredentialArray { ...@@ -117,6 +119,10 @@ public class CredentialArray {
public short getLength() { public short getLength() {
return size; return size;
} }
public short getCount(){
return count;
}
/** /**
* Returns the credential at position, or null if none. * Returns the credential at position, or null if none.
* @param position the position to get. * @param position the position to get.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment