Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BCrypt and Argon2 password handling to crypto module #577

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c25a395
[Automated] Update the native jar versions
randilt Jan 9, 2025
0714c09
Implement a password handling library using BCrypt
randilt Jan 9, 2025
296d158
Merge branch 'ballerina-platform:master' into implement-password-hand…
randilt Jan 9, 2025
0dee40b
Add Argon2 password hashing and verification functions with tests
randilt Jan 9, 2025
408b7ef
Add parameter validation to hashPasswordArgon2 and update testcase
randilt Jan 9, 2025
1824e22
Merge branch 'implement-password-handling-bcrypt' of https://github.c…
randilt Jan 9, 2025
62c3d0c
Add PasswordUtils class for password handling and validation functions
randilt Jan 9, 2025
a44a579
[Automated] Update the native jar versions
randilt Jan 9, 2025
5c44829
Refactor PasswordArgon2 to utilize PasswordUtils for salt generation …
randilt Jan 9, 2025
b6dd7b3
Add tests for password hash uniqueness and remove unused constant tim…
randilt Jan 10, 2025
e295de0
Remove debug print statements from password hashing tests and add not…
randilt Jan 10, 2025
8e6248f
Add copyright headers and improve documentation for password hashing …
randilt Jan 10, 2025
8262eae
Move all password handling functions to password.bal
randilt Jan 10, 2025
89d0995
Refactor PasswordArgon2 to use constants from PasswordUtils for Argon…
randilt Jan 10, 2025
ba7a1d5
Update license headers and remove .vscode folder
randilt Jan 13, 2025
d6c2a4e
Update native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Pas…
randilt Jan 14, 2025
f8a9cbe
Update native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Pas…
randilt Jan 14, 2025
e737920
Update native/src/main/java/io/ballerina/stdlib/crypto/PasswordUtils.…
randilt Jan 14, 2025
1e6a247
Apply suggestions from code review
randilt Jan 16, 2025
7626a78
Rename password hashing functions for clarity and update related tests
randilt Jan 16, 2025
aa04351
Rename password hashing functions in tests for consistency and clarity
randilt Jan 16, 2025
f1fce08
Add validation for empty passwords in Password and PasswordArgon2 cla…
randilt Jan 16, 2025
d939829
Add documentation for password hashing using BCrypt and Argon2 algori…
randilt Jan 16, 2025
2064262
Enhance documentation for password hashing algorithms, including deta…
randilt Jan 16, 2025
9c6d497
Update documentation links for password hashing section and algorithms
randilt Jan 16, 2025
927c46c
Update ballerina/tests/password_argon2_test.bal
randilt Jan 16, 2025
9bd44a9
Remove obsolete Argon2 test file to streamline test suite
randilt Jan 16, 2025
379bf97
Update changelog to include new APIs for password hashing and verific…
randilt Jan 16, 2025
9afed2b
Remove unreleased version from changelog
randilt Jan 16, 2025
8e5cc4b
Move BCrypt and Argon2 password hashing and verification functions to…
randilt Jan 17, 2025
5658f3e
Apply suggestions from code review
randilt Jan 17, 2025
aef45d0
Update changelog.md
randilt Jan 17, 2025
8249072
Implement suggested security fixes and use Locale.ROOT in String.form…
randilt Jan 19, 2025
20bbda9
Refactor constantTimeArrayEquals to use MessageDigest.isEqual from st…
randilt Jan 19, 2025
1569a4c
Add proposal for BCrypt and Argon2id password hashing support in Ball…
randilt Jan 20, 2025
c4793f3
Enhance password hashing proposal with future additions and API enhan…
randilt Jan 20, 2025
4c74cbf
Clarify future additions proposal for bcrypt and Argon2id hashing API…
randilt Jan 20, 2025
ce5419f
Update proposal document for bcrypt and Argon2id hashing APIs to incl…
randilt Jan 20, 2025
ea9fc44
Update bcrypt and Argon2id hashing proposal to include reviewer detai…
randilt Jan 20, 2025
f7e61af
Update bcrypt and Argon2id hashing proposal to include additional iss…
randilt Jan 20, 2025
cb75962
Update bcrypt and Argon2id hashing proposal to include reviewer infor…
randilt Jan 20, 2025
7becdb6
Update docs/proposals/bcrypt-argon2id-hashing-apis.md
randilt Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.11.0-20241121-075100-c4c87cbc"
distribution-version = "2201.11.0-20241218-101200-109f6cc7"

[[package]]
org = "ballerina"
Expand Down
61 changes: 61 additions & 0 deletions ballerina/hash.bal
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,64 @@ public isolated function crc32b(byte[] input) returns string = @java:Method {
name: "crc32b",
'class: "io.ballerina.stdlib.crypto.nativeimpl.Hash"
} external;

# Returns a BCrypt hash of the given password with optional work factor.
# ```ballerina
# string password = "mySecurePassword123";
# string|crypto:Error hash = crypto:hashBcrypt(password);
# ```
#
# + password - Password string to be hashed
# + workFactor - Optional work factor (cost parameter) between 4 and 31. Default is 12
# + return - BCrypt hashed password string or Error if hashing fails
public isolated function hashBcrypt(string password, int workFactor = 12) returns string|Error = @java:Method {
name: "hashPassword",
'class: "io.ballerina.stdlib.crypto.nativeimpl.Password"
} external;

# Verifies if a password matches a BCrypt hashed password.
# ```ballerina
# string password = "mySecurePassword123";
# string hashedPassword = "$2a$12$LQV3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewYpwBAM7RHF.H9m";
# boolean|crypto:Error matches = crypto:verifyBcrypt(password, hashedPassword);
# ```
#
# + password - Password string to verify
# + hashedPassword - BCrypt hashed password to verify against
# + return - Boolean indicating if password matches or Error if verification fails
public isolated function verifyBcrypt(string password, string hashedPassword) returns boolean|Error = @java:Method {
name: "verifyPassword",
'class: "io.ballerina.stdlib.crypto.nativeimpl.Password"
} external;

# Returns an Argon2id hash of the given password with optional parameters.
# ```ballerina
# string password = "mySecurePassword123";
# string|crypto:Error hash = crypto:hashArgon2(password);
# ```
#
# + password - Password string to be hashed
# + iterations - Optional number of iterations. Default is 3
# + memory - Optional memory usage in KB. Default is 65536 (64MB)
# + parallelism - Optional degree of parallelism. Default is 4
# + return - Argon2id hashed password string or Error if hashing fails
public isolated function hashArgon2(string password, int iterations = 3, int memory = 65536, int parallelism = 4) returns string|Error = @java:Method {
name: "hashPasswordArgon2",
'class: "io.ballerina.stdlib.crypto.nativeimpl.PasswordArgon2"
} external;

# Verifies if a password matches an Argon2id hashed password.
# ```ballerina
# string password = "mySecurePassword123";
# string hashedPassword = "$argon2id$v=19$m=65536,t=3,p=4$c29tZXNhbHQ$hash";
# boolean|crypto:Error matches = crypto:verifyArgon2(password, hashedPassword);
# ```
#
# + password - Password string to verify
# + hashedPassword - Argon2id hashed password to verify against
# + return - Boolean indicating if password matches or Error if verification fails
public isolated function verifyArgon2(string password, string hashedPassword) returns boolean|Error = @java:Method {
name: "verifyPasswordArgon2",
'class: "io.ballerina.stdlib.crypto.nativeimpl.PasswordArgon2"
} external;

Loading
Loading