@@ -1278,6 +1278,93 @@ public void SignZipFile()
12781278 } ) ;
12791279 }
12801280
1281+ [ Fact ]
1282+ public void SignArchivesUsingDetachedSignature ( )
1283+ {
1284+ // List of files to be considered for signing
1285+ var itemsToSign = new List < ItemToSign > ( )
1286+ {
1287+ new ItemToSign ( GetResourcePath ( "test.zip" ) ) ,
1288+ new ItemToSign ( GetResourcePath ( "test.tgz" ) ) ,
1289+ new ItemToSign ( GetResourcePath ( "NestedZip.zip" ) ) ,
1290+ new ItemToSign ( GetResourcePath ( "InnerZipFile.zip" ) )
1291+ } ;
1292+
1293+ var strongNameSignInfo = new Dictionary < string , List < SignInfo > > ( ) ;
1294+
1295+ // Overriding information
1296+ var explicitCertKeys = new Dictionary < ExplicitCertificateKey , string > ( )
1297+ {
1298+ { new ExplicitCertificateKey ( "test.zip" ) , "ArchiveCert" } ,
1299+ { new ExplicitCertificateKey ( "test.tgz" ) , "ArchiveCert" } ,
1300+ { new ExplicitCertificateKey ( "InnerZipFile.zip" ) , "ArchiveCert" }
1301+ } ;
1302+
1303+ var additionalCertificateInfo = new Dictionary < string , List < AdditionalCertificateInformation > > ( )
1304+ {
1305+ { "ArchiveCert" ,
1306+ new List < AdditionalCertificateInformation > ( ) {
1307+ new AdditionalCertificateInformation ( ) { GeneratesDetachedSignature = true }
1308+ }
1309+ }
1310+ } ;
1311+
1312+ ValidateFileSignInfos ( itemsToSign , strongNameSignInfo , explicitCertKeys , s_fileExtensionSignInfo , new [ ]
1313+ {
1314+ "File 'NativeLibrary.dll' Certificate='Microsoft400'" ,
1315+ "File 'SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
1316+ "File 'Nested.NativeLibrary.dll' Certificate='Microsoft400'" ,
1317+ "File 'Nested.SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
1318+ "File 'test.zip' Certificate='ArchiveCert'" ,
1319+ "File 'test.tgz' Certificate='ArchiveCert'" ,
1320+ "File 'InnerZipFile.zip' Certificate='ArchiveCert'" ,
1321+ "File 'Mid.SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
1322+ "File 'MidNativeLibrary.dll' Certificate='Microsoft400'" ,
1323+ "File 'NestedZip.zip'" ,
1324+ } ,
1325+ additionalCertificateInfo : additionalCertificateInfo ,
1326+ expectedCopyFiles : new [ ]
1327+ {
1328+ $ "{ Path . Combine ( _tmpDir , "ContainerSigning" , "6" , "InnerZipFile.zip" ) } -> { Path . Combine ( _tmpDir , "InnerZipFile.zip" ) } ",
1329+ $ "{ Path . Combine ( _tmpDir , "ContainerSigning" , "6" , "InnerZipFile.zip.sig" ) } -> { Path . Combine ( _tmpDir , "InnerZipFile.zip.sig" ) } "
1330+ } ) ;
1331+
1332+ ValidateGeneratedProject ( itemsToSign , strongNameSignInfo , explicitCertKeys , s_fileExtensionSignInfo , new [ ]
1333+ {
1334+ $@ "
1335+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "0" , "NativeLibrary.dll" ) ) } "">
1336+ <Authenticode>Microsoft400</Authenticode>
1337+ </FilesToSign>
1338+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "1" , "SOS.NETCore.dll" ) ) } "">
1339+ <Authenticode>Microsoft400</Authenticode>
1340+ </FilesToSign>
1341+ <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" ) ) } "">
1342+ <Authenticode>Microsoft400</Authenticode>
1343+ </FilesToSign>
1344+ <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" ) ) } "">
1345+ <Authenticode>Microsoft400</Authenticode>
1346+ </FilesToSign>
1347+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "7" , "Mid.SOS.NETCore.dll" ) ) } "">
1348+ <Authenticode>Microsoft400</Authenticode>
1349+ </FilesToSign>
1350+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "8" , "MidNativeLibrary.dll" ) ) } "">
1351+ <Authenticode>Microsoft400</Authenticode>
1352+ </FilesToSign>
1353+ " ,
1354+ $@ "
1355+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "test.zip" ) ) } "">
1356+ <Authenticode>ArchiveCert</Authenticode>
1357+ </FilesToSign>
1358+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "test.tgz" ) ) } "">
1359+ <Authenticode>ArchiveCert</Authenticode>
1360+ </FilesToSign>
1361+ <FilesToSign Include=""{ Uri . EscapeDataString ( Path . Combine ( _tmpDir , "ContainerSigning" , "6" , "InnerZipFile.zip" ) ) } "">
1362+ <Authenticode>ArchiveCert</Authenticode>
1363+ </FilesToSign>
1364+ "
1365+ } , additionalCertificateInfo : additionalCertificateInfo ) ;
1366+ }
1367+
12811368 /// <summary>
12821369 /// Verifies that signing of pkgs can be done on Windows, even though
12831370 /// we will not unpack or repack them.
@@ -2587,6 +2674,11 @@ public void ValidateSignToolTaskParsing()
25872674 } ) ,
25882675 // Signed pe file
25892676 new TaskItem ( GetResourcePath ( "SignedLibrary.dll" ) , new Dictionary < string , string >
2677+ {
2678+ { SignToolConstants . CollisionPriorityId , "123" }
2679+ } ) ,
2680+ // Sign a test.zip
2681+ new TaskItem ( GetResourcePath ( "test.zip" ) , new Dictionary < string , string >
25902682 {
25912683 { SignToolConstants . CollisionPriorityId , "123" }
25922684 } )
@@ -2618,6 +2710,11 @@ public void ValidateSignToolTaskParsing()
26182710 { "CertificateName" , "DualSignCertificate" } ,
26192711 { "PublicKeyToken" , "31bf3856ad364e35" } ,
26202712 { "CollisionPriorityId" , "123" }
2713+ } ) ,
2714+ new TaskItem ( "test.zip" , new Dictionary < string , string >
2715+ {
2716+ { "CertificateName" , "DetachedArchiveCert" } ,
2717+ { "CollisionPriorityId" , "123" }
26212718 } )
26222719 } ;
26232720
@@ -2634,7 +2731,11 @@ public void ValidateSignToolTaskParsing()
26342731 { "MacCertificate" , "MacDeveloperHarden" } ,
26352732 { "MacNotarizationAppName" , "com.microsoft.dotnet" } ,
26362733 { "CollisionPriorityId" , "123" }
2637- } )
2734+ } ) ,
2735+ new TaskItem ( "DetachedArchiveCert" , new Dictionary < string , string >
2736+ {
2737+ { "DetachedSignature" , "true" }
2738+ } ) ,
26382739 } ;
26392740
26402741 var task = new SignToolTask
@@ -2667,7 +2768,11 @@ public void ValidateSignToolTaskParsing()
26672768 "File 'ProjectOne.dll' TargetFramework='.NETCoreApp,Version=v2.1' Certificate='3PartySHA2' StrongName='ArcadeStrongTest'" ,
26682769 "File 'ProjectOne.dll' TargetFramework='.NETStandard,Version=v2.0' Certificate='OverrideCertificateName' StrongName='ArcadeStrongTest'" ,
26692770 "File 'ContainerOne.1.0.0.nupkg' Certificate='NuGet'" ,
2670- "File 'SignedLibrary.dll' TargetFramework='.NETCoreApp,Version=v2.0' Certificate='DualSignCertificate'"
2771+ "File 'SignedLibrary.dll' TargetFramework='.NETCoreApp,Version=v2.0' Certificate='DualSignCertificate'" ,
2772+ "File 'SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
2773+ "File 'Nested.NativeLibrary.dll' Certificate='Microsoft400'" ,
2774+ "File 'Nested.SOS.NETCore.dll' TargetFramework='.NETCoreApp,Version=v1.0' Certificate='Microsoft400'" ,
2775+ "File 'test.zip' Certificate='DetachedArchiveCert'"
26712776 } ;
26722777 task . ParsedSigningInput . FilesToSign . Select ( f => f . ToString ( ) ) . Should ( ) . BeEquivalentTo ( expected ) ;
26732778 }
0 commit comments