Cleaning environment prefs

pull/1/head
Frederic Jacobs 11 years ago
parent 3031ae741e
commit 4b2acd62f3

@ -168,6 +168,7 @@ static Environment* environment = nil;
+(void)resetAppData{
[SGNKeychainUtil wipeKeychain];
[NSUserDefaults resetStandardUserDefaults];
[[[Environment getCurrent] preferences] clear];
}
@end

@ -12,7 +12,7 @@
require(macKey != nil);
require(cipherIvSalt != nil);
require([cipherIvSalt length] == IV_SALT_LENGTH);
SrtpStream* s = [SrtpStream new];
s->cipherIvSalt = cipherIvSalt;
s->macKey = macKey;
@ -24,38 +24,38 @@
-(RtpPacket*) encryptAndAuthenticateNormalRtpPacket:(RtpPacket*)normalRtpPacket {
require(normalRtpPacket != nil);
NSData* payload = [normalRtpPacket payload];
NSData* iv = [self getIvForSequenceNumber:[normalRtpPacket sequenceNumber] andSynchronizationSourceIdentifier:[normalRtpPacket synchronizationSourceIdentifier]];
NSData* encryptedPayload = [payload encryptWithAesInCounterModeWithKey:cipherKey andIv:iv];
RtpPacket* encryptedRtpPacket = [normalRtpPacket withPayload:encryptedPayload];
NSData* hmac = [[encryptedRtpPacket rawPacketDataUsingInteropOptions:@[]] hmacWithSha1WithKey:macKey];
NSData* authenticatedEncryptedPayload = [@[encryptedPayload, hmac] concatDatas];
return [encryptedRtpPacket withPayload:authenticatedEncryptedPayload];
}
-(RtpPacket*) verifyAuthenticationAndDecryptSecuredRtpPacket:(RtpPacket*)securedRtpPacket {
require(securedRtpPacket != nil);
checkOperationDescribe([[securedRtpPacket payload] length] >= HMAC_LENGTH, @"Payload not long enough to include hmac");
NSData* authenticatedData = [securedRtpPacket rawPacketDataUsingInteropOptions:nil];
NSData* includedHmac = [authenticatedData takeLastVolatile:HMAC_LENGTH];
NSData* expectedHmac = [[authenticatedData skipLastVolatile:HMAC_LENGTH] hmacWithSha1WithKey:macKey];
checkOperationDescribe([expectedHmac length] == HMAC_LENGTH, @"Hmac length constant is wrong");
checkOperationDescribe([includedHmac isEqualToData_TimingSafe:expectedHmac], @"Authentication failed.");
NSData* iv = [self getIvForSequenceNumber:[securedRtpPacket sequenceNumber] andSynchronizationSourceIdentifier:[securedRtpPacket synchronizationSourceIdentifier]];
NSData* encryptedPayload = [[securedRtpPacket payload] skipLastVolatile:HMAC_LENGTH];
NSData* decryptedPayload = [encryptedPayload decryptWithAesInCounterModeWithKey:cipherKey andIv:iv];
return [securedRtpPacket withPayload:decryptedPayload];
}
-(NSData*)getIvForSequenceNumber:(uint16_t)sequenceNumber andSynchronizationSourceIdentifier:(uint64_t)synchronizationSourceIdentifier {
int64_t logicalSequence = [sequenceCounter convertNext:sequenceNumber];
NSMutableData* iv = [NSMutableData dataWithLength:IV_LENGTH];
[iv replaceBytesStartingAt:0 withData:cipherIvSalt];
uint8_t* b = (uint8_t*)[iv bytes];
@ -67,7 +67,7 @@
b[11] ^= (uint8_t)((logicalSequence >> 16) & 0xFF);
b[12] ^= (uint8_t)((logicalSequence >> 8) & 0xFF);
b[13] ^= (uint8_t)((logicalSequence >> 0) & 0xFF);
return iv;
}

Loading…
Cancel
Save