Skip to content

Feature/crytpo pbkdf2 - #5380

Merged
oleiade merged 23 commits into
grafana:masterfrom
rahulmedicharla:feature/crytpo-pbkdf2
Jan 13, 2026
Merged

Feature/crytpo pbkdf2#5380
oleiade merged 23 commits into
grafana:masterfrom
rahulmedicharla:feature/crytpo-pbkdf2

Conversation

@rahulmedicharla

@rahulmedicharla rahulmedicharla commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

What

This PR implements the PBKDF2 support in the webcrypto module following the WebCrypto Api specification.

Why?

Having support of the PBKDF2 makes our implementation compliant with web crypto API

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Closes #4267

rahulmedicharla and others added 4 commits November 7, 2025 07:37
This PR made this race condition apparent, so instead of adding another
PR to fix it, I've added a small commit here to fix the issue.
@rahulmedicharla
rahulmedicharla requested a review from a team as a code owner November 7, 2025 16:54
@rahulmedicharla
rahulmedicharla requested review from AgnesToulet and mstoykov and removed request for a team November 7, 2025 16:54
@CLAassistant

CLAassistant commented Nov 7, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 7, 2025 17:21 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 7, 2025 17:24 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 7, 2025 23:10 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 7, 2025 23:11 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 8, 2025 08:37 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 8, 2025 08:39 — with GitHub Actions Inactive
@mstoykov mstoykov added this to the v1.5.0 milestone Nov 17, 2025
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing November 18, 2025 12:45 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing January 2, 2026 10:31 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing January 2, 2026 10:32 — with GitHub Actions Inactive
@AgnesToulet AgnesToulet modified the milestones: v1.5.0, v1.6.0 Jan 5, 2026
oleiade
oleiade previously approved these changes Jan 7, 2026

@oleiade oleiade left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a couple of nits behind, but overall, this looks good to me 👍🏻

Great work there, and really happy to see this feature move forward 🙇🏻

Comment on lines +94 to +97
byteSalt, err := common.ToBytes(salt.Export())
if err != nil {
return nil, err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nit

I'm not sure where they got it from (I couldn't get a hold of that specific requirement in the specification), but the mozilla web api documentation for the PBKDF2 Params struct indicates it should be at least 16 bytes long, which makes sense to me: https://developer.mozilla.org/en-US/docs/Web/API/Pbkdf2Params#salt.

I remember the IV for encryption/decryption with AES should be 16 bytes though, maybe that's linked.

Even though there is no specific test for it in WPT, I think it would make sense to add that guardrail nonetheless, and add a unit test of our own, and document that behavior?

  byteSalt, err := common.ToBytes(salt.Export())
  if err != nil {
      return nil, err
  }
  if len(byteSalt) < 16 {
      return nil, NewError(OperationError, "salt must be at least 16 bytes")  // Similar error as when the iv is not 16 bytes in AES
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oleiade some WPT pbkdf2 tests use a 4 byte salt. I can update the tests to make them at min 16, but wanted to run it by you first if you wanted to me to change the actual test cases.

Comment thread examples/webcrypto/derive_bits/derive-bits-pbkdf2.js Outdated
Comment thread examples/webcrypto/derive_key/derive-key-pbkdf2.js Outdated
oleiade
oleiade previously approved these changes Jan 8, 2026
@oleiade
oleiade requested a review from AgnesToulet January 8, 2026 12:11
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing January 8, 2026 12:16 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing January 8, 2026 12:18 — with GitHub Actions Inactive
@oleiade

oleiade commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

@rahulmedicharla I wouldn't, we really want to keep the WPT tests as close as possible to the originals 🙇🏻

The Web Platform Tests are currently red though (I did not notice) was it always the case or did it just happen?

@rahulmedicharla

Copy link
Copy Markdown
Contributor Author

@oleiade no that just happened, it's because the WPT tests have valid test cases where the salt length is 4 bytes, so if I add the 16 byte restriction they are failing. If we don't want to change the WPT tests, we may have to revert that change.

@oleiade

oleiade commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

@rahulmedicharla I see, then apologies for the useless round-trip. Please revert the 16 bytes restriction. Our top priority should be for the WPT suite to pass. Sorry again for making you lose time.

I poked the k6 maintainers team on this PR, and once the tests are green again, I'll make sure we merge it as soon as possible 🙇🏻

@rahulmedicharla

Copy link
Copy Markdown
Contributor Author

@oleiade, no worries, I reverted the changes so it should pass now.

@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing January 9, 2026 13:24 — with GitHub Actions Inactive
@rahulmedicharla
rahulmedicharla temporarily deployed to azure-trusted-signing January 9, 2026 13:26 — with GitHub Actions Inactive

@AgnesToulet AgnesToulet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for your contribution 🚀

@AgnesToulet
AgnesToulet requested a review from oleiade January 13, 2026 13:35
@oleiade
oleiade merged commit 04a33c6 into grafana:master Jan 13, 2026
79 of 97 checks passed
@oleiade

oleiade commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Thanks a ton for you contribution @rahulmedicharla 🙇🏻

inancgumus added a commit to grafana/k6-docs that referenced this pull request Feb 4, 2026
Add documentation for the new PBKDF2 key derivation support:

- Add Pbkdf2Params documentation with properties (name, hash, salt, iterations)
- Add deriveKey method documentation with supported algorithms
- Update deriveBits to include PBKDF2 support and add Throws section
- Update importKey with PBKDF2 constraints (extractable=false, raw format only)
- Update supported algorithms tables to include PBKDF2

This documents the changes for grafana/k6#5380
inancgumus added a commit to grafana/k6-docs that referenced this pull request Feb 5, 2026
Add documentation for the new PBKDF2 key derivation support:

- Add Pbkdf2Params documentation with properties (name, hash, salt, iterations)
- Add deriveKey method documentation with supported algorithms
- Update deriveBits to include PBKDF2 support and add Throws section
- Update importKey with PBKDF2 constraints (extractable=false, raw format only)
- Update supported algorithms tables to include PBKDF2

This documents the changes for grafana/k6#5380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement PBKDF2 across supported API

6 participants