moby--moby/vendor/src/github.com/miekg/pkcs11
Riyaz Faizullabhoy 0bb1acee37 bumping miekg/pkcs11 dependency for go1.6
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
2016-02-25 21:29:37 -08:00
..
.gitignore update notary vendors 2015-11-13 13:19:09 -08:00
.travis.yml bumping miekg/pkcs11 dependency for go1.6 2016-02-25 21:29:37 -08:00
LICENSE update notary vendors 2015-11-13 13:19:09 -08:00
README.md bumping miekg/pkcs11 dependency for go1.6 2016-02-25 21:29:37 -08:00
const.go bumping miekg/pkcs11 dependency for go1.6 2016-02-25 21:29:37 -08:00
error.go update notary vendors 2015-11-13 13:19:09 -08:00
hsm.db update notary vendors 2015-11-13 13:19:09 -08:00
pkcs11.go bumping miekg/pkcs11 dependency for go1.6 2016-02-25 21:29:37 -08:00
pkcs11.h update and run vendor script 2015-12-16 09:58:20 -08:00
pkcs11f.h update and run vendor script 2015-12-16 09:58:20 -08:00
pkcs11t.h update notary vendors 2015-11-13 13:19:09 -08:00
softhsm.conf update notary vendors 2015-11-13 13:19:09 -08:00
types.go bumping miekg/pkcs11 dependency for go1.6 2016-02-25 21:29:37 -08:00

README.md

PKCS#11 Build Status

This is a Go implementation of the PKCS#11 API. It wraps the library closely, but uses Go idiom were 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 libsofthsm.so as the pkcs11 module:

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

Examples

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

p := pkcs11.New("/usr/lib/softhsm/libsofthsm.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.

TODO

  • Fix/double check endian stuff, see types.go NewAttribute()
  • Look at the memory copying in fast functions (sign, hash etc)