Skip to content

Commit e4c6d4c

Browse files
Jim Nortondanielinux
authored andcommitted
Added support for custom-tlv-string
1 parent 31a4b7e commit e4c6d4c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tools/keytools/sign.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,44 @@ int main(int argc, char** argv)
20722072
}
20732073
CMD.custom_tlvs++;
20742074
i += 2;
2075+
} else if (strcmp(argv[i], "--custom-tlv-string") == 0) {
2076+
int p = CMD.custom_tlvs;
2077+
uint16_t tag, len;
2078+
uint32_t j;
2079+
if (p >= MAX_CUSTOM_TLVS) {
2080+
fprintf(stderr, "Too many custom TLVs.\n");
2081+
exit(16);
2082+
}
2083+
if (argc < (i + 2)) {
2084+
fprintf(stderr, "Invalid custom TLV fields. \n");
2085+
exit(16);
2086+
}
2087+
tag = (uint16_t)arg2num(argv[i + 1], 2);
2088+
len = (uint16_t)strlen(argv[i + 2]);
2089+
if (tag < 0x0030) {
2090+
fprintf(stderr, "Invalid custom tag: %s\n", argv[i + 1]);
2091+
exit(16);
2092+
}
2093+
if ( ((tag & 0xFF00) == 0xFF00) || ((tag & 0xFF) == 0xFF) ) {
2094+
fprintf(stderr, "Invalid custom tag: %s\n", argv[i + 1]);
2095+
exit(16);
2096+
}
2097+
if (len > 255) {
2098+
fprintf(stderr, "custom tlv buffer size too big: %s\n", argv[i + 2]);
2099+
exit(16);
2100+
}
2101+
CMD.custom_tlv[p].tag = tag;
2102+
CMD.custom_tlv[p].len = len;
2103+
CMD.custom_tlv[p].buffer = malloc(len);
2104+
if (CMD.custom_tlv[p].buffer == NULL) {
2105+
fprintf(stderr, "Error malloc for custom tlv buffer %d\n", len);
2106+
exit(16);
2107+
}
2108+
for (j = 0; j < len; j++) {
2109+
CMD.custom_tlv[p].buffer[j] = (uint8_t)argv[i+2][j];
2110+
}
2111+
CMD.custom_tlvs++;
2112+
i += 2;
20752113
}
20762114
else {
20772115
i--;

0 commit comments

Comments
 (0)