Skip to content

Commit

Permalink
[msbuild] Sign simulator apps by default. Fixes #18469.
Browse files Browse the repository at this point in the history
Fixes #18469.
  • Loading branch information
rolfbjarne committed Nov 28, 2023
1 parent 2652f49 commit 72e9bc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,64 +582,7 @@ public override bool Execute ()
return !Log.HasLoggedErrors;
}
} else {
// Framework is either iOS, tvOS or watchOS
if (SdkIsSimulator) {
if (AppleSdkSettings.XcodeVersion.Major >= 8 && RequireProvisioningProfile) {
// Note: Starting with Xcode 8.0, we need to codesign iOS Simulator builds that enable Entitlements
// in order for them to run. The "-" key is a special value allowed by the codesign utility that
// allows us to get away with not having an actual codesign key.
DetectedCodeSigningKey = "-";

if (!IsAutoCodeSignProfile (ProvisioningProfile)) {
identity.Profile = MobileProvisionIndex.GetMobileProvision (platform, ProvisioningProfile);

if (identity.Profile is null) {
Log.LogError (MSBStrings.E0140, PlatformName, ProvisioningProfile);
return false;
}

identity.AppId = ConstructValidAppId (identity.Profile, identity.BundleId);
if (identity.AppId is null) {
Log.LogError (MSBStrings.E0141, identity.BundleId, ProvisioningProfile);
return false;
}

provisioningProfileName = identity.Profile.Name;

DetectedProvisioningProfile = identity.Profile.Uuid;
DetectedDistributionType = identity.Profile.DistributionType.ToString ();
} else {
certs = new X509Certificate2 [0];

if ((profiles = GetProvisioningProfiles (platform, type, identity, certs)) is null)
return false;

if ((pairs = GetCodeSignIdentityPairs (profiles, certs)) is null)
return false;

var match = GetBestMatch (pairs, identity);
identity.Profile = match.Profile;
identity.AppId = match.AppId;

if (identity.Profile is not null) {
DetectedDistributionType = identity.Profile.DistributionType.ToString ();
DetectedProvisioningProfile = identity.Profile.Uuid;
provisioningProfileName = identity.Profile.Name;
}

DetectedAppId = identity.AppId;
}
} else {
// Note: Do not codesign. Codesigning seems to break the iOS Simulator in older versions of Xcode.
DetectedCodeSigningKey = null;
}

ReportDetectedCodesignInfo ();

return !Log.HasLoggedErrors;
}

if (!SdkIsSimulator && !RequireCodeSigning) {
if (SdkIsSimulator || !RequireCodeSigning) {
// The "-" key is a special value allowed by the codesign utility that
// allows us to get away with not having an actual codesign key.
DetectedCodeSigningKey = "-";
Expand Down
8 changes: 3 additions & 5 deletions msbuild/Xamarin.Shared/Xamarin.Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ Copyright (C) 2020 Microsoft. All rights reserved.
</PropertyGroup>

<!-- RequireCodeSigning -->
<!-- iOS/watchOS/tvOS is simple: device builds require code signing, simulator builds do not. This is a big lie, for some simulator builds need to be signed, but the _DetectCodeSigning task handles those cases. -->
<!-- iOS/watchOS/tvOS is simple: device builds require code signing, simulator builds technically don't even though some important features won't work unless the app is signed (launch screen won't show for instance) -->
<PropertyGroup Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">
<!-- Make it possible to override the default logic by setting EnableCodeSigning -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == ''">$(EnableCodeSigning)</_RequireCodeSigning>
<!-- Device builds must be signed -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == '' And '$(ComputedPlatform)' == 'iPhone'">true</_RequireCodeSigning>
<!-- Otherwise code signing is disabled by default (simulator builds)-->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == ''">false</_RequireCodeSigning>
<!-- Device builds must be signed, and some features won't work in the simulator if the app isn't signed (launch screen for instance), so default to always sign -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == ''">true</_RequireCodeSigning>
</PropertyGroup>
<!-- macOS is a bit more complicated:
* 'EnableCodeSigning' specifies whether the app is signed or not, and this defaults to false if it's not set.
Expand Down
11 changes: 8 additions & 3 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1801,9 +1801,14 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</PropertyGroup>

<Target Name="_DetectSigningIdentity" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="$(_DetectSigningIdentityDependsOn)">
<PropertyGroup>
<_CodesignEntitlements Condition="'$(_CodesignEntitlements)' == '' And '$(_SdkIsSimulator)' != 'true'">$(CodesignEntitlement)</_CodesignEntitlements>
<_CodesignProvision Condition="'$(_CodesignProvision)' == '' And '$(_SdkIsSimulator)' != 'true'">$(CodesignProvision)</_CodesignProvision>
<_SigningKey Condition="'$(_SigningKey)' == '' And '$(_SdkIsSimulator)' != 'true'">$(_SpecifiedCodesignKey)</_SigningKey>
</PropertyGroup>
<DetectSigningIdentity
SessionId="$(BuildSessionId)"
CodesignEntitlements="$(CodesignEntitlements)"
CodesignEntitlements="$(_CodesignEntitlements)"
CodesignRequireProvisioningProfile="$(CodesignRequireProvisioningProfile)"
Condition="'$(IsMacEnabled)' == 'true'"
AppBundleName="$(_AppBundleName)"
Expand All @@ -1812,8 +1817,8 @@ Copyright (C) 2018 Microsoft. All rights reserved.
RequireCodeSigning="$(_RequireCodeSigning)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkPlatform="$(_SdkPlatform)"
ProvisioningProfile="$(CodesignProvision)"
SigningKey="$(_SpecifiedCodesignKey)"
ProvisioningProfile="$(_CodesignProvision)"
SigningKey="$(_SigningKey)"
DetectedCodeSigningKey="$(_CodeSigningKey)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
>
Expand Down

0 comments on commit 72e9bc4

Please sign in to comment.