DSSEEnvelopeFromBundle Extracts a DSSE envelope from a Sigstore bundle (Sigstore bundles have their own protobuf implementation for DSSE)
(bundle *protobundle.Bundle)
| 45 | |
| 46 | // DSSEEnvelopeFromBundle Extracts a DSSE envelope from a Sigstore bundle (Sigstore bundles have their own protobuf implementation for DSSE) |
| 47 | func DSSEEnvelopeFromBundle(bundle *protobundle.Bundle) *dsse.Envelope { |
| 48 | sigstoreEnvelope := bundle.GetDsseEnvelope() |
| 49 | sig := sigstoreEnvelope.GetSignatures()[0].GetSig() |
| 50 | // See bug: https://github.com/chainloop-dev/chainloop/issues/1832 |
| 51 | // signature might be encoded twice. Let's try to fix it first. |
| 52 | // TODO: remove this once the bug is fixed |
| 53 | sigBytes := sig |
| 54 | dst := make([]byte, base64.RawURLEncoding.DecodedLen(len(sig))) |
| 55 | i, err := base64.StdEncoding.Decode(dst, sig) |
| 56 | if err == nil { |
| 57 | // it was already encoded, let's use the decoded one |
| 58 | sigBytes = dst[:i] |
| 59 | } |
| 60 | return &dsse.Envelope{ |
| 61 | PayloadType: sigstoreEnvelope.PayloadType, |
| 62 | Payload: base64.StdEncoding.EncodeToString(sigstoreEnvelope.Payload), |
| 63 | Signatures: []dsse.Signature{ |
| 64 | { |
| 65 | KeyID: sigstoreEnvelope.GetSignatures()[0].GetKeyid(), |
| 66 | Sig: base64.StdEncoding.EncodeToString(sigBytes), |
| 67 | }, |
| 68 | }, |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | func BundleFromDSSEEnvelope(dsseEnvelope *dsse.Envelope) (*protobundle.Bundle, error) { |
| 73 | if len(dsseEnvelope.Signatures) == 0 { |
no outgoing calls