@@ -1281,6 +1281,93 @@ public void SignZipFile()
12811281 } ) ;
12821282 }
12831283
1284+ [ Fact ]
1285+ public void SignArchivesUsingDetachedSignature ( )
1286+ {
1287+ // List of files to be considered for signing
1288+ var itemsToSign = new List < ItemToSign > ( )
1289+ {
1290+ new ItemToSign ( GetResourcePath ( "test.zip" ) ) ,
1291+ new ItemToSign ( GetResourcePath ( "test.tgz" ) ) ,
1292+ new ItemToSign ( GetResourcePath ( "NestedZip.zip" ) ) ,
1293+ new ItemToSign ( GetResourcePath ( "InnerZipFile.zip" ) )
1294+ } ;
1295+
1296+ var strongNameSignInfo = new Dictionary < string , List < SignInfo > > ( ) ;
1297+
1298+ // Overriding information
1299+ var explicitCertKeys = new Dictionary < ExplicitCertificateKey , string > ( )
1300+ {
1301+ { new ExplicitCertificateKey ( "test.zip" ) , "ArchiveCert" } ,
1302+ { new ExplicitCertificateKey ( "test.tgz" ) , "ArchiveCert" } ,
1303+ { new ExplicitCertificateKey ( "InnerZipFile.zip" ) , "ArchiveCert" }
1304+ } ;
1305+
1306+ var additionalCertificateInfo = new Dictionary < string , List < AdditionalCertificateInformation > > ( )
1307+ {
1308+ { "ArchiveCert" ,
1309+ new List < AdditionalCertificateInformation > ( ) {
1310+ new AdditionalCertificateInformation ( ) { GeneratesDetachedSignature = true }
1311+ }
1312+ }
1313+ } ;
1314+
1315+ ValidateFileSignInfos ( itemsToSign , strongNameSignInfo , explicitCertKeys , s_fileExtensionSignInfo , new [ ]
1316+ {
1317+ "File 'NativeLibrary.dll' Certificate='Microsoft400'" ,
1318+ "File 'SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
1319+ "File 'Nested.NativeLibrary.dll' Certificate='Microsoft400'" ,
1320+ "File 'Nested.SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
1321+ "File 'test.zip' Certificate='ArchiveCert'" ,
1322+ "File 'test.tgz' Certificate='ArchiveCert'" ,
1323+ "File 'InnerZipFile.zip' Certificate='ArchiveCert'" ,
1324+ "File 'Mid.SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
1325+ "File 'MidNativeLibrary.dll' Certificate='Microsoft400'" ,
1326+ "File 'NestedZip.zip'" ,
1327+ } ,
1328+ additionalCertificateInfo : additionalCertificateInfo ,
1329+ expectedCopyFiles : new [ ]
1330+ {
1331+ $ "{ Path . Combine ( _tmpDir , "ContainerSigning" , "6" , "InnerZipFile.zip" ) } -> { Path . Combine ( _tmpDir , "InnerZipFile.zip" ) } ",
1332+ $ "{ Path . Combine ( _tmpDir , "ContainerSigning" , "6" , "InnerZipFile.zip.sig" ) } -> { Path . Combine ( _tmpDir , "InnerZipFile.zip.sig" ) } "
1333+ } ) ;
1334+
1335+ ValidateGeneratedProject ( itemsToSign , strongNameSignInfo , explicitCertKeys , s_fileExtensionSignInfo , new [ ]
1336+ {
1337+ $@ "
1338+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "0" , "NativeLibrary.dll" ) ) } "">
1339+ <Authenticode>Microsoft400</Authenticode>
1340+ </FilesToSign>
1341+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "1" , "SOS.NETCore.dll" ) ) } "">
1342+ <Authenticode>Microsoft400</Authenticode>
1343+ </FilesToSign>
1344+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "2" , "this_is_a_big_folder_name_look/this_is_an_even_more_longer_folder_name/but_this_one_is_ever_longer_than_the_previous_other_two/Nested.NativeLibrary.dll" ) ) } "">
1345+ <Authenticode>Microsoft400</Authenticode>
1346+ </FilesToSign>
1347+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "3" , "this_is_a_big_folder_name_look/this_is_an_even_more_longer_folder_name/but_this_one_is_ever_longer_than_the_previous_other_two/Nested.SOS.NETCore.dll" ) ) } "">
1348+ <Authenticode>Microsoft400</Authenticode>
1349+ </FilesToSign>
1350+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "7" , "Mid.SOS.NETCore.dll" ) ) } "">
1351+ <Authenticode>Microsoft400</Authenticode>
1352+ </FilesToSign>
1353+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "8" , "MidNativeLibrary.dll" ) ) } "">
1354+ <Authenticode>Microsoft400</Authenticode>
1355+ </FilesToSign>
1356+ " ,
1357+ $@ "
1358+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "test.zip" ) ) } "">
1359+ <Authenticode>ArchiveCert</Authenticode>
1360+ </FilesToSign>
1361+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "test.tgz" ) ) } "">
1362+ <Authenticode>ArchiveCert</Authenticode>
1363+ </FilesToSign>
1364+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "6" , "InnerZipFile.zip" ) ) } "">
1365+ <Authenticode>ArchiveCert</Authenticode>
1366+ </FilesToSign>
1367+ "
1368+ } , additionalCertificateInfo : additionalCertificateInfo ) ;
1369+ }
1370+
12841371 /// <summary>
12851372 /// Verifies that signing of pkgs can be done on Windows, even though
12861373 /// we will not unpack or repack them.
@@ -2590,6 +2677,11 @@ public void ValidateSignToolTaskParsing()
25902677 } ) ,
25912678 // Signed pe file
25922679 new TaskItem ( GetResourcePath ( "SignedLibrary.dll" ) , new Dictionary < string , string >
2680+ {
2681+ { SignToolConstants . CollisionPriorityId , "123" }
2682+ } ) ,
2683+ // Sign a test.zip
2684+ new TaskItem ( GetResourcePath ( "test.zip" ) , new Dictionary < string , string >
25932685 {
25942686 { SignToolConstants . CollisionPriorityId , "123" }
25952687 } )
@@ -2621,6 +2713,11 @@ public void ValidateSignToolTaskParsing()
26212713 { "CertificateName" , "DualSignCertificate" } ,
26222714 { "PublicKeyToken" , "31bf3856ad364e35" } ,
26232715 { "CollisionPriorityId" , "123" }
2716+ } ) ,
2717+ new TaskItem ( "test.zip" , new Dictionary < string , string >
2718+ {
2719+ { "CertificateName" , "DetachedArchiveCert" } ,
2720+ { "CollisionPriorityId" , "123" }
26242721 } )
26252722 } ;
26262723
@@ -2637,7 +2734,11 @@ public void ValidateSignToolTaskParsing()
26372734 { "MacCertificate" , "MacDeveloperHarden" } ,
26382735 { "MacNotarizationAppName" , "com.microsoft.dotnet" } ,
26392736 { "CollisionPriorityId" , "123" }
2640- } )
2737+ } ) ,
2738+ new TaskItem ( "DetachedArchiveCert" , new Dictionary < string , string >
2739+ {
2740+ { "DetachedSignature" , "true" }
2741+ } ) ,
26412742 } ;
26422743
26432744 var task = new SignToolTask
@@ -2670,7 +2771,11 @@ public void ValidateSignToolTaskParsing()
26702771 "File 'ProjectOne.dll' TargetFramework='.NETCoreApp,Version=v2.1' Certificate='3PartySHA2' StrongName='ArcadeStrongTest'" ,
26712772 "File 'ProjectOne.dll' TargetFramework='.NETStandard,Version=v2.0' Certificate='OverrideCertificateName' StrongName='ArcadeStrongTest'" ,
26722773 "File 'ContainerOne.1.0.0.nupkg' Certificate='NuGet'" ,
2673- "File 'SignedLibrary.dll' TargetFramework='.NETCoreApp,Version=v2.0' Certificate='DualSignCertificate'"
2774+ "File 'SignedLibrary.dll' TargetFramework='.NETCoreApp,Version=v2.0' Certificate='DualSignCertificate'" ,
2775+ "File 'SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
2776+ "File 'Nested.NativeLibrary.dll' Certificate='Microsoft400'" ,
2777+ "File 'Nested.SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
2778+ "File 'test.zip' Certificate='DetachedArchiveCert'"
26742779 } ;
26752780 task . ParsedSigningInput . FilesToSign . Select ( f => f . ToString ( ) ) . Should ( ) . BeEquivalentTo ( expected ) ;
26762781 }
0 commit comments