ARO-RP/vendor/github.com/miekg/pkcs11
darthhexx 1c4e98933e Vendor installer release 4.10
Switches to go.1.17, OCP 4.10, and Kubernetes 1.23 modules.
2022-05-25 14:49:12 +10:00
..
.gitignore vendor update 2021-01-28 12:04:55 +00:00
LICENSE vendor update 2021-01-28 12:04:55 +00:00
Makefile.release vendor update 2021-01-28 12:04:55 +00:00
README.md Automated updates from "make vendor" 2022-01-25 11:47:15 -05:00
error.go vendor update 2021-01-28 12:04:55 +00:00
hsm.db vendor update 2021-01-28 12:04:55 +00:00
params.go vendor update 2021-01-28 12:04:55 +00:00
pkcs11.go Automated updates from "make vendor" 2022-01-25 11:47:15 -05:00
pkcs11.h vendor update 2021-01-28 12:04:55 +00:00
pkcs11f.h vendor update 2021-01-28 12:04:55 +00:00
pkcs11go.h vendor update 2021-01-28 12:04:55 +00:00
pkcs11t.h vendor update 2021-01-28 12:04:55 +00:00
release.go Automated updates from "make vendor" 2022-01-25 11:47:15 -05:00
softhsm.conf vendor update 2021-01-28 12:04:55 +00:00
softhsm2.conf vendor update 2021-01-28 12:04:55 +00:00
types.go Automated updates from "make vendor" 2022-01-25 11:47:15 -05:00
vendor.go vendor update 2021-01-28 12:04:55 +00:00
zconst.go Automated updates from "make vendor" 2022-01-25 11:47:15 -05:00

README.md

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:

    p := pkcs11.New("/usr/lib/softhsm/libsofthsm2.so")
    

Examples

A skeleton program would look somewhat like this (yes, pkcs#11 is verbose):

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, please see github.com/thalesignite/crypto11.