]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm2-util: add helper for setting TPM2B_AUTH in binary
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Oct 2023 15:51:26 +0000 (17:51 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Nov 2023 10:21:35 +0000 (11:21 +0100)
src/shared/tpm2-util.c
src/shared/tpm2-util.h

index a62fd3c6c005b6bb79ce2bb4a33d2340f6c3110c..783e44145d37d04d10261bc955e34d6760da7be9 100644 (file)
@@ -3000,9 +3000,25 @@ int tpm2_get_pin_auth(TPMI_ALG_HASH hash, const char *pin, TPM2B_AUTH *ret_auth)
         return 0;
 }
 
-static int tpm2_set_auth(Tpm2Context *c, const Tpm2Handle *handle, const char *pin) {
-        TPM2B_AUTH auth = {};
+int tpm2_set_auth_binary(Tpm2Context *c, const Tpm2Handle *handle, const TPM2B_AUTH *auth) {
         TSS2_RC rc;
+
+        assert(c);
+        assert(handle);
+
+        if (!auth)
+                return 0;
+
+        rc = sym_Esys_TR_SetAuth(c->esys_context, handle->esys_handle, auth);
+        if (rc != TSS2_RC_SUCCESS)
+                return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
+                                       "Failed to load PIN in TPM: %s", sym_Tss2_RC_Decode(rc));
+
+        return 0;
+}
+
+int tpm2_set_auth(Tpm2Context *c, const Tpm2Handle *handle, const char *pin) {
+        TPM2B_AUTH auth = {};
         int r;
 
         assert(c);
@@ -3017,12 +3033,7 @@ static int tpm2_set_auth(Tpm2Context *c, const Tpm2Handle *handle, const char *p
         if (r < 0)
                 return r;
 
-        rc = sym_Esys_TR_SetAuth(c->esys_context, handle->esys_handle, &auth);
-        if (rc != TSS2_RC_SUCCESS)
-                return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
-                                       "Failed to load PIN in TPM: %s", sym_Tss2_RC_Decode(rc));
-
-        return 0;
+        return tpm2_set_auth_binary(c, handle, &auth);
 }
 
 static bool tpm2_is_encryption_session(Tpm2Context *c, const Tpm2Handle *session) {
index 7444cef02ebd33f6329ab67874b815c78e332a56..b6940dbab1098ed9ff7512b6dd738ae236379a0d 100644 (file)
@@ -201,6 +201,8 @@ int tpm2_pcr_read(Tpm2Context *c, const TPML_PCR_SELECTION *pcr_selection, Tpm2P
 int tpm2_pcr_read_missing_values(Tpm2Context *c, Tpm2PCRValue *pcr_values, size_t n_pcr_values);
 
 int tpm2_get_pin_auth(TPMI_ALG_HASH hash, const char *pin, TPM2B_AUTH *ret_auth);
+int tpm2_set_auth(Tpm2Context *c, const Tpm2Handle *handle, const char *pin);
+int tpm2_set_auth_binary(Tpm2Context *c, const Tpm2Handle *handle, const TPM2B_AUTH *auth);
 
 int tpm2_make_policy_session(Tpm2Context *c, const Tpm2Handle *primary, const Tpm2Handle *encryption_session, Tpm2Handle **ret_session);
 int tpm2_policy_auth_value(Tpm2Context *c, const Tpm2Handle *session, TPM2B_DIGEST **ret_policy_digest);