@@ -230,20 +230,38 @@ fn tool(program: &str, args: &[&std::ffi::OsStr]) -> Result<String, &'static str
230230 String :: from_utf8 ( bytes) . map_err ( |_| "PACKAGE_VERIFY_FAILED" )
231231}
232232
233- /// `None` still requires a present TeamIdentifier plus Developer ID Application.
234- /// A pinned team, when supplied, must match that identifier exactly.
233+ /// Apple Team ID baked in at compile time by the trusted packaging identity.
234+ /// A candidate package cannot supply this value.
235+ pub fn trusted_developer_id_team ( ) -> Option < & ' static str > {
236+ option_env ! ( "HIROUTE_DEVELOPER_ID_TEAM" ) . filter ( |team| !team. is_empty ( ) )
237+ }
238+
239+ /// Self-signed packages stay adhoc. Developer ID requires a configured matching team.
235240#[ cfg( any( target_os = "macos" , test) ) ]
236- fn developer_id_signature_ok ( signature : & str , expected_team : Option < & str > ) -> bool {
237- let Some ( team) = signature. lines ( ) . find_map ( |line| {
238- line. strip_prefix ( "TeamIdentifier=" )
239- . filter ( |team| !team. is_empty ( ) && * team != "not set" )
240- } ) else {
241- return false ;
242- } ;
243- if expected_team. is_some_and ( |expected| expected != team) {
244- return false ;
241+ fn publisher_identity_status (
242+ distribution : & str ,
243+ signature : & str ,
244+ expected_team : Option < & str > ,
245+ ) -> Result < ( ) , & ' static str > {
246+ if distribution == "controlled-trial" {
247+ if signature. lines ( ) . any ( |line| line == "Signature=adhoc" ) {
248+ Ok ( ( ) )
249+ } else {
250+ Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" )
251+ }
252+ } else {
253+ let team = expected_team
254+ . filter ( |team| !team. is_empty ( ) )
255+ . ok_or ( "UPGRADE_SIGNATURE_IDENTITY_UNCONFIGURED" ) ?;
256+ let expected = format ! ( "TeamIdentifier={team}" ) ;
257+ if signature. lines ( ) . any ( |line| line == expected)
258+ && signature. contains ( "Authority=Developer ID Application:" )
259+ {
260+ Ok ( ( ) )
261+ } else {
262+ Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" )
263+ }
245264 }
246- signature. contains ( "Authority=Developer ID Application:" )
247265}
248266
249267#[ cfg( target_os = "macos" ) ]
@@ -317,14 +335,8 @@ pub fn verify_desktop_app(
317335 identity. app_path . as_os_str ( ) ,
318336 ] ,
319337 ) ?;
320- if identity. distribution == "controlled-trial" {
321- if !signature. lines ( ) . any ( |l| l == "Signature=adhoc" ) {
322- return Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" ) ;
323- }
324- } else {
325- if !developer_id_signature_ok ( & signature, expected_team) {
326- return Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" ) ;
327- }
338+ publisher_identity_status ( & identity. distribution , & signature, expected_team) ?;
339+ if identity. distribution != "controlled-trial" {
328340 tool (
329341 "/usr/sbin/spctl" ,
330342 & [
@@ -426,26 +438,64 @@ mod tests {
426438 }
427439
428440 #[ test]
429- fn developer_id_signature_requires_present_team_without_pinning ( ) {
441+ fn trusted_developer_id_team_matches_compile_time_env ( ) {
442+ assert_eq ! (
443+ trusted_developer_id_team( ) ,
444+ option_env!( "HIROUTE_DEVELOPER_ID_TEAM" ) . filter( |team| !team. is_empty( ) )
445+ ) ;
446+ }
447+
448+ #[ test]
449+ fn developer_id_requires_configured_matching_team_and_keeps_self_signed ( ) {
430450 let signature = "\
431451 Authority=Developer ID Application: Example Org (ABCD123456)
432452Authority=Developer ID Certification Authority
433453TeamIdentifier=ABCD123456
434454" ;
435- assert ! ( developer_id_signature_ok( signature, None ) ) ;
436- assert ! ( developer_id_signature_ok( signature, Some ( "ABCD123456" ) ) ) ;
437- assert ! ( !developer_id_signature_ok( signature, Some ( "OTHERTEAM1" ) ) ) ;
438- assert ! ( !developer_id_signature_ok(
439- "Signature=adhoc\n TeamIdentifier=not set\n " ,
440- None
441- ) ) ;
442- assert ! ( !developer_id_signature_ok(
443- "Authority=Developer ID Application: Example Org (ABCD123456)\n " ,
444- None
445- ) ) ;
446- assert ! ( !developer_id_signature_ok(
447- "TeamIdentifier=ABCD123456\n " ,
448- None
449- ) ) ;
455+ assert_eq ! (
456+ publisher_identity_status( "developer-id" , signature, None ) ,
457+ Err ( "UPGRADE_SIGNATURE_IDENTITY_UNCONFIGURED" )
458+ ) ;
459+ assert_eq ! (
460+ publisher_identity_status( "developer-id" , signature, Some ( "" ) ) ,
461+ Err ( "UPGRADE_SIGNATURE_IDENTITY_UNCONFIGURED" )
462+ ) ;
463+ assert_eq ! (
464+ publisher_identity_status( "developer-id" , signature, Some ( "ABCD123456" ) ) ,
465+ Ok ( ( ) )
466+ ) ;
467+ assert_eq ! (
468+ publisher_identity_status( "developer-id" , signature, Some ( "OTHERTEAM1" ) ) ,
469+ Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" )
470+ ) ;
471+ assert_eq ! (
472+ publisher_identity_status(
473+ "developer-id" ,
474+ "Authority=Developer ID Application: Example Org (ABCD123456)\n " ,
475+ Some ( "ABCD123456" )
476+ ) ,
477+ Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" )
478+ ) ;
479+ assert_eq ! (
480+ publisher_identity_status(
481+ "developer-id" ,
482+ "TeamIdentifier=ABCD123456\n " ,
483+ Some ( "ABCD123456" )
484+ ) ,
485+ Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" )
486+ ) ;
487+ let adhoc = "Signature=adhoc\n TeamIdentifier=not set\n " ;
488+ assert_eq ! (
489+ publisher_identity_status( "controlled-trial" , adhoc, None ) ,
490+ Ok ( ( ) )
491+ ) ;
492+ assert_eq ! (
493+ publisher_identity_status( "controlled-trial" , adhoc, Some ( "ABCD123456" ) ) ,
494+ Ok ( ( ) )
495+ ) ;
496+ assert_eq ! (
497+ publisher_identity_status( "controlled-trial" , signature, None ) ,
498+ Err ( "PACKAGE_SIGNATURE_IDENTITY_MISMATCH" )
499+ ) ;
450500 }
451501}
0 commit comments