Skip to content

Commit a106f55

Browse files
committed
[release-branch.go1.12] all: base64-encode binaries that will cause Apple notarization to fail
Starting with macOS 10.15 (Catalina), Apple now requires all software distributed outside of the App Store to be notarized. Any binaries we distribute must abide by a strict set of requirements like code-signing and having a minimum target SDK of 10.9 (amongst others). Apple’s notarization service will recursively inspect archives looking to find notarization candidate binaries. If it finds a binary that does not meet the requirements or is unable to decompress an archive, it will reject the entire distribution. From cursory testing, it seems that the service uses content sniffing to determine file types, so changing the file extension will not work. There are some binaries and archives included in our distribution that are being detected by Apple’s service as potential candidates for notarization or decompression. As these are files used by tests and some are intentionally invalid, we don’t intend to ever make them compliant. As a workaround for this, we base64-encode any binaries or archives that Apple’s notarization service issues a warning for, as these warnings will become errors in January 2020. Updates #34986 Updates #35747 Change-Id: I106fbb6227b61eb221755568f047ee11103c1680 Reviewed-on: https://go-review.googlesource.com/c/go/+/208118 Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> (cherry picked from commit 8bbfc51) Reviewed-on: https://go-review.googlesource.com/c/go/+/208220 Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent a852806 commit a106f55

35 files changed

+192
-43
lines changed

src/archive/zip/reader_test.go

+25-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bytes"
99
"encoding/binary"
1010
"encoding/hex"
11+
"internal/obscuretestdata"
1112
"io"
1213
"io/ioutil"
1314
"os"
@@ -19,11 +20,12 @@ import (
1920
)
2021

2122
type ZipTest struct {
22-
Name string
23-
Source func() (r io.ReaderAt, size int64) // if non-nil, used instead of testdata/<Name> file
24-
Comment string
25-
File []ZipTestFile
26-
Error error // the error that Opening this file should return
23+
Name string
24+
Source func() (r io.ReaderAt, size int64) // if non-nil, used instead of testdata/<Name> file
25+
Comment string
26+
File []ZipTestFile
27+
Obscured bool // needed for Apple notarization (golang.org/issue/34986)
28+
Error error // the error that Opening this file should return
2729
}
2830

2931
type ZipTestFile struct {
@@ -189,8 +191,12 @@ var tests = []ZipTest{
189191
},
190192
{
191193
// created by Go, before we wrote the "optional" data
192-
// descriptor signatures (which are required by OS X)
193-
Name: "go-no-datadesc-sig.zip",
194+
// descriptor signatures (which are required by macOS).
195+
// Use obscured file to avoid Apple’s notarization service
196+
// rejecting the toolchain due to an inability to unzip this archive.
197+
// See golang.org/issue/34986
198+
Name: "go-no-datadesc-sig.zip.base64",
199+
Obscured: true,
194200
File: []ZipTestFile{
195201
{
196202
Name: "foo.txt",
@@ -208,7 +214,7 @@ var tests = []ZipTest{
208214
},
209215
{
210216
// created by Go, after we wrote the "optional" data
211-
// descriptor signatures (which are required by OS X)
217+
// descriptor signatures (which are required by macOS)
212218
Name: "go-with-datadesc-sig.zip",
213219
File: []ZipTestFile{
214220
{
@@ -496,8 +502,18 @@ func readTestZip(t *testing.T, zt ZipTest) {
496502
rat, size := zt.Source()
497503
z, err = NewReader(rat, size)
498504
} else {
505+
path := filepath.Join("testdata", zt.Name)
506+
if zt.Obscured {
507+
tf, err := obscuretestdata.DecodeToTempFile(path)
508+
if err != nil {
509+
t.Errorf("obscuretestdata.DecodeToTempFile(%s): %v", path, err)
510+
return
511+
}
512+
defer os.Remove(tf)
513+
path = tf
514+
}
499515
var rc *ReadCloser
500-
rc, err = OpenReader(filepath.Join("testdata", zt.Name))
516+
rc, err = OpenReader(path)
501517
if err == nil {
502518
defer rc.Close()
503519
z = &rc.Reader
-330 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UEsDBBQACAAAAGWHaECoZTJ+BAAAAAQAAAAHABgAZm9vLnR4dFVUBQAD3lVZT3V4CwABBPUBAAAEFAAAAGZvbwqoZTJ+BAAAAAQAAABQSwMEFAAIAAAAZodoQOmzogQEAAAABAAAAAcAGABiYXIudHh0VVQFAAPgVVlPdXgLAAEE9QEAAAQUAAAAYmFyCumzogQEAAAABAAAAFBLAQIUAxQACAAAAGWHaECoZTJ+BAAAAAQAAAAHABgAAAAAAAAAAACkgQAAAABmb28udHh0VVQFAAPeVVlPdXgLAAEE9QEAAAQUAAAAUEsBAhQDFAAIAAAAZodoQOmzogQEAAAABAAAAAcAGAAAAAAAAAAAAKSBTQAAAGJhci50eHRVVAUAA+BVWU91eAsAAQT1AQAABBQAAABQSwUGAAAAAAIAAgCaAAAAmgAAAAAA

src/cmd/internal/buildid/buildid_test.go

+26-15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package buildid
77
import (
88
"bytes"
99
"crypto/sha256"
10+
"internal/obscuretestdata"
1011
"io/ioutil"
1112
"os"
1213
"reflect"
@@ -19,13 +20,6 @@ const (
1920
)
2021

2122
func TestReadFile(t *testing.T) {
22-
var files = []string{
23-
"p.a",
24-
"a.elf",
25-
"a.macho",
26-
"a.pe",
27-
}
28-
2923
f, err := ioutil.TempFile("", "buildid-test-")
3024
if err != nil {
3125
t.Fatal(err)
@@ -34,26 +28,43 @@ func TestReadFile(t *testing.T) {
3428
defer os.Remove(tmp)
3529
f.Close()
3630

37-
for _, f := range files {
38-
id, err := ReadFile("testdata/" + f)
31+
// Use obscured files to prevent Apple’s notarization service from
32+
// mistaking them as candidates for notarization and rejecting the entire
33+
// toolchain.
34+
// See golang.org/issue/34986
35+
var files = []string{
36+
"p.a.base64",
37+
"a.elf.base64",
38+
"a.macho.base64",
39+
"a.pe.base64",
40+
}
41+
42+
for _, name := range files {
43+
f, err := obscuretestdata.DecodeToTempFile("testdata/" + name)
44+
if err != nil {
45+
t.Errorf("obscuretestdata.DecodeToTempFile(testdata/%s): %v", name, err)
46+
continue
47+
}
48+
defer os.Remove(f)
49+
id, err := ReadFile(f)
3950
if id != expectedID || err != nil {
4051
t.Errorf("ReadFile(testdata/%s) = %q, %v, want %q, nil", f, id, err, expectedID)
4152
}
4253
old := readSize
4354
readSize = 2048
44-
id, err = ReadFile("testdata/" + f)
55+
id, err = ReadFile(f)
4556
readSize = old
4657
if id != expectedID || err != nil {
47-
t.Errorf("ReadFile(testdata/%s) [readSize=2k] = %q, %v, want %q, nil", f, id, err, expectedID)
58+
t.Errorf("ReadFile(%s) [readSize=2k] = %q, %v, want %q, nil", f, id, err, expectedID)
4859
}
4960

50-
data, err := ioutil.ReadFile("testdata/" + f)
61+
data, err := ioutil.ReadFile(f)
5162
if err != nil {
5263
t.Fatal(err)
5364
}
5465
m, _, err := FindAndHash(bytes.NewReader(data), expectedID, 1024)
5566
if err != nil {
56-
t.Errorf("FindAndHash(testdata/%s): %v", f, err)
67+
t.Errorf("FindAndHash(%s): %v", f, err)
5768
continue
5869
}
5970
if err := ioutil.WriteFile(tmp, data, 0666); err != nil {
@@ -68,7 +79,7 @@ func TestReadFile(t *testing.T) {
6879
err = Rewrite(tf, m, newID)
6980
err2 := tf.Close()
7081
if err != nil {
71-
t.Errorf("Rewrite(testdata/%s): %v", f, err)
82+
t.Errorf("Rewrite(%s): %v", f, err)
7283
continue
7384
}
7485
if err2 != nil {
@@ -77,7 +88,7 @@ func TestReadFile(t *testing.T) {
7788

7889
id, err = ReadFile(tmp)
7990
if id != newID || err != nil {
80-
t.Errorf("ReadFile(testdata/%s after Rewrite) = %q, %v, want %q, nil", f, id, err, newID)
91+
t.Errorf("ReadFile(%s after Rewrite) = %q, %v, want %q, nil", f, id, err, newID)
8192
}
8293
}
8394
}
-12.5 KB
Binary file not shown.

src/cmd/internal/buildid/testdata/a.elf.base64

+1
Large diffs are not rendered by default.
-13.2 KB
Binary file not shown.

src/cmd/internal/buildid/testdata/a.macho.base64

+1
Large diffs are not rendered by default.
-3.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TVqQAAMABAAAAAAA//8AAIsAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQ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p2ZXJzaW9uIDUKCgACAQFwAAsACwABAAokJApfZ29fLm8gICAgICAgICAgMCAgICAgICAgICAgMCAgICAgMCAgICAgNjQ0ICAgICAyMjMgICAgICAgYApnbyBvYmplY3QgZGFyd2luIGFtZDY0IGRldmVsICszYjMzYWY1ZDY4IFRodSBPY3QgNSAxNjo1OTowMCAyMDE3IC0wNDAwIFg6ZnJhbWVwb2ludGVyCmJ1aWxkIGlkICJhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ei4xMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0IgotLS0tCgoKIQoAAGdvMTlsZAEA/wAAAAAAAP//Z28xOWxkAA==

src/cmd/nm/nm_test.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"fmt"
9+
"internal/obscuretestdata"
910
"internal/testenv"
1011
"io/ioutil"
1112
"os"
@@ -57,8 +58,8 @@ func TestNonGoExecs(t *testing.T) {
5758
testfiles := []string{
5859
"debug/elf/testdata/gcc-386-freebsd-exec",
5960
"debug/elf/testdata/gcc-amd64-linux-exec",
60-
"debug/macho/testdata/gcc-386-darwin-exec",
61-
"debug/macho/testdata/gcc-amd64-darwin-exec",
61+
"debug/macho/testdata/gcc-386-darwin-exec.base64", // golang.org/issue/34986
62+
"debug/macho/testdata/gcc-amd64-darwin-exec.base64", // golang.org/issue/34986
6263
// "debug/pe/testdata/gcc-amd64-mingw-exec", // no symbols!
6364
"debug/pe/testdata/gcc-386-mingw-exec",
6465
"debug/plan9obj/testdata/amd64-plan9-exec",
@@ -67,6 +68,16 @@ func TestNonGoExecs(t *testing.T) {
6768
}
6869
for _, f := range testfiles {
6970
exepath := filepath.Join(runtime.GOROOT(), "src", f)
71+
if strings.HasSuffix(f, ".base64") {
72+
tf, err := obscuretestdata.DecodeToTempFile(exepath)
73+
if err != nil {
74+
t.Errorf("obscuretestdata.DecodeToTempFile(%s): %v", exepath, err)
75+
continue
76+
}
77+
defer os.Remove(tf)
78+
exepath = tf
79+
}
80+
7081
cmd := exec.Command(testnmpath, exepath)
7182
out, err := cmd.CombinedOutput()
7283
if err != nil {

src/compress/gzip/gunzip_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package gzip
77
import (
88
"bytes"
99
"compress/flate"
10+
"encoding/base64"
1011
"io"
1112
"io/ioutil"
1213
"os"
@@ -413,11 +414,16 @@ func TestDecompressor(t *testing.T) {
413414
}
414415

415416
func TestIssue6550(t *testing.T) {
416-
f, err := os.Open("testdata/issue6550.gz")
417+
// Apple’s notarization service will recursively attempt to decompress
418+
// files in order to find binaries to notarize. Since the service is
419+
// unable to decompress this file, it may reject the entire toolchain. Use a
420+
// base64-encoded version to avoid this.
421+
// See golang.org/issue/34986
422+
f, err := os.Open("testdata/issue6550.gz.base64")
417423
if err != nil {
418424
t.Fatal(err)
419425
}
420-
gzip, err := NewReader(f)
426+
gzip, err := NewReader(base64.NewDecoder(base64.StdEncoding, f))
421427
if err != nil {
422428
t.Fatalf("NewReader(testdata/issue6550.gz): %v", err)
423429
}
-64 KB
Binary file not shown.

src/compress/gzip/testdata/issue6550.gz.base64

+1
Large diffs are not rendered by default.

src/debug/macho/file_test.go

+50-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package macho
66

77
import (
8+
"bytes"
9+
"internal/obscuretestdata"
10+
"io"
811
"reflect"
912
"testing"
1013
)
@@ -19,7 +22,7 @@ type fileTest struct {
1922

2023
var fileTests = []fileTest{
2124
{
22-
"testdata/gcc-386-darwin-exec",
25+
"testdata/gcc-386-darwin-exec.base64",
2326
FileHeader{0xfeedface, Cpu386, 0x3, 0x2, 0xc, 0x3c0, 0x85},
2427
[]interface{}{
2528
&SegmentHeader{LoadCmdSegment, 0x38, "__PAGEZERO", 0x0, 0x1000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
@@ -45,7 +48,7 @@ var fileTests = []fileTest{
4548
nil,
4649
},
4750
{
48-
"testdata/gcc-amd64-darwin-exec",
51+
"testdata/gcc-amd64-darwin-exec.base64",
4952
FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0x2, 0xb, 0x568, 0x85},
5053
[]interface{}{
5154
&SegmentHeader{LoadCmdSegment64, 0x48, "__PAGEZERO", 0x0, 0x100000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
@@ -73,7 +76,7 @@ var fileTests = []fileTest{
7376
nil,
7477
},
7578
{
76-
"testdata/gcc-amd64-darwin-exec-debug",
79+
"testdata/gcc-amd64-darwin-exec-debug.base64",
7780
FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0xa, 0x4, 0x5a0, 0},
7881
[]interface{}{
7982
nil, // LC_UUID
@@ -101,7 +104,7 @@ var fileTests = []fileTest{
101104
nil,
102105
},
103106
{
104-
"testdata/clang-386-darwin-exec-with-rpath",
107+
"testdata/clang-386-darwin-exec-with-rpath.base64",
105108
FileHeader{0xfeedface, Cpu386, 0x3, 0x2, 0x10, 0x42c, 0x1200085},
106109
[]interface{}{
107110
nil, // LC_SEGMENT
@@ -125,7 +128,7 @@ var fileTests = []fileTest{
125128
nil,
126129
},
127130
{
128-
"testdata/clang-amd64-darwin-exec-with-rpath",
131+
"testdata/clang-amd64-darwin-exec-with-rpath.base64",
129132
FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0x2, 0x10, 0x4c8, 0x200085},
130133
[]interface{}{
131134
nil, // LC_SEGMENT
@@ -149,7 +152,7 @@ var fileTests = []fileTest{
149152
nil,
150153
},
151154
{
152-
"testdata/clang-386-darwin.obj",
155+
"testdata/clang-386-darwin.obj.base64",
153156
FileHeader{0xfeedface, Cpu386, 0x3, 0x1, 0x4, 0x138, 0x2000},
154157
nil,
155158
nil,
@@ -184,7 +187,7 @@ var fileTests = []fileTest{
184187
},
185188
},
186189
{
187-
"testdata/clang-amd64-darwin.obj",
190+
"testdata/clang-amd64-darwin.obj.base64",
188191
FileHeader{0xfeedfacf, CpuAmd64, 0x3, 0x1, 0x4, 0x200, 0x2000},
189192
nil,
190193
nil,
@@ -221,11 +224,47 @@ var fileTests = []fileTest{
221224
},
222225
}
223226

227+
func readerAtFromObscured(name string) (io.ReaderAt, error) {
228+
b, err := obscuretestdata.ReadFile(name)
229+
if err != nil {
230+
return nil, err
231+
}
232+
return bytes.NewReader(b), nil
233+
}
234+
235+
func openObscured(name string) (*File, error) {
236+
ra, err := readerAtFromObscured(name)
237+
if err != nil {
238+
return nil, err
239+
}
240+
ff, err := NewFile(ra)
241+
if err != nil {
242+
return nil, err
243+
}
244+
return ff, nil
245+
}
246+
247+
func openFatObscured(name string) (*FatFile, error) {
248+
ra, err := readerAtFromObscured(name)
249+
if err != nil {
250+
return nil, err
251+
}
252+
ff, err := NewFatFile(ra)
253+
if err != nil {
254+
return nil, err
255+
}
256+
return ff, nil
257+
}
258+
224259
func TestOpen(t *testing.T) {
225260
for i := range fileTests {
226261
tt := &fileTests[i]
227262

228-
f, err := Open(tt.file)
263+
// Use obscured files to prevent Apple’s notarization service from
264+
// mistaking them as candidates for notarization and rejecting the entire
265+
// toolchain.
266+
// See golang.org/issue/34986
267+
f, err := openObscured(tt.file)
229268
if err != nil {
230269
t.Error(err)
231270
continue
@@ -318,7 +357,7 @@ func TestOpenFailure(t *testing.T) {
318357
}
319358

320359
func TestOpenFat(t *testing.T) {
321-
ff, err := OpenFat("testdata/fat-gcc-386-amd64-darwin-exec")
360+
ff, err := openFatObscured("testdata/fat-gcc-386-amd64-darwin-exec.base64")
322361
if err != nil {
323362
t.Fatal(err)
324363
}
@@ -350,8 +389,8 @@ func TestOpenFatFailure(t *testing.T) {
350389
t.Errorf("OpenFat %s: succeeded unexpectedly", filename)
351390
}
352391

353-
filename = "testdata/gcc-386-darwin-exec" // not a fat Mach-O
354-
ff, err := OpenFat(filename)
392+
filename = "testdata/gcc-386-darwin-exec.base64" // not a fat Mach-O
393+
ff, err := openFatObscured(filename)
355394
if err != ErrNotFat {
356395
t.Errorf("OpenFat %s: got %v, want ErrNotFat", filename, err)
357396
}
Binary file not shown.

0 commit comments

Comments
 (0)