@@ -25,8 +25,10 @@ import (
2525 "fmt"
2626 "strings"
2727
28+ "github.com/containers/ocicrypt/config/pkcs11config"
2829 "github.com/containers/ocicrypt/crypto/pkcs11"
2930 "github.com/go-jose/go-jose/v4"
31+ "go.yaml.in/yaml/v3"
3032 "golang.org/x/crypto/openpgp"
3133)
3234
@@ -216,22 +218,37 @@ func SortDecryptionKeys(b64ItemList string) (map[string][][]byte, error) {
216218 return nil , errors .New ("Could not base64 decode a passed decryption key password" )
217219 }
218220 }
221+
219222 var key string
220- isPrivKey , err := IsPrivateKey (keyData , password )
221- if IsPasswordError (err ) {
222- return nil , err
223- }
224- if isPrivKey {
225- key = "privkeys"
226- if _ , ok := dcparameters ["privkeys-passwords" ]; ! ok {
227- dcparameters ["privkeys-passwords" ] = [][]byte {password }
228- } else {
229- dcparameters ["privkeys-passwords" ] = append (dcparameters ["privkeys-passwords" ], password )
223+ if IsPkcs11PrivateKey (keyData ) {
224+ p11conf , err := pkcs11config .GetUserPkcs11Config ()
225+ if err != nil {
226+ return nil , err
227+ }
228+ p11ConfYaml , err := yaml .Marshal (p11conf )
229+ if err != nil {
230+ return nil , fmt .Errorf ("Could not marshal Pkcs11Config to Yaml: %w" , err )
231+ }
232+ dcparameters ["pkcs11-config" ] = [][]byte {p11ConfYaml }
233+
234+ key = "pkcs11-yamls"
235+ } else {
236+ isPrivKey , err := IsPrivateKey (keyData , password )
237+ if IsPasswordError (err ) {
238+ return nil , err
239+ }
240+ if isPrivKey {
241+ key = "privkeys"
242+ if _ , ok := dcparameters ["privkeys-passwords" ]; ! ok {
243+ dcparameters ["privkeys-passwords" ] = [][]byte {password }
244+ } else {
245+ dcparameters ["privkeys-passwords" ] = append (dcparameters ["privkeys-passwords" ], password )
246+ }
247+ } else if IsCertificate (keyData ) {
248+ key = "x509s"
249+ } else if IsGPGPrivateKeyRing (keyData ) {
250+ key = "gpg-privatekeys"
230251 }
231- } else if IsCertificate (keyData ) {
232- key = "x509s"
233- } else if IsGPGPrivateKeyRing (keyData ) {
234- key = "gpg-privatekeys"
235252 }
236253 if key != "" {
237254 values := dcparameters [key ]
0 commit comments