Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vds_byte* staticVector = NULL;
- vds_byte* dynamicVector = NULL;
- @try
- {
- // Creates the VASCO Notification Identifier from the token provided by the system
- // The VASCO Notification Identifier must be transmitted to the server for a notification sending purpose
- NSString* vascoNotificationIdentifier = [NotificationSDKClient getVASCONotificationIdentifer:devToken];
- // Gets the device fingerprint
- NSString* deviceFingerprintDigipass = [DeviceBindingSDK getDeviceFingerPrintWithDynamicSalt:[Utils getSaltDigipass]];
- NSString* deviceFingerprintStorage = [DeviceBindingSDK getDeviceFingerPrintWithDynamicSalt:[Utils getSaltStorage]];
- vds_ascii* fingerprintDigipass = (vds_ascii*) [deviceFingerprintDigipass cStringUsingEncoding:NSASCIIStringEncoding];
- // Gets the previous VASCO Notification Identifier from the storage
- SecureStorageSDK* storage = [[SecureStorageSDK alloc] initWithFileName:STORAGE_FILE_NAME useFingerPrint:deviceFingerprintStorage andIterationNumber:ITERATION_COUNTER];
- NSString* previousVASCONotificationIdentifier = nil;
- if ([storage containsKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER])
- {
- previousVASCONotificationIdentifier = [storage getStringForKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER];
- }
- // Checks whether the VASCO Notification Identifier must be transmitted to the server
- bool mustBeSent = previousVASCONotificationIdentifier == nil || ![previousVASCONotificationIdentifier isEqualToString:vascoNotificationIdentifier];
- // Checks whether the DIGIPASS has already been activated
- bool alreadyActivated = [storage containsKey:STORAGE_KEY_DYNAMIC_VECTOR];
- [Utils displayAlertWithTitle:@"Information" andMessage:[NSString stringWithFormat:@"mustBeSent: %d", mustBeSent]];
- [Utils displayAlertWithTitle:@"Information" andMessage:[NSString stringWithFormat:@"alreadyActivated: %d", alreadyActivated]];
- if (mustBeSent && alreadyActivated)
- {
- // Loads the static vector from the storage
- NSData* nsStaticVector = [storage getBytesForKey:STORAGE_KEY_STATIC_VECTOR];
- vds_int32 staticVectorLength = (vds_int32) nsStaticVector.length;
- staticVector = (vds_byte*) malloc(sizeof(vds_byte) * staticVectorLength);
- [nsStaticVector getBytes:staticVector length:staticVectorLength];
- // Loads the dynamic vector from the storage
- NSData* nsDynamicVector = [storage getBytesForKey:STORAGE_KEY_DYNAMIC_VECTOR];
- vds_int32 dynamicVectorFromStorageLength = (vds_int32) nsDynamicVector.length;
- vds_byte* dynamicVectorFromStorage = (vds_byte*) malloc(sizeof(vds_byte) * dynamicVectorFromStorageLength);
- [nsDynamicVector getBytes:dynamicVectorFromStorage length:dynamicVectorFromStorageLength];
- // Allocates the dynamic vector with a correct length
- // Indeed, if the DIGIPASS SDK is updated, the dynamic vector length can increase
- int dynamicVectorLength;
- vds_int32 dynamicVectorLengthNew = dynamicVectorLength;
- vds_int32 retCode = DPSDK_GetDynamicVectorLength(staticVector, staticVectorLength, &dynamicVectorLengthNew);
- if(retCode != RETURN_CODE_SUCCESS){
- [Utils displayAlertWithTitle:@"DynamicVectorLength ERROR" andMessage:[NSString stringWithFormat:@"Retcode: %d", retCode]];
- return @"DynamicVectorLength ERROR";
- }
- dynamicVectorLength = dynamicVectorLengthNew;
- vds_byte* dynamicVector = (vds_byte*) malloc(sizeof(vds_byte) * dynamicVectorLength);
- memset(dynamicVector, 0, dynamicVectorLength);
- memcpy(dynamicVector, dynamicVectorFromStorage, dynamicVectorFromStorageLength);
- free(dynamicVectorFromStorage);
- // Encrypts the VASCO Notification Identifier
- SecureChannelMessage secureChannelMessage;
- memset(&secureChannelMessage, 0, sizeof(SecureChannelMessage));
- retCode = DPSDK_GenerateSecureChannelInformationMessage(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, (vds_ascii*) vascoNotificationIdentifier.UTF8String,
- SECURE_CHANNEL_MESSAGE_PROTECTION_HMAC_AESCTR, fingerprintDigipass, &secureChannelMessage);
- if (retCode != RETURN_CODE_SUCCESS)
- {
- NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot encrypt message. Error code: %d", (int)retCode];
- [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
- return message;
- }
- // Gets the serial number
- vds_ascii serialNumber[LENGTH_SERIAL_NUMBER + 1];
- memset(serialNumber, 0, sizeof(serialNumber));
- retCode = DPSDK_GetDigipassProperty(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, PROPERTY_SERIAL_NUMBER, serialNumber, sizeof(serialNumber), 0);
- if (retCode != RETURN_CODE_SUCCESS)
- {
- NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot get serial number. Error code: %d", (int)retCode];
- [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
- return message;
- }
- // Gets the sequence number
- vds_byte sequenceNumber;
- retCode = DPSDK_GetDigipassProperty(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, PROPERTY_SEQUENCE_NUMBER, &sequenceNumber, sizeof(sequenceNumber), 0);
- if (retCode != RETURN_CODE_SUCCESS)
- {
- NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot get sequence number property. Error code: %d", (int)retCode];
- [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
- return message;
- }
- // Sends the VASCO Notification Identifier
- NSMutableString* request = [NSMutableString stringWithString:NETWORK_KEY_NOTIFICATION_REGISTRATION];
- [request appendFormat:@"&%@=%s", NETWORK_KEY_SERIAL_NUMBER, serialNumber];
- [request appendFormat:@"&%@=%d", NETWORK_KEY_SEQUENCE_NUMBER, sequenceNumber];
- [request appendFormat:@"&%@=%s", NETWORK_KEY_VASCO_NOTIFICATION_IDENTIFIER, secureChannelMessage.rawData];
- NSLog(@"Request content: %@", request);
- NSDictionary* response = [Utils performNetworkRequest:@"/dp-gateway/registerNotif" withContent:request multiDevice:YES];
- NSString* returnCode = [response valueForKey:NETWORK_KEY_RETCODE];
- if (returnCode.intValue != 0)
- {
- NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot register VASCO notification ID. Error code: %@", returnCode];
- [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
- return message;
- }
- // Stores the VASCO Notification Identifier
- [storage putString:vascoNotificationIdentifier forKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER];
- [storage writeWithFingerPrint:deviceFingerprintStorage andIterationNumber:ITERATION_COUNTER];
- }
- }
- @catch (NSException* e)
- {
- [Utils displayAlertWithTitle:@"Register push notification failed." andMessage:e.reason];
- }
- @finally
- {
- // Frees the memory
- if (staticVector != NULL)
- {
- free(staticVector);
- }
- if (dynamicVector != NULL)
- {
- free(dynamicVector);
- }
- }
- [Utils displayAlertWithTitle:@"Information" andMessage: @"Register for push notification successful"];
- return @"";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement