work = asn1_encode_oid(work, end_work, tpm2key_oid,
asn1_oid_len(tpm2key_oid));
if (options->blobauth_len == 0) { unsignedcharbool[3], *w = bool; /* tag 0 is emptyAuth */
w = asn1_encode_boolean(w, w + sizeof(bool), true); if (WARN(IS_ERR(w), "BUG: Boolean failed to encode")) {
ret = PTR_ERR(w); goto err;
}
work = asn1_encode_tag(work, end_work, 0, bool, w - bool);
}
/* * Assume both octet strings will encode to a 2 byte definite length * * Note: For a well behaved TPM, this warning should never * trigger, so if it does there's something nefarious going on
*/ if (WARN(work - scratch + pub_len + priv_len + 14 > SCRATCH_SIZE, "BUG: scratch buffer is too small")) {
ret = -EINVAL; goto err;
}
work = asn1_encode_integer(work, end_work, options->keyhandle);
work = asn1_encode_octet_string(work, end_work, pub, pub_len);
work = asn1_encode_octet_string(work, end_work, priv, priv_len);
work1 = payload->blob;
work1 = asn1_encode_sequence(work1, work1 + sizeof(payload->blob),
scratch, work - scratch); if (IS_ERR(work1)) {
ret = PTR_ERR(work1);
pr_err("BUG: ASN.1 encoder failed with %d\n", ret); goto err;
}
/** * tpm2_buf_append_auth() - append TPMS_AUTH_COMMAND to the buffer. * * @buf: an allocated tpm_buf instance * @session_handle: session handle * @nonce: the session nonce, may be NULL if not used * @nonce_len: the session nonce length, may be 0 if not used * @attributes: the session attributes * @hmac: the session HMAC or password, may be NULL if not used * @hmac_len: the session HMAC or password length, maybe 0 if not used
*/ staticvoid tpm2_buf_append_auth(struct tpm_buf *buf, u32 session_handle, const u8 *nonce, u16 nonce_len,
u8 attributes, const u8 *hmac, u16 hmac_len)
{
tpm_buf_append_u32(buf, 9 + nonce_len + hmac_len);
tpm_buf_append_u32(buf, session_handle);
tpm_buf_append_u16(buf, nonce_len);
if (nonce && nonce_len)
tpm_buf_append(buf, nonce, nonce_len);
if (hmac && hmac_len)
tpm_buf_append(buf, hmac, hmac_len);
}
/** * tpm2_seal_trusted() - seal the payload of a trusted key * * @chip: TPM chip to use * @payload: the key data in clear and encrypted form * @options: authentication values and other options * * Return: < 0 on error and 0 on success.
*/ int tpm2_seal_trusted(struct tpm_chip *chip, struct trusted_key_payload *payload, struct trusted_key_options *options)
{
off_t offset = TPM_HEADER_SIZE; struct tpm_buf buf, sized; int blob_len = 0;
u32 hash;
u32 flags; int i; int rc;
for (i = 0; i < ARRAY_SIZE(tpm2_hash_map); i++) { if (options->hash == tpm2_hash_map[i].crypto_id) {
hash = tpm2_hash_map[i].tpm_id; break;
}
}
if (i == ARRAY_SIZE(tpm2_hash_map)) return -EINVAL;
if (!options->keyhandle) return -EINVAL;
rc = tpm_try_get_ops(chip); if (rc) return rc;
rc = tpm2_start_auth_session(chip); if (rc) goto out_put;
if (!options->policyhandle) {
tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT,
options->blobauth,
options->blobauth_len);
} else { /* * FIXME: The policy session was generated outside the * kernel so we don't known the nonce and thus can't * calculate a HMAC on it. Therefore, the user can * only really use TPM2_PolicyPassword and we must * send down the plain text password, which could be * intercepted. We can still encrypt the returned * key, but that's small comfort since the interposer * could repeat our actions with the exfiltrated * password.
*/
tpm2_buf_append_auth(&buf, options->policyhandle,
NULL /* nonce */, 0, 0,
options->blobauth, options->blobauth_len);
tpm_buf_append_hmac_session_opt(chip, &buf, TPM2_SA_ENCRYPT,
NULL, 0);
}
if (tpm_buf_length(&buf) < TPM_HEADER_SIZE + 6 + data_len) {
rc = -EFAULT; goto out;
}
data = &buf.data[TPM_HEADER_SIZE + 6];
if (payload->old_format) { /* migratable flag is at the end of the key */
memcpy(payload->key, data, data_len - 1);
payload->key_len = data_len - 1;
payload->migratable = data[data_len - 1];
} else { /* * migratable flag already collected from key * attributes
*/
memcpy(payload->key, data, data_len);
payload->key_len = data_len;
}
}
out:
tpm_buf_destroy(&buf); return rc;
}
/** * tpm2_unseal_trusted() - unseal the payload of a trusted key * * @chip: TPM chip to use * @payload: the key data in clear and encrypted form * @options: authentication values and other options * * Return: Same as with tpm_send.
*/ int tpm2_unseal_trusted(struct tpm_chip *chip, struct trusted_key_payload *payload, struct trusted_key_options *options)
{
u32 blob_handle; int rc;
rc = tpm_try_get_ops(chip); if (rc) return rc;
rc = tpm2_load_cmd(chip, payload, options, &blob_handle); if (rc) goto out;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.