cs_blobs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //from: xnu osfmk/kern/cs_blobs.h
  2. typedef struct __attribute__((packed)) {
  3. uint32_t magic; /* magic number (CSMAGIC_CODEDIRECTORY) */
  4. uint32_t length; /* total length of CodeDirectory blob */
  5. uint32_t version; /* compatibility version */
  6. uint32_t flags; /* setup and mode flags */
  7. uint32_t hashOffset; /* offset of hash slot element at index zero */
  8. uint32_t identOffset; /* offset of identifier string */
  9. uint32_t nSpecialSlots; /* number of special hash slots */
  10. uint32_t nCodeSlots; /* number of ordinary (code) hash slots */
  11. uint32_t codeLimit; /* limit to main image signature range */
  12. uint8_t hashSize; /* size of each hash in bytes */
  13. uint8_t hashType; /* type of hash (cdHashType* constants) */
  14. uint8_t platform; /* platform identifier; zero if not platform binary */
  15. uint8_t pageSize; /* log2(page size in bytes); 0 => infinite */
  16. uint32_t spare2; /* unused (must be zero) */
  17. char end_earliest[0];
  18. /* Version 0x20100 */
  19. uint32_t scatterOffset; /* offset of optional scatter vector */
  20. char end_withScatter[0];
  21. /* Version 0x20200 */
  22. uint32_t teamOffset; /* offset of optional team identifier */
  23. char end_withTeam[0];
  24. /* Version 0x20300 */
  25. uint32_t spare3; /* unused (must be zero) */
  26. uint64_t codeLimit64; /* limit to main image signature range, 64 bits */
  27. char end_withCodeLimit64[0];
  28. /* Version 0x20400 */
  29. uint64_t execSegBase; /* offset of executable segment */
  30. uint64_t execSegLimit; /* limit of executable segment */
  31. uint64_t execSegFlags; /* executable segment flags */
  32. char end_withExecSeg[0];
  33. } CodeDirectory;
  34. typedef struct __attribute__((packed)) {
  35. uint32_t type; /* type of entry */
  36. uint32_t offset; /* offset of entry */
  37. } CS_BlobIndex;
  38. typedef struct __attribute__((packed)) {
  39. uint32_t magic; /* magic number */
  40. uint32_t length; /* total length of SuperBlob */
  41. uint32_t count; /* number of index entries following */
  42. CS_BlobIndex index[]; /* (count) entries */
  43. /* followed by Blobs in no particular order as indicated by offsets in index */
  44. } CS_SuperBlob;
  45. /*
  46. * Magic numbers used by Code Signing
  47. */
  48. enum {
  49. CSMAGIC_REQUIREMENT = 0xfade0c00, /* single Requirement blob */
  50. CSMAGIC_REQUIREMENTS = 0xfade0c01, /* Requirements vector (internal requirements) */
  51. CSMAGIC_CODEDIRECTORY = 0xfade0c02, /* CodeDirectory blob */
  52. CSMAGIC_EMBEDDED_SIGNATURE = 0xfade0cc0, /* embedded form of signature data */
  53. CSMAGIC_EMBEDDED_SIGNATURE_OLD = 0xfade0b02, /* XXX */
  54. CSMAGIC_EMBEDDED_ENTITLEMENTS = 0xfade7171, /* embedded entitlements */
  55. CSMAGIC_DETACHED_SIGNATURE = 0xfade0cc1, /* multi-arch collection of embedded signatures */
  56. CSMAGIC_BLOBWRAPPER = 0xfade0b01, /* CMS Signature, among other things */
  57. CS_SUPPORTSSCATTER = 0x20100,
  58. CS_SUPPORTSTEAMID = 0x20200,
  59. CS_SUPPORTSCODELIMIT64 = 0x20300,
  60. CS_SUPPORTSEXECSEG = 0x20400,
  61. CSSLOT_CODEDIRECTORY = 0, /* slot index for CodeDirectory */
  62. CSSLOT_INFOSLOT = 1,
  63. CSSLOT_REQUIREMENTS = 2,
  64. CSSLOT_RESOURCEDIR = 3,
  65. CSSLOT_APPLICATION = 4,
  66. CSSLOT_ENTITLEMENTS = 5,
  67. CSSLOT_ALTERNATE_CODEDIRECTORIES = 0x1000, /* first alternate CodeDirectory, if any */
  68. CSSLOT_ALTERNATE_CODEDIRECTORY_MAX = 5, /* max number of alternate CD slots */
  69. CSSLOT_ALTERNATE_CODEDIRECTORY_LIMIT = CSSLOT_ALTERNATE_CODEDIRECTORIES + CSSLOT_ALTERNATE_CODEDIRECTORY_MAX, /* one past the last */
  70. CSSLOT_SIGNATURESLOT = 0x10000, /* CMS Signature */
  71. CSTYPE_INDEX_REQUIREMENTS = 0x00000002, /* compat with amfi */
  72. CSTYPE_INDEX_ENTITLEMENTS = 0x00000005, /* compat with amfi */
  73. CS_HASHTYPE_SHA1 = 1,
  74. CS_HASHTYPE_SHA256 = 2,
  75. CS_HASHTYPE_SHA256_TRUNCATED = 3,
  76. CS_HASHTYPE_SHA384 = 4,
  77. CS_SHA1_LEN = 20,
  78. CS_SHA256_LEN = 32,
  79. CS_SHA256_TRUNCATED_LEN = 20,
  80. CS_CDHASH_LEN = 20, /* always - larger hashes are truncated */
  81. CS_HASH_MAX_SIZE = 48, /* max size of the hash we'll support */
  82. /*
  83. * Currently only to support Legacy VPN plugins,
  84. * but intended to replace all the various platform code, dev code etc. bits.
  85. */
  86. CS_SIGNER_TYPE_UNKNOWN = 0,
  87. CS_SIGNER_TYPE_LEGACYVPN = 5,
  88. };
  89. /*
  90. * Choose among different hash algorithms.
  91. * Higher is better, 0 => don't use at all.
  92. */
  93. static const uint32_t hashPriorities[] = {
  94. CS_HASHTYPE_SHA1,
  95. CS_HASHTYPE_SHA256_TRUNCATED,
  96. CS_HASHTYPE_SHA256,
  97. CS_HASHTYPE_SHA384,
  98. };