Search code examples
redhatrpmdockerrpmbuild

How to build the rpm package with SHA-256 checksum for files?


In standard alone RHEL 6.4 rpm build environment, the rpm packages is generated with SHA-256 check sum, which is gotten by command rpm -qp --dump xxx.rpm

[user@redhat64 abc]$ rpm -qp --dump package/rpm/abc-1.0.1-1.x86_64.rpm
..
/opt/company/abc/abc/1.0.1-1/bin/start.sh 507 1398338016 d8820685b6446ee36a85cc1f7387d14537d6f8bf5ce4c5a4ccd2f70e9066c859 0100750 user abcc 0
..

While if it is build in docker environment (still RHEL6.4) the checksum is md5

[user@c1cbdf51d189 abc]$ rpm -qp --dump package/rpm/abc-1.0.1-1.x86_64.rpm
..
/opt/company/abc/abc/1.0.1-1/bin/start.sh 507 1401952578 f229759944ba77c3c8ba2982c55bbe70 0100750 user abcc 0
..

If I checked the real file, the file is the same

[user@c1cbdf51d189 1.0.1-1]$ sha256sum bin/start.sh
d8820685b6446ee36a85cc1f7387d14537d6f8bf5ce4c5a4ccd2f70e9066c859  bin/start.sh
[user@c1cbdf51d189 1.0.1-1]$ md5sum bin/start.sh
f229759944ba77c3c8ba2982c55bbe70  bin/start.sh

How I configure rpmbuild to let generated rpm file is SHA-256 based ?


Solution

  • It is not related with docker, it can be enabled by follow configuration

    echo "%_binary_filedigest_algorithm  8" >> $HOME/.rpmmacros
    

    The reason for it is ok in standard alone RHEL 6.4 is because it has the redhat-rpm-config packages.

    bash-4.1# yum install redhat-rpm-config
    

    In the package, this configuration exists in /usr/lib/rpm/redhat/macros

    bash-4.1# grep digest /usr/lib/rpm/redhat/macros
    %_source_filedigest_algorithm 8
    %_binary_filedigest_algorithm 8
    

    You can use command rpmbuild --showrc to check all the configuration.