Improper order of operations for ident export

This commit is contained in:
Manevolent
2018-12-22 11:59:36 -05:00
parent d9c2805528
commit 7b25be6420
2 changed files with 14 additions and 37 deletions
@@ -200,14 +200,23 @@ public class LocalIdentity extends Identity {
identityData, 0 identityData, 0
); );
int nullIndex = 0x0; // STATIC //int nullIdx = identityArr.AsSpan(20).IndexOf((byte)0);
int nullIndex = -1;
for (int i = 20; i < identityData.length; i ++)
if (identityData[i] == 0x0) {
nullIndex = i-20;
break;
}
//var hash = Hash1It(identityArr, 20, nullIdx < 0 ? identityArr.Length - 20 : nullIdx);
byte[] hash = Ts3Crypt.hash128( byte[] hash = Ts3Crypt.hash128(
identityData, identityData,
20, 20,
nullIndex < 0 ? identityData.length - 20 : nullIndex nullIndex < 0 ? identityData.length - 20 : nullIndex
); );
//XorBinary(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b, int len, Span<byte> outBuf)
//XorBinary(identityArr, hash, 20, identityArr);
Ts3Crypt.xor( Ts3Crypt.xor(
identityData, 0, identityData, 0,
hash, 0, hash, 0,
@@ -298,7 +307,6 @@ public class LocalIdentity extends Identity {
String utf8Decoded = new String(identityData, Charset.forName("UTF8")); String utf8Decoded = new String(identityData, Charset.forName("UTF8"));
LocalIdentity identity = Ts3Crypt.loadIdentityFromAsn(Base64.getDecoder().decode(utf8Decoded)); LocalIdentity identity = Ts3Crypt.loadIdentityFromAsn(Base64.getDecoder().decode(utf8Decoded));
identity.setKeyOffset(level); identity.setKeyOffset(level);
identity.setLastCheckedKeyOffset(level); identity.setLastCheckedKeyOffset(level);
@@ -6,7 +6,9 @@ import com.github.manevolent.ts3j.util.Ts3Debugging;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.StringBufferInputStream; import java.io.StringBufferInputStream;
import java.security.GeneralSecurityException;
import java.util.Base64; import java.util.Base64;
public class IdentitySaveTest extends TestCase { public class IdentitySaveTest extends TestCase {
@@ -17,40 +19,7 @@ public class IdentitySaveTest extends TestCase {
public void testParser() throws Exception { public void testParser() throws Exception {
Ts3Debugging.setEnabled(true); Ts3Debugging.setEnabled(true);
String testIni = "[Identity]\n" + LocalIdentity generatedIdentity = LocalIdentity.generateNew(10);
"id=New identity_1\n" + LocalIdentity readIdentity = LocalIdentity.read(new StringBufferInputStream(generatedIdentity.export()));
"identity=\"171V9UfzzH5tGS4W" +
"V8zptzxuvrqBAWUAMVNkUQJZUgl3XXYJQnBQY0" +
"VnJAsDIgR/VgFiB0ZFBQBhcRFRQn0Jc3ZgVGZH" +
"e0B9IlBiCjRQKw44OSJGX3t3VGZ2K3U3Xl9BLl" +
"95KmB3S3l5QUdBaUJDWG1VWi9jQUtwQUUxbFcr" +
"cnhNdGlaR1ZJUGIzZEtsSWx3cUVMKzVoSzVRPT" +
"0=\"\n";
LocalIdentity localIdentity = LocalIdentity.read(new StringBufferInputStream(testIni));
// Assert that the output of toASN() is fixed, and matches what we expect in the above identity output
// this does not certify encryption; this only affixes the machine-readable ASN1 format
assertEquals(
"MG4DAgeAAgEgAiAOvndZ5WbTh68cjFhCl" +
"uDgPwPFh1DaJ24Sdst70SBw4wIhANPfVvKpIGi" +
"RkPaOoYXGwoLB0SEIBSkhpMlIOPAxyyAGAiBCX" +
"mUZ/cAKpAE1lW+rxMtiZGVIPb3dKlIlwqEL+5h" +
"K5Q==",
Base64.getEncoder().encodeToString(localIdentity.toASN())
);
String identityData = localIdentity.export(null);
LocalIdentity localIdentity2 = LocalIdentity.read(new StringBufferInputStream(identityData));
assertEquals(localIdentity.getSecurityLevel(), localIdentity2.getSecurityLevel());
assertEquals(localIdentity.getPublicKeyString(), localIdentity2.getPublicKeyString());
// If you decide to save this AND import in Teamspeak3, you need to supply a HashMap with the following:
// phonetic_nickname
// nickname
// id
//localIdentity.save(new File("out.ini"));
} }
} }