+
+//
+// Explicitly default to SHA256 (only) digests if the minimum deployment
+// target is young enough.
+//
+void MachORep::prepareForSigning(SigningContext &context)
+{
+ if (context.digestAlgorithms().empty()) {
+ MachO *macho = mainExecutableImage()->architecture();
+ if (const version_min_command *version = macho->findMinVersion()) {
+ uint32_t limit = 0;
+ switch (macho->flip(version->cmd)) {
+ case LC_VERSION_MIN_MACOSX:
+ limit = (10 << 16 | 11 << 8 | 4 << 0);
+ break;
+#if 0 /* need updated libMIS before we can do this switch */
+ case LC_VERSION_MIN_IPHONEOS:
+ limit = (9 << 16 | 3 << 8);
+ break;
+ case LC_VERSION_MIN_WATCHOS:
+ limit = (2 << 16 | 2 << 8);
+ break;
+ case LC_VERSION_MIN_TVOS:
+ limit = (9 << 16 | 2 << 8);
+ break;
+ default:
+ break;
+#else
+ case LC_VERSION_MIN_IPHONEOS:
+ case LC_VERSION_MIN_WATCHOS:
+ case LC_VERSION_MIN_TVOS:
+ return;
+ default:
+ break;
+#endif
+ }
+ if (macho->flip(version->version) >= limit) {
+ // young enough not to need SHA-1 legacy support
+ context.setDigestAlgorithm(kSecCodeSignatureHashSHA256);
+ }
+ }
+ }
+}
+