亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

簽署證書時,授權密鑰標識符被復制到 SKID

簽署證書時,授權密鑰標識符被復制到 SKID

Go
神不在的星期二 2023-03-21 10:37:42
我正在嘗試使用 CSR 和包裝器簽署證書spacemonkeygo/openssl。用于簽署證書的控制臺 openssl 命令按預期工作,我獲得了有效證書。openssl x509 -req -days 365 -in cert_client.csr -CA ca/root.crt -CAkey ca/root.key -set_serial 10101 -out cert_client.crt -extfile ca/extensions.cnf從截圖可以看出,SKID和Issuer的keyid是不一樣的。但是,我在 Go 中的代碼提供了一個錯誤的證書,其中 SKID 包含頒發證書的 keyid 的確切值。它導致在“授權密鑰標識符”中為“頒發者”復制無效值:由于 SKID 與頒發者的 KeyId 相同,它“認為”證書是自行頒發的。如果我不調用SetIssuer,SKID 是新生成的,但生成的證書仍顯示為“無效”。我在代碼中做錯了什么?
查看完整描述

1 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

我已經實施了一個 hacky 解決方法來添加 SKID 和 authorityKeyIdentifier。生成的證書有效。但是,由于structx *C.X509的成員Certificate未導出,因此訪問它們的唯一方法是通過不安全的指針和強制轉換。

這不是推薦的方式,而是spacemonkey/go更新之前的一種方式(我懷疑它會很快發生)。


func addAuthorityKeyIdentifier(c *openssl.Certificate) error {

    var ctx C.X509V3_CTX

    C.X509V3_set_ctx(&ctx, nil, nil, nil, nil, 0)


    // this is ugly and very unsafe!

    cx509 := *(**C.X509)(unsafe.Pointer(c))


    cx509Issuer := cx509

    if c.Issuer != nil {

        cx509Issuer = *(**C.X509)(unsafe.Pointer(c.Issuer))

    }

    ctx.issuer_cert = cx509Issuer


    cExtName := C.CString("authorityKeyIdentifier")

    defer C.free(unsafe.Pointer(cExtName))

    cExtValue := C.CString("keyid:always,issuer:always")

    defer C.free(unsafe.Pointer(cExtValue))


    extension := C.X509V3_EXT_nconf(nil, &ctx, cExtName, cExtValue)

    if extension == nil {

        return errors.New("failed to set 'authorityKeyIdentifier' extension")

    }

    defer C.X509_EXTENSION_free(extension)


    addResult := C.X509_add_ext(cx509, extension, -1)

    if addResult == 0 {

        return errors.New("failed to set 'authorityKeyIdentifier' extension")

    }


    return nil

}


func addSKIDExtension(c *openssl.Certificate) error {

    var ctx C.X509V3_CTX

    C.X509V3_set_ctx(&ctx, nil, nil, nil, nil, 0)

    

    // this is ugly and very unsafe!

    cx509 := *(**C.X509)(unsafe.Pointer(c))

    _ = cx509


    ctx.subject_cert = cx509

    _ = ctx


    cExtName := C.CString("subjectKeyIdentifier")

    defer C.free(unsafe.Pointer(cExtName))

    cExtValue := C.CString("hash")

    defer C.free(unsafe.Pointer(cExtValue))


    extension := C.X509V3_EXT_nconf(nil, &ctx, cExtName, cExtValue)

    if extension == nil {

        return errors.New("failed to set 'subjectKeyIdentifier' extension")

    }

    defer C.X509_EXTENSION_free(extension)


    // adding itself as a subject

    addResult := C.X509_add_ext(cx509, extension, -1)

    if addResult == 0 {

        return errors.New("failed to set 'subjectKeyIdentifier' extension")

    }


    return nil

}



查看完整回答
反對 回復 2023-03-21
  • 1 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號