encoding/asn1: handle UTCTime before the year 2000

UTCTime only has a two digit date field and year values from 50 should
be 1950, not 2050.

R=golang-dev, r, rsc
CC=golang-dev
https://golang.org/cl/5729063
This commit is contained in:
Adam Langley 2012-03-05 11:31:24 -05:00
parent d5f78d77c0
commit 6aed613030

View File

@ -250,10 +250,14 @@ func parseBase128Int(bytes []byte, initOffset int) (ret, offset int, err error)
func parseUTCTime(bytes []byte) (ret time.Time, err error) {
s := string(bytes)
ret, err = time.Parse("0601021504Z0700", s)
if err == nil {
return
if err != nil {
ret, err = time.Parse("060102150405Z0700", s)
}
ret, err = time.Parse("060102150405Z0700", s)
if err == nil && ret.Year() >= 2050 {
// UTCTime only encodes times prior to 2050. See https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
ret = ret.AddDate(-100, 0, 0)
}
return
}