Skip to content

Commit

Permalink
Merge pull request #6 from RaymWong/python3_dev
Browse files Browse the repository at this point in the history
Update NV feature using NV Auth Value
  • Loading branch information
RaymWong authored Apr 27, 2022
2 parents 9a2650f + 59cc072 commit c1c271b
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Python_TPM20_GUI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shell_util as exec_cmd
import images as img
import subprocess
#import wx.lib.inspection
import wx.lib.inspection

class MainFrame(wx.Frame):
def __init__(self, parent, title):
Expand Down
1 change: 1 addition & 0 deletions Python_TPM20_GUI/shell_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Variables to hold the 3 authorisation values
ownerAuth = "owner123"
nvAuth = "nv123"
endorseAuth = "endorsement123"
lockoutAuth = "lockout123"
openssl_cnf=("openssl_conf = openssl_init\n"
Expand Down
179 changes: 125 additions & 54 deletions Python_TPM20_GUI/tab1_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def __init__(self, parent):
read_sizer = wx.BoxSizer(wx.HORIZONTAL)
input_sizer = wx.BoxSizer(wx.HORIZONTAL)
owner_sizer = wx.BoxSizer(wx.HORIZONTAL)
nv_auth_sizer = wx.BoxSizer(wx.HORIZONTAL)
button_row_1 = wx.BoxSizer(wx.HORIZONTAL)
button_row_2 = wx.BoxSizer(wx.HORIZONTAL)
button_row_3 = wx.BoxSizer(wx.HORIZONTAL)
Expand All @@ -445,6 +446,8 @@ def __init__(self, parent):
self.nvm_data = wx.TextCtrl(self, -1)
text_for_owner_auth = wx.StaticText(self, -1, "Owner Authorisation: ")
self.owner_input = wx.TextCtrl(self, -1)
text_for_nv_auth = wx.StaticText(self, -1, "NV Authorisation: ")
self.nv_auth_input = wx.TextCtrl(self, -1)
button_nvdefine = wx.Button(self, -1, 'NV Define')
button_nvwrite = wx.Button(self, -1, 'NV Write')

Expand Down Expand Up @@ -489,13 +492,14 @@ def __init__(self, parent):
index_size_offset_input_sizer.Add(offset_sizer, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(read_sizer, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(owner_sizer, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(nv_auth_sizer, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(button_row_1, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(button_row_2, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(button_row_3, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(button_row_4, 1, wx.EXPAND, 0)

index_size_offset_input_sizer.Add(rsa_sizer, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(ecc_sizer, 1, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(rsa_sizer, 0, wx.EXPAND, 0)
index_size_offset_input_sizer.Add(ecc_sizer, 0, wx.EXPAND, 0)

index_size_offset_input_sizer.Add(icon_sizer, 0, wx.ALL, 5)

Expand All @@ -516,6 +520,9 @@ def __init__(self, parent):

owner_sizer.Add(text_for_owner_auth, 1, wx.ALIGN_CENTRE, 5)
owner_sizer.Add(self.owner_input, 1, wx.ALL, 5)

nv_auth_sizer.Add(text_for_nv_auth, 1, wx.ALIGN_CENTRE, 5)
nv_auth_sizer.Add(self.nv_auth_input, 1, wx.ALL, 5)

button_row_1.Add(button_nvdefine, 1, wx.ALL, 5)
button_row_1.Add(button_nvwrite, 1, wx.ALL, 5)
Expand Down Expand Up @@ -572,12 +579,13 @@ def __init__(self, parent):
self.read_amt.write("32")
self.nvm_data.write("Hello World!")
self.owner_input.write(exec_cmd.ownerAuth)
self.nvm_attr.SetCheckedStrings(["ownerread", "ownerwrite", "read_stclear"])
self.nv_auth_input.write(exec_cmd.nvAuth)
self.nvm_attr.SetCheckedStrings(["authread", "authwrite"])
self.SetSizer(mainsizer)

def OnClickFileName(self, evt):
frame = wx.Frame(None, -1, '*.*')
frame.SetDimensions(0,0,200,50)
frame.SetSize(0,0,200,50)

openFileDialog = wx.FileDialog(frame, "Open", "", "","All|*.bin;*.crt;*.der|Binary|*.bin|Certificate|*.crt;*.der", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() ==wx.ID_CANCEL:
Expand Down Expand Up @@ -714,7 +722,7 @@ def OnReadRSACert(self, evt):


def OnResetAttr(self, evt):
self.nvm_attr.SetCheckedStrings(["ownerread", "ownerwrite", "read_stclear"])
self.nvm_attr.SetCheckedStrings(["authread", "authwrite"])

def OnClear(self, evt):
self.bottom_txt_display.Clear()
Expand All @@ -724,6 +732,7 @@ def OnClear(self, evt):
def OnNVDefine(self, evt):
nvm_index = self.nvm_index.GetValue()
owner_val = self.owner_input.GetValue()
nv_auth_val = self.nv_auth_input.GetValue()
nvm_size = self.nvm_size.GetValue()
temp_attr = []
nvm_attr = ""
Expand All @@ -740,17 +749,37 @@ def OnNVDefine(self, evt):
return
nvm_attr = "|".join(temp_attr)
self.bottom_txt_display.AppendText("Attributes are: " + nvm_attr + "\n")
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvdefine",
nvm_index,
"-C", "o",
"-s", nvm_size,
"-a", nvm_attr,
"-P", owner_val,
])
self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("'tpm2_nvdefine' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")
if (self.owner_input.GetValue()=="" and self.nv_auth_input.GetValue()==""):
self.bottom_txt_display.AppendText("Owner Authorisation and NV Authorisation Empty. Input Again.\n")
return
#if NV field is not specified
if (self.nv_auth_input.GetValue()==""):
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvdefine",
nvm_index,
"-C", "o",
"-s", nvm_size,
"-a", nvm_attr,
"-P", owner_val,
])
self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("'tpm2_nvdefine' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")

#if NV field is specified
elif (self.owner_input.GetValue()!="" and self.nv_auth_input.GetValue()!=""):
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvdefine",
nvm_index,
"-C", "o",
"-s", nvm_size,
"-a", nvm_attr,
"-P", owner_val,
"-p", nv_auth_val,
])
self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("'tpm2_nvdefine' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")

def OnNVWriteFile(self, evt):
nvm_index = self.nvm_index.GetValue()
Expand All @@ -777,22 +806,34 @@ def OnNVWriteFile(self, evt):
def OnNVWrite(self, evt):
nvm_index = self.nvm_index.GetValue()
owner_val = self.owner_input.GetValue()
nv_auth_val = self.nv_auth_input.GetValue()
nvm_data = self.nvm_data.GetValue()
if ((nvm_index == 0) | (nvm_data == 0)):
return
data_file = open("nvm_data.txt", "w")
data_file.write(nvm_data)
data_file.close()
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvwrite",
nvm_index,
"-C", "o",
"-P", owner_val,
"-i","nvm_data.txt",
])
self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("'tpm2_nvwrite' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")
#if NV auth field is not specified
if (self.nv_auth_input.GetValue()==""):
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvwrite",
nvm_index,
"-i","nvm_data.txt",
])
self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("'tpm2_nvwrite' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")
#if NV auth field is specified
elif (self.nv_auth_input.GetValue()!=""):
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvwrite",
nvm_index,
"-i","nvm_data.txt",
"-P", nv_auth_val,
])
self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("'tpm2_nvwrite' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")

def OnNVRelease(self, evt):
nvm_index = self.nvm_index.GetValue()
Expand All @@ -813,6 +854,7 @@ def OnNVRead(self, evt):
nvm_index = self.nvm_index.GetValue()
nvm_size = self.nvm_size.GetValue()
owner_val = self.owner_input.GetValue()
nv_auth_val = self.nv_auth_input.GetValue()
nvm_offset = self.nvm_offset.GetValue()
read_size = self.read_amt.GetValue()
try:
Expand All @@ -824,36 +866,65 @@ def OnNVRead(self, evt):
return
if (int(read_size) == 0):
return
#if NV auth field is not specified
if (self.nv_auth_input.GetValue()==""):
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvread",
nvm_index,
"-s", str(read_size),
"-o","nvdata.txt",
])
if (command_output.find("ERROR") != -1):
self.bottom_txt_display.AppendText(str(command_output)+"\n")
return

#~ f = open("nvdata.txt", "w+")
#~ f.write(command_output)
#~ f.close()
command_output = exec_cmd.execTpmToolsAndCheck([
"xxd", "nvdata.txt",
])

#~ global client_log
#~ command_output = exec_cmd.createProcess("tpm2_nvread -x" + nvm_index + " -a o -s "+ read_size+ " -o 0 -P "+ owner_val+" | xxd > nvdata.txt", client_log)
#~ f = open("nvdata.txt", "r")
#~ text=f.read()

self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("\n")
self.bottom_txt_display.AppendText("'tpm2_nvread' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")

command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvread",
nvm_index,
"-C", "o",
"-s", str(read_size),
"-o", nvm_offset,
"-P", owner_val,
"-o","nvdata.txt",
])
if (command_output.find("ERROR") != -1):
self.bottom_txt_display.AppendText(str(command_output)+"\n")
return
#if NV auth field is specified
elif (self.nv_auth_input.GetValue()!=""):
command_output = exec_cmd.execTpmToolsAndCheck([
"tpm2_nvread",
nvm_index,
"-s", str(read_size),
"-o","nvdata.txt",
"-P", nv_auth_val,

#~ f = open("nvdata.txt", "w+")
#~ f.write(command_output)
#~ f.close()
command_output = exec_cmd.execTpmToolsAndCheck([
"xxd", "nvdata.txt",
])

#~ global client_log
#~ command_output = exec_cmd.createProcess("tpm2_nvread -x" + nvm_index + " -a o -s "+ read_size+ " -o 0 -P "+ owner_val+" | xxd > nvdata.txt", client_log)
#~ f = open("nvdata.txt", "r")
#~ text=f.read()

self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("\n")
self.bottom_txt_display.AppendText("'tpm2_nvread' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")
])
if (command_output.find("ERROR") != -1):
self.bottom_txt_display.AppendText(str(command_output)+"\n")
return

#~ f = open("nvdata.txt", "w+")
#~ f.write(command_output)
#~ f.close()
command_output = exec_cmd.execTpmToolsAndCheck([
"xxd", "nvdata.txt",
])

#~ global client_log
#~ command_output = exec_cmd.createProcess("tpm2_nvread -x" + nvm_index + " -a o -s "+ read_size+ " -o 0 -P "+ owner_val+" | xxd > nvdata.txt", client_log)
#~ f = open("nvdata.txt", "r")
#~ text=f.read()

self.bottom_txt_display.AppendText(str(command_output))
self.bottom_txt_display.AppendText("\n")
self.bottom_txt_display.AppendText("'tpm2_nvread' executed \n")
self.bottom_txt_display.AppendText("++++++++++++++++++++++++++++++++++++++++++++\n")

def OnNVReadLock(self, evt):
nvm_index = self.nvm_index.GetValue()
Expand Down
Binary file modified images/Optiga_Setup/NVM/NVM_Unedited/TPMNVM_Define.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_List.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_ReadECC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_ReadRSA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_ReleaseSuccess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_Screen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_ScreenSelectdefine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_WriteFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_WriteFileSuccess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_WriteFileSuccessInterpreted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/TPMNVM_WritenRead2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Optiga_Setup/NVM/Write_cert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c1c271b

Please sign in to comment.