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

54 lines
1.3 KiB
Go
Raw Normal View History

2012-03-28 01:13:14 +02: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 17:33:40 +02:00
// +build dragonfly freebsd linux nacl netbsd openbsd solaris
2012-03-28 01:13:14 +02:00
2014-09-21 19:33:12 +02:00
package x509
2012-03-28 01:13:14 +02:00
2014-09-21 19:33:12 +02:00
import "io/ioutil"
2012-03-28 01:13:14 +02:00
2015-08-28 17:33:40 +02:00
// Possible directories with certificate files; stop after successfully
// reading at least one file from a directory.
var certDirectories = []string{
2017-04-10 13:32:00 +02:00
"/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
2015-08-28 17:33:40 +02:00
"/system/etc/security/cacerts", // Android
2012-03-28 01:13:14 +02:00
}
2014-09-21 19:33:12 +02:00
func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
return nil, nil
}
func initSystemRoots() {
roots := NewCertPool()
2012-03-28 01:13:14 +02:00
for _, file := range certFiles {
data, err := ioutil.ReadFile(file)
if err == nil {
roots.AppendCertsFromPEM(data)
2014-09-21 19:33:12 +02:00
systemRoots = roots
return
2012-03-28 01:13:14 +02:00
}
}
2014-09-21 19:33:12 +02:00
2015-08-28 17:33:40 +02: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 19:33:12 +02:00
// All of the files failed to load. systemRoots will be nil which will
// trigger a specific error at verification time.
2012-03-28 01:13:14 +02:00
}