第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用“certtostore”從 Golang 中的 Windows 證書存儲(chǔ)獲取證書時(shí)出錯(cuò)?

使用“certtostore”從 Golang 中的 Windows 證書存儲(chǔ)獲取證書時(shí)出錯(cuò)?

Go
白板的微信 2022-12-19 18:14:11
我想使用 Windows 證書商店的證書包,誰(shuí)能告訴我我在這里做錯(cuò)了什么?我的代碼:package mainimport (    "fmt"    "runtime"    "github.com/google/certtostore")type certmgr struct {    certToStore certtostore.CertStorage}func main() {    if runtime.GOOS == "windows" {        var cert certmgr        certInStore, err := cert.certToStore.Cert()        if err != nil {            fmt.Println("message", "Error in getting system store certificate ...")        }        fmt.Println("Windows System Store Certificate", *certInStore)    }}我得到的錯(cuò)誤:panic: runtime error: invalid memory address or nil pointer dereference[signal 0xc0000005 code=0x0 addr=0x0 pc=0xbe2dda]goroutine 1 [running]:main.main()        C:/Users/prajwal.bhagat/go/src/phoenix/mainsvc/cmd/main/test.go:17 +0x1aexit status 2
查看完整描述

1 回答

?
www說(shuō)

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以使用類似 的庫(kù)google/certtostore,它是一個(gè)多平臺(tái)包,允許您在 Linux 上使用 x509 證書,在 Windows 上使用證書存儲(chǔ)。

它不直接獲取證書包,而是使用WindowscertGetCertificateChain調(diào)用,該調(diào)用從最終證書開(kāi)始構(gòu)建證書鏈上下文,并在可能的情況下返回到受信任的根 CA。

它由 所使用CertWithContext(),它使用創(chuàng)建時(shí)提供的頒發(fā)者值執(zhí)行證書查找WinCertStore。
它返回證書及其 Windows 上下文,可用于執(zhí)行其他操作,例如使用 查找私鑰CertKey()。


無(wú)效的內(nèi)存地址或 nil 指針取消引用

你需要初始化var cert certmgr

更一般地說(shuō),您需要先獲取商店,如本例所示

  fmt.Println("open cert store")


    // Open the local cert store. Provider generally shouldn't matter, so use Software which is ubiquitous. See comments in getHostKey.

    store, err := certtostore.OpenWinCertStore(certtostore.ProviderMSSoftware, "", []string{"localhost"}, nil, false)

    

    if err != nil {

        fmt.Errorf("OpenWinCertStore: %v", err)

        return

    }   

    

    fmt.Println("get cert from cert store")

    // Obtain the first cert matching all of container/issuers/intermediates in the store.

    // This function is indifferent to the provider the store was opened with, as the store lists certs

    // from all providers.

    crt, context, err := store.CertWithContext()

    if err != nil {

        fmt.Println("failed to get cert from cert store. ", err)

        return

    }

    

    if crt == nil {

        fmt.Println("no cert")

        return

    }


    fmt.Println("get key from cert")

    // Obtain the private key from the cert. This *should* work regardless of provider because

    // the key is directly linked to the certificate.

    key, err := store.CertKey(context)

    if err != nil {

        fmt.Printf("private key not found in %s, %s", store.ProvName, err)

        return

    }


    if key == nil {

        fmt.Println("no key")

        return

    }


    fmt.Printf("find cert '%s' with private key in container '%s', algo '%s'\n", crt.Subject, key.Container, key.AlgorithmGroup)


查看完整回答
反對(duì) 回復(fù) 2022-12-19
  • 1 回答
  • 0 關(guān)注
  • 268 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)