Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions p11mod/p11mod.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Namecoin Developers LGPLv3+
// Copyright 2021-2022 Namecoin Developers LGPLv3+

package p11mod

Expand Down Expand Up @@ -733,9 +733,47 @@ func (ll *llBackend) GenerateKey(sh pkcs11.SessionHandle, m []*pkcs11.Mechanism,
}

func (ll *llBackend) GenerateKeyPair(sh pkcs11.SessionHandle, m []*pkcs11.Mechanism, public, private []*pkcs11.Attribute) (pkcs11.ObjectHandle, pkcs11.ObjectHandle, error) {
// TODO
log.Println("p11mod GenerateKeyPair: not implemented")
return 0, 0, pkcs11.Error(pkcs11.CKR_FUNCTION_NOT_SUPPORTED)
session, err := ll.getSessionByHandle(sh)
if err != nil {
return 0, 0, err
}

if len(m) != 1 {
log.Println("p11mod GenerateKeyPair: expected exactly one mechanism")
return 0, 0, pkcs11.Error(pkcs11.CKR_MECHANISM_INVALID)
}

if m[0] == nil {
log.Println("p11mod GenerateKeyPair: nil mechanism")
return 0, 0, pkcs11.Error(pkcs11.CKR_MECHANISM_INVALID)
}

request := p11.GenerateKeyPairRequest{
Mechanism: *m[0],
PublicKeyAttributes: public,
PrivateKeyAttributes: private,
}

pair, err := session.session.GenerateKeyPair(request)
if err != nil {
return 0, 0, err
}

session.objects = append(session.objects, p11.Object(pair.Public))

// 0 is never a valid object handle, as per PKCS#11 spec. So the object
// handle of the final object is its index + 1, which is the same as the
// length of the objects slice.
publicHandle := len(session.objects)

session.objects = append(session.objects, p11.Object(pair.Private))

// 0 is never a valid object handle, as per PKCS#11 spec. So the object
// handle of the final object is its index + 1, which is the same as the
// length of the objects slice.
privateHandle := len(session.objects)

return pkcs11.ObjectHandle(publicHandle), pkcs11.ObjectHandle(privateHandle), nil
}

func (ll *llBackend) WrapKey(sh pkcs11.SessionHandle, m []*pkcs11.Mechanism, wrappingkey, key pkcs11.ObjectHandle) ([]byte, error) {
Expand Down
8 changes: 8 additions & 0 deletions testdata/ci-opendnssec-tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ echo "===== test-rsaimport slot 0 (diff via p11proxy) ====="

diff -I '^Modulus: [0-9A-F]\+$' test-rsaimport-default.txt test-rsaimport-p11proxy.txt || testdata/dump-proxy-log-fail.bash

echo "===== test-all slot 0 (via p11proxy) ====="

pkcs11-testing --module ./libp11proxy.so --slot "$SLOT_ID" --pin 1234 --test-all | tee test-all-p11proxy.txt || true

echo "===== test-all slot 0 (diff via p11proxy) ====="

diff -I '^Modulus: [0-9A-F]\+$' test-all-default.txt test-all-p11proxy.txt || testdata/dump-proxy-log-fail.bash

echo "===== init slot 1 ====="

SLOT_ID=$(softhsm2-util --init-token --slot 1 --label softhsm --so-pin 1234 --pin 1234 | grep -oE '[^ ]+$')
Expand Down