mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-03-01 14:20:58 +00:00
reset auth-token if identifierForVendor changed
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#import "BITHockeyAppClient.h"
|
||||
|
||||
static NSString* const kBITAuthenticatorAuthTokenKey = @"BITAuthenticatorAuthTokenKey";
|
||||
static NSString* const kBITAuthenticatorAuthTokenVendorIdentifierKey = @"BITAuthenticatorAuthTokenVendorIdentifierKey";
|
||||
static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthenticatorLastAuthenticatedVersionKey";
|
||||
|
||||
@implementation BITAuthenticator {
|
||||
@@ -459,6 +460,7 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
||||
|
||||
- (void) cleanupInternalStorage {
|
||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
||||
[self setLastAuthenticatedVersion:nil];
|
||||
}
|
||||
|
||||
@@ -486,15 +488,29 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
||||
[self willChangeValueForKey:@"installationIdentification"];
|
||||
if(nil == authenticationToken) {
|
||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
||||
} else {
|
||||
[self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey];
|
||||
NSString *identifierForVendor = self.currentDevice.identifierForVendor.UUIDString;
|
||||
[self addStringValueToKeychain:identifierForVendor forKey:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
||||
}
|
||||
[self didChangeValueForKey:@"installationIdentification"];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)authenticationToken {
|
||||
return [self stringValueFromKeychainForKey:kBITAuthenticatorAuthTokenKey];
|
||||
NSString *authToken = [self stringValueFromKeychainForKey:kBITAuthenticatorAuthTokenKey];
|
||||
if(nil == authToken) return nil;
|
||||
|
||||
//check if this was generated on the same device we're running now
|
||||
NSString *currentVendorUUIDString = self.currentDevice.identifierForVendor.UUIDString;
|
||||
if(![currentVendorUUIDString isEqualToString:[self stringValueFromKeychainForKey:kBITAuthenticatorAuthTokenVendorIdentifierKey]]) {
|
||||
BITHockeyLog(@"Vendor identifier mismatch for stored auth-token. Resetting.");
|
||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
||||
return nil;
|
||||
}
|
||||
return authToken;
|
||||
}
|
||||
|
||||
- (void)setLastAuthenticatedVersion:(NSString *)lastAuthenticatedVersion {
|
||||
|
||||
@@ -27,6 +27,21 @@
|
||||
- (NSString*) uniqueIdentifier {return @"reallyUnique";}
|
||||
@end
|
||||
|
||||
@interface MyDeviceWithIdentifierForVendor : MyDevice
|
||||
@property (copy) NSUUID *identifierForVendor;
|
||||
@end
|
||||
@implementation MyDeviceWithIdentifierForVendor
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
if( self ) {
|
||||
_identifierForVendor = [NSUUID UUID];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
|
||||
@interface BITAuthenticatorTests : SenTestCase
|
||||
@@ -325,4 +340,14 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
assertThat(error, nilValue());
|
||||
}
|
||||
|
||||
- (void) testThatAuthTokenIsResettingWhenVendorIdentifierChanged {
|
||||
MyDeviceWithIdentifierForVendor *device = [MyDeviceWithIdentifierForVendor new];
|
||||
_sut.currentDevice = (id)device;
|
||||
[_sut didAuthenticateWithToken:@"SuperToken"];
|
||||
NSString *ident = [_sut installationIdentification];
|
||||
assertThat(ident, equalTo(@"SuperToken"));
|
||||
device.identifierForVendor = [NSUUID UUID];
|
||||
ident = [_sut installationIdentification];
|
||||
assertThat(ident, isNot(equalTo(@"SuperToken")));
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user