| 32 | } |
| 33 | |
| 34 | func (ts *TimestampSigner) SignMessage(ctx context.Context, payload []byte) ([]byte, error) { |
| 35 | // TSA signature |
| 36 | tsa := sign.NewTimestampAuthority(&sign.TimestampAuthorityOptions{ |
| 37 | URL: ts.tsaURL, |
| 38 | }) |
| 39 | |
| 40 | // See bug: https://github.com/chainloop-dev/chainloop/issues/1832 |
| 41 | // signature might be encoded twice. Let's try to fix it first. |
| 42 | // TODO: remove this once the bug is fixed |
| 43 | toSign := payload |
| 44 | dst := make([]byte, base64.RawURLEncoding.DecodedLen(len(payload))) |
| 45 | i, err := base64.StdEncoding.Decode(dst, payload) |
| 46 | if err == nil { |
| 47 | // get the decoded |
| 48 | toSign = dst[:i] |
| 49 | } |
| 50 | |
| 51 | tsaSig, err := tsa.GetTimestamp(ctx, toSign) |
| 52 | if err != nil { |
| 53 | return nil, fmt.Errorf("getting timestamp signature: %w", err) |
| 54 | } |
| 55 | return tsaSig, nil |
| 56 | } |