Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine 3.13 requires file checksums embedded in the apk #288

Closed
djgilcrease opened this issue Jan 27, 2021 · 21 comments · Fixed by #291
Closed

Alpine 3.13 requires file checksums embedded in the apk #288

djgilcrease opened this issue Jan 27, 2021 · 21 comments · Fixed by #291
Assignees

Comments

@djgilcrease
Copy link
Contributor

The root cause for 284 was an update to alpine 3.13 which causes the apks built with nfpm to fail since we are not embedding the file checksums in the apk.

I am currently researching where and how to embed these values, but so far have had no luck in finding where this is documented.

@djgilcrease djgilcrease self-assigned this Jan 27, 2021
@djgilcrease
Copy link
Contributor Author

In alpine v3.13 they changed the warning about needing embedded checksums to an error.

I am having a hard time figuring out how to store this info properly as I cannot find it documented anywhere. @tcurdt or @bhamail Do either of you know how I would go about embedding the checksums so we do not have any errors on 3.13 of alpine?

@tcurdt
Copy link

tcurdt commented Jan 27, 2021

I am not quite sure I fully understand. Is this about checksums? or signing? (I assume signing)
The code had support for signing from day 1. It was just left out for the first merge.
If that's the case it's time to add it I guess.

@djgilcrease
Copy link
Contributor Author

It is about the file checksums. In alpine 3.13 installing an apk without embedded checksums throws an error.

@tcurdt
Copy link

tcurdt commented Jan 27, 2021

@djgilcrease would be great if you could post the output.

@tcurdt
Copy link

tcurdt commented Jan 27, 2021

Because both my original code and the version in nfpm do create the datahash.

https://github.com/goreleaser/nfpm/blob/master/apk/apk.go#L320

https://wiki.alpinelinux.org/wiki/Alpine_package_format

@djgilcrease
Copy link
Contributor Author

support for packages without embedded checksums will be dropped in apk-tools 3.

@tcurdt
Copy link

tcurdt commented Jan 27, 2021

support for packages without embedded checksums will be dropped in apk-tools 3.

We are creating an embedded checksum (or rather hash). That's why this issue needs more details to help.

@erikgeiser
Copy link
Member

I don't have any additional information but I just want to comment that currently the signature is performed over the SHA1 hash of the control file. This in turn means that the signature only "protects" the package contents via the datahash in the control file. No matter what needs to be fixed for this issue, we should keep that in mind, so we don't accidentally degrade the level of security that is expected from the signature (for example if the control file is signed but the datahash is moved elsewhere and thus isn't implicitly signed anymore).

@nxadm
Copy link

nxadm commented Jan 31, 2021

From my build log, no signing, just regular apk packaging with v2.2.3.

(Tell me if the log is too long so I can put it in a gist.)

2021-01-30T17:43:13.2077485Z + PACKAGER=apk
2021-01-30T17:43:13.2078552Z + INSTALL_CMD='apk add --no-cache --allow-untrusted *.apk'
2021-01-30T17:43:13.2078985Z 
2021-01-30T17:43:13.2079415Z mkdir /staging
2021-01-30T17:43:13.2079767Z + mkdir /staging
2021-01-30T17:43:13.2080694Z nfpm pkg -f config/nfpm.yaml --packager $PACKAGER --target /staging/
2021-01-30T17:43:13.2082059Z + nfpm pkg -f config/nfpm.yaml --packager apk --target /staging/
2021-01-30T17:43:13.2082761Z # Name. (required)
2021-01-30T17:43:13.2083621Z name: rakudo-pkg
2021-01-30T17:43:13.2083900Z 
2021-01-30T17:43:13.2084460Z # Architecture. (required)
2021-01-30T17:43:13.2085028Z arch: x86_64
2021-01-30T17:43:13.2085248Z 
2021-01-30T17:43:13.2085711Z # Platform.
2021-01-30T17:43:13.2086099Z # Defaults to `linux`.
2021-01-30T17:43:13.2086730Z platform: linux
2021-01-30T17:43:13.2086969Z 
2021-01-30T17:43:13.2087444Z # Version. (required)
2021-01-30T17:43:13.2087813Z version: 2020.12
2021-01-30T17:43:13.2088169Z 
2021-01-30T17:43:13.2088483Z # Version Epoch.
2021-01-30T17:43:13.2089177Z # Default is extracted from `version` if it is semver compatible.
2021-01-30T17:43:13.2089825Z #epoch: 2
2021-01-30T17:43:13.2090047Z 
2021-01-30T17:43:13.2090520Z # Version Prerelease.
2021-01-30T17:43:13.2091220Z # Default is extracted from `version` if it is semver compatible.
2021-01-30T17:43:13.2091898Z #prerelease: beta1
2021-01-30T17:43:13.2092189Z 
2021-01-30T17:43:13.2092746Z # Version Metadata (previously deb.metadata).
2021-01-30T17:43:13.2093548Z # Default is extracted from `version` if it is semver compatible.
2021-01-30T17:43:13.2094629Z # Setting metadata might interfere with version comparisons depending on the packager.
2021-01-30T17:43:13.2095457Z #version_metadata: git
2021-01-30T17:43:13.2095857Z 
2021-01-30T17:43:13.2096213Z # Version Release.
2021-01-30T17:43:13.2096853Z release: 01
2021-01-30T17:43:13.2097103Z 
2021-01-30T17:43:13.2097550Z # Section.
2021-01-30T17:43:13.2097923Z section: default
2021-01-30T17:43:13.2098311Z 
2021-01-30T17:43:13.2098623Z # Priority.
2021-01-30T17:43:13.2099135Z priority: extra
2021-01-30T17:43:13.2099667Z 
2021-01-30T17:43:13.2100042Z # Maintaner.
2021-01-30T17:43:13.2100698Z maintainer: me <me@me>
2021-01-30T17:43:13.2101232Z 
2021-01-30T17:43:13.2101572Z # Description.
2021-01-30T17:43:13.2102172Z # Defaults to `no description given`.
2021-01-30T17:43:13.2102956Z description: Rakudo runtime for the Raku programming language
2021-01-30T17:43:13.2103616Z 
2021-01-30T17:43:13.2103910Z # Vendor.
2021-01-30T17:43:13.2104657Z vendor: rakudo-pkg
2021-01-30T17:43:13.2104918Z 
2021-01-30T17:43:13.2105745Z # Package's homepage.
2021-01-30T17:43:13.2106424Z homepage: https://raku.org/
2021-01-30T17:43:13.2106900Z 
2021-01-30T17:43:13.2107212Z # License.
2021-01-30T17:43:13.2107766Z license: Artistic License 2.0
2021-01-30T17:43:13.2108061Z 
2021-01-30T17:43:13.2108870Z # Changelog YAML file, see: https://github.com/goreleaser/chglog
2021-01-30T17:43:13.2109534Z #changelog: "changelog.yaml"
2021-01-30T17:43:13.2109973Z 
2021-01-30T17:43:13.2110424Z # Disables globbing for files, config_files, etc.
2021-01-30T17:43:13.2110924Z #disable_globbing: false
2021-01-30T17:43:13.2111200Z 
2021-01-30T17:43:13.2111607Z # Packages it replaces. (overridable)
2021-01-30T17:43:13.2112211Z #replaces:
2021-01-30T17:43:13.2112724Z #  - foobar
2021-01-30T17:43:13.2113083Z 
2021-01-30T17:43:13.2113488Z # Packages it provides. (overridable)
2021-01-30T17:43:13.2113945Z #provides:
2021-01-30T17:43:13.2114451Z #- rakudo-pkg
2021-01-30T17:43:13.2114698Z 
2021-01-30T17:43:13.2115091Z # Dependencies. (overridable)
2021-01-30T17:43:13.2115535Z #depends:
2021-01-30T17:43:13.2116333Z #  - git
2021-01-30T17:43:13.2116556Z 
2021-01-30T17:43:13.2116989Z # Recommended packages. (overridable)
2021-01-30T17:43:13.2117470Z #recommends:
2021-01-30T17:43:13.2117960Z #  - golang
2021-01-30T17:43:13.2118193Z 
2021-01-30T17:43:13.2118609Z # Suggested packages. (overridable)
2021-01-30T17:43:13.2119062Z #suggests:
2021-01-30T17:43:13.2119619Z #  - bzr
2021-01-30T17:43:13.2119831Z 
2021-01-30T17:43:13.2120255Z # Packages it conflicts with. (overridable)
2021-01-30T17:43:13.2120714Z #conflicts:
2021-01-30T17:43:13.2121198Z #  - mercurial
2021-01-30T17:43:13.2121438Z 
2021-01-30T17:43:13.2121791Z # Contents to add to the package
2021-01-30T17:43:13.2122271Z # This can be binaries or any other files.
2021-01-30T17:43:13.2122709Z contents:
2021-01-30T17:43:13.2123350Z     # Basic file that applies to all packagers
2021-01-30T17:43:13.2124026Z   - src: /opt/rakudo-pkg
2021-01-30T17:43:13.2124564Z     dst: /opt/rakudo-pkg
2021-01-30T17:43:13.2124833Z 
2021-01-30T17:43:13.2125160Z #    # Simple config file
2021-01-30T17:43:13.2125719Z #  - src: path/to/local/foo.conf
2021-01-30T17:43:13.2126123Z #    dst: /etc/foo.conf
2021-01-30T17:43:13.2126492Z #    type: config
2021-01-30T17:43:13.2126716Z 
2021-01-30T17:43:13.2127160Z     # Simple symlink
2021-01-30T17:43:13.2127819Z   - src: /opt/rakudo-pkg/bin/rakudo-pkg_path.sh
2021-01-30T17:43:13.2128552Z     dst: /etc/profile.d/rakudo-pkg.sh
2021-01-30T17:43:13.2129015Z     type: "symlink"
2021-01-30T17:43:13.2129281Z 
2021-01-30T17:43:13.2129882Z #    # Corresponds to %config(noreplace) if the packager is rpm, otherwise it is just a config file
2021-01-30T17:43:13.2130822Z #  - src: path/to/local/bar.conf
2021-01-30T17:43:13.2131224Z #    dst: /etc/bar.conf
2021-01-30T17:43:13.2131649Z #    type: "config|noreplace"
2021-01-30T17:43:13.2131925Z 
2021-01-30T17:43:13.2132438Z     # These files are not actually present in the package, but the file names
2021-01-30T17:43:13.2133214Z     # are added to the package header. From the RPM directives documentation:
2021-01-30T17:43:13.2133759Z     #
2021-01-30T17:43:13.2134224Z     # "There are times when a file should be owned by the package but not
2021-01-30T17:43:13.2135126Z     # installed - log files and state files are good examples of cases you might
2021-01-30T17:43:13.2146855Z     # desire this to happen."
2021-01-30T17:43:13.2147208Z     #
2021-01-30T17:43:13.2147708Z     # "The way to achieve this, is to use the %ghost directive. By adding this
2021-01-30T17:43:13.2148586Z     # directive to the line containing a file, RPM will know about the ghosted
2021-01-30T17:43:13.2149374Z     # file, but will not add it to the package."
2021-01-30T17:43:13.2149775Z     #
2021-01-30T17:43:13.2150257Z     # For non rpm packages ghost files are ignored at this time.
2021-01-30T17:43:13.2151095Z #  - dst: /etc/casper.conf
2021-01-30T17:43:13.2151494Z #    type: ghost
2021-01-30T17:43:13.2152024Z #  - dst: /var/log/boo.log
2021-01-30T17:43:13.2152495Z #    type: ghost
2021-01-30T17:43:13.2152733Z 
2021-01-30T17:43:13.2153269Z #    # You can user the packager field to add files that are unique to a specific packager
2021-01-30T17:43:13.2154051Z #  - src: path/to/rpm/file.conf
2021-01-30T17:43:13.2154494Z #    dst: /etc/file.conf
2021-01-30T17:43:13.2154921Z #    type: "config|noreplace"
2021-01-30T17:43:13.2155323Z #    packager: rpm
2021-01-30T17:43:13.2155877Z #  - src: path/to/deb/file.conf
2021-01-30T17:43:13.2156284Z #    dst: /etc/file.conf
2021-01-30T17:43:13.2156701Z #    type: "config|noreplace"
2021-01-30T17:43:13.2157117Z #    packager: deb
2021-01-30T17:43:13.2157655Z #  - src: path/to/apk/file.conf
2021-01-30T17:43:13.2158076Z #    dst: /etc/file.conf
2021-01-30T17:43:13.2158486Z #    type: "config|noreplace"
2021-01-30T17:43:13.2159024Z #    packager: apk
2021-01-30T17:43:13.2159262Z 
2021-01-30T17:43:13.2159812Z     # Sometimes it is important to be able to set the mtime, mode, owner, or group for a file
2021-01-30T17:43:13.2160677Z     # that differs from what is on the local build system at build time.
2021-01-30T17:43:13.2161379Z #  - src: path/to/foo
2021-01-30T17:43:13.2161753Z #    dst: /usr/local/foo
2021-01-30T17:43:13.2162110Z #    file_info:
2021-01-30T17:43:13.2162731Z #      mode: 0644
2021-01-30T17:43:13.2163425Z #      mtime: 2008-01-02T15:04:05Z
2021-01-30T17:43:13.2163807Z #      owner: notRoot
2021-01-30T17:43:13.2164164Z #      group: notRoot
2021-01-30T17:43:13.2164411Z 
2021-01-30T17:43:13.2164607Z 
2021-01-30T17:43:13.2165090Z # Empty folders your package may need created. (overridable)
2021-01-30T17:43:13.2165636Z #empty_folders:
2021-01-30T17:43:13.2166124Z #  - /var/log/foo
2021-01-30T17:43:13.2166355Z 
2021-01-30T17:43:13.2166790Z # Scripts to run at specific stages. (overridable)
2021-01-30T17:43:13.2167276Z #scripts:
2021-01-30T17:43:13.2167720Z #  preinstall: ./scripts/preinstall.sh
2021-01-30T17:43:13.2168295Z #  postinstall: ./scripts/postinstall.sh
2021-01-30T17:43:13.2168920Z #  preremove: ./scripts/preremove.sh
2021-01-30T17:43:13.2169480Z #  postremove: ./scripts/postremove.sh
2021-01-30T17:43:13.2169830Z 
2021-01-30T17:43:13.2170429Z # All fields above marked as `overridable` can be overriden for a given package format in this section.
2021-01-30T17:43:13.2171207Z #overrides:
2021-01-30T17:43:13.2171920Z #  # The depends override can for example be used to provide version constraints for dependencies where
2021-01-30T17:43:13.2172997Z #  # different package formats use different versions or for dependencies that are named differently.
2021-01-30T17:43:13.2173673Z #  deb:
2021-01-30T17:43:13.2174004Z #    depends:
2021-01-30T17:43:13.2174618Z #      - baz (>= 1.2.3-0)
2021-01-30T17:43:13.2175105Z #      - some-lib-dev
2021-01-30T17:43:13.2175453Z #    # ...
2021-01-30T17:43:13.2175736Z #  rpm:
2021-01-30T17:43:13.2176064Z #    depends:
2021-01-30T17:43:13.2176523Z #      - baz >= 1.2.3-0
2021-01-30T17:43:13.2177205Z #      - some-lib-devel
2021-01-30T17:43:13.2177560Z #    # ...
2021-01-30T17:43:13.2177840Z #  apk:
2021-01-30T17:43:13.2178128Z #    # ...
2021-01-30T17:43:13.2178329Z 
2021-01-30T17:43:13.2178799Z # Custom configuration applied only to the RPM packager.
2021-01-30T17:43:13.2179282Z #rpm:
2021-01-30T17:43:13.2179779Z #  # The package group. This option is deprecated by most distros
2021-01-30T17:43:13.2180444Z #  # but required by old distros like CentOS 5 / EL 5 and earlier.
2021-01-30T17:43:13.2180977Z #  group: Unspecified
2021-01-30T17:43:13.2181312Z #
2021-01-30T17:43:13.2181947Z #  # The package summary. This is, by default, the first line of the
2021-01-30T17:43:13.2182770Z #  # description, but can be explicitly provided here.
2021-01-30T17:43:13.2183411Z #  summary: Explicit Summary for Sample Package
2021-01-30T17:43:13.2183856Z #
2021-01-30T17:43:13.2184224Z #  # Compression algorithm.
2021-01-30T17:43:13.2184686Z #  compression: lzma
2021-01-30T17:43:13.2185028Z #
2021-01-30T17:43:13.2185546Z #  # The package is signed if a key_file is set
2021-01-30T17:43:13.2185975Z #  signature:
2021-01-30T17:43:13.2186756Z #    # PGP secret key (can also be ASCII-armored), the passphrase is taken
2021-01-30T17:43:13.2187447Z #    # from the environment variable  with a fallback
2021-01-30T17:43:13.2187957Z #    # to #NFPM_PASSPHRASE.
2021-01-30T17:43:13.2188368Z #    key_file: key.gpg
2021-01-30T17:43:13.2188610Z 
2021-01-30T17:43:13.2189091Z # Custom configuration applied only to the Deb packager.
2021-01-30T17:43:13.2189569Z #deb:
2021-01-30T17:43:13.2189941Z #  # Custom deb special files.
2021-01-30T17:43:13.2190446Z #  scripts:
2021-01-30T17:43:13.2190825Z #    # Deb rules script.
2021-01-30T17:43:13.2191201Z #    rules: foo.sh
2021-01-30T17:43:13.2191661Z #    # Deb templates file, when using debconf.
2021-01-30T17:43:13.2192181Z #    templates: templates
2021-01-30T17:43:13.2192542Z #
2021-01-30T17:43:13.2193004Z #  # Custom deb triggers
2021-01-30T17:43:13.2193380Z #  triggers:
2021-01-30T17:43:13.2193944Z #    # register interrest on a trigger activated by another package
2021-01-30T17:43:13.2194644Z #    # (also available: interest_await, interest_noawait)
2021-01-30T17:43:13.2195146Z #    interest:
2021-01-30T17:43:13.2195767Z #      - some-trigger-name
2021-01-30T17:43:13.2196408Z #    # activate a trigger for another package
2021-01-30T17:43:13.2197002Z #    # (also available: activate_await, activate_noawait)
2021-01-30T17:43:13.2197476Z #    activate:
2021-01-30T17:43:13.2198064Z #      - another-trigger-name
2021-01-30T17:43:13.2198460Z #
2021-01-30T17:43:13.2198943Z #  # Packages which would break if this package would be installed.
2021-01-30T17:43:13.2200918Z #  # The installation of this package is blocked if `some-package`
2021-01-30T17:43:13.2201862Z #  # is already installed.
2021-01-30T17:43:13.2202269Z #  breaks:
2021-01-30T17:43:13.2202868Z #    - some-package
2021-01-30T17:43:13.2203232Z #
2021-01-30T17:43:13.2203634Z #  # The package is signed if a key_file is set
2021-01-30T17:43:13.2204080Z #  signature:
2021-01-30T17:43:13.2204857Z #    # PGP secret key (can also be ASCII-armored). The passphrase is taken
2021-01-30T17:43:13.2205563Z #    # from the environment variable  with a fallback
2021-01-30T17:43:13.2206102Z #    # to #NFPM_PASSPHRASE.
2021-01-30T17:43:13.2206515Z #    key_file: key.gpg
2021-01-30T17:43:13.2207097Z #    # The type describes the signers role, possible values are "origin",
2021-01-30T17:43:13.2207806Z #    # "maint" and "archive". If unset, the type defaults to "origin".
2021-01-30T17:43:13.2208309Z #    type: origin
2021-01-30T17:43:13.2208556Z 
2021-01-30T17:43:13.2208858Z #apk:
2021-01-30T17:43:13.2209274Z #  # The package is signed if a key_file is set
2021-01-30T17:43:13.2209722Z #  signature:
2021-01-30T17:43:13.2210276Z #    # RSA private key in the PEM format. The passphrase is taken from
2021-01-30T17:43:13.2210927Z #    # the environment variable  with a fallback
2021-01-30T17:43:13.2211567Z #    # to #NFPM_PASSPHRASE.
2021-01-30T17:43:13.2211965Z #    key_file: key.gpg
2021-01-30T17:43:13.2212661Z #    # The name of the signing key. When verifying a package, the signature
2021-01-30T17:43:13.2213400Z #    # is matched to the public key store in /etc/apk/keys/<key_name>.rsa.pub.
2021-01-30T17:43:13.2214108Z #    # If unset, it defaults to the maintainer email address.
2021-01-30T17:43:13.2220532Z #    key_name: origin
2021-01-30T17:43:13.2485407Z using apk packager...
2021-01-30T17:43:16.2045230Z created package: /staging/rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.2065657Z cd /staging
2021-01-30T17:43:16.2066033Z + cd /staging
2021-01-30T17:43:16.2067144Z PKG=`ls -1 *.$PACKAGER`
2021-01-30T17:43:16.2071801Z + ls -1 rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.2077605Z + PKG=rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.2078156Z sha512sum $PKG > $PKG.sha512sum
2021-01-30T17:43:16.2082909Z + sha512sum rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.2980622Z echo "Packarghe sha512sum:"
2021-01-30T17:43:16.2982010Z Packarghe sha512sum:
2021-01-30T17:43:16.2983098Z + echo 'Packarghe sha512sum:'
2021-01-30T17:43:16.2983564Z cat $PKG.sha512sum
2021-01-30T17:43:16.2984239Z + cat rakudo-pkg_2020.12.0-01_x86_64.apk.sha512sum
2021-01-30T17:43:16.2994216Z ls -la
2021-01-30T17:43:16.2994721Z + ls -la
2021-01-30T17:43:16.2997148Z 44a8e4fc86df34928c17e284e706519258b18d1f121163535b2258c52dae81ce2b66bedef00c490feaa904f3162fd507c0df76d147e4a21dcd932a711839620c  rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.3008192Z 
2021-01-30T17:43:16.3008688Z total 15240
2021-01-30T17:43:16.3009493Z drwxr-xr-x    2 root     root          4096 Jan 30 17:43 .
2021-01-30T17:43:16.3010321Z drwxr-xr-x    1 root     root          4096 Jan 30 17:43 ..
2021-01-30T17:43:16.3011124Z -rw-r--r--    1 root     root      15592068 Jan 30 17:43 rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.3012060Z -rw-r--r--    1 root     root           165 Jan 30 17:43 rakudo-pkg_2020.12.0-01_x86_64.apk.sha512sum
2021-01-30T17:43:16.3012900Z # Test the package
2021-01-30T17:43:16.3013511Z rm -rf /opt/rakudo-pkg
2021-01-30T17:43:16.3014170Z + rm -rf /opt/rakudo-pkg
2021-01-30T17:43:16.3331761Z $INSTALL_CMD
2021-01-30T17:43:16.3339838Z + apk add --no-cache --allow-untrusted rakudo-pkg_2020.12.0-01_x86_64.apk
2021-01-30T17:43:16.3403034Z fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
2021-01-30T17:43:16.4716912Z fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
2021-01-30T17:43:16.9533307Z (1/1) Installing rakudo-pkg (2020.12.0-01)
2021-01-30T17:43:16.9535039Z WARNING: rakudo-pkg-2020.12.0-01: support for packages without embedded checksums will be dropped in apk-tools 3.
2021-01-30T17:43:17.3677070Z 1 error; 304 MiB in 55 packages
2021-01-30T17:43:17.4288658Z ##[error]Process completed with exit code 1.

@tcurdt
Copy link

tcurdt commented Jan 31, 2021

Odd. I downloaded version 2.2.3 and could not yet find that error message in the code https://git.alpinelinux.org/apk-tools/tag/?h=v2.2.3

@tcurdt
Copy link

tcurdt commented Jan 31, 2021

@nxadm
Copy link

nxadm commented Jan 31, 2021

@nxadm
Copy link

nxadm commented Jan 31, 2021

Maybe totally irrelevant, but I created a packaged with fpm and it did not have this issue. fpm's implementation is here.

@tcurdt
Copy link

tcurdt commented Jan 31, 2021

Looking at that and this https://github.com/alpinelinux/apk-tools/blob/18b0b45b5b4e8d7be19afa1492c32abb75b9da4a/src/apk_io.h#L39 it seems like use a custom extension to the tar format.

@tcurdt
Copy link

tcurdt commented Jan 31, 2021

This can probably be fixed by adding the appropriate PAXRecords https://golang.org/pkg/archive/tar/#Header

@nxadm
Copy link

nxadm commented Jan 31, 2021

It may be easier to track the function that abuild command uses (tarhdr_checksum). abuild is the tool that Alpine uses in their howtos of how to create packages:

https://github.com/alpinelinux/abuild/blob/bda277481130c1fe5040e5e0f726d118524a6ca2/abuild-tar.c#L94

@tcurdt
Copy link

tcurdt commented Jan 31, 2021

Well, we need both :)

For now I was just wondering where they put the checksum. Because I didn't see anything else but the datahash when working out the format.

@djgilcrease
Copy link
Contributor Author

I tried switching to the PAX tar format and adding the records, but I am getting an error archive/tar: missed writing 10 bytes

var supportedChecksumHash = map[crypto.Hash]string{
	crypto.MD5: "MD5",
	crypto.SHA1: "SHA1",
	crypto.SHA256: "SHA256",
	crypto.SHA512: "SHA512",
}

func writeFile(tw *tar.Writer, header *tar.Header, file io.Reader, doHash bool) error {
	//header.Format = tar.FormatUSTAR
	header.Format = tar.FormatPAX
	header.ChangeTime = time.Time{}
	header.AccessTime = time.Time{}
	header.PAXRecords = make(map[string]string)
	if doHash {
		for hasher, name := range supportedChecksumHash {
			if !hasher.Available() {
				continue
			}
			hash := hasher.New()

			_, err := io.Copy(hash, file)
			if err != nil {
				return err
			}
			header.PAXRecords[fmt.Sprintf("APK-TOOLS.checksum.%s", name)] = fmt.Sprintf("%x", hash.Sum(nil))
			fmt.Printf("APK-TOOLS.checksum.%s = %x\n", name, hash.Sum(nil))
		}
	}

	err := tw.WriteHeader(header)
	if err != nil {
		println("THIS IS WHERE IT ERRORS!")
		return err
	}

	_, err = io.Copy(tw, file)
	if err != nil {
		return err
	}

	return nil
}
APK-TOOLS.checksum.MD5 = 14a7f05778753dec84782c623292a5f2
APK-TOOLS.checksum.SHA1 = da39a3ee5e6b4b0d3255bfef95601890afd80709
APK-TOOLS.checksum.SHA256 = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
APK-TOOLS.checksum.SHA512 = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e

Digging into this more

@tcurdt
Copy link

tcurdt commented Feb 2, 2021

I think the best approach is probably to reverse engineer an official package and compare.

@djgilcrease
Copy link
Contributor Author

djgilcrease commented Feb 3, 2021

90% sure I have it now, just finishing some local acceptance testing to verify.

The issue with my code in #288 (comment) was it was reading from the ioReader many times, so the actual file contents were not being written :p

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants