Skip to content

Commit

Permalink
Merge pull request #4 from Sudhishna/master
Browse files Browse the repository at this point in the history
sig related changes
  • Loading branch information
ydnath authored Mar 17, 2020
2 parents 5c7e3a4 + 47ae88e commit 11b6c2f
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 27 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include jet/jet-certs.pem
include jet/manifest.certs
include jet/manifest.xcerts
12 changes: 8 additions & 4 deletions jet/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def generate_sha1(filename):
return hash.hexdigest()


def sign(input, output, key, cert):
def sign(input, output, key, cert, sha_bits, certs):
"""sign file
:param input: path to input file
Expand All @@ -76,12 +76,16 @@ def sign(input, output, key, cert):
:type key: str
:param cert: path to public key/cert
:type cert: str
:param sha_bits: sha1 or sha256
:type sha_bits: str
:param certs: certs or xcerts
:type certs: str
"""
# get subject from certificate
_subject = subprocess.check_output("openssl x509 -in %s -noout -subject" % cert, shell=True)
subject = _subject.decode("utf8").split(" ", 1)[1].strip()
# create signature
signature = subprocess.check_output("openssl dgst -sha1 -sign %s %s" % (key, input), shell=True)
signature = subprocess.check_output("openssl dgst -%s -sign %s %s" % (sha_bits, key, input), shell=True)
# create base64 from signature
signature64 = base64.b64encode(signature).decode("utf8")
# format signature file
Expand All @@ -94,10 +98,10 @@ def sign(input, output, key, cert):
with open(output, "w+") as f:
f.write(signature_file)
# create certificate chain
with open("%s/manifest.certs" % os.path.dirname(__file__), "r") as f:
with open("%s/jet-certs.pem" % (os.path.dirname(__file__)), "r") as f:
cert_chain = f.read()
with open(cert, "r") as f:
cert_file = f.read()
with open("%s/manifest.certs" % os.path.dirname(output), "w+") as f:
with open("%s/manifest.%s" % (os.path.dirname(output), certs), "w+") as f:
f.write(cert_file)
f.write(cert_chain)
86 changes: 86 additions & 0 deletions jet/jet-certs.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
-----B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KSnVuaXBlciBDQTEYMBYGA1UEAxMPSnVuaXBl
clJvb3RFY0NBMR0wGwYJKoZIhvcNAQkBFg5jYUBqdW5pcGVyLm5ldDBZMBMGByqG
SM49AgEGCCqGSM49AwEHA0IABLLO2jUCDvFohvzVzCghOTz9qj7FmYD/9Tg6DmtI
NJP9lXV1Kb1yIdPFIQKZPxKTDbsnGA/tl/qj6X/+iANVzimjggE+MIIBOjA8Bglg
hkgBhvhCAQMELxYtaHR0cDovL2NybC5qdW5pcGVyLm5ldC9jcmw/Y2E9SnVuaXBl
clJvb3RFY0NBMB0GA1UdDgQWBBQJmLjorDh/ySAu23Esq3vTbteG2TCBzAYDVR0j
BIHEMIHBgBQJmLjorDh/ySAu23Esq3vTbteG2aGBnaSBmjCBlzELMAkGA1UEBhMC
VVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTdW5ueXZhbGUxGTAXBgNVBAoTEEp1
bmlwZXIgTmV0d29ya3MxEzARBgNVBAsTCkp1bmlwZXIgQ0ExGDAWBgNVBAMTD0p1
bmlwZXJSb290RWNDQTEdMBsGCSqGSIb3DQEJARYOY2FAanVuaXBlci5uZXSCCQCU
RpsQnjSUFzAMBgNVHRMEBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQC9k4rzVeuT
Bv41Q/BCz7FgE+wVVp/HJ938AzWCPaXvFgIhAOYjrc9IE/SEJojsBUbVCFFgK+U8
YXW/l1Pxnq1povf5
-----END CERTIFICATE-----
65 changes: 46 additions & 19 deletions jet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,22 @@ def main():
os.makedirs(contents)
contents_pkg = '%s/pkg' % contents
os.makedirs(contents_pkg)
if project["sig"] is not None and project["sig"] == "xsig":
sig = project["sig"]
certs = "xcerts"
sha_bits = "sha256"
else:
sig = "sig"
certs = "certs"
sha_bits = "sha1"

content_manifest = """pkg/manifest uid=0 gid=0 mode=444
pkg/manifest.sha1 uid=0 gid=0 mode=444
pkg/manifest.sig uid=0 gid=0 mode=444
pkg/manifest.certs uid=0 gid=0 mode=444
/set package_id=%s role=%s
""" % (project["package_id"], project["role"])
pkg/manifest.%s uid=0 gid=0 mode=444
pkg/manifest.%s uid=0 gid=0 mode=444
pkg/manifest.%s uid=0 gid=0 mode=444
""" % (sha_bits, sig, certs)
if project["sig"] is None:
content_manifest += "/set package_id=%s role=%s\n" % (project["package_id"], project["role"])
contents_symlink =""
mount_dir = "/packages/mnt/%s" % project["basename"]
for f in project["files"]:
Expand All @@ -96,10 +106,19 @@ def main():
# copy file
shutil.copy(os.path.join(args.source, f['source']), destination)
# add file to manifest
sha1 = crypto.generate_sha1(destination)
content_manifest += "%s sha1=%s uid=%s gid=%s mode=%s\n" % \
(f["destination"][1:] if f["destination"][0] == "/" else f["destination"],
sha1, f["uid"], f["gid"], f["mode"])
if project["sig"] is not None and project["sig"] == "xsig":
sha = crypto.generate_sha256(destination)
else:
sha = crypto.generate_sha1(destination)
if project["scripts"] is not None and sha_bits == "sha1":
content_manifest += "%s %s=%s uid=%s gid=%s mode=%s program_id=%s\n" % \
(f["destination"][1:] if f["destination"][0] == "/" else f["destination"],
sha_bits, sha, f["uid"], f["gid"], f["mode"], f["program_id"])
else:
content_manifest += "%s %s=%s uid=%s gid=%s mode=%s\n" % \
(f["destination"][1:] if f["destination"][0] == "/" else f["destination"],
sha_bits, sha, f["uid"], f["gid"], f["mode"])

if f["symlink"]:
contents_symlink += "%s%s %s\n" % (mount_dir, f["destination"], f["destination"])
if project["scripts"] is not None:
Expand All @@ -113,17 +132,20 @@ def main():
with open(content_manifest_file, "w") as f:
f.write(content_manifest)

content_manifest_sha_file = '%s/manifest.sha1' % contents_pkg
content_manifest_sha_file = '%s/manifest.%s' % (contents_pkg, sha_bits)
with open(content_manifest_sha_file, "w") as f:
f.write("%s\n" % crypto.generate_sha1(content_manifest_file))
if project["sig"] is not None and project["sig"] == "xsig":
f.write("%s\n" % crypto.generate_sha256(content_manifest_file))
else:
f.write("%s\n" % crypto.generate_sha1(content_manifest_file))

contents_symlink_file = '%s.symlinks' % contents
log.info("create symlink file %s", contents_symlink_file)
with open(contents_symlink_file, "w") as f:
f.write(contents_symlink)

log.info("sign manifest file %s" % content_manifest_file)
crypto.sign(content_manifest_file, "%s.sig" % content_manifest_file, args.key, args.cert)
crypto.sign(content_manifest_file, "%s.%s" % (content_manifest_file, sig), args.key, args.cert, sha_bits, certs)

for f in os.listdir(contents_pkg):
os.chmod(os.path.join(contents_pkg, f), 0o444)
Expand All @@ -135,24 +157,29 @@ def main():
log.info("create package.xml")
utils.create_package_xml(project, version, package, args.build)

package_manifest = "/set package_id=31 role=Provider_Daemon\n"
if project["sig"] is not None and project["sig"] == "xsig":
package_manifest = ""
else:
package_manifest = "/set package_id=31 role=Provider_Daemon\n"
package_manifest_files = ["contents/contents.iso", "contents/contents.symlinks", "package.xml"]
if project["scripts"] is not None:
package_manifest_files.append("scripts/%s" % project["scripts"])
package_manifest_files.append("scripts/%s" % project["scripts"])

for f in package_manifest_files:
if f == 'scripts/%s' % project['scripts']:
package_manifest += "%s sha1=%s program_id=1\n" % (f, crypto.generate_sha1(os.path.join(args.build, f)))
else:
package_manifest += "%s sha1=%s\n" % (f, crypto.generate_sha1(os.path.join(args.build, f)))
if f == 'scripts/%s' % project['scripts'] and sha_bits == "sha1":
package_manifest += "%s %s=%s program_id=1\n" % (f, sha_bits, crypto.generate_sha1(os.path.join(args.build, f)))
elif sha_bits == "sha256":
package_manifest += "%s %s=%s\n" % (f, sha_bits, crypto.generate_sha256(os.path.join(args.build, f)))
else:
package_manifest += "%s %s=%s\n" % (f, sha_bits, crypto.generate_sha1(os.path.join(args.build, f)))

package_manifest_file = os.path.join(args.build, "manifest")
log.info("create manifest file %s", package_manifest_file)
with open(package_manifest_file, "w") as f:
f.write(package_manifest)

log.info("sign manifest file %s" % package_manifest_file)
crypto.sign(package_manifest_file, "%s.sig" % package_manifest_file, args.key, args.cert)
crypto.sign(package_manifest_file, "%s.%s" % (package_manifest_file, sig), args.key, args.cert, sha_bits, certs)

log.info("create %s.tgz" % package)
utils.create_tgz(package, args.build)
Expand Down
11 changes: 7 additions & 4 deletions jet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def load_project(project_file, version):
:rtype: dict
"""
with open(project_file , 'r') as f:
project_yaml = yaml.load(f)
project_yaml = yaml.load(f, Loader=yaml.FullLoader)

def required(d, k):
if k in d:
Expand All @@ -115,6 +115,7 @@ def required(d, k):
"basename": required(project_yaml, "basename"),
"scripts": project_yaml.get("scripts", None),
"actions": project_yaml.get("actions", None),
"sig": project_yaml.get("sig", None),
"files": [],
"comment": project_yaml.get("comment", "JET app %s" % project_yaml["basename"]),
"arch": required(project_yaml, "arch"),
Expand Down Expand Up @@ -197,9 +198,11 @@ def package_xml_file(filename):
etree.SubElement(package_xml, "spin").text = project["time"]

if project['actions'] is not None:
act_list = re.split("[, ]", project['actions'])
for act in act_list:
etree.SubElement(package_xml, "%s-action"%act).text = "scripts/%s" % project["scripts"]
act_list = re.split("[, ]", project['actions'])
for act in act_list:
print("%s-action"%act)
print("scripts/%s" % project["scripts"])
etree.SubElement(package_xml, "%s-action"%act).text = "scripts/%s" % project["scripts"]

etree.SubElement(package_xml, "sb-location").text = "JetEZ"

Expand Down

0 comments on commit 11b6c2f

Please sign in to comment.