Skip to content

baycan/pkcs11

This branch is 6 commits behind miekg/pkcs11:master.

Folders and files

NameName
Last commit message
Last commit date
Jan 4, 2022
Jan 18, 2022
Jan 6, 2022
Sep 28, 2018
Aug 14, 2013
Apr 19, 2019
Jan 4, 2022
Jan 6, 2022
Jan 6, 2022
Aug 14, 2013
Apr 1, 2019
Aug 12, 2013
Sep 28, 2018
Jan 26, 2022
Sep 28, 2018
Jan 5, 2022
Sep 15, 2017
Jan 4, 2022
Sep 15, 2017
Sep 28, 2018
Sep 28, 2018
Jan 5, 2022
Aug 10, 2013
Apr 29, 2019
Jan 26, 2022
Jan 5, 2022
Jan 5, 2022

Repository files navigation

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.

About

pkcs11 wrapper for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 52.9%
  • C 47.1%