|
| 1 | +package types |
| 2 | + |
| 3 | +const ( |
| 4 | + // Magic numbers used by Code Signing |
| 5 | + CSMAGIC_REQUIREMENT = 0xfade0c00 // single Requirement blob |
| 6 | + CSMAGIC_REQUIREMENTS = 0xfade0c01 // Requirements vector (internal requirements) |
| 7 | + CSMAGIC_CODEDIRECTORY = 0xfade0c02 // CodeDirectory blob |
| 8 | + CSMAGIC_EMBEDDED_SIGNATURE = 0xfade0cc0 // embedded form of signature data |
| 9 | + CSMAGIC_DETACHED_SIGNATURE = 0xfade0cc1 // multi-arch collection of embedded signatures |
| 10 | + CSMAGIC_BLOBWRAPPER = 0xfade0b01 // used for the cms blob |
| 11 | +) |
| 12 | + |
| 13 | +const ( |
| 14 | + CS_PAGE_SIZE = 4096 |
| 15 | + |
| 16 | + CS_HASHTYPE_SHA1 = 1 |
| 17 | + CS_HASHTYPE_SHA256 = 2 |
| 18 | + CS_HASHTYPE_SHA256_TRUNCATED = 3 |
| 19 | + CS_HASHTYPE_SHA384 = 4 |
| 20 | + |
| 21 | + CS_HASH_SIZE_SHA1 = 20 |
| 22 | + CS_HASH_SIZE_SHA256 = 32 |
| 23 | + CS_HASH_SIZE_SHA256_TRUNCATED = 20 |
| 24 | + |
| 25 | + CSSLOT_CODEDIRECTORY = 0 |
| 26 | + CSSLOT_INFOSLOT = 1 |
| 27 | + CSSLOT_REQUIREMENTS = 2 |
| 28 | + CSSLOT_RESOURCEDIR = 3 |
| 29 | + CSSLOT_APPLICATION = 4 |
| 30 | + CSSLOT_ENTITLEMENTS = 5 |
| 31 | + CSSLOT_ALTERNATE_CODEDIRECTORIES = 0x1000 |
| 32 | + CSSLOT_ALTERNATE_CODEDIRECTORY_MAX = 5 |
| 33 | + CSSLOT_ALTERNATE_CODEDIRECTORY_LIMIT = CSSLOT_ALTERNATE_CODEDIRECTORIES + CSSLOT_ALTERNATE_CODEDIRECTORY_MAX |
| 34 | + CSSLOT_CMS_SIGNATURE = 0x10000 |
| 35 | + |
| 36 | + kSecCodeSignatureAdhoc = 2 |
| 37 | +) |
| 38 | + |
| 39 | +const CS_REQUIRE_LV = 0x0002000 // require library validation |
| 40 | + |
| 41 | +// Structure of a SuperBlob |
| 42 | +type CsBlobIndex struct { |
| 43 | + Type uint32 // type of entry |
| 44 | + Offset uint32 // offset of entry |
| 45 | +} |
| 46 | + |
| 47 | +type CsSuperBlob struct { |
| 48 | + Magic uint32 // magic number |
| 49 | + Length uint32 // total length of SuperBlob |
| 50 | + Count uint32 // number of index entries following |
| 51 | + // Index []CsBlobIndex // (count) entries |
| 52 | + // followed by Blobs in no particular order as indicated by offsets in index |
| 53 | +} |
| 54 | + |
| 55 | +// type CsSuperBlob struct { |
| 56 | +// Magic uint32 // magic number |
| 57 | +// Length uint32 // total length of SuperBlob |
| 58 | +// Count uint32 // number of index entries following |
| 59 | +// Index []CsBlobIndex // (count) entries |
| 60 | +// // followed by Blobs in no particular order as indicated by offsets in index |
| 61 | +// } |
| 62 | + |
| 63 | +// C form of a CodeDirectory. |
| 64 | +type CsCodeDirectory struct { |
| 65 | + Magic uint32 // magic number (CSMAGIC_CODEDIRECTORY) */ |
| 66 | + Length uint32 // total length of CodeDirectory blob |
| 67 | + Version uint32 // compatibility version |
| 68 | + Flags uint32 // setup and mode flags |
| 69 | + HashOffset uint32 // offset of hash slot element at index zero |
| 70 | + IdentOffset uint32 // offset of identifier string |
| 71 | + NSpecialSlots uint32 // number of special hash slots |
| 72 | + NCodeSlots uint32 // number of ordinary (code) hash slots |
| 73 | + CodeLimit uint32 // limit to main image signature range |
| 74 | + HashSize uint8 // size of each hash in bytes |
| 75 | + HashType uint8 // type of hash (cdHashType* constants) |
| 76 | + Platform uint8 // platform identifier zero if not platform binary |
| 77 | + PageSize uint8 // log2(page size in bytes) 0 => infinite |
| 78 | + Spare2 uint32 // unused (must be zero) |
| 79 | + |
| 80 | + EndEarliest [0]uint8 |
| 81 | + |
| 82 | + /* Version 0x20100 */ |
| 83 | + ScatterOffset uint32 /* offset of optional scatter vector */ |
| 84 | + EndWithScatter [0]uint8 |
| 85 | + |
| 86 | + /* Version 0x20200 */ |
| 87 | + TeamOffset uint32 /* offset of optional team identifier */ |
| 88 | + EndWithTeam [0]uint8 |
| 89 | + |
| 90 | + /* Version 0x20300 */ |
| 91 | + Spare3 uint32 /* unused (must be zero) */ |
| 92 | + CodeLimit64 uint64 /* limit to main image signature range, 64 bits */ |
| 93 | + EndWithCodeLimit64 [0]uint8 |
| 94 | + |
| 95 | + /* Version 0x20400 */ |
| 96 | + ExecSegBase uint64 /* offset of executable segment */ |
| 97 | + ExecSegLimit uint64 /* limit of executable segment */ |
| 98 | + ExecSegFlags uint64 /* exec segment flags */ |
| 99 | + EndWithExecSeg [0]uint8 |
| 100 | + |
| 101 | + /* followed by dynamic content as located by offset fields above */ |
| 102 | +} |
| 103 | + |
| 104 | +type CsBlob struct { |
| 105 | + Magic uint32 // magic number |
| 106 | + Length uint32 // total length of blob |
| 107 | +} |
| 108 | + |
| 109 | +type CsRequirementsBlob struct { |
| 110 | + Magic uint32 // magic number |
| 111 | + Length uint32 // total length of blob |
| 112 | + Data uint32 // zero for dyld shared cache |
| 113 | +} |
| 114 | + |
| 115 | +type CsScatter struct { |
| 116 | + Count uint32 // number of pages zero for sentinel (only) |
| 117 | + Base uint32 // first page number |
| 118 | + TargetOffset uint64 // byte offset in target |
| 119 | + Spare uint64 // reserved (must be zero) |
| 120 | +} |
0 commit comments