-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add signature support for the RPM module #27069
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
Merged
techknowlogick
merged 25 commits into
go-gitea:main
from
ExplodingDragon:feature-support-rpm-gpgsign
Aug 6, 2024
Merged
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9fdaf1c
support gpg sign for rpm
ExplodingDragon d2cf61a
Delete routers/api/packages/rpm/rpm.go.orig
ExplodingDragon 3aff155
Merge branch 'go-gitea:main' into feature-support-rpm-gpgsign
ExplodingDragon 6726a26
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 3b940d6
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 9b7585c
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 9215fa6
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 45fc0ce
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 4b7ac81
upgrade go-rpmutils to v0.4.0
ExplodingDragon 6ee4a63
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon e695115
Merge branch 'go-gitea:main' into feature-support-rpm-gpgsign
ExplodingDragon ca21f30
add test
ExplodingDragon 181cac8
add test
ExplodingDragon 613045b
clean style
ExplodingDragon 7c0b523
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 2c17a43
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon a45daa0
Merge branch 'feature-support-rpm-gpgsign' of https://github.com/Expl…
ExplodingDragon bd72a8f
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon a48fd6f
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 7ebc829
fix typo
ExplodingDragon 8278cd3
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 954e8ff
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon 4ff9396
clean style
ExplodingDragon b7337d4
Merge remote-tracking branch 'origin/feature-support-rpm-gpgsign' int…
ExplodingDragon d2d961a
Merge branch 'main' into feature-support-rpm-gpgsign
ExplodingDragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package rpm | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/packages" | ||
|
||
"github.com/ProtonMail/go-crypto/openpgp" | ||
"github.com/sassoftware/go-rpmutils" | ||
) | ||
|
||
func SignPackage(rpm *packages.HashedBuffer, privateKey string) (*packages.HashedBuffer, error) { | ||
keyring, err := openpgp.ReadArmoredKeyRing(bytes.NewReader([]byte(privateKey))) | ||
if err != nil { | ||
// failed to parse key | ||
return nil, err | ||
} | ||
entity := keyring[0] | ||
h, err := rpmutils.SignRpmStream(rpm, entity.PrivateKey, nil) | ||
if err != nil { | ||
// error signing rpm | ||
return nil, err | ||
} | ||
signBlob, err := h.DumpSignatureHeader(false) | ||
if err != nil { | ||
// error writing sig header | ||
return nil, err | ||
} | ||
if len(signBlob)%8 != 0 { | ||
log.Info("incorrect padding: got %d bytes, expected a multiple of 8", len(signBlob)) | ||
return nil, err | ||
} | ||
|
||
// move fp to sign end | ||
if _, err := rpm.Seek(int64(h.OriginalSignatureHeaderSize()), io.SeekStart); err != nil { | ||
return nil, err | ||
} | ||
// create signed rpm buf | ||
return packages.CreateHashedBufferFromReader(io.MultiReader(bytes.NewReader(signBlob), rpm)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package rpm | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"encoding/base64" | ||
"io" | ||
"strings" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/packages" | ||
|
||
"github.com/ProtonMail/go-crypto/openpgp" | ||
"github.com/sassoftware/go-rpmutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSignPackage(t *testing.T) { | ||
base64RpmPackageContent := `H4sICFayB2QCAGdpdGVhLXRlc3QtMS4wLjItMS14ODZfNjQucnBtAO2YV4gTQRjHJzl7wbNhhxVF | ||
VNwk2zd2PdvZ9Sxnd3Z3NllNsmF3o6congVFsWFHRWwIImIXfRER0QcRfPBJEXvvBQvWSfZTT0VQ | ||
8TF/MuU33zcz3+zOJGEe73lyuQBRBWKWRzDrEddjuVAkxLMc+lsFUOWfm5bvvReAalWECg/TsivU | ||
dyKa0U61aVnl6wj0Uxe4nc8F92hZiaYE8CO/P0r7/Quegr0c7M/AvoCaGZEIWNGUqMHrhhGROIUT | ||
Zc7gOAOraoQzCNZ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BWxTFEcp2IkYccYGp2LYySEfreq | ||
irue4WRF5XkpKovw2wgpq2rZBI8bQZkzxEkiYaNwxnXCCVvHidzIiB3CM2yMYdNWmjDsaLovaE4c | ||
x3a6mLaTxB7rEj3jWN4M2p7uwPaa1GfI8BHFfcZMKhkycnhR7y781/a+A4t7FpWWTupRUtKbegwZ | ||
XMKwJinTSe70uhRcj55qNu3YHtE922Fdz7FTMTq9Q3TbMdiYrrPudMvT44S6u2miu138eC0tTN9D | ||
2CFGHHtQsHHsGCRFDFbXuT9wx6mUTZfseydlkWZeJkW6xOgYjqXT+LA7I6XHaUx2xmUzqelWymA9 | ||
rCXI9+D1BHbjsITssqhBNysw0tOWjcpmIh6+aViYPfftw8ZSGfRVPUqKiosZj5R5qGmk/8AjjRbZ | ||
d8b3vvngdPHx3HvMeCarIk7VVSwbgoZVkceEVyOmyUmGxBGNYDVKSFSOGlIkGqWnUZFkiY/wsmhK | ||
Mu0UFYgZ/bYnuvn/vz4wtCz8qMwsHUvP0PX3tbYFUctAPdrY6tiiDtcCddDECahx7SuVNP5dpmb5 | ||
9tMDyaXb7OAlk5acuPn57ss9mw6Wym0m1Fq2cej7tUt2LL4/b8enXU2fndk+fvv57ndnt55/cQob | ||
7tpp/pEjDS7cGPZ6BY430+7danDq6f42Nw49b9F7zp6BiKpJb9s5P0AYN2+L159cnrur636rx+v1 | ||
7ae1K28QbMMcqI8CqwIrgwg9nTOp8Oj9q81plUY7ZuwXN8Vvs8wbAAA=` | ||
rpmPackageContent, err := base64.StdEncoding.DecodeString(base64RpmPackageContent) | ||
assert.NoError(t, err) | ||
zr, err := gzip.NewReader(bytes.NewReader(rpmPackageContent)) | ||
assert.NoError(t, err) | ||
content, err := io.ReadAll(zr) | ||
assert.NoError(t, err) | ||
privateKey, publicKey, err := generateKeypair() | ||
assert.NoError(t, err) | ||
buf, err := packages.CreateHashedBufferFromReader(bytes.NewReader(content)) | ||
assert.NoError(t, err) | ||
body, err := SignPackage(buf, privateKey) | ||
assert.NoError(t, err) | ||
signedBody, err := io.ReadAll(body) | ||
assert.NoError(t, err) | ||
pub, err := openpgp.ReadArmoredKeyRing(strings.NewReader(publicKey)) | ||
assert.NoError(t, err) | ||
_, sigs, err := rpmutils.Verify(bytes.NewBuffer(signedBody), pub) | ||
assert.NoError(t, err) | ||
assert.NotEqual(t, len(sigs), 0) | ||
_, sigs, err = rpmutils.Verify(bytes.NewBuffer(content), pub) | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(sigs), 0) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.