我在服务器上设置了一个(私有)apt 存储库。我只允许通过 SSL 访问此存储库,并且只能使用客户端证书。我已经使用curl测试了连接:
$ curl --cacert /opt/CA.crt --cert /opt/user.crt --key /opt/user.key
Run Code Online (Sandbox Code Playgroud)
https://example.com/dists/lucid/main/binary-amd64/Packages.gz 内容按预期下载。
我在 /etc/apt/apt.conf.d/45example-com 中创建了一个文件
Debug::Acquire::https "true";
Acquire::https::example.com {
Verify-Peer "false";
Verify-Host "false";
CaInfo "/opt/CA.crt";
SslCert "/opt/user.crt";
SslKey "/opt/user.key";
};
Run Code Online (Sandbox Code Playgroud)
我在 /etc/apt/sources.list.d/example.com.list 添加了一个文件:
deb https://example.com/ lucid main
CA 证书似乎有问题,当我尝试更新时,出现以下信息:
> apt-get update
> * Connected to example.com (8.0.0.8) port 443 (#0)
> * found 1 certificates in /opt/CA.crt
> * error reading X.509 key or certificate file
> * Closing connection #0
Run Code Online (Sandbox Code Playgroud)
example.com 上的服务器日志显示没有请求到达那里,所以我猜测 apt-get 在尝试发送请求之前失败了(与日志显示的内容相符)。
我很难在互联网上找到有关带有 ssl 的 apt-get 的任何文档,甚至无法找到源代码。
有人有什么想法吗?
这主要发生在目录权限问题上,apt-get 非常清楚密钥和证书文件的权限设置,因此仅设置 777 或 644 是行不通的。
https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1668944中描述的步骤对于缩小此问题的范围非常有帮助。
我执行了以下步骤来解决这个问题,
~# usermod -G ssl-cert _apt
~# chgrp ssl-cert /opt/CA.crt /opt/user.crt /opt/user.key
~# chmod 655 /opt/CA.crt /opt/user.crt /opt/user.key
另外,如果这对您不起作用,您可以尝试读取您的证书和密钥文件,如果可以的su话,那么 apt 与客户端证书应该按预期工作。_apt
只是为了确保您是否使用自签名证书,请确保运行
~# sudo update-ca-certificates
一旦您移动了 ca 证书 /usr/local/share/ca-certificates/