mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-28 14:59:44 +00:00
no message
This commit is contained in:
@@ -49,16 +49,19 @@ static NSData *base64_decode(NSString *str) {
|
||||
NSData *data = [[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||
return data;
|
||||
} else {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
return [[NSData alloc] initWithBase64Encoding:[str stringByReplacingOccurrencesOfString:@"[^A-Za-z0-9+/=]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [str length])]];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
|
||||
@implementation MTBackupAddressSignals
|
||||
|
||||
+ (bool)checkIpData:(MTBackupDatacenterData *)data timestamp:(int32_t)timestamp {
|
||||
+ (bool)checkIpData:(MTBackupDatacenterData *)data timestamp:(int32_t)timestamp source:(NSString *)source {
|
||||
if (data.timestamp >= timestamp + 60 * 20 || data.expirationDate <= timestamp - 60 * 20) {
|
||||
if (MTLogEnabled()) {
|
||||
MTLog(@"[Backup address fetch: backup config validity interval %d ... %d does not include current %d]", data.timestamp, data.expirationDate, timestamp);
|
||||
MTLog(@"[Backup address fetch: backup config from %@ validity interval %d ... %d does not include current %d]", source, data.timestamp, data.expirationDate, timestamp);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
@@ -66,26 +69,6 @@ static NSData *base64_decode(NSString *str) {
|
||||
}
|
||||
}
|
||||
|
||||
+ (MTSignal *)fetchBackupIpsAzure:(bool)isTesting phoneNumber:(NSString *)phoneNumber currentContext:(MTContext *)currentContext {
|
||||
NSDictionary *headers = @{@"Host": @"tcdnb.azureedge.net"};
|
||||
|
||||
return [[[MTHttpRequestOperation dataForHttpUrl:[NSURL URLWithString:isTesting ? @"https://software-download.microsoft.com/testv2/config.txt" : @"https://software-download.microsoft.com/prodv2/config.txt"] headers:headers] mapToSignal:^MTSignal *(NSData *data) {
|
||||
NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
text = [text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"="]];
|
||||
NSData *result = base64_decode(text);
|
||||
NSMutableData *finalData = [[NSMutableData alloc] initWithData:result];
|
||||
[finalData setLength:256];
|
||||
MTBackupDatacenterData *datacenterData = MTIPDataDecode(finalData, phoneNumber);
|
||||
if (datacenterData != nil && [self checkIpData:datacenterData timestamp:(int32_t)[currentContext globalTime]]) {
|
||||
return [MTSignal single:datacenterData];
|
||||
} else {
|
||||
return [MTSignal complete];
|
||||
};
|
||||
}] catch:^MTSignal *(__unused id error) {
|
||||
return [MTSignal complete];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (MTSignal *)fetchBackupIpsResolveGoogle:(bool)isTesting phoneNumber:(NSString *)phoneNumber currentContext:(MTContext *)currentContext {
|
||||
NSArray *hosts = @[
|
||||
@"google.com",
|
||||
@@ -127,7 +110,7 @@ static NSData *base64_decode(NSString *str) {
|
||||
NSMutableData *finalData = [[NSMutableData alloc] initWithData:result];
|
||||
[finalData setLength:256];
|
||||
MTBackupDatacenterData *datacenterData = MTIPDataDecode(finalData, phoneNumber);
|
||||
if (datacenterData != nil && [self checkIpData:datacenterData timestamp:(int32_t)[currentContext globalTime]]) {
|
||||
if (datacenterData != nil && [self checkIpData:datacenterData timestamp:(int32_t)[currentContext globalTime] source:@"resolveGoogle"]) {
|
||||
return [MTSignal single:datacenterData];
|
||||
}
|
||||
}
|
||||
@@ -222,7 +205,6 @@ static NSData *base64_decode(NSString *str) {
|
||||
|
||||
+ (MTSignal * _Nonnull)fetchBackupIps:(bool)isTestingEnvironment currentContext:(MTContext * _Nonnull)currentContext additionalSource:(MTSignal * _Nullable)additionalSource phoneNumber:(NSString * _Nullable)phoneNumber {
|
||||
NSMutableArray *signals = [[NSMutableArray alloc] init];
|
||||
[signals addObject:[self fetchBackupIpsAzure:isTestingEnvironment phoneNumber:phoneNumber currentContext:currentContext]];
|
||||
[signals addObject:[self fetchBackupIpsResolveGoogle:isTestingEnvironment phoneNumber:phoneNumber currentContext:currentContext]];
|
||||
if (additionalSource != nil) {
|
||||
[signals addObject:additionalSource];
|
||||
|
||||
@@ -30,6 +30,10 @@ NSData *MTAesEncrypt(NSData *data, NSData *key, NSData *iv);
|
||||
NSData *MTAesDecrypt(NSData *data, NSData *key, NSData *iv);
|
||||
NSData *MTRsaEncrypt(NSString *publicKey, NSData *data);
|
||||
NSData *MTExp(NSData *base, NSData *exp, NSData *modulus);
|
||||
NSData *MTModSub(NSData *a, NSData *b, NSData *modulus);
|
||||
NSData *MTModMul(NSData *a, NSData *b, NSData *modulus);
|
||||
NSData *MTMul(NSData *a, NSData *b);
|
||||
NSData *MTAdd(NSData *a, NSData *b);
|
||||
bool MTFactorize(uint64_t what, uint64_t *resA, uint64_t *resB);
|
||||
|
||||
NSData *MTAesCtrDecrypt(NSData *data, NSData *key, NSData *iv);
|
||||
|
||||
@@ -369,6 +369,108 @@ NSData *MTExp(NSData *base, NSData *exp, NSData *modulus)
|
||||
return result;
|
||||
}
|
||||
|
||||
NSData *MTModSub(NSData *a, NSData *b, NSData *modulus) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
BIGNUM *bnA = BN_bin2bn(a.bytes, (int)a.length, NULL);
|
||||
|
||||
BIGNUM *bnB = BN_bin2bn(b.bytes, (int)b.length, NULL);
|
||||
|
||||
BIGNUM *bnModulus = BN_bin2bn(modulus.bytes, (int)modulus.length, NULL);
|
||||
|
||||
BIGNUM *bnRes = BN_new();
|
||||
|
||||
BN_mod_sub(bnRes, bnA, bnB, bnModulus, ctx);
|
||||
|
||||
unsigned char *res = malloc((size_t)BN_num_bytes(bnRes));
|
||||
int resLen = BN_bn2bin(bnRes, res);
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
BN_free(bnA);
|
||||
BN_free(bnB);
|
||||
BN_free(bnModulus);
|
||||
BN_free(bnRes);
|
||||
|
||||
NSData *result = [[NSData alloc] initWithBytes:res length:(NSUInteger)resLen];
|
||||
free(res);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NSData *MTModMul(NSData *a, NSData *b, NSData *modulus) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
BIGNUM *bnA = BN_bin2bn(a.bytes, (int)a.length, NULL);
|
||||
|
||||
BIGNUM *bnB = BN_bin2bn(b.bytes, (int)b.length, NULL);
|
||||
|
||||
BIGNUM *bnModulus = BN_bin2bn(modulus.bytes, (int)modulus.length, NULL);
|
||||
|
||||
BIGNUM *bnRes = BN_new();
|
||||
|
||||
BN_mod_mul(bnRes, bnA, bnB, bnModulus, ctx);
|
||||
|
||||
unsigned char *res = malloc((size_t)BN_num_bytes(bnRes));
|
||||
int resLen = BN_bn2bin(bnRes, res);
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
BN_free(bnA);
|
||||
BN_free(bnB);
|
||||
BN_free(bnModulus);
|
||||
BN_free(bnRes);
|
||||
|
||||
NSData *result = [[NSData alloc] initWithBytes:res length:(NSUInteger)resLen];
|
||||
free(res);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NSData *MTMul(NSData *a, NSData *b) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
BIGNUM *bnA = BN_bin2bn(a.bytes, (int)a.length, NULL);
|
||||
|
||||
BIGNUM *bnB = BN_bin2bn(b.bytes, (int)b.length, NULL);
|
||||
|
||||
BIGNUM *bnRes = BN_new();
|
||||
|
||||
BN_mul(bnRes, bnA, bnB, ctx);
|
||||
|
||||
unsigned char *res = malloc((size_t)BN_num_bytes(bnRes));
|
||||
int resLen = BN_bn2bin(bnRes, res);
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
BN_free(bnA);
|
||||
BN_free(bnB);
|
||||
BN_free(bnRes);
|
||||
|
||||
NSData *result = [[NSData alloc] initWithBytes:res length:(NSUInteger)resLen];
|
||||
free(res);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NSData *MTAdd(NSData *a, NSData *b) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
BIGNUM *bnA = BN_bin2bn(a.bytes, (int)a.length, NULL);
|
||||
|
||||
BIGNUM *bnB = BN_bin2bn(b.bytes, (int)b.length, NULL);
|
||||
|
||||
BIGNUM *bnRes = BN_new();
|
||||
|
||||
BN_add(bnRes, bnA, bnB);
|
||||
|
||||
unsigned char *res = malloc((size_t)BN_num_bytes(bnRes));
|
||||
int resLen = BN_bn2bin(bnRes, res);
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
BN_free(bnA);
|
||||
BN_free(bnB);
|
||||
BN_free(bnRes);
|
||||
|
||||
NSData *result = [[NSData alloc] initWithBytes:res length:(NSUInteger)resLen];
|
||||
free(res);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline uint64_t mygcd(uint64_t a, uint64_t b)
|
||||
{
|
||||
while (a != 0 && b != 0)
|
||||
|
||||
Reference in New Issue
Block a user