1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-07-02 10:33:36 +00:00

update to 1.3.5

This commit is contained in:
DrKLO 2013-12-23 15:05:57 +04:00
parent 02c8efb0df
commit 50a92dc44a
4 changed files with 56 additions and 25 deletions

View File

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.telegram.messenger" package="org.telegram.messenger"
android:versionCode="126" android:versionCode="126"
android:versionName="1.3.4"> android:versionName="1.3.5">
<supports-screens android:anyDensity="true" <supports-screens android:anyDensity="true"
android:smallScreens="true" android:smallScreens="true"

View File

@ -324,7 +324,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
return; return;
} }
if (!Utilities.isGoodPrime(dhInnerData.dh_prime)) { if (!Utilities.isGoodPrime(dhInnerData.dh_prime, dhInnerData.g)) {
throw new RuntimeException("bad prime"); throw new RuntimeException("bad prime");
} }
@ -344,15 +344,17 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
b[a] = (byte)(MessagesController.random.nextDouble() * 255); b[a] = (byte)(MessagesController.random.nextDouble() * 255);
} }
BigInteger dhBI = new BigInteger(1, dhInnerData.dh_prime); BigInteger p = new BigInteger(1, dhInnerData.dh_prime);
BigInteger i_g_b = BigInteger.valueOf(dhInnerData.g); BigInteger g_b = BigInteger.valueOf(dhInnerData.g);
i_g_b = i_g_b.modPow(new BigInteger(1, b), dhBI); BigInteger g_a = new BigInteger(1, dhInnerData.g_a);
byte[] g_b = i_g_b.toByteArray(); if (!Utilities.isGoodGaAndGb(g_a, g_b, p)) {
throw new RuntimeException("bad prime");
}
BigInteger i_authKey = new BigInteger(1, dhInnerData.g_a); g_b = g_b.modPow(new BigInteger(1, b), p);
i_authKey = i_authKey.modPow(new BigInteger(1, b), dhBI); g_a = g_a.modPow(new BigInteger(1, b), p);
authKey = i_authKey.toByteArray(); authKey = g_a.toByteArray();
if (authKey.length > 256) { if (authKey.length > 256) {
byte[] correctedAuth = new byte[256]; byte[] correctedAuth = new byte[256];
System.arraycopy(authKey, 1, correctedAuth, 0, 256); System.arraycopy(authKey, 1, correctedAuth, 0, 256);
@ -390,7 +392,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
TLRPC.TL_client_DH_inner_data clientInnerData = new TLRPC.TL_client_DH_inner_data(); TLRPC.TL_client_DH_inner_data clientInnerData = new TLRPC.TL_client_DH_inner_data();
clientInnerData.nonce = authNonce; clientInnerData.nonce = authNonce;
clientInnerData.server_nonce = authServerNonce; clientInnerData.server_nonce = authServerNonce;
clientInnerData.g_b = g_b; clientInnerData.g_b = g_b.toByteArray();
clientInnerData.retry_id = 0; clientInnerData.retry_id = 0;
SerializedData os = new SerializedData(); SerializedData os = new SerializedData();
clientInnerData.serializeToStream(os); clientInnerData.serializeToStream(os);

View File

@ -4811,8 +4811,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
public void processAcceptedSecretChat(final TLRPC.EncryptedChat encryptedChat) { public void processAcceptedSecretChat(final TLRPC.EncryptedChat encryptedChat) {
BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes);
BigInteger i_authKey = new BigInteger(1, encryptedChat.g_a_or_b); BigInteger i_authKey = new BigInteger(1, encryptedChat.g_a_or_b);
i_authKey = i_authKey.modPow(new BigInteger(1, encryptedChat.a_or_b), new BigInteger(1, MessagesStorage.secretPBytes));
if (!Utilities.isGoodGaAndGb(null, i_authKey, p)) {
declineSecretChat(encryptedChat.id);
return;
}
i_authKey = i_authKey.modPow(new BigInteger(1, encryptedChat.a_or_b), p);
byte[] authKey = i_authKey.toByteArray(); byte[] authKey = i_authKey.toByteArray();
if (authKey.length > 256) { if (authKey.length > 256) {
@ -4883,7 +4890,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (error == null) { if (error == null) {
TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig)response; TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig)response;
if (response instanceof TLRPC.TL_messages_dhConfig) { if (response instanceof TLRPC.TL_messages_dhConfig) {
if (!Utilities.isGoodPrime(res.p)) { if (!Utilities.isGoodPrime(res.p, res.g)) {
acceptingChats.remove(encryptedChat.id); acceptingChats.remove(encryptedChat.id);
declineSecretChat(encryptedChat.id); declineSecretChat(encryptedChat.id);
return; return;
@ -4899,19 +4906,27 @@ public class MessagesController implements NotificationCenter.NotificationCenter
salt[a] = (byte)((byte)(random.nextDouble() * 255) ^ res.random[a]); salt[a] = (byte)((byte)(random.nextDouble() * 255) ^ res.random[a]);
} }
encryptedChat.a_or_b = salt; encryptedChat.a_or_b = salt;
BigInteger i_g_b = BigInteger.valueOf(MessagesStorage.secretG); BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes);
i_g_b = i_g_b.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes)); BigInteger g_b = BigInteger.valueOf(MessagesStorage.secretG);
byte[] g_b = i_g_b.toByteArray(); g_b = g_b.modPow(new BigInteger(1, salt), p);
if (g_b.length > 256) { BigInteger g_a = new BigInteger(1, encryptedChat.g_a);
byte[] correctedAuth = new byte[256];
System.arraycopy(g_b, 1, correctedAuth, 0, 256); if (!Utilities.isGoodGaAndGb(g_a, g_b, p)) {
g_b = correctedAuth; acceptingChats.remove(encryptedChat.id);
declineSecretChat(encryptedChat.id);
return;
} }
BigInteger i_authKey = new BigInteger(1, encryptedChat.g_a); byte[] g_b_bytes = g_b.toByteArray();
i_authKey = i_authKey.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes)); if (g_b_bytes.length > 256) {
byte[] correctedAuth = new byte[256];
System.arraycopy(g_b_bytes, 1, correctedAuth, 0, 256);
g_b_bytes = correctedAuth;
}
byte[] authKey = i_authKey.toByteArray(); g_a = g_a.modPow(new BigInteger(1, salt), p);
byte[] authKey = g_a.toByteArray();
if (authKey.length > 256) { if (authKey.length > 256) {
byte[] correctedAuth = new byte[256]; byte[] correctedAuth = new byte[256];
System.arraycopy(authKey, authKey.length - 256, correctedAuth, 0, 256); System.arraycopy(authKey, authKey.length - 256, correctedAuth, 0, 256);
@ -4930,7 +4945,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
encryptedChat.auth_key = authKey; encryptedChat.auth_key = authKey;
TLRPC.TL_messages_acceptEncryption req2 = new TLRPC.TL_messages_acceptEncryption(); TLRPC.TL_messages_acceptEncryption req2 = new TLRPC.TL_messages_acceptEncryption();
req2.g_b = g_b; req2.g_b = g_b_bytes;
req2.peer = new TLRPC.TL_inputEncryptedChat(); req2.peer = new TLRPC.TL_inputEncryptedChat();
req2.peer.chat_id = encryptedChat.id; req2.peer.chat_id = encryptedChat.id;
req2.peer.access_hash = encryptedChat.access_hash; req2.peer.access_hash = encryptedChat.access_hash;
@ -4976,7 +4991,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (error == null) { if (error == null) {
TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig)response; TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig)response;
if (response instanceof TLRPC.TL_messages_dhConfig) { if (response instanceof TLRPC.TL_messages_dhConfig) {
if (!Utilities.isGoodPrime(res.p)) { if (!Utilities.isGoodPrime(res.p, res.g)) {
Utilities.RunOnUIThread(new Runnable() { Utilities.RunOnUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -4996,6 +5011,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
for (int a = 0; a < 256; a++) { for (int a = 0; a < 256; a++) {
salt[a] = (byte)((byte)(random.nextDouble() * 255) ^ res.random[a]); salt[a] = (byte)((byte)(random.nextDouble() * 255) ^ res.random[a]);
} }
BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG); BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG);
i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes)); i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));
byte[] g_a = i_g_a.toByteArray(); byte[] g_a = i_g_a.toByteArray();

View File

@ -100,7 +100,10 @@ public class Utilities {
return new String(hexChars); return new String(hexChars);
} }
public static boolean isGoodPrime(byte[] prime) { public static boolean isGoodPrime(byte[] prime, int g) {
if (!(g >= 2 && g <= 7)) {
return false;
}
String hex = bytesToHex(prime); String hex = bytesToHex(prime);
for (String cached : goodPrimes) { for (String cached : goodPrimes) {
if (cached.equals(hex)) { if (cached.equals(hex)) {
@ -121,6 +124,16 @@ public class Utilities {
return true; return true;
} }
public static boolean isGoodGaAndGb(BigInteger g_a, BigInteger g_b, BigInteger p) {
if (g_a != null && g_a.compareTo(BigInteger.valueOf(1)) != 1) {
return false;
}
if (g_b != null && p != null && g_b.compareTo(p.subtract(BigInteger.valueOf(1))) != -1) {
return false;
}
return true;
}
public static TPFactorizedValue getFactorizedValue(long what) { public static TPFactorizedValue getFactorizedValue(long what) {
long g = doPQNative(what); long g = doPQNative(what);
if (g > 1 && g < what) { if (g > 1 && g < what) {