encoding/asn1: Unmarshal accepts negative dates #11134
Closed
Description
The following program:
package main
import (
"encoding/asn1"
"time"
"fmt"
)
func main() {
data := []byte("\x18\x0f00000100000000Z")
var v time.Time
_, err := asn1.Unmarshal(data, &v)
if err != nil {
return
}
fmt.Printf("%v\n",v)
_, err = asn1.Marshal(v)
if err != nil {
panic(err)
}
}
panics with:
-0001-12-31 00:00:00 +0000 UTC
panic: asn1: structure error: cannot represent time as GeneralizedTime
The value is successfully unmarshalled, but can't be marshalled. I am not sure who exactly is wrong here. This happens because of "date normalization" in time package, it converts day 0 to the last day of the previous month. ASN.1 (ISO 8601) does not define "date normalization", if I understand correctly, assuming that dates and times are valid as is.
I think we should not do time/date normalization, because it is asking for troubles security-wise.