pub struct EntitlementsBlob<'a> { /* private fields */ }Expand description
Represents an Entitlements blob.
An entitlements blob contains an XML plist with a dict. Keys are strings of the entitlements being requested and values appear to be simple bools.
Implementations§
source§impl<'a> EntitlementsBlob<'a>
impl<'a> EntitlementsBlob<'a>
sourcepub fn from_string(s: &impl ToString + ?Sized) -> Self
pub fn from_string(s: &impl ToString + ?Sized) -> Self
Construct an instance using any string as the payload.
Examples found in repository?
src/macho_signing.rs (line 645)
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
pub fn create_special_blobs(
&self,
settings: &SigningSettings,
is_executable: bool,
) -> Result<Vec<(CodeSigningSlot, BlobData<'static>)>, AppleCodesignError> {
let mut res = Vec::new();
let mut requirements = CodeRequirements::default();
match settings.designated_requirement(SettingsScope::Main) {
DesignatedRequirementMode::Auto => {
// If we are using an Apple-issued cert, this should automatically
// derive appropriate designated requirements.
if let Some((_, cert)) = settings.signing_key() {
info!("attempting to derive code requirements from signing certificate");
let identifier = Some(
settings
.binary_identifier(SettingsScope::Main)
.ok_or(AppleCodesignError::NoIdentifier)?
.to_string(),
);
if let Some(expr) = derive_designated_requirements(cert, identifier)? {
requirements.push(expr);
}
}
}
DesignatedRequirementMode::Explicit(exprs) => {
info!("using provided code requirements");
for expr in exprs {
requirements.push(CodeRequirementExpression::from_bytes(expr)?.0);
}
}
}
// Always emit a RequirementSet blob, even if empty. Without it, validation fails
// with `the sealed resource directory is invalid`.
let mut blob = RequirementSetBlob::default();
if !requirements.is_empty() {
info!("code requirements: {}", requirements);
requirements.add_to_requirement_set(&mut blob, RequirementType::Designated)?;
}
res.push((CodeSigningSlot::RequirementSet, blob.into()));
if let Some(entitlements) = settings.entitlements_xml(SettingsScope::Main)? {
info!("adding entitlements XML");
let blob = EntitlementsBlob::from_string(&entitlements);
res.push((CodeSigningSlot::Entitlements, blob.into()));
}
// The DER encoded entitlements weren't always present in the signature. The feature
// appears to have been introduced in macOS 10.14 and is the default behavior as of
// macOS 12 "when signing for all platforms." `codesign` appears to add the DER
// representation whenever entitlements are present, but only if the current binary is
// an executable (.filetype == MH_EXECUTE).
if is_executable {
if let Some(value) = settings.entitlements_plist(SettingsScope::Main) {
info!("adding entitlements DER");
let blob = EntitlementsDerBlob::from_plist(value)?;
res.push((CodeSigningSlot::EntitlementsDer, blob.into()));
}
}
Ok(res)
}sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Obtain the plist representation as a string.
Examples found in repository?
src/reader.rs (line 493)
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
fn try_from(sig: EmbeddedSignature<'a>) -> Result<Self, Self::Error> {
let mut entitlements_plist = None;
let mut code_requirements = vec![];
let mut cms = None;
let code_directory = if let Some(cd) = sig.code_directory()? {
Some(CodeDirectory::try_from(*cd)?)
} else {
None
};
let alternative_code_directories = sig
.alternate_code_directories()?
.into_iter()
.map(|(slot, cd)| Ok((format!("{slot:?}"), CodeDirectory::try_from(*cd)?)))
.collect::<Result<Vec<_>, AppleCodesignError>>()?;
if let Some(blob) = sig.entitlements()? {
entitlements_plist = Some(blob.as_str().to_string());
}
if let Some(req) = sig.code_requirements()? {
let mut temp = vec![];
for (req, blob) in req.requirements {
let reqs = blob.parse_expressions()?;
temp.push((req, format!("{reqs}")));
}
temp.sort_by(|(a, _), (b, _)| a.cmp(b));
code_requirements = temp
.into_iter()
.map(|(req, value)| format!("{req}: {value}"))
.collect::<Vec<_>>();
}
if let Some(signed_data) = sig.signed_data()? {
cms = Some(signed_data.try_into()?);
}
Ok(Self {
superblob_length: sig.length,
blob_count: sig.count,
blobs: sig
.blobs
.iter()
.map(BlobDescription::from)
.collect::<Vec<_>>(),
code_directory,
alternative_code_directories,
entitlements_plist,
code_requirements,
cms,
})
}More examples
src/signing_settings.rs (line 850)
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
pub fn import_settings_from_macho(&mut self, data: &[u8]) -> Result<(), AppleCodesignError> {
info!("inferring default signing settings from Mach-O binary");
for macho in MachFile::parse(data)?.into_iter() {
let index = macho.index.unwrap_or(0);
let scope_main = SettingsScope::Main;
let scope_index = SettingsScope::MultiArchIndex(index);
let scope_arch = SettingsScope::MultiArchCpuType(macho.macho.header.cputype());
// Older operating system versions don't have support for SHA-256 in
// signatures. If the minimum version targeting in the binary doesn't
// support SHA-256, we automatically change the digest targeting settings
// so the binary will be signed correctly.
if let Some(targeting) = macho.find_targeting()? {
let sha256_version = targeting.platform.sha256_digest_support()?;
if !sha256_version.matches(&targeting.minimum_os_version) {
info!(
"activating SHA-1 digests because minimum OS target {} is not {}",
targeting.minimum_os_version, sha256_version
);
// This logic is a bit wonky. We want SHA-1 to be present on all binaries
// within a fat binary. So if we need SHA-1 mode, we set the setting on the
// main scope and then clear any overrides on fat binary scopes so our
// settings are canonical.
self.set_digest_type(DigestType::Sha1);
self.add_extra_digest(scope_main.clone(), DigestType::Sha256);
self.extra_digests.remove(&scope_arch);
self.extra_digests.remove(&scope_index);
}
}
// The Mach-O can have embedded Info.plist data. Use it if available and not
// already defined in settings.
if let Some(info_plist) = macho.embedded_info_plist()? {
if self.info_plist_data(&scope_main).is_some()
|| self.info_plist_data(&scope_index).is_some()
|| self.info_plist_data(&scope_arch).is_some()
{
info!("using Info.plist data from settings");
} else {
info!("preserving Info.plist data already present in Mach-O");
self.set_info_plist_data(scope_index.clone(), info_plist);
}
}
if let Some(sig) = macho.code_signature()? {
if let Some(cd) = sig.code_directory()? {
if self.binary_identifier(&scope_main).is_some()
|| self.binary_identifier(&scope_index).is_some()
|| self.binary_identifier(&scope_arch).is_some()
{
info!("using binary identifier from settings");
} else {
info!("preserving existing binary identifier in Mach-O");
self.set_binary_identifier(scope_index.clone(), cd.ident);
}
if self.team_id.contains_key(&scope_main)
|| self.team_id.contains_key(&scope_index)
|| self.team_id.contains_key(&scope_arch)
{
info!("using team ID from settings");
} else if let Some(team_id) = cd.team_name {
info!("preserving team ID in existing Mach-O signature");
self.team_id
.insert(scope_index.clone(), team_id.to_string());
}
if self.code_signature_flags(&scope_main).is_some()
|| self.code_signature_flags(&scope_index).is_some()
|| self.code_signature_flags(&scope_arch).is_some()
{
info!("using code signature flags from settings");
} else if !cd.flags.is_empty() {
info!("preserving code signature flags in existing Mach-O signature");
self.set_code_signature_flags(scope_index.clone(), cd.flags);
}
if self.runtime_version(&scope_main).is_some()
|| self.runtime_version(&scope_index).is_some()
|| self.runtime_version(&scope_arch).is_some()
{
info!("using runtime version from settings");
} else if let Some(version) = cd.runtime {
info!("preserving runtime version in existing Mach-O signature");
self.set_runtime_version(
scope_index.clone(),
parse_version_nibbles(version),
);
}
}
if let Some(entitlements) = sig.entitlements()? {
if self.entitlements_plist(&scope_main).is_some()
|| self.entitlements_plist(&scope_index).is_some()
|| self.entitlements_plist(&scope_arch).is_some()
{
info!("using entitlements from settings");
} else {
info!("preserving existing entitlements in Mach-O");
self.set_entitlements_xml(
SettingsScope::MultiArchIndex(index),
entitlements.as_str(),
)?;
}
}
}
}
Ok(())
}Trait Implementations§
source§impl<'a> Blob<'a> for EntitlementsBlob<'a>
impl<'a> Blob<'a> for EntitlementsBlob<'a>
source§fn from_blob_bytes(data: &'a [u8]) -> Result<Self, AppleCodesignError>
fn from_blob_bytes(data: &'a [u8]) -> Result<Self, AppleCodesignError>
Attempt to construct an instance by parsing a bytes slice. Read more
source§fn serialize_payload(&self) -> Result<Vec<u8>, AppleCodesignError>
fn serialize_payload(&self) -> Result<Vec<u8>, AppleCodesignError>
Serialize the payload of this blob to bytes. Read more
source§fn to_blob_bytes(&self) -> Result<Vec<u8>, AppleCodesignError>
fn to_blob_bytes(&self) -> Result<Vec<u8>, AppleCodesignError>
Serialize this blob to bytes. Read more
source§fn digest_with(
&self,
hash_type: DigestType
) -> Result<Vec<u8>, AppleCodesignError>
fn digest_with(
&self,
hash_type: DigestType
) -> Result<Vec<u8>, AppleCodesignError>
Obtain the digest of the blob using the specified hasher. Read more
source§impl<'a> Debug for EntitlementsBlob<'a>
impl<'a> Debug for EntitlementsBlob<'a>
source§impl<'a> Display for EntitlementsBlob<'a>
impl<'a> Display for EntitlementsBlob<'a>
source§impl<'a> From<EntitlementsBlob<'a>> for BlobData<'a>
impl<'a> From<EntitlementsBlob<'a>> for BlobData<'a>
source§fn from(b: EntitlementsBlob<'a>) -> Self
fn from(b: EntitlementsBlob<'a>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a> RefUnwindSafe for EntitlementsBlob<'a>
impl<'a> Send for EntitlementsBlob<'a>
impl<'a> Sync for EntitlementsBlob<'a>
impl<'a> Unpin for EntitlementsBlob<'a>
impl<'a> UnwindSafe for EntitlementsBlob<'a>
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Causes
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,
Formats each item in a sequence. Read more
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,
Pipes by value. This is generally the method you want to use. Read more
§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,
Borrows
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,
Mutably borrows
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,
Borrows
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,
Mutably borrows
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,
Immutable access to the
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,
Mutable access to the
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,
Immutable access to the
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,
Mutable access to the
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,
Immutable access to the
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,
Mutable access to the
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
Calls
.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
Calls
.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,
Calls
.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,
Calls
.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,
Calls
.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,
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.