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

[feature/DA-1234] add validation for tags 00 with no meaning #21

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 16 additions & 6 deletions src/main/java/com/payneteasy/tlv/BerTlvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public BerTlvs parse(byte[] aBuf, final int aOffset, int aLen) {
int offset = aOffset;
for(int i=0; i<100; i++) {
ParseResult result = parseWithResult(0, aBuf, offset, aLen-offset);
tlvs.add(result.tlv);

if (!result.ignoreTag) {
tlvs.add(result.tlv);
}

if(result.offset>=aOffset+aLen) {
break;
Expand Down Expand Up @@ -80,6 +83,11 @@ private ParseResult parseWithResult(int aLevel, byte[] aBuf, int aOffset, int aL
log.debug("{}tag = {}, tagBytesCount={}, tagBuf={}", levelPadding, tag, tagBytesCount, HexUtil.toFormattedHexString(aBuf, aOffset, tagBytesCount));
}

// check invalid 00 tag byte with no meaning.
if ((tag.bytes[0] & 0xFF) == 0x00) {
return new ParseResult(null, aOffset + 1, true);
}

// length
int lengthBytesCount = getLengthBytesCount(aBuf, aOffset + tagBytesCount);
int valueLength = getDataLength(aBuf, aOffset + tagBytesCount);
Expand All @@ -99,7 +107,7 @@ private ParseResult parseWithResult(int aLevel, byte[] aBuf, int aOffset, int aL
if(log.isDebugEnabled()) {
log.debug("{}returning constructed offset = {}", levelPadding, resultOffset);
}
return new ParseResult(new BerTlv(tag, list), resultOffset);
return new ParseResult(new BerTlv(tag, list), resultOffset, false);
} else {
// value
byte[] value = new byte[valueLength];
Expand All @@ -109,7 +117,7 @@ private ParseResult parseWithResult(int aLevel, byte[] aBuf, int aOffset, int aL
log.debug("{}value = {}", levelPadding, HexUtil.toFormattedHexString(value));
log.debug("{}returning primitive offset = {}", levelPadding, resultOffset);
}
return new ParseResult(new BerTlv(tag, value), resultOffset);
return new ParseResult(new BerTlv(tag, value), resultOffset, false);
}

}
Expand Down Expand Up @@ -154,9 +162,10 @@ private String createLevelPadding(int aLevel) {
}

private static class ParseResult {
public ParseResult(BerTlv aTlv, int aOffset) {
public ParseResult(BerTlv aTlv, int aOffset, boolean aIgnoreTag) {
tlv = aTlv;
offset = aOffset;
ignoreTag = aIgnoreTag;
}

@Override
Expand All @@ -169,6 +178,7 @@ public String toString() {

private final BerTlv tlv;
private final int offset;
private final boolean ignoreTag;
}


Expand All @@ -189,9 +199,9 @@ private int getTagBytesCount(byte[] aBuf, int aOffset) {
len++;
}
return len;
} else {
return 1;
}

return 1;
}


Expand Down
144 changes: 0 additions & 144 deletions src/test/java/com/payneteasy/tlv/BerTlvParserTest.java

This file was deleted.

Loading