Extract SignalAccount from Manager

This commit is contained in:
AsamK 2018-11-18 15:34:10 +01:00
parent 701328b8c2
commit 35c72f692f
30 changed files with 793 additions and 549 deletions

View file

@ -33,13 +33,18 @@ public class IOUtils {
return output.toString();
}
public static void createPrivateDirectories(String path) throws IOException {
final Path file = new File(path).toPath();
public static void createPrivateDirectories(String directoryPath) throws IOException {
final File file = new File(directoryPath);
if (file.exists()) {
return;
}
final Path path = file.toPath();
try {
Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE);
Files.createDirectories(file, PosixFilePermissions.asFileAttribute(perms));
Files.createDirectories(path, PosixFilePermissions.asFileAttribute(perms));
} catch (UnsupportedOperationException e) {
Files.createDirectories(file);
Files.createDirectories(path);
}
}

View file

@ -1,47 +0,0 @@
package org.asamk.signal.util;
import org.whispersystems.signalservice.internal.util.Base64;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class KeyUtils {
private KeyUtils() {
}
public static String createSignalingKey() {
return getSecret(52);
}
public static byte[] createProfileKey() {
return getSecretBytes(32);
}
public static String createPassword() {
return getSecret(18);
}
public static byte[] createGroupId() {
return getSecretBytes(16);
}
private static String getSecret(int size) {
byte[] secret = getSecretBytes(size);
return Base64.encodeBytes(secret);
}
private static byte[] getSecretBytes(int size) {
byte[] secret = new byte[size];
getSecureRandom().nextBytes(secret);
return secret;
}
private static SecureRandom getSecureRandom() {
try {
return SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
}

View file

@ -1,5 +1,8 @@
package org.asamk.signal.util;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.InvalidObjectException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
@ -53,4 +56,13 @@ public class Util {
return buf.toString();
}
public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
JsonNode node = parent.get(name);
if (node == null) {
throw new InvalidObjectException(String.format("Incorrect file format: expected parameter %s not found ", name));
}
return node;
}
}