Skip to content

Commit

Permalink
Updated20241227123341
Browse files Browse the repository at this point in the history
  • Loading branch information
PIKACHUIM committed Dec 27, 2024
1 parent c15ab9e commit 9581229
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 44 deletions.
38 changes: 19 additions & 19 deletions Config/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@
"============================================\n",
" TPM Virtual Smart Card Manager\n",
"============================================\n",
" 版本:V1.4.0 Dec01 / 2024\n",
" 版本:V1.5.0 Jan 01. 2025\n",
" 作者:Pikachu Ren \n",
" 许可:The MIT License \n",
"============================================\n",
" 项目地址:github.com/PIKACHUIM/TPMSmartCard\n",
"============================================\n"
],
"msg_tpm_check_text": "TPM状态",
"msg_tpm_check_done": "您的设备已启用TPM\n详细信息:\n\n%s",
"msg_tpm_check_fail": "您的设备未启用TPM\n详细信息:\n\n%s",
"msg_tpm_check_none": "未能获取到TPM状态\n详细信息:\n\n%s",
"msg_pass_length_l1": "原密码至少为 4位",
"msg_pass_length_l2": "新密码至少为 4位",
"msg_tpm_check_done": "您的设备已启用TPM,详细信息:\n%s",
"msg_tpm_check_fail": "您的设备未启用TPM,详细信息:\n%s",
"msg_tpm_check_none": "未能获取到TPM状态,详细信息:\n%s",
"msg_pass_length_l1": "原密码至少为 8位",
"msg_pass_length_l2": "新密码至少为 8位",
"msg_pass_not_same_": "两次输入的不匹配",
"msg_pass_next_same": "新旧密码不能相同",
"msg_pass_change_ok": "修改重置密码结果",
Expand Down Expand Up @@ -124,8 +124,8 @@
],
"msg_new_tpm_card": "创建新的TPM虚拟智能卡",
"msg_new_card_txt_e": "卡片的名称不能为空",
"msg_new_card_pin_e": "卡片PIN 长度不正确",
"msg_new_card_puk_e": "卡片PUK 需为8~16位",
"msg_new_card_pin_e": "卡片PIN 需要>= 8位",
"msg_new_card_puk_e": "卡片PUK 必须为16位",
"msg_new_card_key_e": "管理密码必须为48位",
"msg_new_card_dones": "\n卡片信息已经复制到剪贴板,请妥善保存",
"delete_cert_reboot": [
Expand Down Expand Up @@ -191,8 +191,8 @@
"efsUsage": "EFS 加密",
"bitLocks": "Bitlocker",
"anyUsage": "任意用途",
"pfx_text": "注意:只能导入RSA1024/2048和SHA1/256无证书链文件",
"cer_text": "注意:只能导入当前虚拟智能卡已存在对应密钥的证书",
"pfx_text": "注意:只能导入RSA1024/2048和SHA1/256单文件",
"cer_text": "注意:只能导入当前智能卡已存在对应密钥证书",
"sc_title": "未安装OpenSC",
"sc_datas": "您似乎还没有安装OpenSC\n是否立即安装?",
"csp_sets": "使用自定义CSP",
Expand Down Expand Up @@ -280,17 +280,17 @@
"============================================\n",
" TPM Virtual Smart Card Manager\n",
"============================================\n",
" Version: V1.4.0 Dec1/2024\n",
" Version: V1.5.0 Jan1/2025\n",
" Authors: Pikachu Ren \n",
" License: The MIT License \n",
"============================================\n",
" Address: github.com/PIKACHUIM/TPMSmartCard\n",
"============================================\n"
],
"msg_tpm_check_text": "TPM Status",
"msg_tpm_check_done": "Your device has TPM enabled\nDetails:\n\n%s",
"msg_tpm_check_fail": "Your device does not have TPM enabled\nDetails:\n\n%s",
"msg_tpm_check_none": "Failed to obtain TPM status\nDetails:\n\n%s",
"msg_tpm_check_done": "Your device has TPM and enabled, Details:\n%s",
"msg_tpm_check_fail": "Your device may not enabled TPM, Details:\n%s",
"msg_tpm_check_none": "Failed to obtain the TPM status, Details:\n%s",
"msg_pass_length_l1": "Original password must be at least 4 characters",
"msg_pass_length_l2": "New password must be at least 4 characters",
"msg_pass_not_same_": "The two inputs do not match",
Expand Down Expand Up @@ -324,9 +324,9 @@
],
"msg_new_tpm_card": "Create a new TPM virtual smart card",
"msg_new_card_txt_e": "The card name cannot be empty",
"msg_new_card_pin_e": "The card PIN length is incorrect",
"msg_new_card_puk_e": "The card PUK must be 8 to 16 digits",
"msg_new_card_key_e": "The admin key must be 48 digits",
"msg_new_card_pin_e": "The card PIN must >= 8 digits",
"msg_new_card_puk_e": "The card PUK must be 16 digits",
"msg_new_card_key_e": "The main key must be 48 digits",
"msg_new_card_dones": "\nCard information has been copied to the clipboard, please save it properly",
"delete_cert_reboot": [
"\nNote: After the certificate is deleted, the system will not immediately refresh the certificate status",
Expand Down Expand Up @@ -391,8 +391,8 @@
"efsUsage": "EFS Encryption",
"bitLocks": "Bitlocker",
"anyUsage": "Any Purpose",
"pfx_text": "Note: Only the RSA1024/2048+SHA1/256 PFX can import",
"cer_text": "Note: Only the Cert with key on the card can import",
"pfx_text": "Only the RSA1024/2048+SHA1/256 PFX can import",
"cer_text": "Only the Cert with key on the card can import",
"sc_title": "OpenSC not Install",
"sc_datas": "It seems you have not installed OpenSC\nInstall now?",
"csp_sets": "Use custom CSP",
Expand Down
3 changes: 3 additions & 0 deletions Module/AppConfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ def i18n(self, in_name):
if type(temp_data[in_name]) is list:
return "".join(temp_data[in_name])
return temp_data[in_name]

def load_status(self):
pass
31 changes: 17 additions & 14 deletions SmartCardAPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,23 @@ def about_pages(self):
self.i18n("msg_about_about"))

def check_tpm_h(self):
process = subprocess.run(" powershell Get-TPM", text=True,
capture_output=True, shell=True)
results = process.stdout.splitlines()
for line in results:
process = subprocess.run("powershell Get-TPM", text=True, capture_output=True, shell=True)
results = process.stdout.replace(" ", "")
results = [i for i in ''.join(x for x in results if x.isprintable() or x == "\n").split("\n") if len(i)]
results = ["%-25s\t: %s" % (i.split(":")[0] + "\t" * int(16 / len(i.split(":")[0])), i.split(":")[1]) for i in
results]
results = "\n".join(results).replace("TpmOwned\t\t", "TpmOwned\t")
for line in results.split("\n"):
if line.find("TpmActivated") >= 0:
if line.find("True") >= 0:
messagebox.showinfo(self.i18n("msg_tpm_check_text"),
self.i18n("msg_tpm_check_done") % "".join(results))
self.i18n("msg_tpm_check_done") % results)
return True
else:
messagebox.showerror(self.i18n("msg_tpm_check_text"),
self.i18n("msg_tpm_check_fail") % "".join(results))
self.i18n("msg_tpm_check_fail") % results)
messagebox.showwarning(self.i18n("msg_tpm_check_text"),
self.i18n("msg_tpm_check_none") % "\n".join(results))
self.i18n("msg_tpm_check_none") % results)
return False

def open_github(self):
Expand All @@ -501,15 +504,15 @@ def card_change(self, in_type="pin"):
def change(item, tips, is_same=False, *args):
password = item.get()
# print(password)
if len(password) < 4:
if len(password) < 8:
tips.config(text="❌ " + self.i18n("msg_pass_length_l1" if not is_same else "msg_pass_length_l2"))
submit_button.config(state=tk.DISABLED)
elif is_same and next_txt.get() != same_txt.get():
tips.config(text="❌ " + self.i18n("msg_pass_not_same_"))
submit_button.config(state=tk.DISABLED)
else:
tips.config(text="✅ ")
if len(pass_txt.get()) >= 4 and len(next_txt.get()) >= 4:
if len(pass_txt.get()) >= 8 and len(next_txt.get()) >= 8:
if next_txt.get() == same_txt.get():
next_tip.config(text="✅ ")
same_tip.config(text="✅ ")
Expand All @@ -528,11 +531,11 @@ def submit():
pass_new = next_txt.get()
same_new = same_txt.get()
# print(pass_key, pass_new, same_new)
if pass_key == "" or len(pass_key) < 4:
if pass_key == "" or len(pass_key) < 8:
make.attributes('-topmost', False)
messagebox.showwarning(self.i18n("warn"), self.i18n("msg_pass_length_l1"))
make.attributes('-topmost', True)
elif pass_new == "" or len(pass_new) < 4:
elif pass_new == "" or len(pass_new) < 8:
make.attributes('-topmost', False)
messagebox.showwarning(self.i18n("warn"), self.i18n("msg_pass_length_l2"))
make.attributes('-topmost', True)
Expand Down Expand Up @@ -620,10 +623,10 @@ def submit():
if name_txt.get() == "":
make.attributes('-topmost', True)
messagebox.showwarning(self.i18n("fail"), self.i18n("msg_new_card_txt_e"))
elif not 4 <= len(pins_txt.get()) <= 15:
elif not 8 <= len(pins_txt.get()) <= 15:
make.attributes('-topmost', True)
messagebox.showwarning(self.i18n("fail"), self.i18n("msg_new_card_pin_e"))
elif len(puks_txt.get()) > 0 and not 8 <= len(puks_txt.get()) <= 16:
elif len(puks_txt.get()) > 0 and not 16 <= len(puks_txt.get()) <= 16:
make.attributes('-topmost', True)
messagebox.showwarning(self.i18n("fail"), self.i18n("msg_new_card_puk_e"))
elif len(adks_txt.get()) != 48:
Expand Down Expand Up @@ -685,7 +688,7 @@ def cancel():
make.destroy()

make = ttk.Toplevel(self.root)
make.geometry("700x240")
make.geometry("710x240")
make.geometry(f"+{self.size[0]}+{self.size[1]}")
make.attributes('-topmost', True)
make.title(self.i18n("msg_new_tpm_card"))
Expand Down
20 changes: 9 additions & 11 deletions SubApp/CertImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def __init__(self,
self.path_var = tk.StringVar()
self.path_var.trace('w', self.change)
self.path_tag = ttk.Label(self.page, bootstyle="info",
text="%s: " % self.main.i18n("msg_select_file_fp"))
text="%s" % self.main.i18n("msg_select_file_fp"))
self.path_txt = ttk.Entry(self.page, bootstyle="info", width=60, textvariable=self.path_var)
self.path_tip = ttk.Button(self.page, bootstyle="info", command=self.search,
text=self.main.i18n("msg_open") + self.main.i18n("msg_file"))
if self.flag == "pfx":
self.pass_var = tk.StringVar()
self.pass_tag = ttk.Label(self.page, bootstyle="info",
text=self.main.i18n("msg_cert") + self.main.i18n("msg_pass") + ": ")
text=self.main.i18n("msg_cert") + self.main.i18n("msg_pass"))
self.pass_txt = ttk.Entry(self.page, bootstyle="info", width=60, show="*",
textvariable=self.pass_var)
# 导入密码 =====================================================================================
Expand Down Expand Up @@ -145,15 +145,15 @@ def csp_ts(self, *args):
def clouds(self, *args):
# 云端下发 ====================================
if self.v_clouds.get():
self.pass_tag.config(text=self.main.i18n("msg_keys_cloud") + ": ")
self.pass_tag.config(text=self.main.i18n("msg_keys_cloud"))
self.path_tip.grid_forget()
self.x25519()
self.pass_txt.delete(0, tk.END)
self.pass_txt.config(show="")
self.pass_txt.insert(0, self.pub_key)
self.path_tag.config(text=self.main.i18n("msg_urls_cloud"))
self.path_txt.delete(0, tk.END)
self.path_txt.insert(0, "http://127.0.0.1:1080/get/cert")
self.path_txt.insert(0, "https://cert.52pika.cn/card/get/cert")
if len(self.path_txt.get()) == 0:
self.submit_button.config(state=tk.DISABLED)
else:
Expand All @@ -165,7 +165,7 @@ def clouds(self, *args):
else:
self.path_tip.grid(column=3, row=0, pady=10, padx=5)
self.path_txt.delete(0, tk.END)
self.pass_tag.config(text=self.main.i18n("msg_cert") + self.main.i18n("msg_pass") + ": ")
self.pass_tag.config(text=self.main.i18n("msg_cert") + self.main.i18n("msg_pass"))
self.pass_txt.delete(0, tk.END)
self.pass_txt.config(show="*")
# path_tip.config(text=self.la("msg_open") + self.la("msg_file"))
Expand Down Expand Up @@ -212,11 +212,9 @@ def submit(self, ):
encrypted_data.encode()
)
)

# tmp = base64.b64encode(decrypted_data)
# tmp = tmp.decode()
# result = TPMSmartCard.baseCerts(tmp, responded_json['pfxkey'])

tmp = hashlib.sha256(decrypted_data).hexdigest()
cert_path = os.path.join(os.getenv('APPDATA'), tmp + ".pfx")
with open(cert_path, 'wb') as save_file:
Expand All @@ -227,15 +225,14 @@ def submit(self, ):
with open(cert_path, 'wb') as save_file:
for i in range(0, int(len(decrypted_data) / 16 + 1)):
save_file.write(randbytes(16))
self.main.load_status()
else:
messagebox.showwarning(self.main.i18n("fail"),
"Error Responded Data")
messagebox.showwarning(self.main.i18n("fail"), "Error Responded Data")
self.page.attributes('-topmost', True)
if not self.apps:
return False
else:
messagebox.showwarning(self.main.i18n("fail"),
"Error Responded Code")
messagebox.showwarning(self.main.i18n("fail"),"Error Responded Code")
self.page.attributes('-topmost', True)
if not self.apps:
return False
Expand All @@ -255,6 +252,7 @@ def submit(self, ):
in_csp=self.csp_data.get() if self.v_csp_ts.get() else None)
else:
result = TPMSmartCard.loadCerts(self.path_txt.get())
self.main.load_status()
self.page.destroy()
messagebox.showinfo(
self.main.i18n("msg_import") + self.main.i18n("msg_cert") + self.main.i18n("msg_result"),
Expand Down

0 comments on commit 9581229

Please sign in to comment.