Skip to content

Repository files navigation

certstore PkgGoDevReport card

Test macOS (recent Go versions)
Test Windows (recent Go versions)

Certstore is a Go library for accessing user identities stored in platform certificate stores. On Windows and macOS, certstore can enumerate user identities and sign messages with their private keys.

Example

package main
import (
"crypto""encoding/hex""errors""fmt""crypto/rand""crypto/sha256""github.com/github/certstore"
)
funcmain() {
sig, err:=signWithMyIdentity("Ben Toews", "hello, world!")
iferr!=nil {
panic(err)
}
fmt.Println(hex.EncodeToString(sig))
}
funcsignWithMyIdentity(cn, msgstring) ([]byte, error) {
// Open the certificate store for use. This must be Close()'ed once you're// finished with the store and any identities it contains.store, err:=certstore.Open()
iferr!=nil {
returnnil, err
}
deferstore.Close()
// Get an Identity slice, containing every identity in the store. Each of// these must be Close()'ed when you're done with them.idents, err:=store.Identities()
iferr!=nil {
returnnil, err
}
// Iterate through the identities, looking for the one we want.varme certstore.Identityfor_, ident:=rangeidents {
deferident.Close()
crt, errr:=ident.Certificate()
iferrr!=nil {
returnnil, errr
}
ifcrt.Subject.CommonName=="Ben Toews" {
me=ident
}
}
ifme==nil {
returnnil, errors.New("Couldn't find my identity")
}
// Get a crypto.Signer for the identity.signer, err:=me.Signer()
iferr!=nil {
returnnil, err
}
// Digest and sign our message.digest:=sha256.Sum256([]byte(msg))
signature, err:=signer.Sign(rand.Reader, digest[:], crypto.SHA256)
iferr!=nil {
returnnil, err
}
returnsignature, nil
}

About

Go library for using system certificate stores on macOS/Windows

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages