Class: Pliney::AppleCodeSignature::CodeDirectory

Inherits:
Blob
  • Object
show all
Defined in:
lib/pliney/apple_code_signature.rb

Overview

A CodeDirectory

Constant Summary collapse

HASHTYPES =

Types of cryptographic digests (hashes) used to hold code signatures together.

Each combination of type, length, and other parameters is a separate hash type; we don’t understand “families” here.

These type codes govern the digest links that connect a CodeDirectory to its subordinate data structures (code pages, resources, etc.) They do not directly control other uses of hashes (such as the hash-of-CodeDirectory identifiers used in requirements).

{
    0 => :NoHash,     # null value
    1 => :HashSha1,   # SHA-1
    2 => :HashSha256, # SHA-256
    32 => :HashPrestandardSkein160x256, # Skein, 160bits, 256bit pool
    33 => :HashPrestandardSkein256x512, # Skein, 256bits, 512bit pool
}
CURRENT_VERSION =

“version 2.1”

0x20100
COMPATABILITY_LIMIT =

“version 3 with wiggle room”

0x2F000
EARLIEST_VERSION =

earliest supported version

0x20001
SUPPORTS_SCATTER =

first version to support scatter option

0x20100

Instance Attribute Summary collapse

Attributes inherited from Blob

#input, #magic, #size

Instance Method Summary collapse

Methods inherited from Blob

#initialize

Constructor Details

This class inherits a constructor from Pliney::AppleCodeSignature::Blob

Instance Attribute Details

#codeLimitObject (readonly)

uint32 limit to main image signature range



127
128
129
# File 'lib/pliney/apple_code_signature.rb', line 127

def codeLimit
  @codeLimit
end

#dataObject (readonly)

Returns the value of attribute data.



120
121
122
# File 'lib/pliney/apple_code_signature.rb', line 120

def data
  @data
end

#flagsObject (readonly)

uint32 setup and mode flags



122
123
124
# File 'lib/pliney/apple_code_signature.rb', line 122

def flags
  @flags
end

#hashOffsetObject (readonly)

uint32 offset of hash slot element at index zero



123
124
125
# File 'lib/pliney/apple_code_signature.rb', line 123

def hashOffset
  @hashOffset
end

#hashSizeObject (readonly)

size of each hash digest (bytes)



128
129
130
# File 'lib/pliney/apple_code_signature.rb', line 128

def hashSize
  @hashSize
end

#hashTypeObject (readonly)

type of hash (kSecCodeSignatureHash* constants)



129
130
131
# File 'lib/pliney/apple_code_signature.rb', line 129

def hashType
  @hashType
end

#identOffsetObject (readonly)

uint32 offset of identifier string



124
125
126
# File 'lib/pliney/apple_code_signature.rb', line 124

def identOffset
  @identOffset
end

#nCodeSlotsObject (readonly)

uint32 number of ordinary (code) hash slots



126
127
128
# File 'lib/pliney/apple_code_signature.rb', line 126

def nCodeSlots
  @nCodeSlots
end

#nSpecialSlotsObject (readonly)

uint32 number of special hash slots



125
126
127
# File 'lib/pliney/apple_code_signature.rb', line 125

def nSpecialSlots
  @nSpecialSlots
end

#pageSizeObject (readonly)

log2(page size in bytes); 0 => infinite



131
132
133
# File 'lib/pliney/apple_code_signature.rb', line 131

def pageSize
  @pageSize
end

#scatterOffsetObject (readonly)

uint32 offset of optional scatter vector (zero if absent)



133
134
135
# File 'lib/pliney/apple_code_signature.rb', line 133

def scatterOffset
  @scatterOffset
end

#spare1Object (readonly)

unused (must be zero)



130
131
132
# File 'lib/pliney/apple_code_signature.rb', line 130

def spare1
  @spare1
end

#spare2Object (readonly)

uint32 unused (must be zero)



132
133
134
# File 'lib/pliney/apple_code_signature.rb', line 132

def spare2
  @spare2
end

#versionObject (readonly)

uint32 compatibility version



121
122
123
# File 'lib/pliney/apple_code_signature.rb', line 121

def version
  @version
end

Instance Method Details

#hash_typeObject



158
159
160
# File 'lib/pliney/apple_code_signature.rb', line 158

def hash_type
    HASHTYPES[@hashType] || :unknown
end

#parseObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/pliney/apple_code_signature.rb', line 135

def parse
    super() do
        @vers = @input.read_uint32
        @flags = @input.read_uint32
        @hashOffset = @input.read_uint32
        @identOffset = @input.read_uint32
        @nSpecialSlots = @input.read_uint32
        @nCodeSlots = @input.read_uint32
        @codeLimit = @input.read_uint32
        @hashSize = @input.read_uint8
        @hashType = @input.read_uint8
        @spare1 = @input.read_uint8
        @pageSize = @input.read_uint8
        @spare2 = @input.read_uint32
        @scatterOffset = @input.read_uint32
        @data = rest()
    end
end