@@ -319,7 +319,7 @@ internal void Sign(CmiManifestSigner2 signer)
319
319
Sign ( signer , null ) ;
320
320
}
321
321
322
- internal void Sign ( CmiManifestSigner2 signer , string timeStampUrl )
322
+ internal void Sign ( CmiManifestSigner2 signer , string timeStampUrl , bool disallowMansignTimestampFallback = false )
323
323
{
324
324
// Reset signer infos.
325
325
_strongNameSignerInfo = null ;
@@ -350,7 +350,7 @@ internal void Sign(CmiManifestSigner2 signer, string timeStampUrl)
350
350
351
351
// Now create the license DOM, and then sign it.
352
352
licenseDom = CreateLicenseDom ( signer , ExtractPrincipalFromManifest ( ) , ComputeHashFromManifest ( _manifestDom , _useSha256 ) ) ;
353
- AuthenticodeSignLicenseDom ( licenseDom , signer , timeStampUrl , _useSha256 ) ;
353
+ AuthenticodeSignLicenseDom ( licenseDom , signer , timeStampUrl , _useSha256 , disallowMansignTimestampFallback ) ;
354
354
}
355
355
StrongNameSignManifestDom ( _manifestDom , licenseDom , signer , _useSha256 ) ;
356
356
}
@@ -676,7 +676,7 @@ private static XmlDocument CreateLicenseDom(CmiManifestSigner2 signer, XmlElemen
676
676
return licenseDom ;
677
677
}
678
678
679
- private static void AuthenticodeSignLicenseDom ( XmlDocument licenseDom , CmiManifestSigner2 signer , string timeStampUrl , bool useSha256 )
679
+ private static void AuthenticodeSignLicenseDom ( XmlDocument licenseDom , CmiManifestSigner2 signer , string timeStampUrl , bool useSha256 , bool disallowMansignTimestampFallback )
680
680
{
681
681
// Make sure it is RSA, as this is the only one Fusion will support.
682
682
#if RUNTIME_TYPE_NETCORE
@@ -747,7 +747,7 @@ private static void AuthenticodeSignLicenseDom(XmlDocument licenseDom, CmiManife
747
747
// Time stamp it if requested.
748
748
if ( ! string . IsNullOrEmpty ( timeStampUrl ) )
749
749
{
750
- TimestampSignedLicenseDom ( licenseDom , timeStampUrl , useSha256 ) ;
750
+ TimestampSignedLicenseDom ( licenseDom , timeStampUrl , useSha256 , disallowMansignTimestampFallback ) ;
751
751
}
752
752
753
753
// Wrap it inside a RelData element.
@@ -831,7 +831,7 @@ private static string ObtainRFC3161Timestamp(string timeStampUrl, string signatu
831
831
return timestamp ;
832
832
}
833
833
834
- private static void TimestampSignedLicenseDom ( XmlDocument licenseDom , string timeStampUrl , bool useSha256 )
834
+ private static void TimestampSignedLicenseDom ( XmlDocument licenseDom , string timeStampUrl , bool useSha256 , bool disallowMansignTimestampFallback )
835
835
{
836
836
XmlNamespaceManager nsm = new XmlNamespaceManager ( licenseDom . NameTable ) ;
837
837
nsm . AddNamespace ( "r" , LicenseNamespaceUri ) ;
@@ -850,31 +850,38 @@ private static void TimestampSignedLicenseDom(XmlDocument licenseDom, string tim
850
850
// Catch CryptographicException to ensure fallback to old code (non-RFC3161)
851
851
catch ( CryptographicException )
852
852
{
853
- Win32 . CRYPT_DATA_BLOB timestampBlob = new Win32 . CRYPT_DATA_BLOB ( ) ;
853
+ if ( disallowMansignTimestampFallback )
854
+ {
855
+ throw ;
856
+ }
857
+ else
858
+ {
859
+ Win32 . CRYPT_DATA_BLOB timestampBlob = new Win32 . CRYPT_DATA_BLOB ( ) ;
854
860
855
- byte [ ] licenseXml = Encoding . UTF8 . GetBytes ( licenseDom . OuterXml ) ;
861
+ byte [ ] licenseXml = Encoding . UTF8 . GetBytes ( licenseDom . OuterXml ) ;
856
862
857
- unsafe
858
- {
859
- fixed ( byte * pbLicense = licenseXml )
863
+ unsafe
860
864
{
861
- Win32 . CRYPT_DATA_BLOB licenseBlob = new Win32 . CRYPT_DATA_BLOB ( ) ;
862
- IntPtr pvLicense = new IntPtr ( pbLicense ) ;
863
- licenseBlob . cbData = ( uint ) licenseXml . Length ;
864
- licenseBlob . pbData = pvLicense ;
865
-
866
- int hr = Win32 . CertTimestampAuthenticodeLicense ( ref licenseBlob , timeStampUrl , ref timestampBlob ) ;
867
- if ( hr != Win32 . S_OK )
865
+ fixed ( byte * pbLicense = licenseXml )
868
866
{
869
- throw new CryptographicException ( hr ) ;
867
+ Win32 . CRYPT_DATA_BLOB licenseBlob = new Win32 . CRYPT_DATA_BLOB ( ) ;
868
+ IntPtr pvLicense = new IntPtr ( pbLicense ) ;
869
+ licenseBlob . cbData = ( uint ) licenseXml . Length ;
870
+ licenseBlob . pbData = pvLicense ;
871
+
872
+ int hr = Win32 . CertTimestampAuthenticodeLicense ( ref licenseBlob , timeStampUrl , ref timestampBlob ) ;
873
+ if ( hr != Win32 . S_OK )
874
+ {
875
+ throw new CryptographicException ( hr ) ;
876
+ }
870
877
}
871
878
}
872
- }
873
879
874
- byte [ ] timestampSignature = new byte [ timestampBlob . cbData ] ;
875
- Marshal . Copy ( timestampBlob . pbData , timestampSignature , 0 , timestampSignature . Length ) ;
876
- Win32 . HeapFree ( Win32 . GetProcessHeap ( ) , 0 , timestampBlob . pbData ) ;
877
- timestamp = Encoding . UTF8 . GetString ( timestampSignature ) ;
880
+ byte [ ] timestampSignature = new byte [ timestampBlob . cbData ] ;
881
+ Marshal . Copy ( timestampBlob . pbData , timestampSignature , 0 , timestampSignature . Length ) ;
882
+ Win32 . HeapFree ( Win32 . GetProcessHeap ( ) , 0 , timestampBlob . pbData ) ;
883
+ timestamp = Encoding . UTF8 . GetString ( timestampSignature ) ;
884
+ }
878
885
}
879
886
880
887
XmlElement asTimestamp = licenseDom . CreateElement ( "as" , "Timestamp" , AuthenticodeNamespaceUri ) ;
0 commit comments