Skip to content

Commit

Permalink
crypto/x509: revert SystemCertPool implementation for Windows
Browse files Browse the repository at this point in the history
Updates #18609

Change-Id: I8306135660f52cf625bed4c7f53f632e527617de
Reviewed-on: https://go-review.googlesource.com/35265
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
Reviewed-by: Quentin Smith <[email protected]>
  • Loading branch information
bradfitz committed Jan 18, 2017
1 parent fcfd918 commit 2c8b70e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 0 additions & 5 deletions doc/go1.8.html
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,6 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>

<dl id="crypto_x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt>
<dd>
<p> <!-- CL 30578 -->
<a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a>
is now implemented on Windows.
</p>

<p> <!-- CL 24743 -->
PSS signatures are now supported.
</p>
Expand Down
11 changes: 10 additions & 1 deletion src/crypto/x509/cert_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

package x509

import "encoding/pem"
import (
"encoding/pem"
"errors"
"runtime"
)

// CertPool is a set of certificates.
type CertPool struct {
Expand All @@ -26,6 +30,11 @@ func NewCertPool() *CertPool {
// Any mutations to the returned pool are not written to disk and do
// not affect any other pool.
func SystemCertPool() (*CertPool, error) {
if runtime.GOOS == "windows" {
// Issue 16736, 18609:
return nil, errors.New("crypto/x509: system root pool is not available on Windows")
}

return loadSystemRoots()
}

Expand Down
5 changes: 5 additions & 0 deletions src/crypto/x509/root_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
}

func loadSystemRoots() (*CertPool, error) {
// TODO: restore this functionality on Windows. We tried to do
// it in Go 1.8 but had to revert it. See Issue 18609.
// Returning (nil, nil) was the old behavior, prior to CL 30578.
return nil, nil

const CRYPT_E_NOT_FOUND = 0x80092004

store, err := syscall.CertOpenSystemStore(0, syscall.StringToUTF16Ptr("ROOT"))
Expand Down
4 changes: 4 additions & 0 deletions src/crypto/x509/x509_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net"
"os/exec"
"reflect"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -1477,6 +1478,9 @@ func TestMultipleRDN(t *testing.T) {
}

func TestSystemCertPool(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("not implemented on Windows; Issue 16736, 18609")
}
_, err := SystemCertPool()
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 2c8b70e

Please sign in to comment.