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

fix(server): random generate default value #2568

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
HugeAccess::fromEdge);

this.tokenGenerator = new TokenGenerator(config);
LOG.info("Randomly generate a JWT secret key now");

Check warning on line 110 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java#L110

Added line #L110 was not covered by tests

this.ipWhiteList = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import static org.apache.hugegraph.config.OptionChecker.rangeDouble;
import static org.apache.hugegraph.config.OptionChecker.rangeInt;

import java.security.SecureRandom;
import java.util.Base64;

public class AuthOptions extends OptionHolder {

private AuthOptions() {
Expand Down Expand Up @@ -90,7 +93,7 @@
"auth.token_secret",
"Secret key of HS256 algorithm.",
disallowEmpty(),
"FXQXbJtbCLxODc6tGci732pkH1cyf8Qg"
generateRandomBase64Key()

Check warning on line 96 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/AuthOptions.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/AuthOptions.java#L96

Added line #L96 was not covered by tests
);

public static final ConfigOption<Double> AUTH_AUDIT_LOG_RATE =
Expand Down Expand Up @@ -126,4 +129,12 @@
rangeInt(0L, Long.MAX_VALUE),
(3600 * 24L)
);

private static String generateRandomBase64Key() {
SecureRandom random = new SecureRandom();

Check warning on line 134 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/AuthOptions.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/AuthOptions.java#L134

Added line #L134 was not covered by tests
// 32 bytes for HMAC-SHA256
byte[] bytes = new byte[32];
random.nextBytes(bytes);
return Base64.getEncoder().encodeToString(bytes);

Check warning on line 138 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/AuthOptions.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/AuthOptions.java#L136-L138

Added lines #L136 - L138 were not covered by tests
}
}
Loading