Skip to content

Commit 86ff141

Browse files
authored
Merge pull request #430 from libtom/fix/oid-decode
Fix OID issues
2 parents bd542c6 + 2e9c80c commit 86ff141

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/pk/asn1/der/object_identifier/der_decode_object_identifier.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ int der_decode_object_identifier(const unsigned char *in, unsigned long inle
7171
y++;
7272
} else {
7373
if (y == 0) {
74-
words[0] = t / 40;
75-
words[1] = t % 40;
74+
if (t <= 79) {
75+
words[0] = t / 40;
76+
words[1] = t % 40;
77+
} else {
78+
words[0] = 2;
79+
words[1] = t - 80;
80+
}
7681
y = 2;
7782
} else {
7883
words[y++] = t;

src/pk/asn1/der/object_identifier/der_length_object_identifier.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
4848
return CRYPT_INVALID_ARG;
4949
}
5050

51-
/* word1 = 0,1,2,3 and word2 0..39 */
52-
if (words[0] > 3 || (words[0] < 2 && words[1] > 39)) {
51+
/* word1 = 0,1,2 and word2 0..39 */
52+
if (words[0] > 2 || (words[0] < 2 && words[1] > 39)) {
5353
return CRYPT_INVALID_ARG;
5454
}
5555

tests/der_test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,34 @@ static void der_set_test(void)
673673
674674
*/
675675

676+
static void _der_oid_test(void)
677+
{
678+
static const unsigned char oid_x690_8_19_5_example[] = { 0x06, 0x03, 0x88, 0x37, 0x03 };
679+
unsigned long len, oid[3];
680+
unsigned char buf[64];
681+
682+
ltc_asn1_list *decoded_list, static_list[1];
683+
684+
len = sizeof(oid_x690_8_19_5_example);
685+
DO(der_decode_sequence_flexi(oid_x690_8_19_5_example, &len, &decoded_list));
686+
687+
LTC_SET_ASN1(static_list, 0, LTC_ASN1_OBJECT_IDENTIFIER, (void *)decoded_list->data, decoded_list->size);
688+
len = sizeof(buf);
689+
DO(der_encode_object_identifier(decoded_list->data, decoded_list->size, buf, &len));
690+
der_sequence_free(decoded_list);
691+
692+
DO(do_compare_testvector(buf, len, oid_x690_8_19_5_example, sizeof(oid_x690_8_19_5_example), "OID X6.90 Ch. 8.19.5 Example", 0));
693+
694+
oid[0] = 3;
695+
oid[1] = 4;
696+
oid[2] = 5;
697+
698+
len = sizeof(buf);
699+
SHOULD_FAIL(der_encode_object_identifier(oid, 3, buf, &len));
700+
len = sizeof(buf);
701+
SHOULD_FAIL(der_length_object_identifier(oid, 3, &len));
702+
}
703+
676704
static void der_flexi_test(void)
677705
{
678706
static const char printable_str[] = "printable";
@@ -1589,6 +1617,8 @@ int der_test(void)
15891617

15901618
der_cacert_test();
15911619

1620+
_der_oid_test();
1621+
15921622
y = 0xffffff00;
15931623
#if ULONG_MAX == ULLONG_MAX
15941624
y <<= 32;

0 commit comments

Comments
 (0)