@@ -191,21 +191,21 @@ func createGPGClient(context *cli.Context) (encryption.GPGClient, error) {
191191 return encryption .NewGPGClient (context .String ("gpg-version" ), context .String ("gpg-homedir" ))
192192}
193193
194- func getGPGPrivateKeys (context * cli.Context , gpgSecretKeyRingFiles [][]byte , descs []ocispec.Descriptor , mustFindKey bool , dcparameters map [ string ][][] byte ) error {
194+ func getGPGPrivateKeys (context * cli.Context , gpgSecretKeyRingFiles [][]byte , descs []ocispec.Descriptor , mustFindKey bool ) ( gpgPrivKeys [ ][]byte , gpgPrivKeysPwds [][] byte , err error ) {
195195 gpgClient , err := createGPGClient (context )
196196 if err != nil {
197- return err
197+ return nil , nil , err
198198 }
199199
200200 var gpgVault encryption.GPGVault
201201 if len (gpgSecretKeyRingFiles ) > 0 {
202202 gpgVault = encryption .NewGPGVault ()
203203 err = gpgVault .AddSecretKeyRingDataArray (gpgSecretKeyRingFiles )
204204 if err != nil {
205- return err
205+ return nil , nil , err
206206 }
207207 }
208- return encryption .GPGGetPrivateKey (descs , gpgClient , gpgVault , mustFindKey , dcparameters )
208+ return encryption .GPGGetPrivateKey (descs , gpgClient , gpgVault , mustFindKey )
209209}
210210
211211func createLayerFilter (client * containerd.Client , ctx gocontext.Context , desc ocispec.Descriptor , layers []int32 , platformList []ocispec.Platform ) (imgenc.LayerFilter , error ) {
@@ -359,47 +359,62 @@ func filterLayerDescriptors(alldescs []ocispec.Descriptor, layers []int32, pl []
359359 return layerInfos , descs
360360}
361361
362- // CreateDcParameters creates the decryption parameter map from command line options and possibly
362+ // CreateDecryptCryptoConfig creates the CryptoConfig object that contains the necessary
363+ // information to perform decryption from command line options and possibly
363364// LayerInfos describing the image and helping us to query for the PGP decryption keys
364- func CreateDcParameters (context * cli.Context , descs []ocispec.Descriptor ) (map [ string ][][] byte , error ) {
365- dcparameters := make ( map [ string ][][] byte )
365+ func CreateDecryptCryptoConfig (context * cli.Context , descs []ocispec.Descriptor ) (encconfig. CryptoConfig , error ) {
366+ ccs := []encconfig. CryptoConfig {}
366367
367368 // x509 cert is needed for PKCS7 decryption
368369 _ , _ , x509s , err := processRecipientKeys (context .StringSlice ("dec-recipient" ))
369370 if err != nil {
370- return nil , err
371+ return encconfig. CryptoConfig {} , err
371372 }
372373
373374 gpgSecretKeyRingFiles , gpgSecretKeyPasswords , privKeys , privKeysPasswords , err := processPrivateKeyFiles (context .StringSlice ("key" ))
374375 if err != nil {
375- return nil , err
376+ return encconfig. CryptoConfig {} , err
376377 }
377378
378379 _ , err = createGPGClient (context )
379380 gpgInstalled := err == nil
380381 if gpgInstalled {
381382 if len (gpgSecretKeyRingFiles ) == 0 && len (privKeys ) == 0 && descs != nil {
382383 // Get pgp private keys from keyring only if no private key was passed
383- err = getGPGPrivateKeys (context , gpgSecretKeyRingFiles , descs , true , dcparameters )
384+ gpgPrivKeys , gpgPrivKeyPasswords , err : = getGPGPrivateKeys (context , gpgSecretKeyRingFiles , descs , true )
384385 if err != nil {
385- return nil , err
386+ return encconfig. CryptoConfig {} , err
386387 }
387- } else {
388- if len (gpgSecretKeyRingFiles ) == 0 {
389- dcparameters ["gpg-client" ] = [][]byte {[]byte ("1" )}
390- dcparameters ["gpg-client-version" ] = [][]byte {[]byte (context .String ("gpg-version" ))}
391- dcparameters ["gpg-client-homedir" ] = [][]byte {[]byte (context .String ("gpg-homedir" ))}
392- } else {
393- dcparameters ["gpg-privatekeys" ] = gpgSecretKeyRingFiles
394- dcparameters ["gpg-privatekeys-passwords" ] = gpgSecretKeyPasswords
388+
389+ gpgCc , err := encconfig .DecryptWithGpgPrivKeys (gpgPrivKeys , gpgPrivKeyPasswords )
390+ if err != nil {
391+ return encconfig.CryptoConfig {}, err
392+ }
393+ ccs = append (ccs , gpgCc )
394+
395+ } else if len (gpgSecretKeyRingFiles ) > 0 {
396+ gpgCc , err := encconfig .DecryptWithGpgPrivKeys (gpgSecretKeyRingFiles , gpgSecretKeyPasswords )
397+ if err != nil {
398+ return encconfig.CryptoConfig {}, err
395399 }
400+ ccs = append (ccs , gpgCc )
401+
396402 }
397403 }
398- dcparameters ["privkeys" ] = privKeys
399- dcparameters ["privkeys-passwords" ] = privKeysPasswords
400- dcparameters ["x509s" ] = x509s
401404
402- return dcparameters , nil
405+ x509sCc , err := encconfig .DecryptWithX509s (x509s )
406+ if err != nil {
407+ return encconfig.CryptoConfig {}, err
408+ }
409+ ccs = append (ccs , x509sCc )
410+
411+ privKeysCc , err := encconfig .DecryptWithPrivKeys (privKeys , privKeysPasswords )
412+ if err != nil {
413+ return encconfig.CryptoConfig {}, err
414+ }
415+ ccs = append (ccs , privKeysCc )
416+
417+ return encconfig .CombineCryptoConfigs (ccs ), nil
403418}
404419
405420// parsePlatformArray parses an array of specifiers and converts them into an array of specs.Platform
0 commit comments