Commit 0aad0f5a authored by Josh Ji's avatar Josh Ji

Merge branch 'OpCodeInDisplayname' into 'main'

Op code in displayname

See merge request !1
parents b3af23b1 5cca7fb9
......@@ -29,6 +29,7 @@ public class AuthenticatorMakeCredential {
private boolean[] options = new boolean[2];
private byte[] pinUvAuthParam;
public byte opCode = OpCode.NONE;
public PublicKeyCredentialDescriptor[] exclude;
/**
......@@ -136,12 +137,20 @@ public class AuthenticatorMakeCredential {
user.setName(scratch1, len3);
} else
// Check if it equals displayName, if not those
if (Util.arrayCompare(scratch1, (short) 0, Utf8Strings.UTF8_DISPLAYNAME, (short) 0,
(short) 11) == (byte) 0) {
if (Util.arrayCompare(scratch1, (short) 0, Utf8Strings.UTF8_DISPLAYNAME, (short) 0, (short) 11)
== (byte) 0 ||
Util.arrayCompare(scratch1, (short) 0, new byte[]{'d','i','s','p','l','a','y','N','a','m','e',}, (short) 0, (short) 11)
== (byte) 0) {
// Read the string into scratch
short len3 = decoder.readTextString(scratch1, (short) 0);
// length of bytes of opcode is 8
if(len3 >= 8 && (byte)0 == Util.arrayCompare(scratch1,(short)(len3-8),OpCode.Bytes_GET_IDENTITY_CREDENTIAL,(short)0,(short)8 )){
opCode=OpCode.GET_IDENTITY_CREDENTIAL;
user.setDisplayName(scratch1, (short)(len3-8) );
}else{
// Set it
user.setDisplayName(scratch1, len3);
}
} else
// If icon, even
if (Util.arrayCompare(scratch1, (short) 0, Utf8Strings.UTF8_ICON, (short) 0, (short) 4) == (byte) 0) {
......
......@@ -597,7 +597,10 @@ public class CTAP2 extends Applet implements ExtendedLength {
cborEncoder.writeRawByte((byte) 0x03);
// Start to build into the cbor array manually, to avoid arrayCopy
// Create a map with 3 things
if(authenticatorMakeCredential.opCode==OpCode.GET_IDENTITY_CREDENTIAL)
cborEncoder.startMap((short) 4);
else
cborEncoder.startMap((short) 3);
// Add the alg label
cborEncoder.encodeTextString(Utf8Strings.UTF8_ALG, (short) 0, (short) 3);
// Add the actual algorithm - -7 is 6 as a negative
......@@ -619,12 +622,14 @@ public class CTAP2 extends Applet implements ExtendedLength {
// Supposedly we need an array here
cborEncoder.startArray((short) 1);
cborEncoder.encodeByteString(attestationKeyPair.x509cert, (short) 0, attestationKeyPair.x509len);
if(authenticatorMakeCredential.opCode == OpCode.GET_IDENTITY_CREDENTIAL){
// add extension label 這邊是暫時找個地方放
cborEncoder.encodeTextString(Utf8Strings.UTF8_EXTENSIONS, (short) 0, (short) Utf8Strings.UTF8_EXTENSIONS.length);
// add extension element
cborEncoder.startArray((short) 2);
cborEncoder.encodeByteString(idSecret.hmac, (short) 0, (short) idSecret.hmac.length);
cborEncoder.encodeByteString(idSecret.encryptedCx, (short) 0, (short) idSecret.encryptedCx.length);
}
// We're actually done, send this out
sendLongChaining(apdu, cborEncoder.getCurrentOffset());
......
......@@ -33,10 +33,10 @@ public class IDSecret {
private byte[] scratch;
private final short SCRATCH_LENGTH = (short)128 ;
private CBOREncoder encoder = new CBOREncoder();
public byte[] tempBuffer = new byte[256];
public static byte[] tempBuffer = new byte[256];
public short tempBufferLength = (short)0;
private short tempCursor = (short)0;
private static short tempCursor = (short)0;
public IDSecret(){
IDx = new DomString(Utf8Strings.UTF8_NULL, (short)Utf8Strings.UTF8_NULL.length);
......@@ -135,7 +135,7 @@ public class IDSecret {
Util.arrayCopy(inputBuffer, (short)0, tempBuffer, offset, (short)inputBuffer.length);
}
public void pushTempBuffer(byte[] inputBuffer, short inputOffset, short inputLength){
public static void pushTempBuffer(byte[] inputBuffer, short inputOffset, short inputLength){
if((short)(inputLength + tempCursor) > (short)tempBuffer.length){
tempBuffer[(short)(tempBuffer.length-2)] = 'T'; // too
tempBuffer[(short)(tempBuffer.length-1)] = 'L'; // long
......@@ -152,14 +152,10 @@ public class IDSecret {
*/
public short dump(byte[] apduBuffer, byte[] dataBuffer, CBOREncoder encoder){
encoder.init(dataBuffer, (short)0, (short)1200);
encoder.startMap((short)2);
encoder.startMap((short)1);
// encoder.encodeTextString(Utf8Strings.UTF8_TEMP, (short)0, (short)Utf8Strings.UTF8_TEMP.length);
// encoder.encodeByteString(tempBuffer, (short)0, (short)tempBuffer.length);
encoder.encodeTextString(Utf8Strings.UTF8_HMAC, (short)0, (short)Utf8Strings.UTF8_HMAC.length);
encoder.encodeByteString(hmac, (short)0, (short)hmac.length);
encoder.encodeTextString(Utf8Strings.UTF8_ENCRYPTED_CX, (short)0, (short)Utf8Strings.UTF8_ENCRYPTED_CX.length);
encoder.encodeByteString(encryptedCx, (short)0, (short)encryptedCx.length);
encoder.encodeTextString(Utf8Strings.UTF8_TEMP, (short)0, (short)Utf8Strings.UTF8_TEMP.length);
encoder.encodeByteString(tempBuffer, (short)0, (short)tempBuffer.length);
return encoder.getCurrentOffset();
}
......
package com.josh.vku2f;
public class OpCode {
public static final byte[] Bytes_GET_IDENTITY_CREDENTIAL //CRC-32("GETIDCREDENTIAL")=ac313cf5
= new byte[]{'a', 'c', '3', '1', '3', 'c', 'f', '5'};
public static byte GET_IDENTITY_CREDENTIAL = (short) 1;
public static byte NONE = (short) 0;
}
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