1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
use {
cryptographic_message_syntax::CmsError,
std::path::PathBuf,
thiserror::Error,
tugger_apple::UniversalMachOError,
x509_certificate::{KeyAlgorithm, X509CertificateError},
};
#[derive(Debug, Error)]
pub enum AppleCodesignError {
#[error("unknown command")]
CliUnknownCommand,
#[error("bad argument")]
CliBadArgument,
#[error("{0}")]
CliGeneralError(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("binary parsing error: {0}")]
Goblin(#[from] goblin::error::Error),
#[error("invalid Mach-O binary: {0}")]
InvalidBinary(String),
#[error("binary does not have code signature data")]
BinaryNoCodeSignature,
#[error("X.509 certificate handler error: {0}")]
X509(#[from] X509CertificateError),
#[error("CMS error: {0}")]
Cms(#[from] CmsError),
#[error("problems reported during verification")]
VerificationProblems,
#[error("certificate decode error: {0}")]
CertificateDecode(bcder::decode::Error),
#[error("PEM error: {0}")]
CertificatePem(pem::PemError),
#[error("X.509 certificate parsing error: {0}")]
X509Parse(String),
#[error("unsupported key algorithm in certificate: {0:?}")]
CertificateUnsupportedKeyAlgorithm(KeyAlgorithm),
#[error("unspecified cryptography error in certificate")]
CertificateRing(ring::error::Unspecified),
#[error("bad string value in certificate: {0:?}")]
CertificateCharset(bcder::string::CharSetError),
#[error("unable to locate __TEXT segment")]
MissingText,
#[error("unable to locate __LINKEDIT segment")]
MissingLinkedit,
#[error("bad header magic in {0}")]
BadMagic(&'static str),
#[error("data structure parse error: {0}")]
Scroll(#[from] scroll::Error),
#[error("malformed identifier string in code directory")]
CodeDirectoryMalformedIdentifier,
#[error("malformed team name string in code directory")]
CodeDirectoryMalformedTeam,
#[error("plist error in code directory: {0}")]
CodeDirectoryPlist(plist::Error),
#[error("SuperBlob data is malformed")]
SuperblobMalformed,
#[error("functionality not implemented: {0}")]
Unimplemented(&'static str),
#[error("unknown code signature flag: {0}")]
CodeSignatureUnknownFlag(String),
#[error("entitlements data not valid UTF-8: {0}")]
EntitlementsBadUtf8(std::str::Utf8Error),
#[error("unknown executable segment flag: {0}")]
ExecutableSegmentUnknownFlag(String),
#[error("unknown code requirement opcode: {0}")]
RequirementUnknownOpcode(u32),
#[error("unknown code requirement match expression: {0}")]
RequirementUnknownMatchExpression(u32),
#[error("code requirement data malformed: {0}")]
RequirementMalformed(&'static str),
#[error("plist error in code resources: {0}")]
ResourcesPlist(plist::Error),
#[error("base64 error in code resources: {0}")]
ResourcesBase64(base64::DecodeError),
#[error("plist parse error in code resources: {0}")]
ResourcesPlistParse(String),
#[error("bad regular expression in code resources: {0}; {1}")]
ResourcesBadRegex(String, regex::Error),
#[error("__LINKEDIT isn't final Mach-O segment")]
LinkeditNotLast,
#[error("__LINKEDIT segment contains data after signature")]
DataAfterSignature,
#[error("insufficient room to write code signature load command")]
LoadCommandNoRoom,
#[error("no identifier string provided")]
NoIdentifier,
#[error("no signing certificate")]
NoSigningCertificate,
#[error("signature data too large (please report this issue)")]
SignatureDataTooLarge,
#[error("HTTP error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("unknown digest algorithm")]
DigestUnknownAlgorithm,
#[error("unsupported digest algorithm")]
DigestUnsupportedAlgorithm,
#[error("unspecified digest error")]
DigestUnspecified,
#[error("error interfacing with directory-based bundle: {0}")]
DirectoryBundle(anyhow::Error),
#[error("nested bundle does not exist: {0}")]
BundleUnknown(String),
#[error("bundle Info.plist does not define CFBundleIdentifier: {0}")]
BundleNoIdentifier(PathBuf),
#[error("bundle Info.plist does not define CFBundleExecutable: {0}")]
BundleNoMainExecutable(PathBuf),
#[error("unable to parse settings scope: {0}")]
ParseSettingsScope(String),
#[error("incorrect password given when decrypting PFX data")]
PfxBadPassword,
#[error("error parsing PFX data: {0}")]
PfxParseError(String),
#[cfg(target_os = "macos")]
#[error("SecurityFramework error: {0}")]
SecurityFramework(#[from] security_framework::base::Error),
#[error("error interfacing with macOS keychain: {0}")]
KeychainError(String),
#[error("failed to find certificate satisfying requirements: {0}")]
CertificateNotFound(String),
#[error("the given OID does not match a recognized Apple certificate authority extension")]
OidIsntCertificateAuthority,
#[error("the given OID does not match a recognized Apple extended key usage extension")]
OidIsntExtendedKeyUsage,
#[error("the given OID does not match a recognized Apple code signing extension")]
OidIsntCodeSigningExtension,
#[error("error building certificate: {0}")]
CertificateBuildError(String),
#[error("unknown certificate profile: {0}")]
UnknownCertificateProfile(String),
#[error("unknown code execution policy: {0}")]
UnknownPolicy(String),
#[error("unable to generate code requirement policy: {0}")]
PolicyFormulationError(String),
#[error("error producing universal Mach-O binary: {0}")]
UniversalMachO(#[from] UniversalMachOError),
}