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 ExpiringSet not really working & causing memory leaks (#3027) #1

Open
wants to merge 226 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
226 commits
Select commit Hold shift + click to select a range
f5cdb98
Fix ExpiringSet not really working & causing memory leaks (#3027)
lucko May 19, 2021
05c9ca5
Properly cleanup JarInJarClassLoader when plugin disables
lucko May 23, 2021
ad49508
Some misc tidying up
lucko May 23, 2021
044decc
Fabric, fix GameMode.NOT_SET removed in 1.17 (#3053)
TjeuKayim Jun 10, 2021
a63be10
Implement command list updater for Fabric (#3060)
TjeuKayim Jun 10, 2021
8ae7099
Generify SqlStorage shutdown exception message (#3039)
yakovliam Jun 10, 2021
5120292
Update commodore for MC 1.17 support
lucko Jun 12, 2021
4598435
Fix extension loading causing whole plugin to error
lucko Jun 13, 2021
979c80d
Clarify config comments for mongodb-connection-uri option (#3062)
lucko Jun 15, 2021
fb36bd0
Bulk update triggers for group related commands (#3073)
emilyy-dev Jul 4, 2021
563b5be
Implement enable-ops and auto-op on Fabric (#3069)
emilyy-dev Jul 4, 2021
cfb298f
Use different classifier for dependency files with Bukkit-Legacy rema…
lucko Jul 8, 2021
5a377e7
Fix NPE from null primary group in Vault hook (#3103)
lucko Jul 18, 2021
5ea2aee
More helpful error message when user is null in API PlayerAdapter (#3…
lucko Jul 18, 2021
26de6d3
Update Velocity to 3.0.0, use a Continuation for permissions setup event
lucko Jul 9, 2021
4332725
Fix bad Continuation usage in Velocity listener
lucko Jul 31, 2021
0fa3095
Save renamed group before syncing with storage (#3129)
emilyy-dev Aug 6, 2021
b3ebf20
Update adventure-platform for 1.17 (#3127)
lucko Aug 6, 2021
ee6aa47
Listen for ServerPostConnectEvent in Velocity context listener (#3133)
lucko Aug 14, 2021
b232cb9
ReflectionClassPathAppender on Java 16+
lucko Aug 17, 2021
ba52259
Update to Gradle 7 (#3051)
BomBardyGamer Aug 20, 2021
93683c3
Update Fabric to 1.17, fix version placeholder filtering
lucko Aug 20, 2021
a182768
Change user housekeeper to be more lenient towards API usage (#3143)
lucko Aug 25, 2021
062fca3
Fix Fabric version placeholder in metadata file (#3141)
lucko Aug 25, 2021
9cd33d2
Fix toLowerCase/toUpperCase locale sensitivity
lucko Aug 25, 2021
5735e0e
Fix fabric/build.gradle placeholder replacement (#3153)
emilyy-dev Sep 4, 2021
4e2807c
Refactor mod container retrieval in Fabric mod
lucko Sep 10, 2021
d1cb644
Fix empty prefix/suffix strings in YAML storage (#3139, #3160)
lucko Sep 10, 2021
2cf77db
TranslationManager fixes and improvements (#3165)
lucko Sep 18, 2021
04bb035
Add warning nore about enable-ops to config files (#3170)
RedstoneFuture Oct 3, 2021
b2c76ac
Improve translations handling (#3166)
lucko Oct 10, 2021
9c5a43b
Allow meta/prefix/suffix nodes to be negated to cancel inheritance (#…
lucko Oct 18, 2021
f84f425
Better issue templates (#3184)
Laarryy Oct 22, 2021
00b62d7
Edit issue templates
lucko Oct 22, 2021
f896ed7
Edit issue templates (again)
lucko Oct 22, 2021
848fc35
Added redis authentication with username (#3201)
EduardWayland Nov 12, 2021
c9d4c7d
ContextSet performance improvements (#3209)
lucko Nov 17, 2021
272d289
More context performance improvements (#3209)
lucko Nov 18, 2021
9204848
Fix username lookup returning "null" instead of null (#3220)
lucko Nov 27, 2021
594f50b
Add config option to disable context calculators
lucko Nov 27, 2021
10f698b
Add warning for common editor mistakes
lucko Nov 27, 2021
d6c810a
Fix player insert duplicate key issue with PSQL (#3223)
tadhgboyle Nov 27, 2021
6e07d6a
Revert "Fix player insert duplicate key issue with PSQL (#3223)"
lucko Nov 28, 2021
e227d96
Fix sql insert player query (#3225)
lucko Nov 28, 2021
64bd8b5
Add pagination to listgroups command (#3226)
tadhgboyle Nov 30, 2021
fa17404
Fabric 1.18
lucko Nov 30, 2021
f35a9b6
Update dependencies for 1.18
lucko Dec 2, 2021
9c08741
Fix cast to long in MongoStorage
lucko Dec 4, 2021
8cc126f
Add config option to disable bulkupdate functionality
lucko Dec 9, 2021
664cad2
Clarify uuid type in user info command (#3233)
lucko Dec 10, 2021
ae93c97
Add default file name for export command (#3248)
OmegaWeaponDev Dec 31, 2021
2d662cb
Retain cause node information for cached permission/meta data (#3250)
lucko Dec 31, 2021
419d711
Add full support for transient permissions through Vault API (#3258)
CuddleTheif Dec 31, 2021
d319d8d
Fix TristateResult NPE
lucko Dec 31, 2021
acdc259
Fix MetaValueSelector NPE
lucko Dec 31, 2021
6781c1f
Provide API access to cached data result info (#3243)
lucko Jan 1, 2022
4de7448
Include whether a node is normal/transient in InheritanceOriginMetadata
lucko Jan 1, 2022
a53c9fa
Reuse the same InheritanceOrigin object where possible
lucko Jan 1, 2022
f61d9ff
Fix NPE from permission holder initialisation order (#3263)
lucko Jan 2, 2022
d3029a8
Web editor socket connection (#3303)
lucko Feb 7, 2022
ee79f53
SpongeAPI 8 (#2728)
lucko Feb 7, 2022
65751cd
Velocity world context use ServerConnectedEvent (#3245)
lucko Feb 7, 2022
fe80ba6
Shutdown ForkJoinPool worker on disable (#3247)
lucko Feb 7, 2022
1b3b9b5
Update commodore to fix running LP commands from a Forge client (#3299)
lucko Feb 7, 2022
bc15e34
Optimize bulk user loading for editor command (#3273)
lucko Feb 8, 2022
0fe85ed
Ignore http 503 error from socket server
lucko Feb 9, 2022
b13a74c
Pre-generate web editor keypair to speed up initial session init
lucko Feb 9, 2022
d45d9a2
Optimize parent resolution in info commands (#3309)
Sxtanna Feb 9, 2022
59f3866
Warn if the API was classloaded by another plugin
lucko Feb 9, 2022
99c3d68
API 5.4
lucko Feb 9, 2022
3eca620
Fix API buildscript
lucko Feb 9, 2022
86d2523
Fix SpongePlayerCalculator errors
lucko Feb 11, 2022
5c8b0a6
Maintain order in editor users/groups collection
lucko Feb 16, 2022
b235234
Sponge use jar-in-jar loader
lucko Feb 17, 2022
4bdcca6
Update mongodb driver
lucko Feb 20, 2022
8ed6315
Set mongodb uuid representation (#3324)
lucko Feb 27, 2022
775f1ad
Support for command completions on Bukkit 1.18.2
lucko Feb 28, 2022
f840c76
Don't pretty-print exporter json (#3329)
lucko Feb 28, 2022
138f2c1
Provide snakeyaml for Fabric (#3325)
lucko Feb 28, 2022
eeec818
Allow server name to be specified with an env var (#3341)
schneidermr Mar 16, 2022
405c5c3
Fix typo with env var reading (#3345)
schneidermr Mar 18, 2022
fb56189
Improve AbstractJavaScheduler (#3326)
lucko Mar 19, 2022
eece15d
Close web editor sockets on plugin disable (#3326)
lucko Mar 20, 2022
5647b2e
Shutdown okhttp on plugin disable (#3347)
lucko Mar 23, 2022
2e0a4d7
Fix redis close (#3353)
lucko Mar 27, 2022
126631f
Load configuration from env or system props (#3294)
lucko Apr 3, 2022
3487391
Show sql table prefix if set in '/lp info' (#3360)
ZeromaniacMc Apr 8, 2022
207e4aa
Show table prefix in a different colour
lucko Apr 8, 2022
b3cdf67
Add error logging for failed plugin message parse (#3364)
lucko Apr 24, 2022
e0ee2c3
Resolve command entity selectors on Fabric (#3363)
emilyy-dev Apr 24, 2022
c35958b
Fix plugin message string encoding inconsistency (#3364)
lucko Apr 24, 2022
e6cc817
Update nexus mirror url
lucko May 15, 2022
65a4c67
Fix bug in Sponge PermissionServiceProxy
lucko May 19, 2022
6421525
LuckPerms for Forge (#3262)
LXGaming May 20, 2022
62a8891
Fix buildscript
lucko May 20, 2022
a368509
Use Forge default resolver when result is undefined (#3390)
IzzelAliz Jun 6, 2022
7824566
Fabric 1.19 (#3394)
Aurelien30000 Jun 11, 2022
79a0861
Increase memory allocation for Gradle
lucko Jun 12, 2022
9b2bbb3
Bump adventure version
lucko Jun 12, 2022
016f35a
Update Bukkit dependencies for full 1.19 support
lucko Jun 12, 2022
bf93077
MetaCache refactoring
lucko Jul 17, 2022
fbc0787
Implement Fabric meta/options API
lucko Jul 17, 2022
8b0d6fd
Fix compile
lucko Jul 18, 2022
d36341c
Implement standalone/cli app
lucko Jul 20, 2022
48e5f42
Change standalone image name
lucko Jul 20, 2022
ad08b15
Forge 1.19 (#3397)
LXGaming Jul 24, 2022
55d291f
Update dependencies for 1.19.1 support (#3440)
lucko Aug 3, 2022
106455a
Fabric 1.19.1 (#3437)
PotatoPresident Aug 3, 2022
8ebdbdb
Fix Forge user data sometimes missing after switching worlds (#3447)
IzzelAliz Aug 3, 2022
fe0cb2d
Fix Bukkit tab complete (#3449)
lucko Aug 3, 2022
b195363
Add healthcheck for standalone app
lucko Aug 5, 2022
6e0e0e8
Forge 1.19.2 (#3477)
CDAGaming Sep 5, 2022
b6b3788
Change socket is verified check
lucko Sep 5, 2022
afc6904
Fabric 1.19.2
lucko Sep 5, 2022
a2e4a81
Update Paper maven repo (#3393)
BlockyTheDev Sep 5, 2022
1790c0a
Fix concurrent errors in URLClassLoaderAccess (#3403)
OOP-778 Sep 5, 2022
44470c8
Fix yaml usage on Forge/Fabric (#3381)
lucko Sep 30, 2022
8bbb699
Don't pretty-print '/lp export' json (#3489)
maxcom1 Sep 30, 2022
495d951
Declare module name for API (#3482)
lucko Sep 30, 2022
e35f467
Upgrade h2 database engine to v2 (#3458)
lucko Oct 16, 2022
dc22847
Fabric offline permission check event (#3504)
DrexHD Oct 16, 2022
5ff9a12
Preload dependencies in Docker image
lucko Oct 21, 2022
0193c06
Add Nats messenger (#3525)
sadcenter Nov 26, 2022
5555cda
Update nukkit maven repository
lucko Nov 27, 2022
8e1553c
Use unix domain socket for Docker commands
lucko Dec 10, 2022
ed9dd03
Add basic rate-limit for commands (#3546)
lucko Dec 28, 2022
4d726f4
Update Forge and Fabric to 1.19.3 (#3550)
JT122406 Jan 1, 2023
3ecdeac
Add more unit tests (#3555)
lucko Jan 5, 2023
a5ba53d
Restore offline mode support for Fabric servers (#3576)
nikijaz Jan 29, 2023
1bfbd27
Update fabric/forge versions
lucko Jan 29, 2023
ce6031a
Fix obtaining UserCapability on Forge for respawned players
lucko Feb 12, 2023
1f8b66c
Fix suffix.duplicates config setting being ignored (#3592, #3590)
emilyy-dev Feb 19, 2023
4037570
Add 'paste' to verbose command tab completions (#3598)
darbyjack Mar 1, 2023
536c918
Fix Nukkit maven repo
lucko Mar 7, 2023
62f2fc9
Fix Forge player data corrupted on respawn (#3557, #3584, #3596, #3601)
bloodmc Mar 13, 2023
5631a8b
Compile forge/fabric against MC 1.19.4
lucko Mar 15, 2023
1fb62d2
Cleanup classloaders on shutdown (#3605)
emilyy-dev Mar 19, 2023
85a49f0
Handle invalid empty command inputs (#3606)
emilyy-dev Mar 29, 2023
e61ac8b
Add tests for messages/components/translations
lucko Mar 29, 2023
6523e70
Add more tests
lucko Apr 1, 2023
4068c71
Add integration tests for storage and messaging
lucko Apr 1, 2023
9039251
Implement messenger using Postgres listen/notify (#3641)
lucko Apr 30, 2023
0ae751b
Reformat import statements
lucko Apr 30, 2023
ef85fa8
Fix docker tests
lucko May 1, 2023
cfe0d80
Add date on hover to actionlog (#3597)
Diddyy May 1, 2023
9640271
Reattempt RabbitMQ connection on first attempt
lucko May 1, 2023
6d4ed22
Update mariadb driver (#3583)
Kamillaova May 1, 2023
bd08507
Add automated tests for commands
lucko May 1, 2023
84bd2ee
Add more tests
lucko May 1, 2023
6d2a5a6
Fix issues with postgres storage backend (#3647)
lucko Jun 8, 2023
8048427
Tag docker images with LP version
lucko Jun 8, 2023
da08be0
Fix github action to fetch repo with tags
lucko Jun 8, 2023
d859085
Update Fabric/Forge to Minecraft 1.20
lucko May 30, 2023
2e5a1d7
Switch back to official Postgres JDBC driver
lucko Jun 11, 2023
081a4f8
Fix Forge reobf shadowjar (#3675)
lucko Jun 14, 2023
acd8d6e
Include standalone data directory in gitignore (#3671)
powercasgamer Jun 14, 2023
3542a6c
Improve console detection on Fabric/Forge (#3673)
DrexHD Jun 14, 2023
5dd8087
Update Forge/Fabric to 1.20.1
lucko Jun 14, 2023
9f1e74f
Fix user deletion not being correctly processed on SQL backends (#3664)
lucko Jun 18, 2023
7a59536
Add support for redis cluster (#3670)
Dominik48N Jun 23, 2023
feef08a
Update GitHub URLs to new location (#3686)
mja00 Jun 23, 2023
86cc90f
Refactor gradle plugin version handling (#3665)
powercasgamer Jun 23, 2023
35dfc2c
Render minimessage in prefix/suffix/meta values (#3672)
powercasgamer Jun 23, 2023
7297fb8
whoops (#3691)
powercasgamer Jun 24, 2023
f788088
Delete temporary H2 v1 to v2 migration script if exists (#3693)
lucko Jun 25, 2023
77a5a7b
Print test output when ran through Gradle
lucko Jun 25, 2023
9f4082c
Add more unit/integration tests
lucko Jun 25, 2023
8fbd791
Add missing future join call to storage test
lucko Jun 25, 2023
6d8b6bd
Add jacoco report gradle plugin
lucko Aug 5, 2023
b8d1f52
Use ansi component serializer
lucko Aug 5, 2023
71416ba
Use driver class instead of datasource for Postgres (#3705)
lucko Aug 5, 2023
f12d3cd
Fix race error in bulk update integration test
lucko Aug 5, 2023
331a328
Upgrade Fabric to MC 1.20.2
lucko Oct 2, 2023
822c796
Update adventure-platform for MC 1.20.2 support
lucko Oct 2, 2023
3707d2f
Add healthcheck functionality to API
lucko Oct 22, 2023
84fce98
Change healthcheck details return type
lucko Oct 22, 2023
f999f9f
Fix duplicate UUID delete with Mongo storage (#3777)
huanmeng-qwq Nov 6, 2023
f78e2d6
Update Minecraft wiki links in config file comments (#3758)
misode Nov 6, 2023
00ed76c
Update Forge to 1.20.2 (#3787)
bloodmc Dec 6, 2023
f14798b
Upgrade gradle version
lucko Dec 6, 2023
43f4d49
Upgrade Fabric to MC 1.20.3
lucko Dec 6, 2023
5f87de3
Upgrade Fabric/Forge to MC 1.20.4
lucko Dec 11, 2023
754283c
Fix Fabric command manager mixin (#3791)
lucko Dec 12, 2023
5f95b38
Update adventure-platform for MC 1.20.4 support
lucko Jan 6, 2024
0703b98
Small performance optimization in BukkitPlatformListener (#3806)
AoElite Jan 6, 2024
e6599a2
Fix MongoDB uri showing in logs if set using system property (#3808)
powercasgamer Jan 6, 2024
96008f6
Add modifyTrack method to TrackManager (#3823)
rymiel Jan 23, 2024
7d89c97
Don't read nodes twice in SqlStorage (#3836)
FixedDev Feb 15, 2024
79273a8
Add PostNetworkSyncEvent
lucko Feb 18, 2024
8c6586f
Add custom payload message to API (#3840)
lucko Mar 6, 2024
1dffd46
Fix mongodb secrets being logged (#3850, #3851)
powercasgamer Mar 15, 2024
a43f4a1
Update Fabric dependencies
lucko Apr 17, 2024
7cb60f5
Update Fabric to MC 1.20.5 (#3824)
DrexHD Apr 23, 2024
f86585c
Update Dockerfile to use Java 21
lucko Apr 25, 2024
2361ea4
Update Fabric to MC 1.20.6
lucko Apr 29, 2024
d74a4dc
Set mappings namespace to skip remapping on Paper 1.20.5+ (#3881)
jpenilla Apr 30, 2024
484b04c
Add support for Sponge API 9+ (#3885)
bloodmc May 6, 2024
5c1ea56
Update Forge to MC 1.20.6 (#3883)
bloodmc May 8, 2024
b5400f8
Add support for Sponge API 11 (#3896)
avaruus1 May 26, 2024
c3802c2
Fix Forge plugin msg messenger (#3894)
lucko May 26, 2024
9805f8b
Bump adventure-platform to 4.3.3
lucko Jun 2, 2024
f984ebb
Update Fabric to MC 1.21 (#3918)
Wolfdv1 Jun 16, 2024
d748817
Update Forge to MC 1.21
lucko Jun 16, 2024
9e7a3d2
Improve efficiency of action log queries (#3917)
lucko Jun 16, 2024
55440ca
Fix memory leak in Fabric MixinUser (#3931)
DrexHD Jul 7, 2024
9cc1294
Init VerboseHandler earlier (#3932)
lucko Jul 7, 2024
b21753f
Use builtin Fabric world change event
lucko Jul 7, 2024
642f1d3
Port to NeoForge (#3950)
jpenilla Aug 12, 2024
136a485
Update to Minecraft 1.21.1
lucko Aug 12, 2024
9bf30fc
Fix login configuration phase on NeoForge (#3961)
3TUSK Aug 20, 2024
9d80de5
Fix MongoStorage nodeFromDoc integer cast (#3846)
lucko Aug 24, 2024
c773126
Simplify ExpiringSet implementation (#3969)
AlexProgrammerDE Oct 21, 2024
9420efd
Switch to ECDSA keys for web editor socket
lucko Oct 23, 2024
8973abd
Support older signature alg if running on Java 8
lucko Oct 23, 2024
8d65693
Update to Minecraft 1.21.3
lucko Oct 26, 2024
a92e04f
Recreate individual sql tables if they are missing (#3995)
lucko Nov 9, 2024
2e67011
Refactor some unit tests
lucko Dec 4, 2024
29c93fa
Add note about shading LuckPerms API into plugin jars
lucko Dec 4, 2024
b18717e
Remove NeoForge capability attachment
lucko Dec 4, 2024
f2040ab
Update to Minecraft 1.21.4
lucko Dec 7, 2024
0fef481
Add more unit tests
lucko Dec 22, 2024
5b82837
Update Sponge module to API 12
lucko Jan 5, 2025
1bf0deb
Add unit tests for messaging service messages
lucko Jan 20, 2025
f351369
Update CI action versions
lucko Feb 13, 2025
5e24a70
Mark plugin msg channel as optional on Forge (#3954)
lucko Feb 22, 2025
9bc8a61
Add file secret config adapter (#3913)
lucko Feb 22, 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
Prev Previous commit
Next Next commit
Switch to ECDSA keys for web editor socket
lucko committed Oct 23, 2024

Verified

This commit was signed with the committer’s verified signature.
falkTX Filipe Coelho
commit 9420efd3ac8855865d542ff93f176eaaf50f355c
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;

@@ -52,7 +53,7 @@ public static PublicKey parsePublicKey(String base64String) throws IllegalArgume
try {
byte[] bytes = Base64.getDecoder().decode(base64String);
X509EncodedKeySpec spec = new X509EncodedKeySpec(bytes);
KeyFactory rsa = KeyFactory.getInstance("RSA");
KeyFactory rsa = KeyFactory.getInstance("EC");
return rsa.generatePublic(spec);
} catch (Exception e) {
throw new IllegalArgumentException("Exception parsing public key", e);
@@ -66,8 +67,8 @@ public static PublicKey parsePublicKey(String base64String) throws IllegalArgume
*/
public static KeyPair generateKeyPair() {
try {
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(4096);
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
generator.initialize(new ECGenParameterSpec("secp256r1"));
return generator.generateKeyPair();
} catch (Exception e) {
throw new RuntimeException("Exception generating keypair", e);
@@ -83,7 +84,7 @@ public static KeyPair generateKeyPair() {
*/
public static String sign(PrivateKey privateKey, String msg) {
try {
Signature sign = Signature.getInstance("SHA256withRSA");
Signature sign = Signature.getInstance("SHA256withECDSAinP1363Format");
sign.initSign(privateKey);
sign.update(msg.getBytes(StandardCharsets.UTF_8));

@@ -104,7 +105,7 @@ public static String sign(PrivateKey privateKey, String msg) {
*/
public static boolean verify(PublicKey publicKey, String msg, String signatureBase64) {
try {
Signature sign = Signature.getInstance("SHA256withRSA");
Signature sign = Signature.getInstance("SHA256withECDSAinP1363Format");
sign.initVerify(publicKey);
sign.update(msg.getBytes(StandardCharsets.UTF_8));

Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@

public class WebEditorSocket {

private static final int PROTOCOL_VERSION = 1;
private static final int PROTOCOL_VERSION = 2;

/** The plugin */
private final LuckPermsPlugin plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.lucko.luckperms.common.webeditor.socket;

import org.junit.jupiter.api.Test;

import java.security.KeyPair;
import java.security.PublicKey;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CryptographyUtilsTest {

@Test
public void testKeypairGenerate() {
CryptographyUtils.generateKeyPair();
}

@Test
public void testSignVerify() {
KeyPair keyPair = CryptographyUtils.generateKeyPair();

String signature = CryptographyUtils.sign(keyPair.getPrivate(), "test");
assertTrue(CryptographyUtils.verify(keyPair.getPublic(), "test", signature));

assertFalse(CryptographyUtils.verify(keyPair.getPublic(), "test", "bleh"));
assertFalse(CryptographyUtils.verify(keyPair.getPublic(), "test", ""));
assertFalse(CryptographyUtils.verify(keyPair.getPublic(), "test", null));
}

@Test
public void testParseAndVerify() {
// the base64 values are generated from javascript crypto.subtle
PublicKey publicKey = CryptographyUtils.parsePublicKey("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEkF5EWzdsbmVOYprtfMleBZYASm7AXBQQCE29xR2hpGkjVi4Fra/KPazRShqyGvQXY24sINsxIPEd4XamDfFAaQ==");
assertTrue(CryptographyUtils.verify(publicKey, "hello world", "XAZJMxOlR5Mcq7nJxU4oS1fYyViYH1FZxWOXwOC+LRXYF8KeP58k5KLTjc35L974t3RukwAqflul0HY64bJT3w=="));
}

}