aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
2024-04-19Version 4.1.2HEADv4.1.2masterJames Bottomley1-1/+1
* doc updates to add new fields and clarify primary template * test fixes for newer tpm emulators Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-19doc: set the RFC date to when generatednextJames Bottomley1-1/+1
until it goes on to datatracker, this keeps me from having to bump the date periodically to prevent it from expiring. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-18tests: fix checks for illegal curvesJames Bottomley5-9/+28
The openssl check for unknown curve names simply looks for a specific string. Old openssl printed this but didn't error, but new openssl errors out. Update the check firstly to fail on error then check the string. Additionally some vTPMs have started supporting the SM2 curve. When it works in openssl it has the problem that it's only allowed with the SM3 hash, which won't work with any of the generic hash looping tests, so disable testing the SM2 curve. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-18tests: enable sha1 bank if the vtpm comes with it disabledJames Bottomley1-24/+43
Some vTPM implementations are shipping with the TCG recommendation to disable the SHA1 bank. This will cause some PCR based policy tests which depend on it to fail, so re-enable the sha1 bank if this is detected. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-18doc: update draft RFC to specify the template exactlyJames Bottomley1-4/+20
The TCG created some confusion with primary templates over what should be in the unique value. All implementations so far have taken the view that it should be two zero size points. However, the L template and earlier TCG drafts required two 32 byte zero filled points. To clear this up entirely, specify that the P-256 key must use the H-2 template (matching what everyone currently does) and that the RSA2048 key must use the H-1 template. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
2024-04-17doc: add optional rsaParentGary Lin via groups.io1-1/+16
Some implementation such as pcr-oracle prefers RSA 2048 to ECC NIST-P256 for the primary key. This commit introduces a new option, rsaParent, to make it flexible to choose the assymetric algorithm for the primary key. Signed-off-by: Gary Lin <glin@suse.com> [jejb: update option to number 5] Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-17doc: update draft RFC with an optional descriptionMorten Linderud1-0/+9
Useful for application that displays a user visible string to go along with the key. Signed-off-by: Morten Linderud <morten@linderud.pw> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-17tpm2-common: remove misleading comment from the ECC templateMorten Linderud1-3/+0
TPM2_Sign is actually used for ECC keys. Signed-off-by: Morten Linderud <morten@linderud.pw> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-04-17create_tpm2_key: fix missing tabs in --helpMorten Linderud1-9/+9
The blocks are not aligned properly making the output less readable. Signed-off-by: Morten Linderud <morten@linderud.pw> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-01-02Version 4.1.1v4.1.1James Bottomley1-1/+1
* fix 32 bit build Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2024-01-02Fix 32 bit signed conversionJames Bottomley4-8/+8
On 32 bits strtol can't be used to convert a hex number with the high bit set (as happens for persistent handles) because it will overflow and return LONG_MAX, strtoul must be used instead. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-30Version 4.1.0v4.1.0James Bottomley1-1/+1
* implement tpm2_PolicySecret Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-17doc: update draft RFC with TPM2_PolicySecret implementationJames Bottomley1-10/+38
Also update the recommendations for Authorization to make it clear that more than one password per key would cause issues for most crypto systems and should be avoided. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-17tests: add check for signed policiesJames Bottomley3-0/+51
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-17tools: add policy secret optionJames Bottomley8-7/+160
Adds the option --secret <handle> to insert a reliance on the authorization of the object named by <handle> in the policy. This has implications for emptyAuth because if the PolicySecret statement appears in the policy, it must be set (meaning we can no longer condition this on auth being NULL). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-17tpm2-common: add processing of TPM2_PolicySecretJames Bottomley1-0/+28
This uses the consumable authorization scheme where if PolicySecret is specified, it consumes the password in app_data->auth and no password is passed in to the main command. Although TPM2_PolicySecret has many options, the only ones that really matter to the policy hash are the name of the object and the policyRef. We also add a possibly zero handle hint at the beginning to identify persistent objects easily, since finding by name is hard. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-17Rethread handling of authorizations for TPM2_PolicySecretJames Bottomley4-34/+34
In theory, TPM2_PolicySecret allows multiple different passwords to be specified to use an object. However, this is incompatible with the single password model of openssl (and all other crypto systems), so we make the rule that if a policy contains TPM2_PolicySecret, meaning the auth has to be passed in to the policy session, then it can't also be required to authorize the main command as well (i.e. only a single authorization string per policy). We implement this by making the authorization string a return from tpm2_init_session. If authorization hasn't been consumed by policy sessions, it will be the value of app_data->auth otherwise if it has been consumed, it will be NULL. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-17tss: add tpm2_PolicySecretJames Bottomley2-0/+105
Add a cut down version of PolicySecret (with no nonceTPM, cpHashA or expiry and thus no returned timeout or ticket) for use with a PolicySecret statement in the encoded policy statements. For simplicity the authorization string is passed in and the internal routine constructs the necessary HMAC session for encoding it in the command (this saves the calling code from having to worry about multiple sessions). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-15tss: add support for getting the names of objects (including NV objects)James Bottomley5-7/+68
This is a precursor to supporting TPM2_PolicySecret. The essential component of this policy is the name of the object being used for authorization. The most common elements for names are persistent and NV objects. In each case the hash is that of the public area, but the NV object also has to have a special call to retrieve the public area (TPM2_NV_ReadPublic instead of TPM2_ReadPublic). Add a name option to tpm2_ReadPublic to allow it to retrieve the name and add tpm2_NV_ReadPublic to retrieve the name of and NV index. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-14tests: Add testing for the new locality flagJames Bottomley3-0/+25
Fairly simple since the emulator only runs at locality zero. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-14Add locality policyJames Bottomley5-4/+90
This allows the tools to bind to a locality using the policy flag --locality. The locality is a bitmap. The usual localities are 0-4. On kernels which support executing the kernel at a different locality from userspace, this allows things like the creation of sealed data that can only be unsealed in the kernel (or never unsealed in the kernel). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-14TSS: add locality policyJames Bottomley2-0/+31
Update both TSSs to add the ability to do locality policy. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-08doc: add clarity around policyRef in TPM2_PolicyAuthorizeJames Bottomley1-2/+21
When the same policy signing key is used for different TPM objects with signed policy, the policyRef must be unique to prevent policy swapping, so document this in the implementation considerations for signed policies. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-04Version 4.0.2v4.0.2James Bottomley1-1/+1
* Fixes for openssl 3.2 * fix for encrypted secret size * fix for swtpm and swtpm2 simultaneous install * gcc-13 fix * make signed_tpm2_policy match man page Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-04provider: fix reference countingJames Bottomley3-1/+11
The provider originally didn't take references in the context to the peer and standard key for EC derivation. Openssl 3.2 broke this assumption by freeing the peer key early. Fix this by taking the correct references. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-04fix the pkcs12 wrapping test for openssl 3.2James Bottomley1-2/+7
Openssl 3.2 has two problems with this test. The first is that it will no longer use a CA certificate unless it has the CA constraint set and the second is that it seems the pkcs12 required parameters are incompatible with the local openssl.cnf. Fix both by not using the local openssl.cnf when generating non-TPM openssl files and use the v3_ca section of the global openssl.cnf to add the CA constraint. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-12-04Fix dynamic_engine tests for openssl 3.2James Bottomley1-0/+1
Apparently openssl 3.2 no longer accepts the OPENSSL_ENGINE environment variable for the location of the engines directory. This breaks the dynamic engine test, so work around this by adding the engine location to LD_LIBRARY_PATH. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-11-28tpm2-common: fix encrypted secret sizeJames Bottomley1-0/+1
It's been reported that the ASN.1 representation of the encrypted secret is always two bytes too big and zero padded at the end. This is because the written parameter isn't reset to zero when the secret was Marshalled and is in fact left at 2 from a previous use. Fix by initializing to zero before marshalling. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-11-22signed_tpm2_policy: match the man pageJames Bottomley2-85/+162
The man page says we implement three commands: add, ls and rm; but we don't, we only implement add. So fix signed_tpm2_policy to match its man page. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-11-22tpm2-common: add helpers for querying and removing key policyJames Bottomley2-25/+89
These helpers will be used to implement the ls and rm functions of signed_tpm2_policy. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-11-22gcc-13 fixJames Bottomley1-1/+1
gcc-13 started giving an uninitialized variable error in unseal_tpm2_data.c even though reason would be initialized in every error leg. Fix it by initializing to NULL. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-11-22tests: fix for swtpm and tpm_server being installed simultaneouslyJames Bottomley2-5/+5
If both are installed, we will prefer the IBM swtpm2 (tpm_server), so we are still able to run the nonopenssl_ecc test that swtpm fails. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-07-05Version 4.0.1v4.0.1James Bottomley1-1/+1
* Fixes for intel-tss and openssl < 3 * Fix support for the non-reference swtpm (although you should use the reference implementation for testing) * Doc updates to the draft RFC to make it ready for ietf submission * Fix openssl BOOLEAN issues Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-29intel-tss: more openssl-3 fixesJames Bottomley1-6/+6
Update incorrect use of macro to OPENSSL_VERSION_NUMBER Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-29tpm2-common: fix for openssl Boolean problemsJames Bottomley1-2/+4
The ASN.1 standard strictly requires a Boolean to be 0xff for true or 0 for false. Apparently openssl simply writes the value it was given without checking (which is usually a C value true or false), so a lot of our BOOLEANS are ending up with the illegal value 1. Redo the setting of this variable to be either 0xff for true or absent for false (as the standard recommends). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-29configure.ac: always use the reference tpm if availableJames Bottomley1-3/+3
The current formulation of the if clause would use swtpm first if found and then the ibmswtpm2. Since the latter is the reference implementation and the former has deviated from it to the extent that some tests have to be skipped to prevent spurious failures, always prefer testing with the reference implementation. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-28doc: convert to sourcecode tag and add ASN.1 moduleJames Bottomley1-26/+75
David Woodhouse suggested converting from <artwork> to <sourcecode> for the ASN.1 code and Russ Housley suggested adding an ASN.1 module. The ASN.1 module now passes the syntax checker at https://osystest.site/webtools2/asn1SyntaxCheck.php Which necessitated quite a few changes like the addition of commas and the changing of value names to start with lower case Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-26doc: make references to the TCG template explicitJames Bottomley1-4/+15
And add a pointer to the actual provisioning document where the template is specified. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-26tests: skip known test failures for swtpmJames Bottomley1-0/+5
Apparently swtpm has deviated from the TPM2 reference implementation and one consequence of this is that it no longer handles parametrised EC curves correctly. Skip the non openssl curve tests to prevent this causing spurious test failures. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-26intel-tss: fix Intel TSS for swtpmJames Bottomley1-1/+6
Apparently the Intel TSS insists on sending a command to the control socket for the mssim tcti backend. This fails for swtpm (because it isn't listening), so set the swtpm backend for this case. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-26tpm-common: remove support for < 256 bit elliptic curvesJames Bottomley2-111/+1
No shipping TPM actually supports these curves and OpenSSL doesn't produce the correct certificate signatures for them (pads to key length, so signature length check can't determine hash type). Rather than work around this, simply remove the curves. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-06-26intel-tss: fix openssl3 codeJames Bottomley1-6/+6
The correct format of an else if in CPP is #elif not #elsif (not sure why the CPP didn't error). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-04-17doc: fix a typo in draft-bottomley-tpm2-keys.xmlGary Lin via groups.io1-1/+1
Fix "auth{olicy" ==> "authPolicy" Signed-off-by: Gary Lin <glin@suse.com>
2023-03-29Version 4.0.0v4.0.0James Bottomley1-1/+1
* New openssl-3 provider * update intel-tss for openssl-3 * gcc-13 fix for enum/int confusion in prototypes Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-24tpm2-common.c: Fix gcc-13 being picky about int to enum conversionJames Bottomley2-2/+3
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22decode_encode: fix the provider recursion problemJames Bottomley1-0/+19
Normally providers are selected in order, so specifying --provider default --provider tpm2 is enough to ensure that the default provider is used for all routines the tpm2 provider doesn't actually provide. However, there is an exception to this ordering in that openssl will search the cache first before going in provider order, so when the implementation beneath this provider also needs to use openssl (as all tss's do) then you get into a situation where the first use of a tpm2 routine will populate the cache for tpm2 only and then all subsequent uses will find tpm2 before default. This is a serious recursion problem in the tss because it uses elliptic curve derivation to obtain the encrypted salt for sessions but it can't go back around and use this providers routines for EC because they'll eventually need to derive the encrypted salt ... The fix is to artificially populate the cache with the default provider before the tpm2 also gets added. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22tests: add provider testsJames Bottomley4-0/+84
Gate tests on openssl3, but re-run all the engine tests (except the dynamic engine one) using the provider. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22provider: add nv key handling with storeJames Bottomley5-4/+200
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22provider: add decryption functionsJames Bottomley6-7/+282
These take different forms: RSA is a simple RSA padded decryption but for EC it's an ECDH key derivation. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22openssl3 provider: add signaturesJames Bottomley4-1/+187
Add all the signature functions for EC and RSA keys. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22Add openssl3 providerJames Bottomley8-1/+553
Basic provider with decoders, keymanagement and signatures Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22Add missing OpenSSL3 functionsJames Bottomley6-0/+753
OpenSSL-3 apparently has never really tried to build an external provider. There are large swathes of functionality which exists within the openssl internals, but which isn't exposed but which providers actually have to use. Most providers roll their own, but here we provide a MIT licensed library of openssl missing functions that any provider can use. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-22intel-tss: update for openssl-3James Bottomley1-7/+63
The missing routines in the intel-tss over the IBM one need to be updated to use openssl-3 primitives. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17Version 3.4.0v3.4.0James Bottomley1-1/+1
* fix uninitialized variable in tpm2_try_policy() * fix importable key creation with Intel TSS * restructure directory layout to prepare for OpenSSL-3 provider Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tpm2-common.c: fix uninitialized variable in tpm2_try_policy()James Bottomley1-1/+1
tpm2_try_policy() can be handed a zero length policy to check if a signed policy consists of just one element. For this case it returns the initial value of RC, which is uninitialized. Fix by setting it to TPM_RC_SUCCESS. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17seal_tpm2_data: fix importable key creation with Intel TSSJames Bottomley1-0/+10
The intel TSS has an internal handle representation which is habitually used for everything. However, when the data is created off TPM, such as for importable keys, the external handle representation must be used to get the correct handle value. Fix the import case so the default handle is external not internal and add a missing parent string parser. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17doc: update the OID in the RFC to match realityJames Bottomley1-2/+2
Gary Lin noticed that the OID in the RFC is missing a digit compared to what's already in use. This appears to be an oversight from when the negotiations with the TCG were onging and the code got updated but not the RFC. Update the OID base to 2.23.133.10.1 to reflect what everyone is actually using. Cc: Gary Lin <glin@suse.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tpm2-common: factor out RSA decryptionJames Bottomley3-139/+84
We'll need to use this inside both the provider and the engine. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17add tests for elliptic curve parent authorityJames Bottomley1-0/+7
During the construction of the prior elliptic curve refactor patch a mistake was made whereby the parent authority wasn't passed in. This wasn't picked up by any of the current tests, so add a test specifically using parent authority for elliptic curve keys to prevent any regressions in this area. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tpm2-common: allow arbitrary hashes for elliptic curve signaturesJames Bottomley1-5/+13
There's no reason to restrict EC signatures to the TPM allowed hashes since we know how hashes have to be signed with the EC algorithm. Simply use a hash corresponding to the width of the EC key and pad or truncate appropriately. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tpm2-common: factor out elliptic curve signature and derivationJames Bottomley5-163/+175
Since these will have to be shared between the engine and the provider. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tpm2-common: reshuffle pieces for openssl3 providerJames Bottomley10-107/+110
Separate out bio loading (openssl3 uses bios not file names) of TPM keys and export tpm2_curve_get_order(). Use TPM2B_PUBLIC for the public key (saves multiple unmarshals in the provider). Also allows the elimination of the name_alg field which can now be picked out of the TPM2B_PUBLIC. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tests: make engine specification and inputs variablesJames Bottomley26-104/+108
Essentially this means modifying the engine tests to specify a provider or an engine. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17tests: move engine tests to a separate directoryJames Bottomley10-67/+72
Also move tests to be the last item in the Makefile.am SUBDIRS as recommended by the automake documentation. Eventually this will allow for the addition of provider tests which can be run independently from the engine tests. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17Restructure the subdirectories to follow a more common approachJames Bottomley57-83/+74
Eventually we're going to need to build engine and provider objects with the same name, so they'll need to be built in different directories and thus the project needs restructuring to allow this. engine is now in src/engine tpm2-common.c is now built as a library and in src/libcommon common includes are in src/include All the key creation and manipulation tools are in src/tools The tests have been rejigged to change where they look for the engine and consolidate bindir (which is now the src/tools) to a central location in the Makefile.am Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-03-17Version 3.3.2v3.3.2James Bottomley1-1/+1
* Fix memory leak of key authorization Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-02-23Fix memory leak of key authorizationJames Bottomley1-0/+3
The engine never actually frees the memory allocated by the password input routines. This is not only a memory leak, but also a potential sensitive data leak, so fix this by doing a clear_free in the teardown routines if app_data->auth was set. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-31Version 3.3.1v3.3.1James Bottomley1-1/+1
* fix intermittent EC TPM_RC_KEY return * add import section to man pages Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-30man page updatesJames Bottomley3-1/+40
seal_tpm2_key was missing a description of the --policy <file> option. Also add a section to create_tpm2_key nor seal_tpm2_key describing how to create importable keys/sealed data blobs. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-30Pad elliptic curve pointsJames Bottomley1-2/+15
Some tests with EC keys occasionally fail with TPM_RC_KEY. This has been traced to the x or y points of the public key being representable in fewer bytes than the order of the curve. Apparently the MS TPM emulator contains a check that the size of the points is always the order of the curve. Fix this by always padding EC points up to the curve order. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-29Version 3.3.0v3.3.0James Bottomley1-1/+1
* Add importable sealed data * Fix name hash for importable keys and data Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12Tests for name algorithm fixesJames Bottomley2-67/+83
The reason we didn't notice non-sha256 name algorithms didn't work on import is because we didn't test them, so loop all the import tests over different name algorithms to make sure we never regress here. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12name algorithm fixesJames Bottomley3-10/+11
The import options don't work with a non-sha256 name algorithm, primarily because they make the wrong assumptions about which hash they're supposed to be using for the encryption and hmac key derivations (it's always the name algorithm of the parent, never the one of the actual key). Also fix a missing argument to -n on seal_tpm2_data and set the name algorithm from the key file on unseal_tpm2_data. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12tests: add test for importable sealed dataJames Bottomley1-0/+23
Under simple conditions: a key with authorization and a key with pcr policy. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12seal_tpm2_data: allow the creation of importable sealed dataJames Bottomley1-35/+102
In the same way we do with keys, you should be able to use the --import key.pub option to seal data to a known SRK. The SRK should be created with a P-256 elliptic curve template to match the key we usually create as the parent. tsscreateprimary -hi o -ecc nistp256 -st -opem srk.pub Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12tpm2-common: update to allow importable sealed dataJames Bottomley1-3/+7
The original scheme had a different OID for loadable and importable keys. However, this turned out to be unnecessary since we can use the presence of the optional secret to determine whether the object is loadable or importable. For sealed data, we'll use the same OID (2.23.133.10.1.5) and the presence or absence of secret. This means the common routines need to be updated to expect this. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12Move tpm2_outerwrap to commonJames Bottomley3-135/+140
So it can be reused in seal_tpm2_key by adding an --import option Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12Version 3.2.1v3.2.1James Bottomley1-1/+1
* fix double free Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12signed_tpm2_policy: fix double freeJames Bottomley2-1/+3
The routine tpm2_new_signed_policy() frees the key, which contains the policy, on success or failure meaning the TSSAUTHPOLICY has been freed after exit from this function and we trigger an error if we try to free it again. There's also a double free of the EVP_PKEY in tpm2_new_signed_policy(). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-12Version 3.2.0v3.2.0James Bottomley1-1/+1
New Features: * Signed policies for keys and sealed data Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11doc: update draft RFC with signed policyJames Bottomley2-5/+215
Document the use of option [3] in the key for sequences of signed policies which must be tried sequentially. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11tests: add tests for signed policiesJames Bottomley2-0/+88
Run through a sequence of checks to make sure keys with multiple signed policies work in all cases. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11signed_tpm2_policy: add new command for manipulating signed policiesJames Bottomley6-3/+488
This adds the new command signed_tpm2_policy which can add, show and remove policies from a key. The key must first have been created with a --signed-policy <key> option, and you must possess the private part of <key> to add a new policy. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11tpm2-common.c: add processing of signed policy authorizationsJames Bottomley6-81/+242
This changes the way policies are stored in the key and processed. Since signed policies are chains of policies which may or may not work, an additional pols[] array is added to the app_data of the key, with pols[0] being what the prior policy would be and pols[1+] being where additional signed policy may be added or removed. Since a successful TPM2_PolicyAuthorize() invocation replaces the current policy hash with one derived from the key and the nonce, it makes no sense for TPM2_PolicyAuthorize() to be anywhere other than at the beginning of the standard policy or at the end of each of the signed policies. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11TSS: add functions to support PolicyAuthorizeJames Bottomley2-0/+213
TPM2_PolicyAuthorize() requires quite a few additional TPM functions: TPM2_LoadExternal() TPM2_VerifySignature() TPM2_PolicyRestart() TPM2_PolicyGetDigest() So add them all. In addition it requires marshalling TPMT_HA and TPMT_SIGNATURE. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11create_tpm2_key, seal_tpm2_data: add option to create signed policyJames Bottomley4-4/+59
Add a --signed-policy option to both which takes a public key and then uses tpm2_add_signed_policy() to create a key policy which requires additional signed policies. Note that keys/blobs so created cannot be used until at least one signed policy is added. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11tpm2-common, tpm2-asn: add new opt for authorized policiesJames Bottomley3-5/+127
Add a mechanism to keys for using a set of signed policies (only one of which has to pass to use the key). The option [4] of the TSSPRIVKEY ASN is used to store the signed policies and a new type TSSAUTHPOLICY is added as the container for signed policies. TSSAUTHPOLICY has a name field, so any policy may be named for easier location. Any policy may be added at a later date providing it is signed by the private <key>. This addition doesn't have to be done on the machine where the TPM is. Although passing the new TSSAUTHPOLICY is added, no processing is done, the code merely recognizes such a key but mostly can't use it. A new function tpm2_add_signed_policy() is added for key creation routines to use. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2023-01-11tpm2-common: move public key conversion and name algorithm to commonJames Bottomley6-252/+253
Preparatory to adding signed policies, we need access to the routines that convert openssl public keys to TPM ones and generate names so they can be used in the signed policy handling routines. Moving this across also necessitates moving the name algorithm (and openssl error printing) to common code. Also abstract tpm2_md() for converting between EVP hash algorithms and TPM_ALG_... names. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-12-01Version 3.1.2v3.1.2James Bottomley1-1/+1
* Fix segfault in unseal_tpm2_key * Fix pcr sealing error in create_tpm2_key caused by uncleared stack Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-12-01unseal_tpm2_key: fix seg fault if key unsealing failsJames Bottomley1-1/+2
In some circumstances, key unsealing leads to a segmentation fault on failure. The problem is that unseal_tpm2_key passes a NULL ppkey value into tpm2_load_engine_file() because it doesn't want an EVP_PKEY returned. However, there's an error leg in this function that tries to set this to NULL even if no ppkey was passed in (and thus segfaults). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-12-01create_tpm2_key: fix uninitialized data problemJames Bottomley1-3/+1
pcr_lock is created as an on stack variable and then updated additively. On some platforms, the stack isn't zero, so it contains bogus PCR settings that are never cleared which show up as additional PCRs in the range the user hadn't requested. Fix this by zeroing the entire on-stack structure before using it. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-03-01Version 3.1.1v3.1.1James Bottomley1-1/+1
* Fix use after free in dynamic engines Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-28Take an engine reference in the keyJames Bottomley6-9/+17
Apparently openssl doesn't do this for engine keys meaning that the openssl described way of obtaining and engine key if (ENGINE_init(e)) { pkey = ENGINE_load_private_key(e, file, ui_method, &cb_data); ENGINE_finish(e); } results in a dynamic engine being torn down immediately after the key is obtained. Fix this by taking a reference in the binding and releasing it when the key app_data is freed. This requires adding a pointer to the engine to the app_data. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-28Add test for dynamic engine keys to detect possible use after freeJames Bottomley2-0/+30
Add a test to make sure that the engine isn't torn down while keys are currently active (this is succeeding for statically configured engines but failing for dynamic engines). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-28Add key use tracking to detect use after freeJames Bottomley2-0/+15
This allows an error to be thrown if the engine gets torn down while keys are active. This condition is unrecoverable because the key methods (and potentially the engine code) would be freed after this. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-16Version: 3.1.0v3.1.0James Bottomley1-1/+1
* Bandaid openssl-3 support * direct pcr policy creation options * TPM key RFC Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-16Fix tests for openssl-3James Bottomley9-34/+36
Openssl 3 deprecated rsautil which we use for testing. This wouldn't be a problem except they also broke it as well for good measure: it no longer returns an error code when something fails with the key. The test infrastructure relies on this return code, so we have to update all of the rsautl tests to use pkeyutl instead. Also the return error for unknown curve changed from "unknown curve" to "invalid curve" so now we have to look for both. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-16Add an openssl-3 transform to legacy keysJames Bottomley2-0/+8
The engine keys we produce have replaced key methods. However openssl-3 by default looks for provider methods and won't use the key methods unless the keys are "legacy". The input pkey definitely won't be legacy so we have to convert it to a legacy key buy assigning the RSA/EC key back into the pkey. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-16Add openssl-3 supportJames Bottomley2-0/+11
This is just a bandaid at the moment to prevent -Werror from breaking the compile on deprecated API warnings. Since the APIs will be removed in the next release, this buys some time. The final solution will likely have to be a conversion to the new provider interface. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-16fix uninitialized variableJames Bottomley1-1/+2
gcc-11 noticed parentHandle may be uninitialized if the first error branch is taken, so fix it. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2022-02-16doc: add draft RFC for TPM Key formatJames Bottomley4-2/+484
Adds the xml file for the draft RFC and builds text and html versions if the xml2rfc program is found. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-04-11seal_unseal: add --pcr-lock for easy policyJames Bottomley3-7/+72
Just as with create_tpm2_key add the --pcr-lock policy to specify the PCRs to seal to at their current values. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-04-11Add tests for the new --pcr-lock optionJames Bottomley1-0/+45
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-04-11create_tpm2_key: Add PCR policy option to key creationJames Bottomley6-10/+367
The only current way to add policy to a key is to use policymaker to create it. This is actually a bit beyond most people, so this is a patch to simplify that: since most people only want very simple policies like PCR locking. This patch allows PCR policy to be specified as --pcr-lock [hash:]<pcr list>. This option may be repeated multiple times to add new banks. The option will collect the *current* values of the selected PCRs and lock the key to them (this means it can't be used for importable keys which are usually created away from the platform containing the TPM). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-04-11intel-tss: Fix wrong written length in the Marshal commandsJames Bottomley1-1/+1
The written parameter should be set incrementally not absolutely. Fortunately, this bug doesn't manifest in the current engine, because there's no sequence of marshal commands, but it will manifest in future updates. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-04-04Version: 3.0.1v3.0.1James Bottomley1-1/+1
* fix various memory leaks * add fix for privilege reduction of application Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-03-22Handle memory allocation errors tooJonathan Wernberg3-12/+59
Albeit unlikely to occur in practice, according to OpenSSL documentation, NULL or -1 can be returned in case of allocation errors, so these errors must be handled for correctness. Signed-off-by: Jonathan Wernberg <jonathaw@axis.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-03-22Fix memory leaks by rewriting engine init/finish logicJonathan Wernberg5-15/+57
Currently, some memory and indices were allocated by the engine during the binding, but this means the resources would leak if the engine is unloaded again. Instead, refactor the initialization code to use the bound init() and finish() functions, so resources are allocated in init() and can be freed again in finish(). This makes valgrind happy. Signed-off-by: Jonathan Wernberg <jonathaw@axis.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-03-19Introduce env variables to set owner and group of TSS dirRoberto Sassu3-2/+89
Before reading the TPM key, tpm2_set_unique_tssdir() creates a temporary working directory for IBM TSS-generated files. By default permissions are 0700, which means that only the owner is able to access that directory. Unfortunately there is a case, the Apache web server, where the temporary directory is created when the process user is still root, as the process must be able to read the TPM key. Then, the process switches to the apache user and TPM operations cannot be performed because the apache user cannot access the temporary directory. This can be seen in the output of strace: 3030 openat(AT_FDCWD, "/etc/attest-tools/tls_key.pem", O_RDONLY) = 11 3030 openat(AT_FDCWD, "/etc/attest-tools/tls_key_cert.pem", O_RDONLY) = 11 ... 3030 setuid(48) = 0 ... 3087 openat(AT_FDCWD, "/dev/tpmrm0", O_RDWR) = 16 3087 openat(AT_FDCWD, "/run/user/0/tss2.fHbi2k/h81000001.bin", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied) 3087 openat(AT_FDCWD, "/run/user/0/tss2.fHbi2k/hp81000001.bin", O_RDONLY) = -1 EACCES (Permission denied) This patch introduces two new environment variables, XDG_RUNTIME_DIR_OWNER and XDG_RUNTIME_DIR_GROUP, to explicitly set the owner and the group of the temporary directory. XDG_RUNTIME_DIR should also be set if also the parent directory is not accessible (for example, if it is /run/user/0). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-03-04Version: 3.0.0v3.0.0James Bottomley1-1/+1
* Build time support for Intel TSS Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-03-04configure: add a check for a missing Intel TSS API (Esys_TR_GetTpmHandle)James Bottomley1-0/+11
Without it handle abstraction can't be done properly, so it is fairly essential to the operation of the TSS. The check is done as a library functional check instead of a version in case this rather essential API gets backported. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-02-27Work around Intel TSS Null Seed problems (issue 1993)James Bottomley2-3/+22
The Intel TSS doesn't seem to be able to use the NULL seed correctly as a key parent. NULL seed parents are useful for secret keys that can't live beyond a reboot, but the number of consumers for this functionality is tiny, so while the issue is outstanding, simply disable the tests that use the NULL seed to hide the problem. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-02-27Add support for the Intel TSSJames Bottomley7-17/+1045
Using the previously created abstrations, insert wrappers for the Intel TSS. There are significant annoyances like the IBM constants are taken from the TCG TPM guides, which all begin TPM_ and the Intel constants are all taken from the TCG ESAPI guide, which all begin TPM2_ additionally all the ESAPI commands insist on allocating the return structures whereas the IBM TSS, following the command guides, uses on-stack structures. However, the only real results of this are a huge set of definitions in the intel-tss.h and pointless allocation and freeing of structures. Note that the Intel TSS doesn't export enough of the supporting routines to build some required capabilites (even though it actually has them internally), so code providing those are directly copied into intel-tss.h from the IBM TSS and indicated in comments in the header file. Since the IBM TSS is BSD licensed, the resulting code is still under the project Licence LGPL. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-02-26Work around Intel TSS Premature AbstractionJames Bottomley7-42/+96
Apparently no-one at the TCG read the memo on pointless abstractions, so they have an internal and an external representation for the TPM handles. The really annoying thing is that the two are represented by the same type in the Intel TSS, so there's no way for the compiler to check if you've kept everything straight. The other significant problem is that the internal representation is only valid for as long as the context lives, so everything that has a longer lifetime than the context must be in the external representation. Finally, just to trip you up, a small number of commands use the external representation in the API but no-one will tell you which ones. Fix this by introducing APIs for transforming handles from internal to external and back, which are nops on the IBM TSS and add a host of transforms to the code. Proof that this is correct is simply that the Intel TSS works. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-02-26move to functional TSS formJames Bottomley9-466/+796
The IBM TSS uses a single execute primitive whereas the Intel one uses a functional primitive. Neither can be exactly mapped, so create a new functional primitive which can fill the gap between them. Since the Intel TSS has no in/out structures, unwrap all the IBM in/out structures into their respective components. Finally, make tpm2_create used everywhere to become a wrapper for the different context mechanisms. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2021-02-20Preliminary TPM2B conversion to make TSS agnosticJames Bottomley11-154/+122
The eventual goal is to support either the Intel or the IBM TSS. One of the many differences between them is the TPM2B structures are mostly unions in the IBM TSS and straight definitions in the Intel TSS. The IBM TSS often has the straight definitions of TPM2B_XXX structures as XXX_2B, so substitute those where possible and introduce VAL conversion macros to hide other differences. This patch also abstracts all the tss includes and places them via tpm2-tss.h and its IBM specific counterpart ibm-tss.h Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-07-02Version: 2.4.2v2.4.2James Bottomley1-1/+1
* Add every TPM supported curve (as defined by the TCG) * Fix a bug with explicitly parametrised curve handling (needed for BN) * Update the tests to be able to use swtpm * Allow loading public key without password Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-06-23tests: add test for no password public keysJames Bottomley2-2/+2
The openssl rsa and pkey commands will import a public engine key with the -pubin option, so add this and remove the password to exercise the new public key option. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-06-23tpm2-common: support loading public key onlyJames Bottomley5-23/+48
Users are slightly perplexed when we ask for a password to read the public part of the key, since there's no password protected information in there. This is because we implement only the private key load, which always asks for a password if one is required. This can be fixed by implementing the engine load public key method. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-05-10Allow use of swtpm for testingJames Bottomley3-13/+37
In addition to tpm_server there's another tpm emulator called swtpm. Avoid forcing distributions to support both by adjusting the test suite to run with either emulator and detecting in configure which can be used. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-05-09tests: add test for curves openssl doesn't supportJames Bottomley2-0/+31
Most TPMs support curves that openssl doesn't know. However, openssl can explicitly parametrise them, so add a create_nonopenssl_ecc test to create explicitly parametrised public keys and check they can derive the same secret. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-05-09tpm2-common.c: make openssl handle explicitly parametrised curves correclyJames Bottomley1-0/+1
Over the years openssl seems to have changed its handling of elliptic curves to automatically assume the curve is named unless told otherwise. When the engine produces an explicit parametrisation, it now has to reset the asn1_flag of the key to remove the named curve setting otherwise the public key ends up being empty. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-05-09wrap_ecc.sh: Add tests for explicit curve parametrisationJames Bottomley1-1/+13
Openssl can deal with elliptic curves in two ways: named curve for the ones it knows about and explicitly parametrised for ones it doesn't. Expand the wrap_ecc.sh test to add a set of tests for wrapping explicitly parametrised keys. This actually checks the curve numbers hard coded into tpm2-common.c Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-05-09tpm2-common: add support for every currently specified TPM2 curveJames Bottomley1-0/+322
The missing curve parametrisations are NIST_P192, NIST_P224, NIST_P521, BN_P638 and SM2. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-25Version: 2.4.1v2.4.1James Bottomley1-1/+1
* fixes for older OpenSSL and gcc * variable tpm_server location for testing James Bottomley (3): configure.ac: make location of software TPM configurable seal_tpm2_data: fix compile problem on older gcc Fix OpenSSL 1.0.2 build Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-24Fix OpenSSL 1.0.2 buildJames Bottomley2-0/+3
Older versions of OpenSSL are giving the error tpm2-common.h:82:10: error: 'struct stack_st_TSSOPTPOLICY' declared inside parameter list [-Werror] Fix this by adding a DECLARE_STACK_OF to tpm2-asn.1 and including it Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-24seal_tpm2_data: fix compile problem on older gccJames Bottomley1-1/+1
gcc 4.8.5 is giving a spurious uninitialized variable warning for reason. Shut this up by initializing it to the empty string. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-24configure.ac: make location of software TPM configurableJames Bottomley3-5/+15
openSUSE has chosen to put the tpm_server binary in /usr/lib/ibmtss which means the current test programmes can't find it. Fix this by creating a new configuration variable TPMSERVER corresponding to the absolute path of the software TPM. Make failing to find the software TPM a non-fatal but significantly warned about problem because it only affects the running of the tests, not the building of the engine. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-05Version: 2.4.0v2.4.0James Bottomley1-1/+1
* data seal/unseal handling * PKCS12 wrapping support James Bottomley (6): tpm2-common.c: move several routines into common code tpm2-common: export tpm key type from file to app_data Add TPM data sealing and unsealing functions Add test for seal/unseal Add ability to import PKCS12 keys add mailing list in README and bug reporting Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-04add mailing list in README and bug reportingJames Bottomley2-2/+9
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-03-04Add ability to import PKCS12 keysJames Bottomley3-1/+59
PKCS12 is a fairly common key wrapping protocol, particularly used by Microsoft, so add the ability to wrap PKCS12 keys. The wrap merely searches the PKCS12 bag for the private key, ignores all the certificates and produces a TPM wrapped version of the private key it finds. We can discriminate easily between PKCS12 and PEM private keys because the PKCS12 DER is a very specific ASN.1 format, so we don't need to know what type of keyfile we have, we just try both formats to see if it will import. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-26Add test for seal/unsealJames Bottomley2-1/+21
Add a simple test to make sure a key is recognized as not sealed data and to seal and unseal data with a password. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-26Add TPM data sealing and unsealing functionsJames Bottomley12-13/+612
This adds two commands and their manpages: seal_tpm2_data and unseal_tpm2_data plus a new OID 2.23.133.10.1.5 to identify sealed data. The object is to be interoperable with the new kernel sealed data format. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-10tpm2-common: export tpm key type from file to app_dataJames Bottomley2-9/+20
This will be useful for sealed keys to know they were the correct type Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-10tpm2-common.c: move several routines into common codeJames Bottomley3-241/+250
These routines will be used by the seal/unseal command, so make them common to facilitate this. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-10Version: 2.3.1v2.3.1James Bottomley1-1/+1
* bug fixes * add DER handling to key input forms James Bottomley (7): e_tpm2: simplify tpm2_load_key_core tpm2-common: extract file and TPM loading functions load_tpm2_key: use common file parsing and load routines load_tpm2_key: add a test for loading importable keys tpm2-common: make empty auth optional tpm2-common: allow loading of DER keys tests: add a test for DER keys Jonathan Wernberg (1): Fix compile warning on older GCC Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-10tests: add a test for DER keysJames Bottomley2-1/+19
Now that we're supposed to support DER based keys, check that we can use them. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-10tpm2-common: allow loading of DER keysJames Bottomley1-0/+6
One of the reasons for putting an OID at the beginning of the structure was to make the binary DER form uniquely recognizable. This should mean we're safe to try loading the binary form if the PEM form fails. Activate that feature (for the new structure only). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2020-01-10tpm2-common: make empty auth optionalJames Bottomley1-0/+4
The ASN.1 spec lists it as optional and if it's not present it should be treated as boolean false (meaning the key needs authorization). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-12-29load_tpm2_key: add a test for loading importable keysJames Bottomley1-0/+6
Now that the file and key loading is done in common code, test that loading of importable keys actually works. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-12-29load_tpm2_key: use common file parsing and load routinesJames Bottomley4-79/+29
This allows load_tpm2_key to use every format currently allowed for the tpm keys. For load_tpm2_key this means it can now load importable keys. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-12-27tpm2-common: extract file and TPM loading functionsJames Bottomley7-481/+510
The functions needed to load the key file and load a key into the TPM are extracted from create_tpm2_key in preparation for re-used in load_tpm2_key. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-12-27e_tpm2: simplify tpm2_load_key_coreJames Bottomley1-36/+18
The original was designed for a switchable UI and a passed in bio. Since we do neither of these things now, strip out the superfluous coding. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-12-22Fix compile warning on older GCCJonathan Wernberg1-15/+15
GCC cannot, for each possible value of one variable such as "tssl", keep track of which of all other variables such as "pubkey" and "privkey" are uninitialized or not. Some GCC versions just assumes the variable may be uninitialized if it cannot know. Some more recent GCC versions seem to take the opposite approach. Either way, a simple refactoring of the error handling eliminates the uncertainity by making both the if and else clause definitely set the variables "pubkey" and "privkey" to an initialized value, so it now compiles fine. Signed-off-by: Jonathan Wernberg <jonathaw@axis.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-24Version: 2.3.0v2.3.0James Bottomley1-1/+1
* add the ability to produce restricted (storage) keys with defined symmetric seeds * new load_tpm2_key command to load a key file at a NV index Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-24Add tests for restricted keysJames Bottomley2-0/+83
Add general tests of the new command plus a specific test of the ability to create a key to a wrapped parent, clear the TPM (thus effectively creating a new tpm), re-wrapping the key and demonstrating that the old parented key can still be used. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-24load_tpm2_key: add new command to load a key file to a NV handleJames Bottomley4-3/+269
In order to use restricted keys as parents, they have to be loaded into the TPMs NV handle area, so introduce a new command to do that. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-24Make removal of key files from the temporary directory explicitJames Bottomley4-10/+14
We've been obscuring a bug in tpm2_rm_tssdir() for a while in that we create a key file for the parent non volatile key but don't remove it again. We fixed it up in tpm2_rm_tssdir() by hard coding the removal of the key file belonging to 81000001. However, this won't work if we can have an arbitrary NV parent, so make the key file removal explicit. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-24create_tpm2_key: add a --restricted optionJames Bottomley1-0/+73
Right at the moment we create unrestricted signing and decryption keys. These keys are the most useful for cryptographic operations, but they cannot be used as parents for any other key. The addition of the --restricted option allows the creation of restricted decryption keys (aka storage keys) which can be used as parents for other keys. One of the requirements of storage keys is that they must have a symmetric seed that can be used to protect the sensitive parts of child keys. For wrapped keys, we derive the symmetric seed from the public and private parts of the wrapped key, meaning the same wrapped key always has the same symmetric seed. This allows child keys of a wrapped parent to be transported between TPMs. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-19Add .gitignoreJames Bottomley1-0/+33
So git status now shows the correct status without all the temporary and test files interfering. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-15Version: 2.2.0v2.2.0James Bottomley1-1/+1
* Add support for non-PKCS1 padding * Fixups for engines and cross builds Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-14Fix engines install pathJames Bottomley1-1/+1
The variables might contain quotes, so don't re-quote them. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-02-13e_tpm-rsa.c: add additional padding typesJames Bottomley3-17/+58
Up to now we've only handled PKCS1 padding, but since this is being deprecated by NIST, we need to handle all the others. It turns out that the RSA layer of openssl can only really handle OAEP with mgf1(sha1) or unpadded, so add both of those to the engine. All other sophisticated padding in openssl is handled at the pmeth layer and thus only requires an unpadded key operation at the RSA layer, which we've now added, so the tpm2 engine should now work for any padding type supported by openssl. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-01-21Fix up engine installationJames Bottomley2-10/+35
Add an additional --with-enginesdir parameter to allow for specifying the engine directory instad of probing for it. In addition install both engine.so and libengine.so because we don't know which one openssl will be looking for since it depends on the openssl version. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-01-14Add native build dependenciesJames Bottomley1-1/+4
certain steps in the build, like help2man to generate the man pages assume the built binary can be executed on the platform. This is untrue for a cross build, so detect native builds and only take the execution steps for them. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-01-12Version: 2.1.1v2.1.1James Bottomley1-1/+3
* Fix segfault in importable keys * Fix spurious error on old format keys Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-01-12e_tpm2: fix intermittent segfault with importable keysJames Bottomley1-0/+1
The written parameter on the import unmarshal isn't set meaning it contains a bogus value. Occasionally this value causes a segfault, so fix by setting the value to 0. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2019-01-04e_tpm2: fix spurious error on successful operationJames Bottomley1-0/+2
When the engine successfully performs an operation with an older key, we still end up with an apparent error (which can be displayed to the user) about a failed load. This comes from the initial failed attempt to load the new key format and can be fixed by clearing all openssl errors if the old key format load succeeds. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-18Correct engine name in README and man pageFredrik Ternerot2-6/+4
Engine is named tpm2 and not tpm. Signed-off-by: Fredrik Ternerot <fredrikt@axis.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-14Version 2.1.0v2.1.0James Bottomley1-1/+1
Add importable keys Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-14Add tests for importable keysJames Bottomley2-0/+21
Add two simple tests: creating an importable EC key with auth and creating an importable RSA key with policy. Verify a self signed certificate created with each key. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-14Add importable keysJames Bottomley4-41/+387
Importable keys are a new type of key that can be created without access to the receiving TPM. The design of importable keys is that you "wrap" the key (encrypt with a derived key) in such a way that it can only be unwrapped by the TPM local parent key. To do this wrapping you only need to know the public key of the parent, which can be shipped in an ordinary openssl public key file. The key format of importable keys requires an additional encrypted secret parameter, which basically encodes the wrapping key using ECDH so it can be decrypted by the parent on import. Importable keys are designed to be used everywhere the current loadable keys are used, the only difference being that the TPM engine converts the importable key to loadable on first load and thereafter uses it identically to a loadable key. The new command line option of importable keys is create_tpm2_key --import <pubparent> --wrap <private key> tmp.key Where <pubparent> is the parent public key and <private key> is the key you are wrapping (obviously since you have no access to the TPM, this option can only be used to wrap existing private keys). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-13tpm2-common: remove interfaces only used by create-tpm2-keyJames Bottomley3-156/+142
The sensitive to duplicate interface is really only used for key wrapping, and this is only done at key creation time, not on key processing, so it has no place in the common code. When moving to create_tpm2_key.c we change the calling convention to make it more clear that we're not doing full conversion, merely inner wrapping the key. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-13tpm2-common: add point conversion routinesJames Bottomley3-19/+31
Point conversion from openssl to TPM format is now used in a couple of places in the current code, so move it into the common routines. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-12Version 2.0.1v2.0.1James Bottomley1-1/+1
Fix bugs with secrets hiding, name algorithm and policy Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-12check_enhanced_auth.sh: add loop over name algorithm typeJames Bottomley5-75/+85
This test checks for two things, firstly that we get the policy right with different name algorithms and secondly that we actually get the name algorithm correctly specified. This all works because with policyPCR the hash of the expected policy registers has to be done with the name algorithm hash, so we'll get a mismatch here if either the name algorithm is wrong (or the policy parsing fails). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-12create_tpm2_key: policy should use the name algorithmJames Bottomley7-25/+45
For all keys, policy must use the same algorithm as the name algorithm, so fix that and add checks for different algorithms. This also fixes a bug in the PCR policy where we were accidentally getting 32 from the size of the PCR unmarshal selection rather than setting the correct PCR hash algorithm size Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-12e_tpm2-ecc.c: enable response encryption for ecda decryptionJames Bottomley1-1/+1
The response payload could be sensitive, so protect with encryption like the RSA case. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-12Enable TPM parameter encryption for RSA encrypt/decryptFredrik Ternerot1-2/+2
Enable TPM parameter encryption for RSA private encrypt/decrypt to protect sensitive data sent to and received from the TPM. Signed-off-by: Fredrik Ternerot <fredrikt@axis.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-08create_tpm2_key: fix use after freeJames Bottomley1-5/+4
we use pointers to the public and private areas of the TPM import/create commands to fill out the OpenSSL TPM key, but these areas go out of scope and are thus freed before we actually use them. So fix this by declaring the in/out parameters for these commands in global instead of local scope. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-07create_tpm2_key: fix name algorithm selectionJames Bottomley1-7/+3
The results from strcasecmp are zero if it matches, so you need a not in front of strcasecmp() for the condition to be "it matches". The current strncasecmp() in the name algorithm selection were missing the not's resulting in the wrong algorithm being selected if you specified it on the command line. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-05Version 2.0.0v2.0.0James Bottomley1-1/+1
With the updated licence, changed key format and new OIDs, it's time for a major version bump. The other minor addition is time limited keys based on policy. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-01add tests for old keysJames Bottomley3-17/+69
To check that old format keys still work, we add a --deprecated option to create_tpm2_key that allows us to create them still. The test is to create an old format key and prove the engine still accepts it. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-11-01move to TCG defined OIDs for the key typesJames Bottomley2-8/+32
We previously stole an OID in the TCG space to use to identify our keys. With the shift to a new key format, we've also taken the opportunity to clarify with the TCG which OIDs we can use. It turns out the ones we initially chose were non-leaf nodes, so we now finally have a couple of leaf nodes allocated and thus we take advantage of the new key format to switch to using them. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-10-31Allow TSS2 PRIVATE KEY and TSS2 KEY BLOB ASN.1 to divergeDavid Woodhouse3-22/+62
... and indeed do so. Make the pubkey and parent non-optional, for a start, but leave the type field alone for now. The explicit tag of the policy field can change because it's harmles to do so. Signed-off-by: David Woodhouse <dwmw2@infradead.org> [jejb: plumb policy in correctly] Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-10-31Add 'TSS2 PRIVATE KEY' PEM tag, using correct objectAttributesDavid Woodhouse3-4/+14
We can now tweak the ASN.1 definition for the PRIVATE KEY variant... Signed-off-by: David Woodhouse <dwmw2@infradead.org> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-10-31Allow changing objectAttributes for primary key generationDavid Woodhouse5-4/+10
We have agreed that these should have the FIXEDPARENT and FIXEDTPM flags. Firstly, add a flag which indicates that the new flags should be used. Signed-off-by: David Woodhouse <dwmw2@infradead.org> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-10-16LICENCE: tidy up remaining GPLv2 tags and clarify ASN.1 fair useJames Bottomley6-6/+10
After the licence switch to LGPL2.1 there were still some stray GPLv2 tags in the code, so swap these for SPDX tags identifying the chosen LGPL licence. Additionally, since the key format needs to be standardised, clarify that the ASN.1 code defining the key format may be copied under fair use criteria. Reported-by: Fredrik Ternerot <fredrik.trot@gmail.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-10-11LICENCE: Change from GPLv2 to LGPLv2.1James Bottomley2-347/+169
There are two problems being solved here: the first is integration with the OpenSSL licence, which usually requires an exception and also a request from gnutls to reuse some of the engine code. The solution to both of these is to relicense to LGPLv2.1 and then move pieces which might be re-used to a proper library instead of a loadable object. This commit is the precursor licence change. The signoffs below represent all the authors of copyrightable code as required by a licence change. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-08-12policy: fail early for PCR mismatchJames Bottomley1-7/+27
Now we have the ability to produce identifying error prints for failing policy, we can make the PolicyPCR fail at policy check time rather than waiting to find a policy hash mismatch. We do that by adding the expected value of the PCR hash to the policy statement, meaning the policy command fails if the current PCR values don't match the expected ones. We can then check for this failure and print out a more detailed message. There is a slight wrinkle in this scheme in that TPM2_PolicyCounterTimer() returns TPM_RC_POLICY when the policy fails, but TPM2_PolicyPRC() returns TPM_RC_VALUE if the hash is mismatched, so the code must be updated to check for the correct return indicating a policy failure. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-08-12policy: add the ability to have time limited keysJames Bottomley4-8/+126
Implement TPM2_PolicyCounterTimer which allows comparison of the current counter and timer values. There is a problem with the policy file in that traditionally the policy file is simply hashed to make the final policy, but CounterTimer is different: the necessary information has to be hashed and then that hash is hashed into the policy meaning that we have to special case the TPM_CC_PolicyCounterTimer in the computation of the hash. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-08-10Version 1.2.1v1.2.1James Bottomley1-1/+1
Minor update with bug fixes Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-08-10fix error handling for failed policy commandsJames Bottomley3-6/+22
If the policy command of the key fails for any reason, we exit the engine without flushing the policy session, which leads to a build up of policy sessions leading to eventual failure. Fix this by flushing the policy session in tpm2_init_session() if there's any policy failure. Also add a test for this and fix up check_enhanced_auth.sh so that any failed test exits the script. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-08-09tpm2-common: remove duplicate codeRoberto Sassu1-9/+0
Remove unused policy_pcr_unmarshal(). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-30Version: 1.2.0v1.2.0James Bottomley1-1/+1
- Now looks for variable locations for the tss library - Includes updates to support key policy (PCR and password) Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-29create_tpm2_key: man page updatesJames Bottomley1-2/+18
Add a files secton to describe the policy file format (copied from the README file) and lose the bit about us taking 50s to generate the parent if unspecified: now we generate the ECC version which is much faster. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-29create_tpm2_key: fix ordering of password collection and policy file parsingJames Bottomley1-12/+14
The current order goes collect auth first before parsing the policy file which leads to the unfortunate consequence that we'll make you type in a verified password before we error out and tell you you don't have the correct PolicyAuthValue command in your policy file. Reorder this so we only collect the password after we've verified the policy correctly supports it. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-29create_tpm2_key: clean up error handlingJames Bottomley1-22/+38
Right at the moment, if we fail, we print the reason via the tpm error formatting routines which doesn't work so well if the failure isn't a tpm error. Fix this by having a TPM_RC NOT_TPM_ERROR which we set when we just want to print the reason message rather than pass it through tpm error handling. Additionally, don't set a default value for reason to ensure all the error legs have a valid reason (gcc will fail with an error that reason may be uninitialized if an error leg is added but reason isn't correctly set). Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-29create_tpm2_key: correct error checkJames Bottomley1-1/+6
There's no check that we actually have a last argument and the check to see if we have too many is wrong. All of this needs to be relative to optind, so if optind != argc-1 we don't have the final file name. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28openssl_tpm2_engine: add tests for enhanced authorizationRoberto Sassu6-0/+91
Add tests for enhanced authorization: 1) PolicyAuthValue 2) PolicyPCR 3) PolicyAuthValue + PolicyPCR 4) PolicyPCR + PolicyAuthValue Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28create_tpm2_key: introduce --key-policy optionRoberto Sassu2-7/+211
Introduce the --key-policy option to enforce additional restrictions on the new TPM key. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28engine: retrieve policy commands from the keyRoberto Sassu4-6/+105
Retrieve the policy commands from the key and store in the app_data structure. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28tpm2-common: initialize policy sessionRoberto Sassu2-0/+67
Initialize the policy session with the policy command included in the key. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28tpm2-asn: add TPMPolicy definitionRoberto Sassu1-0/+34
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28engine: determine the required session type from USERWITHAUTH flagRoberto Sassu4-10/+29
Determine the type of session required to use a key from USERWITHAUTH flag. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-28tpm2-common: rename tpm2_get_hmac_handle() to tpm2_get_session_handle()Roberto Sassu6-12/+15
Rename the function and add the additional parameter sessionType, so that it can return a handle of a hmac or a policy session. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-19Add variable header locationsJames Bottomley6-23/+33
The tss2 includes are moving from /usr/include/tss2 to /usr/include/ibmtss, so add an AC_CHECK_HEADER for both locations and add a variable path include to each file so the whole system still compiles no matter which style of header path is installed. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-06-14configure.ac: Update for ibmtss2 changesJames Bottomley1-2/+6
As of version 1234, the ibmtss2 is now in libibmtss not in libtss and also requires -DTPM_POSIX or -DTPM_WINDOWS to be provided on the command line. Fix for this by adding libibmtss to the path check for the TSS library and unconditionally adding -DTPM_POSIX. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-02-08Version: 1.1.0v1.1.0James Bottomley1-1/+1
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2018-02-08tests: add prefix change to test_nv_key.shJames Bottomley2-2/+15
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>