Skip to content

Commit ac51418

Browse files
committed
Revert build 622+.
Several incompatibilities with extensions were introduced, so these changes are going to be reverted, and reintroduced after a version bump to 3.3.6.
1 parent 9039fe8 commit ac51418

277 files changed

Lines changed: 8923 additions & 20530 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ nbactions.xml
1717
/preferences.*
1818
.DS_Store
1919
/test-backend/
20-
.mvn/
2120
/nbproject/
2221
dependency-reduced-pom.xml
2322

checkstyle.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
<property name="message" value="Javadoc comment at column [\d]+ has parse error\. Details: no viable alternative at input '[\\t]+ \*' while parsing JAVADOC_TAG"/>
3232
</module>
3333

34-
<!-- Allow braceless else when it directly contains a switch expression -->
35-
<module name="SuppressionXpathSingleFilter">
36-
<property name="checks" value="NeedBraces"/>
37-
<property name="query" value="//LITERAL_ELSE[./EXPR/ASSIGN/LITERAL_SWITCH]"/>
38-
</module>
39-
4034
<!-- Indent must use tab characters -->
4135
<module name="RegexpSinglelineJava">
4236
<property name="format" value="^\t* ([^\*]|$)"/> <!-- Javadoc and multiline comments have a single leading whitespace, so allow " *" -->

pom.xml

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
<properties>
134134
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
135135
<maven.test.failure.ignore>true</maven.test.failure.ignore>
136-
<maven.compiler.source>21</maven.compiler.source>
137-
<maven.compiler.target>21</maven.compiler.target>
136+
<maven.compiler.source>16</maven.compiler.source>
137+
<maven.compiler.target>16</maven.compiler.target>
138138
</properties>
139139
<repositories>
140140
<repository>
@@ -227,7 +227,7 @@
227227
<!-- GPL -->
228228
<groupId>com.mysql</groupId>
229229
<artifactId>mysql-connector-j</artifactId>
230-
<version>9.4.0</version>
230+
<version>8.3.0</version>
231231
<type>jar</type>
232232
<scope>compile</scope>
233233
</dependency>
@@ -248,7 +248,7 @@
248248
<!-- NOTE: If you change this version, you also have to change the install-mssql-auth command to
249249
download the corresponding version of the mssql-auth dll. This will also require users to re-install
250250
it, so an upgrade routine will need to be released as well. -->
251-
<version>12.8.0.jre8</version>
251+
<version>12.6.1.jre11</version>
252252
</dependency>
253253

254254
<!-- Yaml parsing -->
@@ -376,11 +376,6 @@
376376
<artifactId>org.eclipse.lsp4j</artifactId>
377377
<version>0.22.0</version>
378378
</dependency>
379-
<dependency>
380-
<groupId>org.eclipse.lsp4j</groupId>
381-
<artifactId>org.eclipse.lsp4j.debug</artifactId>
382-
<version>0.22.0</version>
383-
</dependency>
384379
<dependency>
385380
<groupId>io.swagger.core.v3</groupId>
386381
<artifactId>swagger-annotations</artifactId>
@@ -399,7 +394,7 @@
399394
<dependency>
400395
<groupId>com.squareup.okio</groupId>
401396
<artifactId>okio-jvm</artifactId>
402-
<version>3.16.0</version>
397+
<version>3.10.0</version>
403398
</dependency>
404399
<dependency>
405400
<groupId>com.google.code.gson</groupId>
@@ -494,12 +489,10 @@
494489
<version>3.12.1</version>
495490
<configuration>
496491
<showDeprecation>true</showDeprecation>
497-
<release>21</release>
492+
<release>16</release>
498493
<compilerArgs>
499494
<arg>-XDignore.symbol.file</arg>
500495
<arg>-parameters</arg>
501-
<arg>-Xmaxwarns</arg>
502-
<arg>9999</arg>
503496
</compilerArgs>
504497
</configuration>
505498
</plugin>
@@ -574,8 +567,6 @@
574567
<include>org.brotli:dec:jar:*</include>
575568
<include>org.eclipse.lsp4j:org.eclipse.lsp4j:jar:*</include>
576569
<include>org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:jar:*</include>
577-
<include>org.eclipse.lsp4j:org.eclipse.lsp4j.debug:jar:*</include>
578-
<include>org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc.debug:jar:*</include>
579570
<!-- We don't currently actually depend on these 2, but lsp4j does, so we
580571
need to shade it in. In the future, we may rip out org.json:json,
581572
and replace it with this, however, in which case we only need to
@@ -849,24 +840,6 @@
849840
<exclude>META-INF/**</exclude>
850841
</excludes>
851842
</filter>
852-
<filter>
853-
<artifact>org.eclipse.lsp4j:org.eclipse.lsp4j.debug:jar:*</artifact>
854-
<includes>
855-
<include>**</include>
856-
</includes>
857-
<excludes>
858-
<exclude>META-INF/**</exclude>
859-
</excludes>
860-
</filter>
861-
<filter>
862-
<artifact>org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc.debug:jar:*</artifact>
863-
<includes>
864-
<include>**</include>
865-
</includes>
866-
<excludes>
867-
<exclude>META-INF/**</exclude>
868-
</excludes>
869-
</filter>
870843
<filter>
871844
<artifact>com.google.code.gson:gson:jar:*</artifact>
872845
<includes>
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
package com.laytonsmith.PureUtilities.Common;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.ObjectInputStream;
7+
import java.io.ObjectOutputStream;
8+
import java.security.InvalidKeyException;
9+
import java.security.Key;
10+
import java.security.KeyPair;
11+
import java.security.KeyPairGenerator;
12+
import java.security.NoSuchAlgorithmException;
13+
import java.security.PrivateKey;
14+
import java.security.PublicKey;
15+
import java.util.Objects;
16+
import javax.crypto.BadPaddingException;
17+
import javax.crypto.Cipher;
18+
import javax.crypto.IllegalBlockSizeException;
19+
import javax.crypto.NoSuchPaddingException;
20+
import org.apache.commons.codec.binary.Base64;
21+
22+
/**
23+
* Given a public/private key pair, this class uses RSA to encrypt/decrypt data.
24+
*/
25+
public class RSAEncrypt {
26+
27+
/**
28+
* The RSA algorithm key.
29+
*/
30+
private static final String ALGORITHM = "RSA";
31+
32+
/**
33+
* Generates a new key, and stores the value in the RSA
34+
*
35+
* @param label The label that will be associated with the public key
36+
* @return
37+
*/
38+
public static RSAEncrypt generateKey(String label) {
39+
KeyPairGenerator keyGen;
40+
try {
41+
keyGen = KeyPairGenerator.getInstance(ALGORITHM);
42+
} catch (NoSuchAlgorithmException ex) {
43+
throw new RuntimeException(ex);
44+
}
45+
keyGen.initialize(1024);
46+
KeyPair key = keyGen.generateKeyPair();
47+
RSAEncrypt enc = new RSAEncrypt(toString(key.getPrivate()), toString(key.getPublic(), label));
48+
return enc;
49+
}
50+
51+
/**
52+
* Given a public key and a label, produces an ssh compatible rsa public key string.
53+
*
54+
* @param key
55+
* @param label
56+
* @return
57+
*/
58+
public static String toString(PublicKey key, String label) {
59+
Objects.requireNonNull(label);
60+
ByteArrayOutputStream pubBOS = new ByteArrayOutputStream();
61+
try {
62+
ObjectOutputStream publicKeyOS = new ObjectOutputStream(pubBOS);
63+
publicKeyOS.writeObject(key);
64+
} catch (IOException ex) {
65+
throw new RuntimeException(ex);
66+
}
67+
String publicKey = Base64.encodeBase64String(pubBOS.toByteArray());
68+
publicKey = "ssh-rsa " + publicKey + " " + label;
69+
return publicKey;
70+
}
71+
72+
/**
73+
* Given a private key, produces an ssh compatible rsa private key string.
74+
*
75+
* @param key
76+
* @return
77+
*/
78+
private static String toString(PrivateKey key) {
79+
ByteArrayOutputStream privBOS = new ByteArrayOutputStream();
80+
ObjectOutputStream privateKeyOS;
81+
try {
82+
privateKeyOS = new ObjectOutputStream(privBOS);
83+
privateKeyOS.writeObject(key);
84+
} catch (IOException ex) {
85+
throw new RuntimeException(ex);
86+
}
87+
String privateKey = Base64.encodeBase64String(privBOS.toByteArray());
88+
89+
StringBuilder privBuilder = new StringBuilder();
90+
privBuilder.append("-----BEGIN RSA PRIVATE KEY-----");
91+
for(int i = 0; i < privateKey.length(); i++) {
92+
if(i % 64 == 0) {
93+
privBuilder.append(StringUtils.nl());
94+
}
95+
privBuilder.append(privateKey.charAt(i));
96+
}
97+
privBuilder.append(StringUtils.nl()).append("-----END RSA PRIVATE KEY-----").append(StringUtils.nl());
98+
privateKey = privBuilder.toString();
99+
return privateKey;
100+
}
101+
102+
private PublicKey publicKey;
103+
private PrivateKey privateKey;
104+
private String label;
105+
106+
/**
107+
* Creates a new RSAEncrypt object, based on the ssh compatible private/public key pair. Only one key needs to be
108+
* provided. If so, only those methods for the key provided will work.
109+
*
110+
* @param privateKey
111+
* @param publicKey
112+
* @throws IllegalArgumentException If the keys are not the correct type. They must be ssh compatible.
113+
*/
114+
public RSAEncrypt(String privateKey, String publicKey) throws IllegalArgumentException {
115+
if(privateKey != null) {
116+
//private key processing
117+
//replace all newlines with nothing
118+
privateKey = privateKey.replaceAll("\r", "");
119+
privateKey = privateKey.replaceAll("\n", "");
120+
//Remove the BEGIN/END tags
121+
privateKey = privateKey.replace("-----BEGIN RSA PRIVATE KEY-----", "");
122+
privateKey = privateKey.replace("-----END RSA PRIVATE KEY-----", "");
123+
ObjectInputStream privOIS;
124+
try {
125+
privOIS = new ObjectInputStream(new ByteArrayInputStream(Base64.decodeBase64(privateKey)));
126+
this.privateKey = (PrivateKey) privOIS.readObject();
127+
} catch (IOException | ClassNotFoundException ex) {
128+
throw new RuntimeException(ex);
129+
}
130+
}
131+
132+
if(publicKey != null) {
133+
//public key processing
134+
String[] split = publicKey.split(" ");
135+
if(split.length != 3) {
136+
throw new IllegalArgumentException("Invalid public key passed in.");
137+
}
138+
if(!"ssh-rsa".equals(split[0])) {
139+
throw new IllegalArgumentException("Invalid public key type. Expecting ssh-rsa, but found \"" + split[0] + "\"");
140+
}
141+
this.label = split[2];
142+
ObjectInputStream pubOIS;
143+
try {
144+
pubOIS = new ObjectInputStream(new ByteArrayInputStream(Base64.decodeBase64(split[1])));
145+
this.publicKey = (PublicKey) pubOIS.readObject();
146+
} catch (IOException | ClassNotFoundException ex) {
147+
throw new RuntimeException(ex);
148+
}
149+
}
150+
}
151+
152+
/**
153+
* Encrypts the data with the public key, which can be decrypted with the private key. This is only valid if the
154+
* public key was provided.
155+
*
156+
* @param data
157+
* @return
158+
*/
159+
public byte[] encryptWithPublic(byte[] data) {
160+
Objects.requireNonNull(publicKey);
161+
return crypt(data, publicKey, Cipher.ENCRYPT_MODE);
162+
}
163+
164+
/**
165+
* Encrypts the data with the private key, which can be decrypted with the public key. This is only valid if the
166+
* private key was provided.
167+
*
168+
* @param data
169+
* @return
170+
* @throws InvalidKeyException
171+
*/
172+
public byte[] encryptWithPrivate(byte[] data) throws InvalidKeyException {
173+
Objects.requireNonNull(privateKey);
174+
return crypt(data, privateKey, Cipher.ENCRYPT_MODE);
175+
}
176+
177+
/**
178+
* Decrypts the data with the public key, which will have been encrypted with the private key. This is only valid if
179+
* the public key was provided.
180+
*
181+
* @param data
182+
* @return
183+
*/
184+
public byte[] decryptWithPublic(byte[] data) {
185+
Objects.requireNonNull(publicKey);
186+
return crypt(data, publicKey, Cipher.DECRYPT_MODE);
187+
}
188+
189+
/**
190+
* Decrypts the data with the private key, which will have been encrypted with the public key. This is only valid if
191+
* the private key was provided.
192+
*
193+
* @param data
194+
* @return
195+
*/
196+
public byte[] decryptWithPrivate(byte[] data) {
197+
Objects.requireNonNull(privateKey);
198+
return crypt(data, privateKey, Cipher.DECRYPT_MODE);
199+
}
200+
201+
/**
202+
* Utility method that actually does the de/encrypting.
203+
*
204+
* @param data
205+
* @param key
206+
* @param cryptMode
207+
* @return
208+
*/
209+
private byte[] crypt(byte[] data, Key key, int cryptMode) {
210+
byte[] cipherValue = null;
211+
Cipher cipher;
212+
try {
213+
cipher = Cipher.getInstance(ALGORITHM);
214+
cipher.init(cryptMode, key);
215+
cipherValue = cipher.doFinal(data);
216+
} catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException | NoSuchPaddingException ex) {
217+
throw new RuntimeException(ex);
218+
}
219+
return cipherValue;
220+
}
221+
222+
/**
223+
* Returns the private key string.
224+
*
225+
* @return
226+
*/
227+
public String getPrivateKey() {
228+
return toString(privateKey);
229+
}
230+
231+
/**
232+
* Returns the public key string.
233+
*
234+
* @return
235+
*/
236+
public String getPublicKey() {
237+
return toString(publicKey, label);
238+
}
239+
240+
/**
241+
* Returns the label on the public key.
242+
*
243+
* @return
244+
*/
245+
public String getLabel() {
246+
return label;
247+
}
248+
249+
}

0 commit comments

Comments
 (0)