Retro68/gcc/libgo/go/crypto/x509/root_unix.go

54 lines
1.3 KiB
Go
Raw Normal View History

2012-03-27 23:13:14 +00:00
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2015-08-28 15:33:40 +00:00
// +build dragonfly freebsd linux nacl netbsd openbsd solaris
2012-03-27 23:13:14 +00:00
2014-09-21 17:33:12 +00:00
package x509
2012-03-27 23:13:14 +00:00
2014-09-21 17:33:12 +00:00
import "io/ioutil"
2012-03-27 23:13:14 +00:00
2015-08-28 15:33:40 +00:00
// Possible directories with certificate files; stop after successfully
// reading at least one file from a directory.
var certDirectories = []string{
2017-04-10 11:32:00 +00:00
"/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
2015-08-28 15:33:40 +00:00
"/system/etc/security/cacerts", // Android
2012-03-27 23:13:14 +00:00
}
2014-09-21 17:33:12 +00:00
func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
return nil, nil
}
func initSystemRoots() {
roots := NewCertPool()
2012-03-27 23:13:14 +00:00
for _, file := range certFiles {
data, err := ioutil.ReadFile(file)
if err == nil {
roots.AppendCertsFromPEM(data)
2014-09-21 17:33:12 +00:00
systemRoots = roots
return
2012-03-27 23:13:14 +00:00
}
}
2014-09-21 17:33:12 +00:00
2015-08-28 15:33:40 +00:00
for _, directory := range certDirectories {
fis, err := ioutil.ReadDir(directory)
if err != nil {
continue
}
rootsAdded := false
for _, fi := range fis {
data, err := ioutil.ReadFile(directory + "/" + fi.Name())
if err == nil && roots.AppendCertsFromPEM(data) {
rootsAdded = true
}
}
if rootsAdded {
systemRoots = roots
return
}
}
2014-09-21 17:33:12 +00:00
// All of the files failed to load. systemRoots will be nil which will
// trigger a specific error at verification time.
2012-03-27 23:13:14 +00:00
}