Skip to content

Commit b0c8c79

Browse files
Cleanup a few warnings (#6764)
1 parent 1adb77a commit b0c8c79

7 files changed

Lines changed: 18 additions & 169 deletions

File tree

api/src/org/labkey/api/reader/BufferedReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ We use this implementation as it grows its buffer incrementally instead of alloc
3434
* -Replaced StringBuilder with StringBuffer
3535
*/
3636

37+
import org.jetbrains.annotations.NotNull;
38+
3739
import java.io.IOException;
3840
import java.io.Reader;
3941

@@ -260,7 +262,7 @@ public int read() throws IOException {
260262
* if this reader is closed or some other I/O error occurs.
261263
*/
262264
@Override
263-
public int read(char[] buffer, int offset, int length) throws IOException {
265+
public int read(char @NotNull [] buffer, int offset, int length) throws IOException {
264266
synchronized (lock) {
265267
if (isClosed()) {
266268
throw new IOException();

api/src/org/labkey/api/search/AbstractXMLDocumentParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void parseContent(InputStream stream, ContentHandler handler) throws IOEx
4545
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
4646
parser.getXMLReader().setFeature("http://xml.org/sax/features/validation", false);
4747
parser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
48+
parser.getXMLReader().setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
4849
parser.parse(stream, createSAXHandler(handler));
4950
}
5051
catch (ParserConfigurationException e)

api/src/org/labkey/api/security/Crypt.java

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -208,68 +208,10 @@ public boolean matches(String credentials, String digest)
208208
@Override
209209
public String digest(String credentials)
210210
{
211-
// long n = System.nanoTime();
212-
String ret = org.labkey.api.security.BCrypt.hashpw(credentials, org.labkey.api.security.BCrypt.gensalt(11));
213-
// double d = (System.nanoTime() - n)/1000000000.0;
214-
return ret;
211+
return org.labkey.api.security.BCrypt.hashpw(credentials, org.labkey.api.security.BCrypt.gensalt(11));
215212
}
216213
}
217214

218-
219-
/* public static class _saltaes extends Crypt
220-
{
221-
private static final String _algorithm = "AES";
222-
private static final int _keylen = 24;
223-
private static final String _text = "eUpeZclKWup36fRxihyIVcKf"; // don't change me!
224-
225-
226-
public boolean matches(String credentials, String crypt)
227-
{
228-
return crypt.equals(_digest(credentials,crypt));
229-
}
230-
231-
public String digest(String pwd)
232-
{
233-
return _digest(pwd, null);
234-
}
235-
236-
private String _digest(String pwd, String salt)
237-
{
238-
pwd = StringUtils.trimToEmpty(pwd);
239-
salt = makeSalt(salt);
240-
241-
String crypt = "";
242-
243-
int[] keyInts = new int[_keylen];
244-
for (int i = 0; i < pwd.length() ; i++)
245-
keyInts[i % _keylen] = keyInts[i%_keylen] * 31 + pwd.charAt(i);
246-
byte[] keyBytes = new byte[_keylen];
247-
for (int i = 0; i < _keylen ; i++)
248-
keyBytes[i] = (byte)keyInts[i];
249-
byte[] textBytes = new byte[_keylen];
250-
for (int i = 0; i < _keylen; i++)
251-
textBytes[i] = (byte)(salt.charAt(i % salt.length()) ^ _text.charAt(i));
252-
253-
try
254-
{
255-
SecretKeySpec skey = new SecretKeySpec(keyBytes, _algorithm);
256-
Cipher cipher = Cipher.getInstance(_algorithm);
257-
cipher.init(Cipher.ENCRYPT_MODE, skey);
258-
byte[] cipherBytes = cipher.doFinal(textBytes);
259-
crypt = new String(Base64.encodeBase64(cipherBytes, false));
260-
}
261-
catch (Exception x)
262-
{
263-
x.printStackTrace(System.err);
264-
return null;
265-
}
266-
267-
return salt + crypt.substring(0, 32);
268-
}
269-
}
270-
*/
271-
272-
273215
private static String makeSalt(String salt)
274216
{
275217
if (null == salt)
@@ -311,7 +253,7 @@ public static String encodeBase64(byte[] bytes)
311253

312254
private static char _randChar()
313255
{
314-
int i = (int) (Math.random() * 62);
256+
int i = (int) (Encryption.SR.nextDouble() * 62);
315257
if (i > 52)
316258
return (char) ('0' + i - 52);
317259
return (char) (0 == (i & 0x0001)

api/src/org/labkey/api/security/Encryption.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,23 @@ public class Encryption
7676
private static final Logger LOG = LogHelper.getLogger(Encryption.class, "Encryption operations");
7777
private static final String CATEGORY = "Encryption";
7878
private static final String SALT_KEY = "Salt";
79-
private static final SecureRandom SR = new SecureRandom();
79+
public static final SecureRandom SR;
8080
private static final String ENCRYPTION_PASS_PHRASE;
8181
private static final String KEY_CHANGE_GUIDANCE = "An administrator should change the encryption key back to the previous value, follow the official encryption key change process, or be prepared to re-enter and re-save all saved credentials.";
8282

8383
static
8484
{
8585
ENCRYPTION_PASS_PHRASE = loadEncryptionPassPhrase();
8686

87+
try
88+
{
89+
SR = SecureRandom.getInstanceStrong();
90+
}
91+
catch (NoSuchAlgorithmException e)
92+
{
93+
throw new ConfigurationException("Could not initialize SecureRandom", e);
94+
}
95+
8796
WarningService.get().register(new WarningProvider() {
8897
@Override
8998
public void addDynamicWarnings(@NotNull Warnings warnings, @Nullable ViewContext context, boolean showAllWarnings)

api/src/org/labkey/api/util/XMLFileType.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

core/src/client/AssayDesigner/AssayDesigner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class App extends React.Component<any, State> {
5656

5757
// hack, if the returnUrl has stripped off the rowId because of encoding/decoding issues (see TODO in AbstractAssayProvider.getManageMenuNavTree()) add it back on
5858
let returnUrl = ActionURL.getReturnUrl();
59-
if (rowId !== undefined && returnUrl && returnUrl.indexOf('rowId') === returnUrl.length - 5) {
59+
if (rowId !== undefined && returnUrl && returnUrl.endsWith('rowId')) {
6060
returnUrl = returnUrl + '=' + rowId;
6161
}
6262

study/resources/web/study/assayPublish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function assayPublish_onLinkToStudy(el, fieldNames)
2222
var array = formData[e.name];
2323
if (!array)
2424
array = formData[e.name] = [];
25-
array.push(e.value.replace("\t"," "));
25+
array.push(e.value.replace(/\t/g, " "));
2626
}
2727
}
2828

0 commit comments

Comments
 (0)