Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miekg/pkcs11
pkcs11 wrapper for Go
https://github.com/miekg/pkcs11
c go hsm pkcs11 softhsm
Last synced: 7 days ago
JSON representation
pkcs11 wrapper for Go
- Host: GitHub
- URL: https://github.com/miekg/pkcs11
- Owner: miekg
- License: bsd-3-clause
- Created: 2012-09-20T13:32:28.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-04-06T22:13:40.000Z (7 months ago)
- Last Synced: 2024-10-19T16:05:10.073Z (18 days ago)
- Topics: c, go, hsm, pkcs11, softhsm
- Language: Go
- Size: 817 KB
- Stars: 376
- Watchers: 29
- Forks: 133
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PKCS#11
This is a Go implementation of the PKCS#11 API. It wraps the library closely, but uses Go idiom where
it makes sense. It has been tested with SoftHSM.## SoftHSM
* Make it use a custom configuration file `export SOFTHSM_CONF=$PWD/softhsm.conf`
* Then use `softhsm` to init it
~~~
softhsm --init-token --slot 0 --label test --pin 1234
~~~* Then use `libsofthsm2.so` as the pkcs11 module:
~~~ go
p := pkcs11.New("/usr/lib/softhsm/libsofthsm2.so")
~~~## Examples
A skeleton program would look somewhat like this (yes, pkcs#11 is verbose):
~~~ go
p := pkcs11.New("/usr/lib/softhsm/libsofthsm2.so")
err := p.Initialize()
if err != nil {
panic(err)
}defer p.Destroy()
defer p.Finalize()slots, err := p.GetSlotList(true)
if err != nil {
panic(err)
}session, err := p.OpenSession(slots[0], pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION)
if err != nil {
panic(err)
}
defer p.CloseSession(session)err = p.Login(session, pkcs11.CKU_USER, "1234")
if err != nil {
panic(err)
}
defer p.Logout(session)p.DigestInit(session, []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_SHA_1, nil)})
hash, err := p.Digest(session, []byte("this is a string"))
if err != nil {
panic(err)
}for _, d := range hash {
fmt.Printf("%x", d)
}
fmt.Println()
~~~Further examples are included in the tests.
To expose PKCS#11 keys using the [crypto.Signer interface](https://golang.org/pkg/crypto/#Signer),
please see [github.com/thalesignite/crypto11](https://github.com/thalesignite/crypto11).