containerd/vendor/github.com/miekg/pkcs11
Kazuyoshi Kato 388ee880d2 Upgrade containerd/imgcrypt and opencontainers/image-spec
- Upgrade github.com/containerd/imgcrypt to prepare for typeurl upgrade
  (see https://github.com/containerd/imgcrypt/pull/72)
- Upgrade github.com/opencontainers/image-spec since imgcrypto needs at
  least 1.0.2.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2022-03-22 21:17:18 +00:00
..
.gitignore Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
error.go Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
hsm.db Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
LICENSE Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
Makefile.release Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
params.go Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
pkcs11.go Upgrade containerd/imgcrypt and opencontainers/image-spec 2022-03-22 21:17:18 +00:00
pkcs11.h Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
pkcs11f.h Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
pkcs11go.h Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
pkcs11t.h Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
README.md Upgrade containerd/imgcrypt and opencontainers/image-spec 2022-03-22 21:17:18 +00:00
release.go Upgrade containerd/imgcrypt and opencontainers/image-spec 2022-03-22 21:17:18 +00:00
softhsm2.conf Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
softhsm.conf Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
types.go Upgrade containerd/imgcrypt and opencontainers/image-spec 2022-03-22 21:17:18 +00:00
vendor.go Update to newest imgcrypt, aufs and zfs 2021-03-01 12:23:03 -05:00
zconst.go Upgrade containerd/imgcrypt and opencontainers/image-spec 2022-03-22 21:17:18 +00: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.