grafana / xk6-webcrypto

WIP implementation of the WebCrypto specification for k6
GNU Affero General Public License v3.0
7 stars 4 forks source link

Ensure to actually copy bytes when the specification requests it #42

Closed oleiade closed 1 year ago

oleiade commented 1 year ago

Certain steps in the WebCrypto API specification state something along the lines of:

Let data be the result of [getting a copy of the bytes held by](http://heycam.github.io/webidl/#dfn-get-buffer-source-copy) the data parameter passed to the [sign](https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-sign) method."

So far we had only extracted the bytes, without explicitly copying them. We recently found out this can lead to bugs. We should make sure that everywhere we implement such step, we actually copy the passed in buffer's bytes. This can be achieved with the following snippet:

    ab, err := exportArrayBuffer(sc.vu.Runtime(), signature)
    if err != nil {
        reject(err)
        return promise
    }
    signatureData := make([]byte, len(ab))
    copy(signatureData, ab)
oleiade commented 1 year ago

Make sure we use the existing constructs in the digest function 👀