debian-forge-composer/vendor/github.com/miekg/pkcs11
Ondřej Budai 0359647a82 go.mod: update to Go 1.18
Fedora 35 support was dropped, so we can update to a newer Go.

Stable RHEL 8 and 9 and Fedora 36 ships Go 1.18, so let's switch to it.

"//go:build" directives are now apparently enforced by go fmt, so that's why
there were added.

Also, all the github actions were adjusted to use Go 1.18.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2023-01-09 14:03:18 +01:00
..
.gitignore container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
error.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
hsm.db container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
LICENSE container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
Makefile.release container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
params.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
pkcs11.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
pkcs11.h container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
pkcs11f.h container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
pkcs11go.h container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
pkcs11t.h container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
README.md container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
release.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
softhsm.conf container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
softhsm2.conf container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
types.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
vendor.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00
zconst.go container: add support for uploading to registries 2022-06-29 10:02:46 +02:00

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.