tpm and software token cannot be used together
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
opencryptoki (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
I cannot write objects to a TPM-backed opencryptoki token. Although writes appear to succeed and the count of objects seems to have been updated, you can't read attributes from any objects or use them for crypto operations.
This happens on Precise with version 2.3.1+dfsg-3 of opencryptoki.
Steps to reproduce (as root):
1. Enable and clear the TPM in BIOS.
2. Install trousers, opencryptoki, and opensc.
3. Take ownership of the TPM with tpm_takeownership.
4. Initialize the PKCS#11 token and set SO and user PINs:
- pkcsconf -I -c 0 -S 87654321
- pkcsconf -P -c 0 -S 87654321 -n 111111
- pkcsconf -u -c 0 -S 111111 -n 000000
5. Write any X.509 certificate in DER format to the token:
- pkcs11-tool --module /usr/lib/
6. Attempt to list objects in the token:
- pkcs11-tool --module /usr/lib/
Expected results:
pkcs11-tool should list one certificate object and exit with no warnings.
Actual results:
pkcs11-tool reports lots of warnings and doesn't seem to know anything about the certificate:
--------
# pkcs11-tool --module /usr/lib/
Using slot 0 with a present token (0x0)
warning: PKCS11 function C_GetAttributeV
Data object 1
warning: PKCS11 function C_GetAttributeV
label: <empty>
warning: PKCS11 function C_GetAttributeV
application: <empty>
warning: PKCS11 function C_GetAttributeV
app_id: <empty>
warning: PKCS11 function C_GetAttributeV
warning: PKCS11 function C_GetAttributeV
flags:
--------
Additionally, no object file seems to have been written to disk. Opencryptoki should have written a numbered object file to /var/lib/
summary: |
- Cannot write objects to TPM token + tpm and software token cannot be used together |
Changed in opencryptoki (Ubuntu): | |
assignee: | nobody → Stéphane Graber (stgraber) |
tags: | added: css-sponsored-p rls-mgr-p-tracking |
Changed in opencryptoki (Ubuntu): | |
assignee: | Stéphane Graber (stgraber) → nobody |
Out of the box, opencryptoki configures both the TPM token and software token. But that combination exposes a bug in opencryptoki.
To start seeing this problem, compare the output of listing tokens with the opencryptoki "pkcsconf" command:
1) When only the software token is configured in /var/lib/ opencryptoki/ pk_config_ data:
Token #0 Info: REQUIRED| CLOCK_ON_ TOKEN|USER_ PIN_TO_ BE_CHANGED| SO_PIN_ TO_BE_CHANGED) 0xFFFFFFFF 0xFFFFFFFF
Label: IBM OS PKCS#11
Manufacturer: IBM Corp.
Model: IBM SoftTok
Serial Number: 123
Flags: 0x880045 (RNG|LOGIN_
Sessions: -1/-1
R/W Sessions: -1/-1
PIN Length: 4-8
Public Memory: 0xFFFFFFFF/
Private Memory: 0xFFFFFFFF/
Hardware Version: 1.0
Firmware Version: 1.0
Time: 01:53:10 PM
2) When only using the TPM token:
Token #0 Info: REQUIRED| CLOCK_ON_ TOKEN|USER_ PIN_TO_ BE_CHANGED| SO_PIN_ TO_BE_CHANGED| ) 0xFFFFFFFF 0xFFFFFFFF
Label: IBM PKCS#11 TPM Token
Manufacturer: IBM Corp.
Model: TPM v1.1 Token
Serial Number: 123
Flags: 0x880045 (RNG|LOGIN_
Sessions: -1/-1
R/W Sessions: -1/-1
PIN Length: 6-127
Public Memory: 0xFFFFFFFF/
Private Memory: 0xFFFFFFFF/
Hardware Version: 1.0
Firmware Version: 1.0
Time: 01:56:09 PM
3) When both are configured, you see two of whichever is listed first:
Token #0 Info: REQUIRED| CLOCK_ON_ TOKEN|TOKEN_ INITIALIZED| USER_PIN_ TO_BE_CHANGED| ) 0xFFFFFFFF 0xFFFFFFFF REQUIRED| CLOCK_ON_ TOKEN|TOKEN_ INITIALIZED| USER_PIN_ TO_BE_CHANGED| ) 0xFFFFFFFF 0xFFFFFFFF
Label: IBM PKCS#11 TPM Token
Manufacturer: IBM Corp.
Model: TPM v1.1 Token
Serial Number: 123
Flags: 0x80445 (RNG|LOGIN_
Sessions: -1/-1
R/W Sessions: -1/-1
PIN Length: 4-8
Public Memory: 0xFFFFFFFF/
Private Memory: 0xFFFFFFFF/
Hardware Version: 1.0
Firmware Version: 1.0
Time: 01:55:49 PM
Token #1 Info:
Label: IBM PKCS#11 TPM Token
Manufacturer: IBM Corp.
Model: TPM v1.1 Token
Serial Number: 123
Flags: 0x80445 (RNG|LOGIN_
Sessions: -1/-1
R/W Sessions: -1/-1
PIN Length: 4-8
Public Memory: 0xFFFFFFFF/
Private Memory: 0xFFFFFFFF/
Hardware Version: 1.0
Firmware Version: 1.0
Time: 01:55:49 PM
The out of the box config is to have both the TPM and software tokens configured which is broken.
Using only the software token, I am able to follow the instructions in the original bug report to write a certificate and private key to the token. Just for completeness, these are the commands I used to create the cert and key:
openssl req -outform der -out cert.der -new -x509 -newkey rsa:2048 -keyout key.tmp -subj '/O=dds/CN=dds' -days 3650
openssl rsa -inform pem -outform der -in key.tmp -out key.der
And I also used "--attr-from cert.der" argument to pkcs11-tool when writing the certificate and private key to the token.
Actions to take:
1) Test opencryptoki 2.4.1 to confirm this bug still exists in the more recent versions. If the bug is still present, identify root cause (for now, I'm suspecting some poor memory management in the common opencryptoki code).
2) Change the opencryptoki init script to not run pkcs11_star...