Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization #51

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Applet/src/com/android/javacard/keymaster/KMAsn1Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ public class KMAsn1Parser {
public static final byte ASN1_A0_TAG = (byte) 0xA0;
public static final byte ASN1_A1_TAG = (byte) 0xA1;
public static final byte ASN1_BIT_STRING = 0x03;

public static final byte ASN1_UTF8_STRING = 0x0C;
public static final byte ASN1_TELETEX_STRING = 0x14;
public static final byte ASN1_PRINTABLE_STRING = 0x13;
public static final byte ASN1_UNIVERSAL_STRING = 0x1C;
public static final byte ASN1_BMP_STRING = 0x1E;

public static final byte[] EC_CURVE = {
0x06,0x08,0x2a,(byte)0x86,0x48,(byte)0xce,0x3d,0x03,
0x01,0x07
Expand Down Expand Up @@ -58,7 +64,7 @@ public short decodeSubject(short blob) {
header(ASN1_SET);
header(ASN1_SEQUENCE);
objectIdentifier(COMMON_NAME_OID);
return header(ASN1_UTF8_STRING);
return subjectHeader();
}

public short decodeEcSubjectPublicKeyInfo(short blob) {
Expand Down Expand Up @@ -215,6 +221,18 @@ private short header(short tag){
return getLength();
}

private short subjectHeader(){
short t = getByte();
if(t != ASN1_UTF8_STRING &&
t != ASN1_TELETEX_STRING &&
t != ASN1_PRINTABLE_STRING &&
t != ASN1_UNIVERSAL_STRING &&
t != ASN1_BMP_STRING) {
KMException.throwIt(KMError.UNKNOWN_ERROR);
}
return getLength();
}

private byte getByte(){
byte d = data[cur];
incrementCursor((short)1);
Expand Down
11 changes: 7 additions & 4 deletions Applet/src/com/android/javacard/keymaster/KMDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,13 @@ private short decodeKeyParam(short exp) {
obj = decode(tagClass);
KMArray.cast(vals).add(arrPos++, obj);
break;
}catch(KMException e){
if(KMException.reason() == KMError.INVALID_TAG &&
!ignoreInvalidTags){
KMException.throwIt(KMError.INVALID_TAG);
} catch(KMException e){
if (KMException.reason() == KMError.INVALID_TAG) {
if(!ignoreInvalidTags){
KMException.throwIt(KMError.INVALID_TAG);
}
}else {
KMException.throwIt(KMException.reason());
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Applet/src/com/android/javacard/keymaster/KMEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void encode(short obj) {
push(obj);
}

// Use this function, when the max len
// Use this function, when the max len is given
public short encode(short object, byte[] buffer, short startOff, short maxLength) {
scratchBuf[STACK_PTR_OFFSET] = 0;
bufferRef[0] = buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,6 @@ private KMAttestationCert makeCommonCert(byte[] scratchPad) {
return cert;
}


private KMAttestationCert makeAttestationCert(short attKeyBlob, short attKeyParam,
short attChallenge, short issuer, byte[] scratchPad) {
KMAttestationCert cert = makeCommonCert(scratchPad);
Expand Down Expand Up @@ -1382,7 +1381,12 @@ private KMAttestationCert makeAttestationCert(short attKeyBlob, short attKeyPara
KMException.throwIt(KMError.INCOMPATIBLE_PURPOSE);
}
KMAsn1Parser asn1Decoder = KMAsn1Parser.instance();
short length = asn1Decoder.decodeSubject(issuer);
short length = 0;
try {
length = asn1Decoder.decodeSubject(issuer);
} catch (KMException e) {
KMException.throwIt(KMError.INVALID_ISSUER_SUBJECT_NAME);
}
if (length > KMType.MAX_SUBJECT_CN_LEN) {
KMException.throwIt(KMError.INVALID_ISSUER_SUBJECT_NAME);
}
Expand Down