Ubuntu 的存档签名密钥是否可以通过 HTTPS 某处获得?

Tri*_*her 5 security gnupg https

我正在编写一个程序,需要为各种发行版下载 GPG 密钥以进行无人值守的网络安装。为了以自动方式安全地执行此操作,我需要通过 HTTPS 下载密钥,这意味着“gpg --recv-keys”不是一个选项。其他发行版(例如 Fedora)通过 HTTPS(例如https://fedoraproject.org/static/E8E40FDE.txt)在其网站上提供其密钥,但我在 ubuntu.com 上的任何地方都找不到 Ubuntu 密钥文件。有谁知道我可以从哪里通过 HTTPS 获取它?

mur*_*uru 2

钥匙在ubuntu-keyring包装中。因此,与任何 Ubuntu 软件包一样,您可以从Launchpad下载它,它提供 HTTPS(选择合适的版本并根据需要下载 tarball 或 deb 文件)。


碰巧,您可以让 GnuPG2 通过 HKPS(带有 SSL 的 HKP)导入密钥,因此可以--recv-keys安全地进行,但这个过程有点烦人。要使用 HKPS,我们需要:

  • 告诉dirmngr使用 HKPS 密钥服务器
  • 告诉dirmngrCA 证书在哪里
  • gpg2通过而不是gpg-apt-key命令调用来获取密钥gpg,并且gpg似乎不支持 HKPS (无论如何,它尝试执行,/usr/lib/gnupg/gpgkeys_hkp但由于不支持的协议错误而失败)
  • 导出密钥并将其导入sudo apt-key add

HKPS 和 dirmngr

理想情况下,我们应该使用和gpgconf来设置配置选项。但不理解我们使用的一个选项,for 。所以我们不妨手动完成这一切。dirmngrgpg2gpgconf--hkp-cacertdirmngr

首先,让我们创建一个符号链接,/etc/ssl/certs/ca-certificates.crt因为dirmngr需要 PEM 扩展:

ln -s /etc/ssl/certs/ca-certificates.crt ~/.ca-certs.pem
Run Code Online (Sandbox Code Playgroud)

编辑~/.gnupg/dirmngr.conf(如果需要的话创建)并向其中添加这两个选项:

keyserver hkps://keyserver.ubuntu.com
hkp-cacert ~/.ca-certs.pem
Run Code Online (Sandbox Code Playgroud)

如有必要,杀死 dirmngr:

pkill dirmngr
Run Code Online (Sandbox Code Playgroud)

使用 GnuPG2 导入密钥

设置 dirmngr 选项后,这很简单:

$ gpg2 --verbose --recv-keys 0xBA6932366A755776
gpg: no running Dirmngr - starting '/usr/bin/dirmngr'
gpg: waiting for the dirmngr to come up ... (5s)
gpg: connection to the dirmngr established
gpg: data source: https://cassava.canonical.com:443
gpg: armor header: Version: SKS 1.1.6
gpg: armor header: Comment: Hostname: keyserver.ubuntu.com
gpg: pub  rsa4096/6A755776 2017-07-29  Launchpad PPA for deadsnakes
gpg: key 6A755776: "Launchpad PPA for deadsnakes" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
Run Code Online (Sandbox Code Playgroud)

耶!

将密钥添加到 apt

另一个简单的步骤:

$ gpg2 --export 0xBA6932366A755776 | sudo apt-key add
OK
Run Code Online (Sandbox Code Playgroud)

(可选)我们现在可以从用户密钥环中删除添加的密钥,因为不太可能再次需要它:

$ gpg2 --delete-keys 0xBA6932366A755776
gpg (GnuPG) 2.1.11; Copyright (C) 2016 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

pub  rsa4096/6A755776 2017-07-29 Launchpad PPA for deadsnakes

Delete this key from the keyring? (y/N) y
Run Code Online (Sandbox Code Playgroud)

这些步骤并不难实现自动化。


Pan*_*her 1

我建议你使用 ""gpg --recv-keys" ,然后 apt 会确认密钥

apt 如何使用 Release.gpg

Secure apt在下载Release文件时总是下载Release.gpg文件,如果它无法下载Release.gpg,或者签名不好,它会抱怨,并会注意到Release文件指向的Packages文件,其中列出的所有软件包均来自不受信任的来源。这是 apt-get 更新期间的样子:

W:GPG 错误:http://ftp.us.debian.org测试版本:由于公钥不可用,无法验证以下签名:NO_PUBKEY 010908312D230C5F

请参阅http://wiki.debian.org/SecureApt

http://wiki.debian.org/SecureApt#How_to_tell_if_the_key_is_safe