gen_manifest 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env python2
  2. import os
  3. import sys
  4. import subprocess
  5. import re
  6. from shutil import copyfile
  7. runtime_libs = ['libc',
  8. 'libdl',
  9. 'libm',
  10. 'libpthread',
  11. 'libutil',
  12. 'libnss_dns',
  13. 'libresolv',
  14. 'librt']
  15. def parse_libs (bin_path) :
  16. print (bin_path)
  17. ldd_out = subprocess.check_output(['ldd', bin_path])
  18. lib_list = []
  19. for line in ldd_out.splitlines():
  20. match = re.match(r'\t(.*) => (.*) \(0x', line)
  21. if match and match.group(1) and match.group(2):
  22. full_lib_name = match.group(1)
  23. name_match = re.match(r'([\w\d]*)(\.*)(.*)', full_lib_name)
  24. if name_match:
  25. lib_name = name_match.group(1)
  26. lib_path = match.group(2)
  27. if lib_name not in runtime_libs :
  28. lib_list.append((name_match.group(1), match.group(2)))
  29. return lib_list
  30. def make_exec(path) :
  31. mode = os.stat(path).st_mode
  32. mode |= (mode & 0o444) >> 2 # copy R bits to X
  33. os.chmod(path, mode)
  34. def gen_manifest(app_name, bin_name, g_path) :
  35. m_path = g_path + '/LibOS/shim/test/apps/' + app_name + "/" + app_name +"." + "manifest"
  36. print (m_path)
  37. mf = open(m_path, "w")
  38. make_exec(m_path)
  39. mf.write("#!" + g_path + "/Runtime/pal_loader \n")
  40. mf.write("loader.preload = file:../../../../../Runtime/libsysdb.so \n")
  41. # Get Path of Binary
  42. bin_path = subprocess.check_output(['which', bin_name]).strip()
  43. mf.write('loader.exec = file:' + bin_path + '\n')
  44. mf.write('loader.execname = ' + bin_name + '\n')
  45. mf.write('loader.env.LD_LIBRARY_PATH = /graphene:/graphene/resolv:/host:/usr/local/lib:/usr/lib:/usr/lib/x86_64-linux-gnu \n')
  46. mf.write('loader.env.PATH = /usr/local/bin:/usr/bin:/bin \n' +
  47. 'loader.env.USERNAME = \n' +
  48. 'loader.env.PWD = \n' +
  49. 'loader.debug_type = none \n')
  50. mf.write('\n')
  51. # File system setting
  52. mf.write('fs.mount.lib1.type = chroot \n' +
  53. 'fs.mount.lib1.path = /graphene \n' +
  54. 'fs.mount.lib1.uri = file:../../../../../Runtime \n \n')
  55. mf.write('fs.mount.lib2.type = chroot \n' +
  56. 'fs.mount.lib2.path = /host \n' +
  57. 'fs.mount.lib2.uri = file:/lib/x86_64-linux-gnu \n \n')
  58. mf.write('fs.mount.bin.type = chroot \n' +
  59. 'fs.mount.bin.path = /bin \n' +
  60. 'fs.mount.bin.uri = file:/bin \n \n')
  61. mf.write('fs.mount.usr.type = chroot \n' +
  62. 'fs.mount.usr.path = /usr \n' +
  63. 'fs.mount.usr.uri = file:/usr \n \n')
  64. mf.write('fs.mount.etc.type = chroot \n' +
  65. 'fs.mount.etc.path = /etc \n' +
  66. 'fs.mount.etc.uri = file: \n \n')
  67. # Set Dependent Libraries
  68. mf.write('sgx.trusted_files.ld = file:../../../../../Runtime/ld-linux-x86-64.so.2 \n' +
  69. 'sgx.trusted_files.libc = file:../../../../../Runtime/libc.so.6 \n' +
  70. 'sgx.trusted_files.libdl = file:../../../../../Runtime/libdl.so.2 \n' +
  71. 'sgx.trusted_files.libm = file:../../../../../Runtime/libm.so.6 \n' +
  72. 'sgx.trusted_files.libpthread = file:../../../../../Runtime/libpthread.so.0 \n' +
  73. 'sgx.trusted_files.libutil = file:../../../../../Runtime/libutil.so.1 \n' +
  74. 'sgx.trusted_files.libnss3 = file:../../../../../Runtime/libnss_dns.so.2 \n' +
  75. 'sgx.trusted_files.libresolv = file:../../../../../Runtime/libresolv.so.2 \n')
  76. lib_list = parse_libs(bin_path)
  77. for lib_name, lib_path in lib_list :
  78. print ("lib name: " + lib_name)
  79. print ("lib path: " + lib_path)
  80. mf.write('sgx.trusted_files.' + lib_name + ' = file:' + lib_path + '\n')
  81. mf.write('\n')
  82. # 'sgx.allowed_files.usr = file:/usr \n')
  83. mf.close()
  84. if __name__ == "__main__":
  85. if len(sys.argv) != 4:
  86. print ("Usage: gen_manifest [App Name] [bin_name] [Graphene Path]")
  87. exit()
  88. app_name = sys.argv[1]
  89. bin_name = sys.argv[2]
  90. g_path = sys.argv[3]
  91. gen_manifest(app_name, bin_name, g_path)