doupo5861 2014-11-21 06:28
浏览 135
已采纳

无法在基于linux-amd64构建的darwin-amd64二进制文件中使用https

I build a darwin-amd64 version of my program on linux-amd64, the cross-compiling command is:

GOOS=darwin GOARCH=amd64 GOBIN=/tmp go install <myprogram>

Before that I've prepared the darwin-amd64 tool-chain using:

sudo GOOS=darwin GOARCH=amd64 ./make.bash

However, after giving this darwin-amd64 version binary to my colleagues, they can't use it for login because login will send a HTTPS request, which will use CGO. Errmsg returned is:

x509: failed to load system roots and no roots provided

Any suggestions on how to fix this?

  • 写回答

1条回答 默认 最新

  • drsdvwsvo78320812 2014-11-21 07:03
    关注

    That looks like a certificate issue, as the one mentioned in "Building Docker Images for Static Go Binaries"

    The reason for this is that on Linux systems the tls package reads the root CA certificates from /etc/ssl/certs/ca-certificates.crt, which is missing from the scratch image.
    The Contributors app gets around this problem by bundling a copy of the root CA certificates and configuring outbound calls to use them.

    So you can check if that /etc/ssl/certs/ca-certificates.crt is there on your colleague's workstation.

    But this bug report suggests:

    Just got some clarifications from go-nuts. It's due to cross-compile won't work for loading x509 cert...

    the cross-compiler can't use 'cgo' during compilation, but 'cgo' is required to access the root certificate store on Darwin.

    I had a similar issue, was solved after copying crt file from any of these linux distro. for golang to read the file, you have to place the file in the exact same directory.
    crypto/x509 will loop over all the possible certificate files.

    Another solution involves cross-compiling with "export CGO_ENABLED=0".

    The bug 8349 shows some progress too with more recent Go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多