I am running a part of the open-source fleet code from:
.go
When I use my .crt
and .key
file in this code:
func EnrollHandler(w http.ResponseWriter, r *http.Request) {
// Some code
// Load raw Root CA
rootCertificateDer, err := ioutil.ReadFile("./identity/identity.crt")
if err != nil {
panic(err)
}
rootPrivateKeyDer, err := ioutil.ReadFile("./identity/identity.key")
if err != nil {
panic(err)
}
// Convert the raw Root CA cert & key to parsed version
rootCert, err := x509.ParseCertificate(rootCertificateDer)
if err != nil {
panic(err)
}
// rest of the code
}
This line throw a panic:
rootCert, err := x509.ParseCertificate(rootCertificateDer)
2025/03/11 03:24:50 http: panic serving 127.0.0.1:40172: x509: malformed certificate
goroutine 22 [running]:
net/http.(*conn).serve.func1()
/usr/lib/go-1.23/src/net/http/server.go:1947 +0xbe
panic({0x6dde80?, 0xc0000967e0?})
/usr/lib/go-1.23/src/runtime/panic.go:785 +0x132
I have created .crt
and .key
using OpenSSL:
openssl genrsa -out identity.key 2048
openssl req -new -x509 -key identity.key -out identity.crt -days 365 -subj "/CN=MDM-Root-CA"
I would like to know that why my .crt
is malformed, and how I can solve this issue?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744798041a4594321.html
评论列表(0条)