最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论