Golang从哪里获取根CA?

时间:2016-10-14 20:07:13

标签: go

crypto/tls.Config.RootCAs states

// RootCAs defines the set of root certificate authorities
// that clients use when verifying server certificates.
// If RootCAs is nil, TLS uses the host's root CA set.

在Linux上,"主机的根CA设置"从中获取?我需要知道这可以全局添加另一个根CA来信任。

4 个答案:

答案 0 :(得分:3)

这些是位置;找到一个后停止:

    import java.util.Scanner;
    public class KI23CriclesDriver
    {
       public static void main (String[] args)
       {
          //Declare Variables
          int x1, y1, x2, y2;
          String print;
          double center;
          double center2;
          String radius;
          int validLength = 1;
          int validLength2 = 2;

          //Instantiate Objects
          KI23GetC gc = new KI23GetC();
          KI23GetCircles gs = new KI23GetCircles();
          KI23PrintC p = new KI23PrintC();
          System.out.println("Do you want to enter (Option 1) center and radius or (Option 2) end points of diameter?");
          x1 = 0;
          y1 = 0;
          x2 = 0;
          y2 = 0;
          Scanner scanner = new Scanner(System.in);
          radius = scanner.nextLine();
          if( radius.length() == validLength )
          {
             System.out.println("Please enter the center and radius");
             x2 = gc.getX();
             y2 = gc.getY();
             x1 = gc.getX();
             y1 = gc.getY();
             center = gs.getCenter(x1, y1, x2, y2);
             center2 = gs.getCenter2(x1, y1, x2, y2);  
             p.print(x1, y1, x2, y2, center, center2);
          }

          if( radius.length() == validLength2) // doesnt work since validlength2 is the same as validlength
          {
             System.out.println("Please enter the end points of diameter");
             x1 = gc.getX();
             y1 = gc.getY();
             x2 = gc.getX();
             y2 = gc.getY();
             center = gs.getCenter(x1, y1, x2, y2);
             center2 = gs.getCenter2(x1, y1, x2, y2);  
             p.print(x1, y1, x2, y2, center, center2);

          }
          else
          {
             System.out.println("Please enter 1 or 2");
             x1 = 0;
             y1 = 0;
             x2 = 0;
             y2 = 0;
             radius = scanner.nextLine();  
          }
    // 

答案 1 :(得分:2)

答案 2 :(得分:0)

在最新版本的 Golang 中,除了上面已经提到的证书路径之外,Golang 还会为任何证书 PEM 搜索一组通用目录:

/etc/ssl/certs                 // SLES10/SLES11
/etc/pki/tls/certs             // Fedora/RHEL
/system/etc/security/cacerts   // Android

Linux 操作系统的路径在此处定义:https://golang.org/src/crypto/x509/root_linux.go。证书的实际查找和添加发生在这里:https://golang.org/src/crypto/x509/root_unix.go

答案 3 :(得分:0)

您还可以设置环境变量“SSL_CERT_FILE”,让 Golang 使用您的自定义证书文件。