Skip to content

Commit 8a37809

Browse files
philiptaronwilliamcroberts
authored andcommitted
pcks11: use bytes.decode on stderr
Before: ``` RuntimeError: Could not execute tpm2_create: b'WARNING:esys:src/tss2-esys/api/Esys_Create.c:399:Esys_Create_Finish() Received TPM Error \nERROR:esys:src/tss2-esys/api/Esys_Create.c:134:Esys_Create() Esys Finish ErrorCode (0x0000098e) \nERROR: Esys_Create(0x98E) - tpm:session(1):the authorization HMAC check failed and DA counter incremented\nERROR: Unable to run /nix/store/n9b9hqgmw2f08f8kdcp41pfbs06p9b8v-tpm2-tools-5.7/bin/tpm2_create\n' ``` After: ``` RuntimeError: Could not execute tpm2_create: WARNING:esys:src/tss2-esys/api/Esys_Create.c:399:Esys_Create_Finish() Received TPM Error ERROR:esys:src/tss2-esys/api/Esys_Create.c:134:Esys_Create() Esys Finish ErrorCode (0x0000098e) ERROR: Esys_Create(0x98E) - tpm:session(1):the authorization HMAC check failed and DA counter incremented ERROR: Unable to run /nix/store/n9b9hqgmw2f08f8kdcp41pfbs06p9b8v-tpm2-tools-5.7/bin/tpm2_create ``` Signed-off-by: Philip Taron <philip.taron@gmail.com>
1 parent b95c802 commit 8a37809

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

tools/tpm2_pkcs11/tpm2.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def createprimary(self, hierarchyauth=None, objauth=None, alg=None, attrs=None,)
8484
_, stderr = p.communicate()
8585
if (p.wait()):
8686
raise RuntimeError("Could not execute tpm2_createprimary: %s" %
87-
stderr)
87+
stderr.decode())
8888
return ctx
8989

9090
def evictcontrol(self, hierarchyauth, ctx, handle=None):
@@ -103,13 +103,12 @@ def evictcontrol(self, hierarchyauth, ctx, handle=None):
103103
stdout, stderr = p.communicate()
104104
if (p.wait()):
105105
raise RuntimeError("Could not execute tpm2_evictcontrol: %s" %
106-
stderr)
106+
stderr.decode())
107107
return tr_file
108108

109109
def evictcontrol_remove(self, hierarchyauth, ctx, handle=None):
110110

111-
# Only provide persistent handle when removing
112-
# persistent objects
111+
# Only provide persistent handle when removing persistent objects
113112
cmd = ['tpm2_evictcontrol', '-c', str(ctx)]
114113

115114
if hierarchyauth and len(hierarchyauth) > 0:
@@ -122,7 +121,7 @@ def evictcontrol_remove(self, hierarchyauth, ctx, handle=None):
122121
stdout, stderr = p.communicate()
123122
if (p.wait()):
124123
raise RuntimeError("Could not execute tpm2_evictcontrol: %s" %
125-
stderr)
124+
stderr.decode())
126125
return stdout
127126

128127
def readpublic(self, handle, get_tr_file=True, pub_blob_path=None):
@@ -141,7 +140,7 @@ def readpublic(self, handle, get_tr_file=True, pub_blob_path=None):
141140
stdout, stderr = p.communicate()
142141
if (p.wait()):
143142
raise RuntimeError("Could not execute tpm2_readpublic: %s" %
144-
stderr)
143+
stderr.decode())
145144
return (stdout, tr_file if get_tr_file else None)
146145

147146
def load(self, pctx, pauth, priv, pub):
@@ -174,7 +173,7 @@ def load(self, pctx, pauth, priv, pub):
174173
_, stderr = p.communicate()
175174
rc = p.wait()
176175
if rc:
177-
raise RuntimeError("Could not execute tpm2_load: %s" % stderr)
176+
raise RuntimeError("Could not execute tpm2_load: %s" % stderr.decode())
178177
return ctx
179178

180179
def unseal(self, ctx, auth):
@@ -185,7 +184,7 @@ def unseal(self, ctx, auth):
185184
stdout, stderr = p.communicate()
186185
rc = p.wait()
187186
if rc:
188-
raise RuntimeError("Could not execute tpm2_unseal: %s" % stderr)
187+
raise RuntimeError("Could not execute tpm2_unseal: %s" % stderr.decode())
189188
return stdout
190189

191190
def _encryptdecrypt(self, ctx, auth, data, decrypt=False):
@@ -200,7 +199,7 @@ def _encryptdecrypt(self, ctx, auth, data, decrypt=False):
200199
rc = p.wait()
201200
if rc:
202201
raise RuntimeError("Could not execute tpm2_encryptdecrypt: %s" %
203-
stderr)
202+
stderr.decode())
204203
return stdout
205204

206205
def encrypt(self, ctx, auth, data):
@@ -246,7 +245,7 @@ def create(self,
246245
os.remove(pub)
247246
os.remove(priv)
248247
raise RuntimeError("Could not execute tpm2_create: %s" %
249-
str(stderr))
248+
stderr.decode())
250249

251250
return priv, pub, stdout
252251

@@ -258,7 +257,7 @@ def getcap(self, cap):
258257
stdout, stderr = p.communicate()
259258
rc = p.wait()
260259
if rc:
261-
raise RuntimeError("Could not execute tpm2_getcap: %s" % stderr)
260+
raise RuntimeError("Could not execute tpm2_getcap: %s" % stderr.decode())
262261
return stdout
263262

264263
def importkey(self,
@@ -373,7 +372,7 @@ def importkey(self,
373372
os.remove(priv)
374373
print("command: %s" % str(" ".join(cmd)))
375374
raise RuntimeError("Could not execute tpm2_import: %s" %
376-
stderr)
375+
stderr.decode())
377376

378377
return priv, pub, stdout
379378

@@ -397,7 +396,7 @@ def changeauth(self, pctx, objctx, oldobjauth, newobjauth):
397396
_, stderr = p.communicate()
398397
rc = p.wait()
399398
if rc:
400-
raise RuntimeError("Could not execute tpm2_changeauth: %s" % stderr)
399+
raise RuntimeError("Could not execute tpm2_changeauth: %s" % stderr.decode())
401400

402401
return newpriv
403402

@@ -423,7 +422,7 @@ def sign(self, ctx, halg, scheme, message):
423422
if (rc != 0):
424423
print("command: %s" % str(" ".join(cmd)))
425424
raise RuntimeError("Could not execute tpm2_import: %s" %
426-
str(stderr))
425+
stderr.decode())
427426
data = open(sig, "rb").read()
428427
os.unlink(sig)
429428
return data

0 commit comments

Comments
 (0)