Struct apple_codesign::notarization::Notarizer
source · pub struct Notarizer { /* private fields */ }Expand description
An entity for performing notarizations.
Notarization works by uploading content to Apple, waiting for Apple to inspect and react to that upload, then downloading a notarization “ticket” from Apple and incorporating it into the entity being signed.
Implementations§
source§impl Notarizer
impl Notarizer
sourcepub fn from_api_key_id(
issuer_id: impl ToString,
key_id: impl ToString
) -> Result<Self, AppleCodesignError>
pub fn from_api_key_id(
issuer_id: impl ToString,
key_id: impl ToString
) -> Result<Self, AppleCodesignError>
Construct an instance from an API issuer ID and API key.
Examples found in repository?
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
fn notarizer_from_args(args: &ArgMatches) -> Result<Notarizer, AppleCodesignError> {
let api_key_path = args.get_one::<PathBuf>("api_key_path");
let api_issuer = args.get_one::<String>("api_issuer");
let api_key = args.get_one::<String>("api_key");
if let Some(api_key_path) = api_key_path {
Notarizer::from_api_key(api_key_path)
} else if let (Some(issuer), Some(key)) = (api_issuer, api_key) {
Notarizer::from_api_key_id(issuer, key)
} else {
Err(AppleCodesignError::NotarizeNoAuthCredentials)
}
}sourcepub fn from_api_key(path: &Path) -> Result<Self, AppleCodesignError>
pub fn from_api_key(path: &Path) -> Result<Self, AppleCodesignError>
Construct an instance from a file containing a JSON encoded API key.
Examples found in repository?
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
fn notarizer_from_args(args: &ArgMatches) -> Result<Notarizer, AppleCodesignError> {
let api_key_path = args.get_one::<PathBuf>("api_key_path");
let api_issuer = args.get_one::<String>("api_issuer");
let api_key = args.get_one::<String>("api_key");
if let Some(api_key_path) = api_key_path {
Notarizer::from_api_key(api_key_path)
} else if let (Some(issuer), Some(key)) = (api_issuer, api_key) {
Notarizer::from_api_key_id(issuer, key)
} else {
Err(AppleCodesignError::NotarizeNoAuthCredentials)
}
}sourcepub fn notarize_path(
&self,
path: &Path,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
pub fn notarize_path(
&self,
path: &Path,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
Attempt to notarize an asset defined by a filesystem path.
The type of path is sniffed out and the appropriate notarization routine is called.
Examples found in repository?
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970
fn command_notary_submit(args: &ArgMatches) -> Result<(), AppleCodesignError> {
let path = PathBuf::from(
args.get_one::<String>("path")
.expect("clap should have validated arguments"),
);
let staple = args.get_flag("staple");
let wait = args.get_flag("wait") || staple;
let wait_limit = if wait {
Some(notarizer_wait_duration(args)?)
} else {
None
};
let notarizer = notarizer_from_args(args)?;
let upload = notarizer.notarize_path(&path, wait_limit)?;
if staple {
match upload {
crate::notarization::NotarizationUpload::UploadId(_) => {
panic!(
"NotarizationUpload::UploadId should not be returned if we waited successfully"
);
}
crate::notarization::NotarizationUpload::NotaryResponse(_) => {
let stapler = crate::stapling::Stapler::new()?;
stapler.staple_path(&path)?;
}
}
}
Ok(())
}sourcepub fn notarize_bundle(
&self,
bundle: &DirectoryBundle,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
pub fn notarize_bundle(
&self,
bundle: &DirectoryBundle,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
Attempt to notarize an on-disk bundle.
If wait_limit is provided, we will wait for the upload to finish processing.
Otherwise, this returns as soon as the upload is performed.
Examples found in repository?
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
pub fn notarize_path(
&self,
path: &Path,
wait_limit: Option<Duration>,
) -> Result<NotarizationUpload, AppleCodesignError> {
match PathType::from_path(path)? {
PathType::Bundle => {
let bundle = DirectoryBundle::new_from_path(path)
.map_err(AppleCodesignError::DirectoryBundle)?;
self.notarize_bundle(&bundle, wait_limit)
}
PathType::Xar => self.notarize_flat_package(path, wait_limit),
PathType::Zip => self.notarize_flat_package(path, wait_limit),
PathType::Dmg => self.notarize_dmg(path, wait_limit),
PathType::MachO | PathType::Other => Err(AppleCodesignError::NotarizeUnsupportedPath(
path.to_path_buf(),
)),
}
}sourcepub fn notarize_dmg(
&self,
dmg_path: &Path,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
pub fn notarize_dmg(
&self,
dmg_path: &Path,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
Attempt to notarize a DMG file.
Examples found in repository?
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
pub fn notarize_path(
&self,
path: &Path,
wait_limit: Option<Duration>,
) -> Result<NotarizationUpload, AppleCodesignError> {
match PathType::from_path(path)? {
PathType::Bundle => {
let bundle = DirectoryBundle::new_from_path(path)
.map_err(AppleCodesignError::DirectoryBundle)?;
self.notarize_bundle(&bundle, wait_limit)
}
PathType::Xar => self.notarize_flat_package(path, wait_limit),
PathType::Zip => self.notarize_flat_package(path, wait_limit),
PathType::Dmg => self.notarize_dmg(path, wait_limit),
PathType::MachO | PathType::Other => Err(AppleCodesignError::NotarizeUnsupportedPath(
path.to_path_buf(),
)),
}
}sourcepub fn notarize_flat_package(
&self,
pkg_path: &Path,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
pub fn notarize_flat_package(
&self,
pkg_path: &Path,
wait_limit: Option<Duration>
) -> Result<NotarizationUpload, AppleCodesignError>
Attempt to notarize a flat package (.pkg) installer or a .zip file.
Examples found in repository?
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
pub fn notarize_path(
&self,
path: &Path,
wait_limit: Option<Duration>,
) -> Result<NotarizationUpload, AppleCodesignError> {
match PathType::from_path(path)? {
PathType::Bundle => {
let bundle = DirectoryBundle::new_from_path(path)
.map_err(AppleCodesignError::DirectoryBundle)?;
self.notarize_bundle(&bundle, wait_limit)
}
PathType::Xar => self.notarize_flat_package(path, wait_limit),
PathType::Zip => self.notarize_flat_package(path, wait_limit),
PathType::Dmg => self.notarize_dmg(path, wait_limit),
PathType::MachO | PathType::Other => Err(AppleCodesignError::NotarizeUnsupportedPath(
path.to_path_buf(),
)),
}
}source§impl Notarizer
impl Notarizer
sourcepub fn get_submission(
&self,
submission_id: &str
) -> Result<SubmissionResponse, AppleCodesignError>
pub fn get_submission(
&self,
submission_id: &str
) -> Result<SubmissionResponse, AppleCodesignError>
Examples found in repository?
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
pub fn wait_on_notarization(
&self,
submission_id: &str,
wait_limit: Duration,
) -> Result<notary_api::SubmissionResponse, AppleCodesignError> {
warn!(
"waiting up to {}s for package upload {} to finish processing",
wait_limit.as_secs(),
submission_id
);
let start_time = std::time::Instant::now();
loop {
let status = self.get_submission(submission_id)?;
let elapsed = start_time.elapsed();
info!(
"poll state after {}s: {:?}",
elapsed.as_secs(),
status.data.attributes.status
);
if status.data.attributes.status != notary_api::SubmissionResponseStatus::InProgress {
warn!("Notary API Server has finished processing the uploaded asset");
return Ok(status);
}
if elapsed >= wait_limit {
warn!("reached wait limit after {}s", elapsed.as_secs());
return Err(AppleCodesignError::NotarizeWaitLimitReached);
}
std::thread::sleep(self.wait_poll_interval);
}
}sourcepub fn wait_on_notarization(
&self,
submission_id: &str,
wait_limit: Duration
) -> Result<SubmissionResponse, AppleCodesignError>
pub fn wait_on_notarization(
&self,
submission_id: &str,
wait_limit: Duration
) -> Result<SubmissionResponse, AppleCodesignError>
Examples found in repository?
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
pub fn wait_on_notarization_and_fetch_log(
&self,
submission_id: &str,
wait_limit: Duration,
) -> Result<notary_api::SubmissionResponse, AppleCodesignError> {
let status = self.wait_on_notarization(submission_id, wait_limit)?;
let log = self.fetch_notarization_log(submission_id)?;
for line in serde_json::to_string_pretty(&log)?.lines() {
warn!("notary log> {}", line);
}
Ok(status)
}sourcepub fn fetch_notarization_log(
&self,
submission_id: &str
) -> Result<Value, AppleCodesignError>
pub fn fetch_notarization_log(
&self,
submission_id: &str
) -> Result<Value, AppleCodesignError>
Obtain the processing log from an upload.
Examples found in repository?
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
fn command_notary_log(args: &ArgMatches) -> Result<(), AppleCodesignError> {
let notarizer = notarizer_from_args(args)?;
let submission_id = args
.get_one::<String>("submission_id")
.expect("submission_id is required");
let log = notarizer.fetch_notarization_log(submission_id)?;
for line in serde_json::to_string_pretty(&log)?.lines() {
println!("{line}");
}
Ok(())
}More examples
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
pub fn wait_on_notarization_and_fetch_log(
&self,
submission_id: &str,
wait_limit: Duration,
) -> Result<notary_api::SubmissionResponse, AppleCodesignError> {
let status = self.wait_on_notarization(submission_id, wait_limit)?;
let log = self.fetch_notarization_log(submission_id)?;
for line in serde_json::to_string_pretty(&log)?.lines() {
warn!("notary log> {}", line);
}
Ok(status)
}sourcepub fn wait_on_notarization_and_fetch_log(
&self,
submission_id: &str,
wait_limit: Duration
) -> Result<SubmissionResponse, AppleCodesignError>
pub fn wait_on_notarization_and_fetch_log(
&self,
submission_id: &str,
wait_limit: Duration
) -> Result<SubmissionResponse, AppleCodesignError>
Waits on an app store package upload and fetches and logs the upload log.
This is just a convenience around [Self::wait_on_app_store_package_upload()] and [Self::fetch_upload_log()].
Examples found in repository?
More examples
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
fn upload_s3_and_maybe_wait(
&self,
submission: notary_api::NewSubmissionResponse,
upload_data: UploadKind,
wait_limit: Option<Duration>,
) -> Result<NotarizationUpload, AppleCodesignError> {
self.upload_s3_package(&submission, upload_data)?;
let status = if let Some(wait_limit) = wait_limit {
self.wait_on_notarization_and_fetch_log(&submission.data.id, wait_limit)?
} else {
return Ok(NotarizationUpload::UploadId(submission.data.id));
};
// Make sure notarization was successful.
let status = status.into_result()?;
Ok(NotarizationUpload::NotaryResponse(status))
}Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Notarizer
impl Send for Notarizer
impl Sync for Notarizer
impl Unpin for Notarizer
impl UnwindSafe for Notarizer
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
self, then passes self.as_mut() into the pipe
function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.