blobPipelineDecryptionStep updates *stream to decrypt if, it necessary. srcInfo is only used for error messages. Returns data for other steps; the caller should eventually use updateCryptoOperation.
(stream *sourceStream, srcInfo types.BlobInfo)
| 34 | // srcInfo is only used for error messages. |
| 35 | // Returns data for other steps; the caller should eventually use updateCryptoOperation. |
| 36 | func (ic *imageCopier) blobPipelineDecryptionStep(stream *sourceStream, srcInfo types.BlobInfo) (*bpDecryptionStepData, error) { |
| 37 | if !isOciEncrypted(stream.info.MediaType) || ic.c.options.OciDecryptConfig == nil { |
| 38 | return &bpDecryptionStepData{ |
| 39 | decrypting: false, |
| 40 | }, nil |
| 41 | } |
| 42 | |
| 43 | if ic.cannotModifyManifestReason != "" { |
| 44 | return nil, fmt.Errorf("layer %s should be decrypted, but we can’t modify the manifest: %s", srcInfo.Digest, ic.cannotModifyManifestReason) |
| 45 | } |
| 46 | |
| 47 | desc := imgspecv1.Descriptor{ |
| 48 | Annotations: stream.info.Annotations, |
| 49 | } |
| 50 | // DecryptLayer supposedly returns a digest of the decrypted stream. |
| 51 | // In practice, that value is never set in the current implementation. |
| 52 | // And we shouldn’t use it anyway, because it is not trusted: encryption can be made to a public key, |
| 53 | // i.e. it doesn’t authenticate the origin of the metadata in any way. |
| 54 | reader, _, err := ocicrypt.DecryptLayer(ic.c.options.OciDecryptConfig, stream.reader, desc, false) |
| 55 | if err != nil { |
| 56 | return nil, fmt.Errorf("decrypting layer %s: %w", srcInfo.Digest, err) |
| 57 | } |
| 58 | |
| 59 | stream.reader = reader |
| 60 | stream.info.Digest = "" |
| 61 | stream.info.Size = -1 |
| 62 | maps.DeleteFunc(stream.info.Annotations, func(k string, _ string) bool { |
| 63 | return strings.HasPrefix(k, "org.opencontainers.image.enc") |
| 64 | }) |
| 65 | return &bpDecryptionStepData{ |
| 66 | decrypting: true, |
| 67 | }, nil |
| 68 | } |
| 69 | |
| 70 | // updateCryptoOperation sets *operation, if necessary. |
| 71 | func (d *bpDecryptionStepData) updateCryptoOperation(operation *types.LayerCrypto) { |
no test coverage detected