Wrap creation of CryptoConfig in constructors
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
f7761411b8
commit
364de4c35d
@ -88,11 +88,8 @@ var decryptCommand = cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cc := &encconfig.CryptoConfig{
|
cc := encconfig.InitDecryption(dcparameters)
|
||||||
DecryptConfig: &encconfig.DecryptConfig{
|
|
||||||
Parameters: dcparameters,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err = decryptImage(client, ctx, local, newName, cc, layers32, context.StringSlice("platform"))
|
_, err = decryptImage(client, ctx, local, newName, cc, layers32, context.StringSlice("platform"))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -133,14 +133,8 @@ var encryptCommand = cli.Command{
|
|||||||
dcparameters["privkeys-passwords"] = privKeysPasswords
|
dcparameters["privkeys-passwords"] = privKeysPasswords
|
||||||
dcparameters["x509s"] = decX509s
|
dcparameters["x509s"] = decX509s
|
||||||
|
|
||||||
cc := &encconfig.CryptoConfig{
|
cc := encconfig.InitEncryption(parameters, dcparameters)
|
||||||
EncryptConfig: &encconfig.EncryptConfig{
|
|
||||||
Parameters: parameters,
|
|
||||||
DecryptConfig: encconfig.DecryptConfig{
|
|
||||||
Parameters: dcparameters,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err = encryptImage(client, ctx, local, newName, cc, layers32, context.StringSlice("platform"))
|
_, err = encryptImage(client, ctx, local, newName, cc, layers32, context.StringSlice("platform"))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -129,14 +129,7 @@ func TestImageEncryption(t *testing.T) {
|
|||||||
dcparameters["privkeys"] = [][]byte{privateKey}
|
dcparameters["privkeys"] = [][]byte{privateKey}
|
||||||
dcparameters["privkeys-passwords"] = [][]byte{{}}
|
dcparameters["privkeys-passwords"] = [][]byte{{}}
|
||||||
|
|
||||||
cc := &encconfig.CryptoConfig{
|
cc := encconfig.InitEncryption(parameters, dcparameters)
|
||||||
EncryptConfig: &encconfig.EncryptConfig{
|
|
||||||
Parameters: parameters,
|
|
||||||
DecryptConfig: encconfig.DecryptConfig{
|
|
||||||
Parameters: dcparameters,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform encryption of image
|
// Perform encryption of image
|
||||||
encSpec, modified, err := imgenc.EncryptImage(ctx, client.ContentStore(), image.Target, cc, lf)
|
encSpec, modified, err := imgenc.EncryptImage(ctx, client.ContentStore(), image.Target, cc, lf)
|
||||||
@ -156,11 +149,8 @@ func TestImageEncryption(t *testing.T) {
|
|||||||
t.Fatalf("Unable to create image: %v", err)
|
t.Fatalf("Unable to create image: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cc = &encconfig.CryptoConfig{
|
cc = encconfig.InitDecryption(dcparameters)
|
||||||
DecryptConfig: &encconfig.DecryptConfig{
|
|
||||||
Parameters: dcparameters,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
// Clean up function cancels lease before deleting the image so the images are
|
// Clean up function cancels lease before deleting the image so the images are
|
||||||
// properly deleted
|
// properly deleted
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -415,15 +415,13 @@ func DecryptImage(ctx context.Context, cs content.Store, desc ocispec.Descriptor
|
|||||||
// It takes decrypting of the layers only as far as decrypting the asymmetrically encrypted data
|
// It takes decrypting of the layers only as far as decrypting the asymmetrically encrypted data
|
||||||
// The decryption is only done for the current platform
|
// The decryption is only done for the current platform
|
||||||
func CheckAuthorization(ctx context.Context, cs content.Store, desc ocispec.Descriptor, dc *encconfig.DecryptConfig) error {
|
func CheckAuthorization(ctx context.Context, cs content.Store, desc ocispec.Descriptor, dc *encconfig.DecryptConfig) error {
|
||||||
cc := encconfig.CryptoConfig{
|
cc := encconfig.InitDecryption(dc.Parameters)
|
||||||
DecryptConfig: dc,
|
|
||||||
}
|
|
||||||
|
|
||||||
lf := func(desc ocispec.Descriptor) bool {
|
lf := func(desc ocispec.Descriptor) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := cryptImage(ctx, cs, desc, &cc, lf, cryptoOpUnwrapOnly)
|
_, _, err := cryptImage(ctx, cs, desc, cc, lf, cryptoOpUnwrapOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "you are not authorized to use this image")
|
return errors.Wrapf(err, "you are not authorized to use this image")
|
||||||
}
|
}
|
||||||
|
@ -38,3 +38,26 @@ type CryptoConfig struct {
|
|||||||
EncryptConfig *EncryptConfig
|
EncryptConfig *EncryptConfig
|
||||||
DecryptConfig *DecryptConfig
|
DecryptConfig *DecryptConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitDecryption initialized a CryptoConfig object with parameters used for decryption
|
||||||
|
func InitDecryption(dcparameters map[string][][]byte) *CryptoConfig {
|
||||||
|
return &CryptoConfig{
|
||||||
|
DecryptConfig: &DecryptConfig{
|
||||||
|
Parameters: dcparameters,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitEncryption initializes a CryptoConfig object with parameters used for encryption
|
||||||
|
// It also takes dcparameters that may be needed for decryption when adding a recipient
|
||||||
|
// to an already encrypted image
|
||||||
|
func InitEncryption(parameters, dcparameters map[string][][]byte) *CryptoConfig {
|
||||||
|
return &CryptoConfig{
|
||||||
|
EncryptConfig: &EncryptConfig{
|
||||||
|
Parameters: parameters,
|
||||||
|
DecryptConfig: DecryptConfig{
|
||||||
|
Parameters: dcparameters,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user