go - How can i create a root key and X.509 Certificate - Stack Overflow

I am running a part of the open-source fleet code from:.goWhen I use my .crt and .key file in this code

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

相关推荐

  • go - How can i create a root key and X.509 Certificate - Stack Overflow

    I am running a part of the open-source fleet code from:.goWhen I use my .crt and .key file in this code

    2天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信