Skip to content

Commit ef496fb

Browse files
committed
windows: re-enable TestWinVerifyTrust with newly signed file
Rather than disabling this test, let's just not make it rely on Microsoft files, whose signing validity period we can't depend on. Instead, we include our own EV-signed artifact, with a Digicert timestamp using a certificate valid for a decade. Fixes golang/go#49651. Fixes golang/go#49266. For golang/go#46906. Change-Id: Idadba346810017b8f769d6fac1ddd357d4dee93c Reviewed-on: https://go-review.googlesource.com/c/sys/+/366655 Trust: Jason A. Donenfeld <[email protected]> Trust: Brad Fitzpatrick <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent dee7805 commit ef496fb

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

windows/syscall_windows_test.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,10 @@ func TestCommandLineRecomposition(t *testing.T) {
627627
}
628628

629629
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)
638632
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)
640634
}
641635
data := &windows.WinTrustData{
642636
Size: uint32(unsafe.Sizeof(windows.WinTrustData{})),
@@ -646,39 +640,39 @@ func TestWinVerifyTrust(t *testing.T) {
646640
StateAction: windows.WTD_STATEACTION_VERIFY,
647641
FileOrCatalogOrBlobOrSgnrOrCert: unsafe.Pointer(&windows.WinTrustFileInfo{
648642
Size: uint32(unsafe.Sizeof(windows.WinTrustFileInfo{})),
649-
FilePath: ntoskrnl16,
643+
FilePath: evsignedfile16,
650644
}),
651645
}
652646
verifyErr := windows.WinVerifyTrustEx(windows.InvalidHWND, &windows.WINTRUST_ACTION_GENERIC_VERIFY_V2, data)
653647
data.StateAction = windows.WTD_STATEACTION_CLOSE
654648
closeErr := windows.WinVerifyTrustEx(windows.InvalidHWND, &windows.WINTRUST_ACTION_GENERIC_VERIFY_V2, data)
655649
if verifyErr != nil {
656-
t.Errorf("ntoskrnl.exe did not verify: %v", verifyErr)
650+
t.Errorf("%s did not verify: %v", evsignedfile, verifyErr)
657651
}
658652
if closeErr != nil {
659653
t.Errorf("unable to free verification resources: %v", closeErr)
660654
}
661655

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.
663657

664658
dir, err := ioutil.TempDir("", "go-build")
665659
if err != nil {
666660
t.Fatalf("failed to create temp directory: %v", err)
667661
}
668662
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)
671665
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)
673667
}
674-
if len(ntoskrnlBytes) > 0 {
675-
ntoskrnlBytes[len(ntoskrnlBytes)/2-1]++
668+
if len(evsignedfileBytes) > 0 {
669+
evsignedfileBytes[len(evsignedfileBytes)/2-1]++
676670
}
677-
err = ioutil.WriteFile(corruptedNtoskrnl, ntoskrnlBytes, 0755)
671+
err = ioutil.WriteFile(corruptedEvsignedfile, evsignedfileBytes, 0755)
678672
if err != nil {
679673
t.Fatalf("unable to write corrupted ntoskrnl.exe bytes: %v", err)
680674
}
681-
ntoskrnl16, err = windows.UTF16PtrFromString(corruptedNtoskrnl)
675+
evsignedfile16, err = windows.UTF16PtrFromString(corruptedEvsignedfile)
682676
if err != nil {
683677
t.Fatalf("unable to get utf16 of ntoskrnl.exe: %v", err)
684678
}
@@ -690,14 +684,14 @@ func TestWinVerifyTrust(t *testing.T) {
690684
StateAction: windows.WTD_STATEACTION_VERIFY,
691685
FileOrCatalogOrBlobOrSgnrOrCert: unsafe.Pointer(&windows.WinTrustFileInfo{
692686
Size: uint32(unsafe.Sizeof(windows.WinTrustFileInfo{})),
693-
FilePath: ntoskrnl16,
687+
FilePath: evsignedfile16,
694688
}),
695689
}
696690
verifyErr = windows.WinVerifyTrustEx(windows.InvalidHWND, &windows.WINTRUST_ACTION_GENERIC_VERIFY_V2, data)
697691
data.StateAction = windows.WTD_STATEACTION_CLOSE
698692
closeErr = windows.WinVerifyTrustEx(windows.InvalidHWND, &windows.WINTRUST_ACTION_GENERIC_VERIFY_V2, data)
699693
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)
701695
}
702696
if closeErr != nil {
703697
t.Errorf("unable to free verification resources: %v", closeErr)

windows/testdata/README

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This folder contains various pre-generated artifacts for testing. Descriptions
2+
of each follow below.
3+
4+
## ev-signed-file.exe
5+
6+
This was generated with:
7+
8+
int main(void)
9+
{
10+
puts("Hello Gophers!");
11+
return 0;
12+
}
13+
14+
And then a simple clang/mingw compilation:
15+
16+
i686-w64-mingw32-gcc -Os -s a.c
17+
18+
After, it was copied to a Windows computer where it was signed with an EV
19+
certificate using:
20+
21+
signtool sign /sha1 <ID of certificate> /fd sha256 /tr http://timestamp.digicert.com /td sha256 /d "Go Project EV Signing Test" a.exe

windows/testdata/ev-signed-file.exe

17.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)