2021-03-17 15:53:31 +01:00
|
|
|
#!/usr/bin/env python3
|
2016-11-23 06:35:12 +01:00
|
|
|
|
|
|
|
import sys, os, os.path
|
|
|
|
import pywii
|
|
|
|
|
|
|
|
pywii.loadkeys_dpki()
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
mode = args.pop(0)
|
|
|
|
infile = args.pop(0)
|
|
|
|
outfile = args.pop(0)
|
|
|
|
certfile = args.pop(0)
|
|
|
|
issuer = args.pop(0)
|
|
|
|
|
|
|
|
if sys.argv[1] == "-cetk":
|
|
|
|
signed = pywii.WiiTik(open(infile, "rb").read())
|
|
|
|
elif sys.argv[1] == "-tmd":
|
|
|
|
signed = pywii.WiiTmd(open(infile, "rb").read())
|
|
|
|
else:
|
2021-03-17 15:53:31 +01:00
|
|
|
print("EYOUFAILIT")
|
2016-11-23 06:35:12 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
certs, certlist = pywii.parse_certs(open(certfile).read())
|
|
|
|
|
|
|
|
signed.update_issuer(issuer)
|
|
|
|
|
|
|
|
if not signed.sign(certs):
|
2021-03-17 15:53:31 +01:00
|
|
|
print("dpki signing failed")
|
2016-11-23 06:35:12 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
open(outfile, "wb").write(signed.data)
|
|
|
|
|
2021-03-17 15:53:31 +01:00
|
|
|
print("successfully signed %s" % outfile)
|
2016-11-23 06:35:12 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|