github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/src/crypto/x509/root_unix.go (about)

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build dragonfly freebsd linux nacl netbsd openbsd solaris
     6  
     7  package x509
     8  
     9  import "io/ioutil"
    10  
    11  // Possible directories with certificate files; stop after successfully
    12  // reading at least one file from a directory.
    13  var certDirectories = []string{
    14  	"/system/etc/security/cacerts", // Android
    15  }
    16  
    17  func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
    18  	return nil, nil
    19  }
    20  
    21  func initSystemRoots() {
    22  	roots := NewCertPool()
    23  	for _, file := range certFiles {
    24  		data, err := ioutil.ReadFile(file)
    25  		if err == nil {
    26  			roots.AppendCertsFromPEM(data)
    27  			systemRoots = roots
    28  			return
    29  		}
    30  	}
    31  
    32  	for _, directory := range certDirectories {
    33  		fis, err := ioutil.ReadDir(directory)
    34  		if err != nil {
    35  			continue
    36  		}
    37  		rootsAdded := false
    38  		for _, fi := range fis {
    39  			data, err := ioutil.ReadFile(directory + "/" + fi.Name())
    40  			if err == nil && roots.AppendCertsFromPEM(data) {
    41  				rootsAdded = true
    42  			}
    43  		}
    44  		if rootsAdded {
    45  			systemRoots = roots
    46  			return
    47  		}
    48  	}
    49  
    50  	// All of the files failed to load. systemRoots will be nil which will
    51  	// trigger a specific error at verification time.
    52  }