-
Notifications
You must be signed in to change notification settings - Fork 15
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
Incorrect time format for expiry dates after 2050? #73
Comments
`@peculiar/x509` may be representing everything as UTCTime - dates after 2050 should be GeneralizedTime so are rejected by compliant TLS implementations. Reduce the maximum validty of certificates to keep them under 2050 - this can be re-evaluated after PeculiarVentures/x509#73 is fixed.
`@peculiar/x509` may be representing everything as UTCTime - dates after 2050 should be GeneralizedTime so are rejected by compliant TLS implementations. Reduce the maximum validty of certificates to keep them under 2050 - this can be re-evaluated after PeculiarVentures/x509#73 is fixed.
In accordance with RFC5280 (https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.5):
The current version of the module does not support the capability to specify the desired time type for The implementation class that determines the choice between |
`@peculiar/x509` may be representing everything as UTCTime - dates after 2050 should be GeneralizedTime so are rejected by compliant TLS implementations. Reduce the maximum validty of certificates to keep them under 2050 - this can be re-evaluated after PeculiarVentures/x509#73 is fixed.
@achingbrain I utilized one of the tests to generate an X509 certificate with GeneralizedTime and attempted to read this certificate using OpenSSL.
OpenSSL successfully read the certificate without any issues. SEQUENCE (3 elem)
SEQUENCE (8 elem)
[0] (1 elem)
INTEGER 2
INTEGER 1
SEQUENCE (2 elem)
OBJECT IDENTIFIER 1.2.840.113549.1.1.11 sha256WithRSAEncryption (PKCS #1)
NULL
SEQUENCE (2 elem)
SET (1 elem)
SEQUENCE (2 elem)
OBJECT IDENTIFIER 2.5.4.3 commonName (X.520 DN component)
PrintableString Test
SET (1 elem)
SEQUENCE (2 elem)
OBJECT IDENTIFIER 2.5.4.10 organizationName (X.520 DN component)
UTF8String Дом
SEQUENCE (2 elem)
UTCTime 2019-12-31 23:00:00 UTC
GeneralizedTime 2059-12-31 23:00:00 UTC
I also tried to read the generated certificate using Go, and it worked as well. package main
import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"log"
)
func main() {
// Read the PEM certificate file
data, err := ioutil.ReadFile("cert.pem")
if err != nil {
log.Fatalf("Failed to read the certificate file: %v", err)
}
// Parse the PEM certificate
block, _ := pem.Decode(data)
if block == nil || block.Type != "CERTIFICATE" {
log.Fatalf("Failed to decode PEM block containing the certificate")
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
log.Fatalf("Failed to parse certificate: %v", err)
}
// Print the NotBefore and NotAfter fields
fmt.Printf("NotBefore: %v\n", cert.NotBefore)
fmt.Printf("NotAfter: %v\n", cert.NotAfter)
} Output
|
I'm not too fond of the idea of exposing ASN.1 encoding types in X509, I do not believe we do this elsewhere, and it looks like a footgun to do so. As per RFC5280 GeneralizedTime should work today and after 250 and it is my understanding that is what the library does today. I suspect the issue is in the validator. |
I see an error with this certificate, generated with
OpenSSL can parse it: % openssl x509 -in ./cert.pem -text -noout
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1761912615501990288 (0x1873923054468990)
Signature Algorithm: ecdsa-with-SHA256
Issuer:
Validity
Not Before: Apr 2 10:02:08 2024 GMT
Not After : Mar 9 11:02:08.386 2124 GMT
Subject:
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:09:b9:6f:b8:a4:8a:7c:4b:f7:b7:9d:ab:36:8b:
c8:0a:ee:72:37:59:db:f3:24:89:72:59:9d:e8:04:
99:07:21:e5:31:bc:16:84:b3:06:1c:5b:7e:da:7b:
44:24:2b:0f:76:9b:95:8d:af:4f:77:da:b6:a1:62:
ff:44:ec:72:53
ASN1 OID: prime256v1
NIST CURVE: P-256
X509v3 extensions:
1.3.6.1.4.1.53594.1.1: critical
..........0.. 0..3...+.....0.."0
........z'[....%Y^..82..~...>.....b...a.G.......+...........[P.I..jXA......s....zEm%..[..N.*g.....E....!..5.T...t<7(.BD.!...{.......y...K..0.o4J....;...&*........j3..^..a.....p.....t.l......1...H..i.Qj.q..J..a.....w.A.Mc.=p..p..<o...Ea.\FV..m.............Y.`..Ci...-..\...or...{C...........5..K....;..$...6..P.).v8.m7....x$ld}qT.F........,...a...5..
........q.n..}.+~..\q........_....l.'.V.Y..f.]..h..K].).{.G..Q..q '.
Signature Algorithm: ecdsa-with-SHA256
Signature Value:
30:46:02:21:00:88:e4:c8:0c:54:60:ad:19:68:05:00:d8:82:
b9:9f:cd:95:0c:fe:fa:5b:21:7e:c2:12:3b:0f:5e:c9:8d:9d:
e5:02:21:00:b5:dd:b0:b4:45:98:5e:4d:5a:8c:f5:86:59:2c:
8c:8f:62:93:6a:37:f3:1c:cd:07:30:97:89:43:10:d2:5f:33 Go fails using the script from above: % go run parse.go
2024/04/02 12:09:15 Failed to parse certificate: asn1: time did not serialize back to the original value and may be invalid: given "21240309110208.386Z", but serialized as "21240309110208Z"
exit status 1 RFC 5280 says:
Maybe this has something to do with it? Certainly setting the ms of the |
I'm creating certificates with expiry dates in the far future.
Trying to use them over TLS results in errors on the remote like:
From what I understand X.509 has two time representations, UTCTime if the date is 2049 or earlier, and GeneralizedTime if the date is 2050 or later.
If I make the expiry date before 2049 everything works as expected.
Could this module be representing everything as
UTCTime
?The text was updated successfully, but these errors were encountered: