@@ -627,16 +627,10 @@ func TestCommandLineRecomposition(t *testing.T) {
627
627
}
628
628
629
629
func TestWinVerifyTrust (t * testing.T ) {
630
- t .Skip ("skipping fragile test; see https://golang.org/issue/49266 and https://golang.org/issue/49651" )
631
-
632
- system32 , err := windows .GetSystemDirectory ()
633
- if err != nil {
634
- t .Errorf ("unable to find system32 directory: %v" , err )
635
- }
636
- ntoskrnl := filepath .Join (system32 , "ntoskrnl.exe" )
637
- ntoskrnl16 , err := windows .UTF16PtrFromString (ntoskrnl )
630
+ evsignedfile := `.\testdata\ev-signed-file.exe`
631
+ evsignedfile16 , err := windows .UTF16PtrFromString (evsignedfile )
638
632
if err != nil {
639
- t .Fatalf ("unable to get utf16 of ntoskrnl.exe : %v" , err )
633
+ t .Fatalf ("unable to get utf16 of %s : %v" , evsignedfile , err )
640
634
}
641
635
data := & windows.WinTrustData {
642
636
Size : uint32 (unsafe .Sizeof (windows.WinTrustData {})),
@@ -646,39 +640,39 @@ func TestWinVerifyTrust(t *testing.T) {
646
640
StateAction : windows .WTD_STATEACTION_VERIFY ,
647
641
FileOrCatalogOrBlobOrSgnrOrCert : unsafe .Pointer (& windows.WinTrustFileInfo {
648
642
Size : uint32 (unsafe .Sizeof (windows.WinTrustFileInfo {})),
649
- FilePath : ntoskrnl16 ,
643
+ FilePath : evsignedfile16 ,
650
644
}),
651
645
}
652
646
verifyErr := windows .WinVerifyTrustEx (windows .InvalidHWND , & windows .WINTRUST_ACTION_GENERIC_VERIFY_V2 , data )
653
647
data .StateAction = windows .WTD_STATEACTION_CLOSE
654
648
closeErr := windows .WinVerifyTrustEx (windows .InvalidHWND , & windows .WINTRUST_ACTION_GENERIC_VERIFY_V2 , data )
655
649
if verifyErr != nil {
656
- t .Errorf ("ntoskrnl.exe did not verify: %v" , verifyErr )
650
+ t .Errorf ("%s did not verify: %v" , evsignedfile , verifyErr )
657
651
}
658
652
if closeErr != nil {
659
653
t .Errorf ("unable to free verification resources: %v" , closeErr )
660
654
}
661
655
662
- // Now that we've verified legitimate ntoskrnl.exe verifies, let's corrupt it and see if it correctly fails.
656
+ // Now that we've verified the legitimate file verifies, let's corrupt it and see if it correctly fails.
663
657
664
658
dir , err := ioutil .TempDir ("" , "go-build" )
665
659
if err != nil {
666
660
t .Fatalf ("failed to create temp directory: %v" , err )
667
661
}
668
662
defer os .RemoveAll (dir )
669
- corruptedNtoskrnl := filepath .Join (dir , "ntoskrnl.exe " )
670
- ntoskrnlBytes , err := ioutil .ReadFile (ntoskrnl )
663
+ corruptedEvsignedfile := filepath .Join (dir , "corrupted-file " )
664
+ evsignedfileBytes , err := ioutil .ReadFile (evsignedfile )
671
665
if err != nil {
672
- t .Fatalf ("unable to read ntoskrnl.exe bytes: %v" , err )
666
+ t .Fatalf ("unable to read %s bytes: %v" , evsignedfile , err )
673
667
}
674
- if len (ntoskrnlBytes ) > 0 {
675
- ntoskrnlBytes [len (ntoskrnlBytes )/ 2 - 1 ]++
668
+ if len (evsignedfileBytes ) > 0 {
669
+ evsignedfileBytes [len (evsignedfileBytes )/ 2 - 1 ]++
676
670
}
677
- err = ioutil .WriteFile (corruptedNtoskrnl , ntoskrnlBytes , 0755 )
671
+ err = ioutil .WriteFile (corruptedEvsignedfile , evsignedfileBytes , 0755 )
678
672
if err != nil {
679
673
t .Fatalf ("unable to write corrupted ntoskrnl.exe bytes: %v" , err )
680
674
}
681
- ntoskrnl16 , err = windows .UTF16PtrFromString (corruptedNtoskrnl )
675
+ evsignedfile16 , err = windows .UTF16PtrFromString (corruptedEvsignedfile )
682
676
if err != nil {
683
677
t .Fatalf ("unable to get utf16 of ntoskrnl.exe: %v" , err )
684
678
}
@@ -690,14 +684,14 @@ func TestWinVerifyTrust(t *testing.T) {
690
684
StateAction : windows .WTD_STATEACTION_VERIFY ,
691
685
FileOrCatalogOrBlobOrSgnrOrCert : unsafe .Pointer (& windows.WinTrustFileInfo {
692
686
Size : uint32 (unsafe .Sizeof (windows.WinTrustFileInfo {})),
693
- FilePath : ntoskrnl16 ,
687
+ FilePath : evsignedfile16 ,
694
688
}),
695
689
}
696
690
verifyErr = windows .WinVerifyTrustEx (windows .InvalidHWND , & windows .WINTRUST_ACTION_GENERIC_VERIFY_V2 , data )
697
691
data .StateAction = windows .WTD_STATEACTION_CLOSE
698
692
closeErr = windows .WinVerifyTrustEx (windows .InvalidHWND , & windows .WINTRUST_ACTION_GENERIC_VERIFY_V2 , data )
699
693
if verifyErr != windows .Errno (windows .TRUST_E_BAD_DIGEST ) {
700
- t .Errorf ("ntoskrnl.exe did not fail to verify as expected: %v" , verifyErr )
694
+ t .Errorf ("%s did not fail to verify as expected: %v" , corruptedEvsignedfile , verifyErr )
701
695
}
702
696
if closeErr != nil {
703
697
t .Errorf ("unable to free verification resources: %v" , closeErr )
0 commit comments