New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/asn1: valid GeneralizedTime not parsed #15842
Comments
We don't use the issue tracker for questions. Please https://golang.org/wiki/Questions . I don't know the answer to this, but I think you just need to unmarshal into a string and parse the time yourself. It doesn't seem like a bug, so I'm going to close this. Please comment if you think this is a bug that needs to be fixed in the Go standard library. |
A valid GeneralizedTime is rejected. Even disclaimed as limitation it is still a good thing to keep request to fix it open, I think. The way the asn1 is organised (it encodes the type in the serialised data) it is not possible to interpret the data as something else without changing the package ... and as I already said it is provided from 3rdparty in my case. It is probably a good idea asn1 to offer a mechanism a customer defined parser to be hooked instead of the internal ones. There might be other cases where replacement is desirable/needed. |
We're not going to introduce a hook for a custom defined parser. Just copy the package and modify it for your needs. I'll reopen this issue for generalized time, but it would help to have a more complete example. |
This seems as reliable source for what are the valid GeneralizedTime format(s) http://www.obj-sys.com/asn1tutorial/node14.html I will copy the content just in case the link is dropped. GeneralizedTime Type GeneralizedTime takes values of the year, month, day, hour, time, minute,second, and second fraction in any of three forms. Local time only.
then any of the following three values of CurrentTime are valid: |
I have stumbled across this when using the Go package github.com/digitorus/timestamp with the RFC3161 Time Stamping Authority freetsa.org, which encodes GeneralizedTimes like 20180329224911.41882Z into their responses (up to six fractional digits). These ASN1 objects with fractional digits will be decoded fine with The restriction to three fractional digits, which is suggested in the tutorial at the obj-sys.com page linked in the comment above, doesn't appear in the ITU documents:
See also the section in RFC3161 starting with
From my point of view the fix would be to change the format string Line 361 in 72b0fb5
to 20060102150405.999999999Z0700 . With this change, all GeneralizedTimes, with no fractional digits or up to nine fractional digits would be properly decoded. It will make sure that fractional digits not only get parsed (which is the case even without including .9 ... in the format string), but also reproduced identically, so that the error condition serialized != s won't be fullfilled anymore.
|
Change https://golang.org/cl/108355 mentions this issue: |
Change https://golang.org/cl/108435 mentions this issue: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Tentatively milestoning as 1.14 since this has a proposed fix (108355) which has been waiting for review for more than 18 months. |
Howdy, kindly pinging @FiloSottile @katiehockman as this issue’s CL has been ready for a while. Thank you. |
Kindly paging @katiehockman @FiloSottile @agl as this CL has been around for many cycles, but the fix is simple and the Go1.15 tree bank closes in a few hours. |
This comment has been minimized.
This comment has been minimized.
Moving to Go1.16. |
Any chance this could be fixed for go 1.21? 🙏 |
…lizedTime A GeneralizedTime value may contain an optional fractional seconds element (according to X.680 46.2, restricted by X.690 11.7.3). This change adds support for this fractional part, up to nine digits, so that Unmarshal won't fail when decoding a DER encoded GeneralizedTime value with fractional digits. Also, test cases related to this change have been added. X.680 and X.690 can be found at: https://www.itu.int/rec/T-REC-X.680 https://www.itu.int/rec/T-REC-X.690 Fixes golang#15842 Change-Id: If217c007e01b686db508a940e9e2ed3bfb901879 Reviewed-on: https://go-review.googlesource.com/c/go/+/108355 Run-TryBot: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.6.2 darwin/amd64
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/.../golang"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="/usr/local/bin/gcc-5"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fno-common"
CXX="/usr/local/bin/c++-5"
CGO_ENABLED="1"
I Unmarshall 3rdparty asn1 data
It to be unmarshalled successfully it is correct.
asn1: time did not serialize back to the original value and may be invalid: given "20160525195606.36Z", but serialized as "20160525195606Z"
Note that the data is 3rdparty, I have no control over it. I see that golang asn1 disclames limited support. I am curious what are my options to workaround the issue - is it just a fork of the original library or there are other ways to hook my own parser for the GeneralizedTime?
The text was updated successfully, but these errors were encountered: