@@ -329,8 +329,7 @@ public void prepareApplicationFiles(Map<String, ? super Object> params)
329
329
}
330
330
331
331
copyRuntimeFiles (params );
332
-
333
- doSigning (params );
332
+ sign (params );
334
333
}
335
334
336
335
private void copyRuntimeFiles (Map <String , ? super Object > params )
@@ -356,12 +355,7 @@ private void copyRuntimeFiles(Map<String, ? super Object> params)
356
355
}
357
356
}
358
357
359
- private void doSigning (Map <String , ? super Object > params )
360
- throws IOException {
361
-
362
- // signing or not, unsign first ...
363
- unsignAppBundle (params , root );
364
-
358
+ private void sign (Map <String , ? super Object > params ) throws IOException {
365
359
if (Optional .ofNullable (
366
360
SIGN_BUNDLE .fetchFrom (params )).orElse (Boolean .TRUE )) {
367
361
try {
@@ -653,52 +647,7 @@ public static void restoreKeychainList(Map<String, ? super Object> params)
653
647
IOUtils .exec (pb );
654
648
}
655
649
656
- private static void unsignAppBundle (Map <String , ? super Object > params ,
657
- Path appLocation ) throws IOException {
658
-
659
- // unsign all dylibs and executables
660
- try (Stream <Path > stream = Files .walk (appLocation )) {
661
- stream .peek (path -> { // fix permissions
662
- try {
663
- Set <PosixFilePermission > pfp =
664
- Files .getPosixFilePermissions (path );
665
- if (!pfp .contains (PosixFilePermission .OWNER_WRITE )) {
666
- pfp = EnumSet .copyOf (pfp );
667
- pfp .add (PosixFilePermission .OWNER_WRITE );
668
- Files .setPosixFilePermissions (path , pfp );
669
- }
670
- } catch (IOException e ) {
671
- Log .verbose (e );
672
- }
673
- }).filter (p -> Files .isRegularFile (p ) &&
674
- (Files .isExecutable (p ) || p .toString ().endsWith (".dylib" ))
675
- && !(p .toString ().contains ("dylib.dSYM/Contents" ))
676
- ).forEach (p -> {
677
- // If p is a symlink then skip.
678
- if (Files .isSymbolicLink (p )) {
679
- Log .verbose (MessageFormat .format (I18N .getString (
680
- "message.ignoring.symlink" ), p .toString ()));
681
- } else {
682
- List <String > args = new ArrayList <>();
683
- args .addAll (Arrays .asList ("/usr/bin/codesign" ,
684
- "--remove-signature" , p .toString ()));
685
- try {
686
- Set <PosixFilePermission > oldPermissions =
687
- Files .getPosixFilePermissions (p );
688
- p .toFile ().setWritable (true , true );
689
- ProcessBuilder pb = new ProcessBuilder (args );
690
- IOUtils .exec (pb );
691
- Files .setPosixFilePermissions (p ,oldPermissions );
692
- } catch (IOException ioe ) {
693
- Log .verbose (ioe );
694
- return ;
695
- }
696
- }
697
- });
698
- }
699
- }
700
-
701
- private static void signAppBundle (
650
+ static void signAppBundle (
702
651
Map <String , ? super Object > params , Path appLocation ,
703
652
String signingIdentity , String identifierPrefix , Path entitlements )
704
653
throws IOException {
@@ -733,7 +682,29 @@ private static void signAppBundle(
733
682
Log .verbose (MessageFormat .format (I18N .getString (
734
683
"message.ignoring.symlink" ), p .toString ()));
735
684
} else {
736
- List <String > args = new ArrayList <>();
685
+ List <String > args ;
686
+ // runtime and Framework files will be signed below
687
+ // but they need to be unsigned first here
688
+ if ((p .toString ().contains ("/Contents/runtime" )) ||
689
+ (p .toString ().contains ("/Contents/Frameworks" ))) {
690
+
691
+ args = new ArrayList <>();
692
+ args .addAll (Arrays .asList ("/usr/bin/codesign" ,
693
+ "--remove-signature" , p .toString ()));
694
+ try {
695
+ Set <PosixFilePermission > oldPermissions =
696
+ Files .getPosixFilePermissions (p );
697
+ p .toFile ().setWritable (true , true );
698
+ ProcessBuilder pb = new ProcessBuilder (args );
699
+ IOUtils .exec (pb );
700
+ Files .setPosixFilePermissions (p ,oldPermissions );
701
+ } catch (IOException ioe ) {
702
+ Log .verbose (ioe );
703
+ toThrow .set (ioe );
704
+ return ;
705
+ }
706
+ }
707
+ args = new ArrayList <>();
737
708
args .addAll (Arrays .asList ("/usr/bin/codesign" ,
738
709
"--timestamp" ,
739
710
"--options" , "runtime" ,
0 commit comments