Skip to content

Commit 03aa690

Browse files
bgn42soumeh01jkrech
authored
Introduced cache for PDSC files in .WEB. (#627)
… PDSC files need to be updated," Issue #2217 ## Fixes [Remove requirement that all PDSC files need to be updated](Open-CMSIS-Pack/devtools#2217) ## Changes Create and maintain a new cache.pidx file for .Web ## Checklist <!-- Put an `x` in the boxes. All tasks must be completed and boxes checked before merging. --> - [x] 🤖 This change is covered by unit tests (if applicable). - [x] 🤹 Manual testing has been performed (if necessary). - [x] 🛡️ Security impacts have been considered (if relevant). - [x] 📖 Documentation updates are complete (if required). - [x] 🧠 Third-party dependencies and TPIP updated (if required). --------- Co-authored-by: Sourabh Mehta <[email protected]> Co-authored-by: Sourabh Mehta <[email protected]> Co-authored-by: Joachim Krech <[email protected]>
1 parent e0b1a69 commit 03aa690

File tree

22 files changed

+2660
-253
lines changed

22 files changed

+2660
-253
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ jobs:
5555
- name: Install xmllint
5656
run: sudo apt-get update && sudo apt-get install libxml2-utils
5757

58+
- name: Archive tpip report
59+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
60+
with:
61+
name: tpip-report
62+
path: ./build/cpackget-ubuntu-amd64.txt
63+
5864
- name: Check if local_repository.pidx is valid
5965
run: |
6066
make test-xmllint-localrepository

cmd/commands/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Add a pack using the following "<pack>" specification or using packs provided by
100100
installer.UnlockPackRoot()
101101
for _, packPath := range args {
102102
var err error
103-
if filepath.Ext(packPath) == installer.PdscExtension {
103+
if filepath.Ext(packPath) == utils.PdscExtension {
104104
err = installer.AddPdsc(packPath)
105105
} else {
106106
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, false, viper.GetInt("timeout"))

cmd/commands/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot htt
5353
return err
5454
}
5555

56-
err = installer.UpdatePublicIndex(indexPath, true, true, initCmdFlags.downloadPdscFiles, false, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
56+
err = installer.UpdatePublicIndex(indexPath, true, initCmdFlags.downloadPdscFiles, false, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
5757
return err
5858
},
5959
}

cmd/commands/rm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ please use "--purge".`,
6060
installer.UnlockPackRoot()
6161
for _, packPath := range args {
6262
var err error
63-
if filepath.Ext(packPath) == installer.PdscExtension {
63+
if filepath.Ext(packPath) == utils.PdscExtension {
6464
err = installer.RemovePdsc(packPath)
6565
if err == errs.ErrPdscEntryNotFound {
6666
err = errs.ErrPackNotInstalled

cmd/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
7979
// Exclude index updating commands to not double update
8080
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "list" {
8181
installer.UnlockPackRoot()
82-
err = installer.UpdatePublicIndex(installer.ActualPublicIndex, true, true, false, false, false, true, 0, 0)
82+
err = installer.UpdatePublicIndex(installer.ActualPublicIndex, true, false, false, false, true, 0, 0)
8383
if err != nil {
8484
return err
8585
}

cmd/commands/update_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var UpdateIndexCmd = &cobra.Command{
4444
return err
4545
}
4646

47-
err = installer.UpdatePublicIndex("", true, updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
47+
err = installer.UpdatePublicIndex("", updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
4848
return err
4949
},
5050
}

cmd/cryptography/checksum.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
12-
"github.com/open-cmsis-pack/cpackget/cmd/installer"
1312
"github.com/open-cmsis-pack/cpackget/cmd/utils"
1413
log "github.com/sirupsen/logrus"
1514
)
@@ -64,7 +63,7 @@ func GenerateChecksum(sourcePack, destinationDir, hashFunction string) error {
6463
if !utils.DirExists(destinationDir) {
6564
return errs.ErrDirectoryNotFound
6665
}
67-
base = filepath.Clean(destinationDir) + string(filepath.Separator) + strings.TrimSuffix(string(filepath.Base(sourcePack)), installer.PackExtension)
66+
base = filepath.Clean(destinationDir) + string(filepath.Separator) + strings.TrimSuffix(string(filepath.Base(sourcePack)), utils.PackExtension)
6867
}
6968
checksumFilename := base + "." + strings.ReplaceAll(hashFunction, "-", "") + ".checksum"
7069
if utils.FileExists(checksumFilename) {
@@ -96,7 +95,7 @@ func VerifyChecksum(packPath, checksumPath string) error {
9695
// exist .checksums with different algos in the same dir
9796
if checksumPath == "" {
9897
for _, hash := range Hashes {
99-
checksumPath = strings.ReplaceAll(packPath, installer.PackExtension, "."+hash+".checksum")
98+
checksumPath = strings.ReplaceAll(packPath, utils.PackExtension, "."+hash+".checksum")
10099
if utils.FileExists(checksumPath) {
101100
break
102101
}

cmd/cryptography/signature.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ func validateSignatureScheme(zip *zip.ReadCloser, version string, signing bool)
4848
return "invalid"
4949
}
5050
// Warn the user if the tag was made by an older cpackget version
51-
if utils.SemverCompare(strings.Split(sv, "-")[1][1:], strings.Split(version, "-")[0][1:]) == -1 {
52-
log.Warnf("This pack was signed with an older version of cpackget (%s)", sv)
51+
svParts := strings.Split(sv, "-")
52+
versionParts := strings.Split(version, "-")
53+
if len(svParts) > 1 && len(versionParts) > 0 {
54+
// Extract version strings safely
55+
svVersion := strings.TrimPrefix(svParts[1], "v")
56+
vVersion := strings.TrimPrefix(versionParts[0], "v")
57+
if utils.SemverCompare(svVersion, vVersion) == -1 {
58+
log.Warnf("This pack was signed with an older version of cpackget (%s)", sv)
59+
}
5360
}
5461
if s[1] == "f" && len(s) == 4 {
5562
if !utils.IsBase64(s[2]) && !utils.IsBase64(s[3]) {
@@ -148,12 +155,19 @@ func sanityCheckCertificate(cert *x509.Certificate, vendor string) error {
148155
log.Warn("Certificate should not be a CA certificate")
149156
}
150157
ku := getKeyUsage(cert.KeyUsage)
151-
if len(ku) == 2 {
152-
if ku[0] != "\"Digital Signature\"" || ku[1] != "\"Content Commitment\"" {
153-
log.Warn("Does not have \"Digital Signature\" and \"Content Commitment\" key usage fields")
158+
// Check for required key usages: "Digital Signature" and "Content Commitment"
159+
hasDigitalSig := false
160+
hasContentCommit := false
161+
for _, usage := range ku {
162+
if usage == "\"Digital Signature\"" {
163+
hasDigitalSig = true
164+
}
165+
if usage == "\"Content Commitment\"" {
166+
hasContentCommit = true
154167
}
155-
} else {
156-
log.Warn("Does not have \"Digital Signature\" and \"Content Commitment\" key usage fields")
168+
}
169+
if !hasDigitalSig || !hasContentCommit {
170+
log.Warn("Does not have required \"Digital Signature\" and \"Content Commitment\" key usage fields")
157171
}
158172
return nil
159173
}
@@ -196,6 +210,7 @@ func exportCertificate(b64Cert, path string) error {
196210
if err != nil {
197211
return err
198212
}
213+
defer out.Close()
199214
b64, err := base64.StdEncoding.DecodeString(b64Cert)
200215
if err != nil {
201216
return err
@@ -237,7 +252,10 @@ func signPackHashX509(keyPath string, cert *x509.Certificate, hash []byte) ([]by
237252
b, err := isPrivateKeyFromCertificate(cert, block.Bytes, "PKCS1")
238253
if !b {
239254
log.Error("Private key does not derive from provided x509 certificate")
240-
return nil, err
255+
if err != nil {
256+
return nil, err
257+
}
258+
return nil, errs.ErrBadPrivateKey
241259
}
242260
rsaPrivateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
243261
if err != nil {
@@ -247,7 +265,10 @@ func signPackHashX509(keyPath string, cert *x509.Certificate, hash []byte) ([]by
247265
b, err := isPrivateKeyFromCertificate(cert, block.Bytes, "PKCS8")
248266
if !b {
249267
log.Error("Private key does not derive from provided x509 certificate")
250-
return nil, err
268+
if err != nil {
269+
return nil, err
270+
}
271+
return nil, errs.ErrBadPrivateKey
251272
}
252273
pk, err := x509.ParsePKCS8PrivateKey(block.Bytes)
253274
if err != nil {

0 commit comments

Comments
 (0)