Skip to content

Commit 1faeef9

Browse files
mateusz834gopherbot
authored andcommitted
cryptobyte: reject Object Identifiers with leading 0x80
Change-Id: Ie3a1b53e801077cd86963799e644b9783943933c GitHub-Last-Rev: 6629bd7 GitHub-Pull-Request: #255 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/483955 Run-TryBot: Mateusz Poliwczak <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 00fd4ff commit 1faeef9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: cryptobyte/asn1.go

+8
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,14 @@ func (s *String) readBase128Int(out *int) bool {
431431
}
432432
ret <<= 7
433433
b := s.read(1)[0]
434+
435+
// ITU-T X.690, section 8.19.2:
436+
// The subidentifier shall be encoded in the fewest possible octets,
437+
// that is, the leading octet of the subidentifier shall not have the value 0x80.
438+
if i == 0 && b == 0x80 {
439+
return false
440+
}
441+
434442
ret |= int(b & 0x7f)
435443
if b&0x80 == 0 {
436444
*out = ret

Diff for: cryptobyte/asn1_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func TestASN1ObjectIdentifier(t *testing.T) {
276276
{[]byte{6, 7, 85, 0x02, 0x85, 0xc7, 0xcc, 0xfb, 0x01}, true, []int{2, 5, 2, 1492336001}},
277277
{[]byte{6, 7, 0x55, 0x02, 0x87, 0xff, 0xff, 0xff, 0x7f}, true, []int{2, 5, 2, 2147483647}}, // 2**31-1
278278
{[]byte{6, 7, 0x55, 0x02, 0x88, 0x80, 0x80, 0x80, 0x00}, false, []int{}}, // 2**31
279+
{[]byte{6, 3, 85, 0x80, 0x02}, false, []int{}}, // leading 0x80 octet
279280
}
280281

281282
for i, test := range testData {

0 commit comments

Comments
 (0)