Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES key gen with ePass2003 not working #41

Closed
Phaestion opened this issue Oct 3, 2016 · 1 comment
Closed

AES key gen with ePass2003 not working #41

Phaestion opened this issue Oct 3, 2016 · 1 comment

Comments

@Phaestion
Copy link

Hi there

I need to generate/store generated AES keys in an ePass2003. The hardware clearly supports AES. I implemented my code with SoftHSMv2 for generating an AES key and for storing an AES key, through the CreateObject function.

After I've tested everything with SoftHSM2, I started using the ePass2003. I used the exact same CreateObject and attributes but I get a: CKR_ATTRIBUTE_VALUE_INVALID error.

I then implemented AES key generation instead of the CreateObject function. I tested it with SoftHSM and it worked 100%. When I tested it with the ePass2003 I get a CKR_FUNCTION_NOT_SUPPORTED error.

Here is my code for the CreateObject function:

key := []byte("0123456789123456")

attr := []*pkcs11.Attribute{
       pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_SECRET_KEY),
       pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_AES),
       pkcs11.NewAttribute(pkcs11.CKA_TOKEN, true),
       pkcs11.NewAttribute(pkcs11.CKA_LABEL, "My AES KEY"),
       pkcs11.NewAttribute(pkcs11.CKA_ENCRYPT, true),
       pkcs11.NewAttribute(pkcs11.CKA_VALUE, key),
       pkcs11.NewAttribute(pkcs11.CKA_EXTRACTABLE, false),
}

_, err = p.CreateObject(session, attr)

if err != nil {
       panic(err)
}

And here is my code for the GenerateKey function:

attr := []*pkcs11.Attribute{
       pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_SECRET_KEY),
       pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_AES),
       pkcs11.NewAttribute(pkcs11.CKA_ENCRYPT, true),
       pkcs11.NewAttribute(pkcs11.CKA_DECRYPT, true),
       pkcs11.NewAttribute(pkcs11.CKA_SIGN, true),
       pkcs11.NewAttribute(pkcs11.CKA_VERIFY, true),
       pkcs11.NewAttribute(pkcs11.CKA_TOKEN, true),
       pkcs11.NewAttribute(pkcs11.CKA_PRIVATE, false),
       pkcs11.NewAttribute(pkcs11.CKA_VALUE_LEN, 16),
       pkcs11.NewAttribute(pkcs11.CKA_LABEL, "My AES KEY"),
}

mech := []*pkcs11.Mechanism{
       pkcs11.NewMechanism(pkcs11.CKM_AES_KEY_GEN, nil),
}

_, err = p.GenerateKey(session, mech, attr)
if err != nil {
       panic(err)
}

Does the library support using AES on hardware keys? Any help would be greatly appreciated.

@optnfast
Copy link
Contributor

optnfast commented Mar 8, 2017

The library supports AES; I can generate AES keys through it on a different device. The error is probably from the device or its PKCS#11 library. Perhaps it supports key storage/use but not key generation?

@miekg miekg closed this as completed Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants