ubuntu 创建本地deb软件包时,对Release文件做gpg签名

2024-06-07 09:32

本文主要是介绍ubuntu 创建本地deb软件包时,对Release文件做gpg签名,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Ubuntu 16.04 (xenial) 在将本地deb软件包创建repo时候,跟14.04以前的版本相比,强制要求gpg对Release文件签名,否则无法使用:

Reading package lists... Done
W: The repository 'http://10.245.254.93/linux/ubuntu/updates/xenial ./ Release' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.


这时候, gpg 软件登场了。

1.1 GPG 创建的密匙,可供加密文件及签名文件使用, 也可创建专供签名文件使用的密匙。
密钥创建过程中,需要使用到足够的随机数(random),可先行安装rng-tools, 该工具可以常驻后台的方式, 生成随机数,避免gpg密钥创建过程中的长时间等待问题

# apt-get install rng-tools
# rngd -r /dev/urandom
# gpg --gen-key
gpg (GnuPG) 1.4.20; Copyright (C) 2015 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.Please select what kind of key you want:(1) RSA and RSA (default)(2) DSA and Elgamal(3) DSA (sign only)(4) RSA (sign only)
Your selection? 4
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.0 = key does not expire<n>  = key expires in n days<n>w = key expires in n weeks<n>m = key expires in n months<n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) yYou need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"Real name: Ubuntu Local Archive Automatic Signing Key
Email address: mac@ispc.cn
Comment: 2017
You selected this USER-ID:"Ubuntu Local Archive Automatic Signing Key (2017) <mac@ispc.cn>"Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.gpg: gpg-agent is not available in this session
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
......+++++
+++++
gpg: key 7A1E912A marked as ultimately trusted
public and secret key created and signed.gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   4096R/7A1E912A 2017-03-15Key fingerprint = A11A 69B7 15AB B83A C6AC  4282 02FE 7153 F5A2 4A14
uid                  Ubuntu Local Archive Automatic Signing Key (2017) <mac@ispc.cn

 

1.2 导出gpg公钥和私钥,并放到可下载的地方,比如某个web
私钥,供Server端,对release文件签名使用
公钥,需在Ubuntu client 导入,供apt-get使用

# gpg --list-key
# gpg -k
/root/.gnupg/pubring.gpg
------------------------
pub   4096R/7A1E912A 2017-03-02 [expires: 2022-03-01]
uid                  Ubuntu Local Archive Automatic Signing Key (2017) <mac@ispc.cn># gpg -a --export 7A1E912A > Ubuntu_Local_Archive_Automatic_Signing_Key_2017.pub
# gpg -a --export-secret-keys 7A1E912A > Ubuntu_Local_Archive_Automatic_Signing_Key_2017.sec

 

2. 创建Package file

# rm -f Packages.gz Packages
# apt-ftparchive packages . | gzip -9c > Packages.gz
# gunzip -k Packages.gz

使用下面这种internet上常见的方式,必须先安装dpkg-dev软件包, 与使用apt-ftparchive 方式,可一样达到目的,但apt-ftparchive是系统默认已经安装的软件包,不需要再安装,个人认为有优势
(但不能检查并提示同名软件包的不同版本。解决办法是,提前在deb软件包尚在目录内/var/cache/apt/archives的时候,使用apt-get autoclean命令,清除老版本软件包)
# dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz


3. 创建release file

# apt-ftparchive release ./ > Release
# gpg -abs --default-key 7A1E912A -o Release.gpg Release
# gpg --clearsign --default-key 7A1E912A -o InRelease Release

4. 对release file签名

# gpg -abs --default-key 7A1E912A -o Release.gpg Release
# gpg --clearsign --default-key 7A1E912A -o InRelease Release

 

5. 修改ubuntu client sources.list

# echo "deb [arch=amd64] http://10.245.254.93/linux/ubuntu/updates/xenial ./" >> /etc/apt/sources.list

6. 下载并导入给release file 签名的公钥

#wget http://10.245.254.93/linux/ubuntu/updates/gpg/Ubuntu_Local_Archive_Automatic_Signing_Key_2017.pub
# apt-key add Ubuntu_Local_Archive_Automatic_Signing_Key_2017.pub

7. 可以使用了
# apt-get udpate

 


【重要】
GPG在给文件签名时候,默认使用SHA1算法,导致在后续使用过程中,出现下述告警:
    Release.gpg: Signature by key ADAF3EDBBB0035413FD4FEDBB3E7CC5C7A1E912A uses weak digest algorithm (SHA1)

解决办法:
http://apache.org/dev/openpgp.html
https://keyring.debian.org/creating-key.html
这2个比较权威的网站上的冗长的解释,那是因为人家要做全面解释介绍,步骤当然多点。
文章中提到的参数default-preference-list(默认偏好清单),并定义:SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed. 个人认为, 这里定义的是可使用的加密算法清单,而不是算法顺序, 谁在前谁在后,无关大雅。可在这里定义,或者直接使用默认值,所以压根不用关心这个步骤。

 

最后,只需要下面简单步骤:

在给Releases文件签名前,修改~/.gnupg/gpg.conf, 定义参数personal-digest-preferences(the digest used for signing messages)为SHA256。
另SHA224,SHA256,SHA384,SHA512几个选项,可根据需求随意选择,只要不用SHA1就好,要不你就又绕回去了:(

# echo "personal-digest-preferences SHA256" >> ~/.gnupg/gpg.conf
# gpg -abs --default-key 7A1E912A -o Release.gpg Release
also can use gpg command option, example:# gpg -abs --default-key 7A1E912A --personal-digest-preferences SHA256 -o Release.gpg Release

 

-----------------------------
8. 脚本方式使用

8.1 Server site

wget http://10.245.254.93/linux/ubuntu/updates/gpg/Ubuntu_Local_Archive_Automatic_Signing_Key_2017.sec
gpg --import Ubuntu_Local_Archive_Automatic_Signing_Key_2017.sec
echo "personal-digest-preferences SHA256" >> ~/.gnupg/gpg.confmkdir /opt/xenial
cp -rp /var/cache/apt/archives /opt/xenialcd /opt/xenial
rm -rf Packages.gz Packages archives/lock archives/partial
apt-ftparchive packages . | gzip -9c > Packages.gz
gunzip -k Packages.gz
apt-ftparchive release ./ > Release
gpg -abs --default-key 7A1E912A --passphrase YourPasswd -o Release.gpg Release
gpg --clearsign --default-key 7A1E912A --passphrase YourPasswd -o InRelease Releaseecho "deb [arch=amd64] file:///opt/xenial ./" >> /etc/apt/sources.list
apt-get update


8.2 Client site

echo "deb [arch=amd64] http://10.245.254.93/linux/ubuntu/updates/xenial ./" >> /etc/apt/sources.list
wget http://10.245.254.93/linux/ubuntu/updates/gpg/Ubuntu_Local_Archive_Automatic_Signing_Key_2017.pub
apt-key add Ubuntu_Local_Archive_Automatic_Signing_Key_2017.pub
apt-get update

 

补充:ubuntu apt-get 对软件包索引,首先要求InRelease文件,其次才去找Release、Release.gpg文件; 这情况下, 其实只需要创建InRelease文件(包含Release文件和明文签名)即可:

 # gpg --clearsign --default-key 7A1E912A --passphrase YourPasswd -o InRelease Release

 

转载地址:

https://my.oschina.net/u/3362827/blog/860711

这篇关于ubuntu 创建本地deb软件包时,对Release文件做gpg签名的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1038791

相关文章

Java中对象的创建和销毁过程详析

《Java中对象的创建和销毁过程详析》:本文主要介绍Java中对象的创建和销毁过程,对象的创建过程包括类加载检查、内存分配、初始化零值内存、设置对象头和执行init方法,对象的销毁过程由垃圾回收机... 目录前言对象的创建过程1. 类加载检查2China编程. 分配内存3. 初始化零值4. 设置对象头5. 执行

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

Ubuntu固定虚拟机ip地址的方法教程

《Ubuntu固定虚拟机ip地址的方法教程》本文详细介绍了如何在Ubuntu虚拟机中固定IP地址,包括检查和编辑`/etc/apt/sources.list`文件、更新网络配置文件以及使用Networ... 1、由于虚拟机网络是桥接,所以ip地址会不停地变化,接下来我们就讲述ip如何固定 2、如果apt安

Python创建Excel的4种方式小结

《Python创建Excel的4种方式小结》这篇文章主要为大家详细介绍了Python中创建Excel的4种常见方式,文中的示例代码简洁易懂,具有一定的参考价值,感兴趣的小伙伴可以学习一下... 目录库的安装代码1——pandas代码2——openpyxl代码3——xlsxwriterwww.cppcns.c

一文教你使用Python实现本地分页

《一文教你使用Python实现本地分页》这篇文章主要为大家详细介绍了Python如何实现本地分页的算法,主要针对二级数据结构,文中的示例代码简洁易懂,有需要的小伙伴可以了解下... 在项目开发的过程中,遇到分页的第一页就展示大量的数据,导致前端列表加载展示的速度慢,所以需要在本地加入分页处理,把所有数据先放

本地搭建DeepSeek-R1、WebUI的完整过程及访问

《本地搭建DeepSeek-R1、WebUI的完整过程及访问》:本文主要介绍本地搭建DeepSeek-R1、WebUI的完整过程及访问的相关资料,DeepSeek-R1是一个开源的人工智能平台,主... 目录背景       搭建准备基础概念搭建过程访问对话测试总结背景       最近几年,人工智能技术

如何在本地部署 DeepSeek Janus Pro 文生图大模型

《如何在本地部署DeepSeekJanusPro文生图大模型》DeepSeekJanusPro模型在本地成功部署,支持图片理解和文生图功能,通过Gradio界面进行交互,展示了其强大的多模态处... 目录什么是 Janus Pro1. 安装 conda2. 创建 python 虚拟环境3. 克隆 janus

使用Python在Excel中创建和取消数据分组

《使用Python在Excel中创建和取消数据分组》Excel中的分组是一种通过添加层级结构将相邻行或列组织在一起的功能,当分组完成后,用户可以通过折叠或展开数据组来简化数据视图,这篇博客将介绍如何使... 目录引言使用工具python在Excel中创建行和列分组Python在Excel中创建嵌套分组Pyt

本地私有化部署DeepSeek模型的详细教程

《本地私有化部署DeepSeek模型的详细教程》DeepSeek模型是一种强大的语言模型,本地私有化部署可以让用户在自己的环境中安全、高效地使用该模型,避免数据传输到外部带来的安全风险,同时也能根据自... 目录一、引言二、环境准备(一)硬件要求(二)软件要求(三)创建虚拟环境三、安装依赖库四、获取 Dee