Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #520 from bitstadium/cleanup/remove-code-for-authe…
Browse files Browse the repository at this point in the history
…ntication-by-itunesartwork

Remove code to magically authenticate using the itunesartwork. This i…
  • Loading branch information
guperrot authored Jun 15, 2018
2 parents 133099c + 352f5b0 commit 4f16b55
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions Classes/BITAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
static NSString *const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAuthTokenTypeKey";

typedef unsigned int bit_uint32;
static unsigned char kBITPNGHeader[8] = {137, 80, 78, 71, 13, 10, 26, 10};
static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};


@interface BITAuthenticator()

Expand Down Expand Up @@ -158,7 +155,6 @@ - (void)identifyWithCompletion:(void (^)(BOOL identified, NSError *))completion
return;
}

[self processFullSizeImage];
if (self.identified) {
if (completion) { completion(YES, nil); }
return;
Expand Down Expand Up @@ -766,93 +762,6 @@ - (void)cleanupInternalStorage {
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenTypeKey];
}

- (void)processFullSizeImage {
#ifdef BIT_INTERNAL_DEBUG
NSString* path = [[NSBundle mainBundle] pathForResource:@"iTunesArtwork" ofType:@"png"];
#else
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/../iTunesArtwork"];
#endif

struct stat fs;
int fd = open([path UTF8String], O_RDONLY, 0);
if (fstat(fd, &fs) < 0) {
// File not found
close(fd);
return;
}

BITHockeyLogDebug(@"Processing full size image for possible authentication");

unsigned char *buffer, *source;
source = (unsigned char *)malloc((unsigned long)fs.st_size);
if (read(fd, source, (unsigned long)fs.st_size) != fs.st_size) {
close(fd);
// Couldn't read file
free(source);
return;
}

if ((fs.st_size < 20) || (memcmp(source, kBITPNGHeader, 8))) {
// Not a PNG
free(source);
return;
}

buffer = source + 8;

NSString *result = nil;
bit_uint32 length;
unsigned char *name;
unsigned char *data;
int chunk_index = 0;
long long bytes_left = fs.st_size - 8;
do {
memcpy(&length, buffer, 4);
length = ntohl(length);

buffer += 4;
name = (unsigned char *)malloc(5);
name[4] = 0;
memcpy(name, buffer, 4);

buffer += 4;
data = (unsigned char *)malloc(length + 1);

if (bytes_left >= length) {
memcpy(data, buffer, length);

buffer += length;
buffer += 4;
if (!strcmp((const char *)name, "tEXt")) {
data[length] = 0;
NSString *key = [NSString stringWithCString:(char *)data encoding:NSUTF8StringEncoding];

if ([key isEqualToString:@"Data"]) {
result = [NSString stringWithCString:(char *)(data + key.length + 1) encoding:NSUTF8StringEncoding];
}
}

if (!memcmp(name, kBITPNGEndChunk, 4)) {
chunk_index = 128;
}
}

free(data);
free(name);

bytes_left -= (length + 3 * 4);
} while ((chunk_index++ < 128) && (bytes_left > 8));

free(source);

if (result) {
BITHockeyLogDebug(@"Authenticating using full size image information: %@", result);
[self handleOpenURL:[NSURL URLWithString:result] sourceApplication:nil annotation:nil];
} else {
BITHockeyLogDebug(@"No authentication information found");
}
}

#pragma mark - NSNotification

- (void)registerObservers {
Expand Down

0 comments on commit 4f16b55

Please sign in to comment.