Advertisement
neetrath

Untitled

Aug 27th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vds_byte* staticVector = NULL;
  2.     vds_byte* dynamicVector = NULL;
  3.    
  4.     @try
  5.     {
  6.        
  7.         // Creates the VASCO Notification Identifier from the token provided by the system
  8.         // The VASCO Notification Identifier must be transmitted to the server for a notification sending purpose
  9.         NSString* vascoNotificationIdentifier = [NotificationSDKClient getVASCONotificationIdentifer:devToken];
  10.        
  11.         // Gets the device fingerprint
  12.         NSString* deviceFingerprintDigipass = [DeviceBindingSDK getDeviceFingerPrintWithDynamicSalt:[Utils getSaltDigipass]];
  13.         NSString* deviceFingerprintStorage = [DeviceBindingSDK getDeviceFingerPrintWithDynamicSalt:[Utils getSaltStorage]];
  14.         vds_ascii* fingerprintDigipass = (vds_ascii*) [deviceFingerprintDigipass cStringUsingEncoding:NSASCIIStringEncoding];
  15.        
  16.         // Gets the previous VASCO Notification Identifier from the storage
  17.         SecureStorageSDK* storage = [[SecureStorageSDK alloc] initWithFileName:STORAGE_FILE_NAME useFingerPrint:deviceFingerprintStorage andIterationNumber:ITERATION_COUNTER];
  18.         NSString* previousVASCONotificationIdentifier = nil;
  19.         if ([storage containsKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER])
  20.         {
  21.             previousVASCONotificationIdentifier = [storage getStringForKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER];
  22.         }
  23.        
  24.         // Checks whether the VASCO Notification Identifier must be transmitted to the server
  25.         bool mustBeSent = previousVASCONotificationIdentifier == nil || ![previousVASCONotificationIdentifier isEqualToString:vascoNotificationIdentifier];
  26.        
  27.         // Checks whether the DIGIPASS has already been activated
  28.         bool alreadyActivated = [storage containsKey:STORAGE_KEY_DYNAMIC_VECTOR];
  29.         if (mustBeSent && alreadyActivated)
  30.         {
  31.            
  32.             // Loads the static vector from the storage
  33.             NSData* nsStaticVector = [storage getBytesForKey:STORAGE_KEY_STATIC_VECTOR];
  34.             vds_int32 staticVectorLength = (vds_int32) nsStaticVector.length;
  35.             staticVector = (vds_byte*) malloc(sizeof(vds_byte) * staticVectorLength);
  36.             [nsStaticVector getBytes:staticVector length:staticVectorLength];
  37.            
  38.             // Loads the dynamic vector from the storage
  39.             NSData* nsDynamicVector = [storage getBytesForKey:STORAGE_KEY_DYNAMIC_VECTOR];
  40.             vds_int32 dynamicVectorFromStorageLength = (vds_int32) nsDynamicVector.length;
  41.             vds_byte* dynamicVectorFromStorage = (vds_byte*) malloc(sizeof(vds_byte) * dynamicVectorFromStorageLength);
  42.             [nsDynamicVector getBytes:dynamicVectorFromStorage length:dynamicVectorFromStorageLength];
  43.            
  44.             // Allocates the dynamic vector with a correct length
  45.             // Indeed, if the DIGIPASS SDK is updated, the dynamic vector length can increase
  46.             int dynamicVectorLength;
  47.             vds_int32 dynamicVectorLengthNew = dynamicVectorLength;
  48.             vds_int32 retCode = DPSDK_GetDynamicVectorLength(staticVector, staticVectorLength, &dynamicVectorLengthNew);
  49.             if(retCode != RETURN_CODE_SUCCESS){
  50.                 [Utils displayAlertWithTitle:@"DynamicVectorLength ERROR" andMessage:[NSString stringWithFormat:@"Retcode: %d", retCode]];
  51.                 return @"DynamicVectorLength ERROR";
  52.             }
  53.             dynamicVectorLength = dynamicVectorLengthNew;
  54.             vds_byte* dynamicVector = (vds_byte*) malloc(sizeof(vds_byte) * dynamicVectorLength);
  55.             memset(dynamicVector, 0, dynamicVectorLength);
  56.             memcpy(dynamicVector, dynamicVectorFromStorage, dynamicVectorFromStorageLength);
  57.             free(dynamicVectorFromStorage);
  58.            
  59.             // Encrypts the VASCO Notification Identifier
  60.             SecureChannelMessage secureChannelMessage;
  61.             memset(&secureChannelMessage, 0, sizeof(SecureChannelMessage));
  62.             retCode = DPSDK_GenerateSecureChannelInformationMessage(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, (vds_ascii*) vascoNotificationIdentifier.UTF8String,
  63.                                                                     SECURE_CHANNEL_MESSAGE_PROTECTION_HMAC_AESCTR, fingerprintDigipass, &secureChannelMessage);
  64.             if (retCode != RETURN_CODE_SUCCESS)
  65.             {
  66.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot encrypt message. Error code: %d", (int)retCode];
  67.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  68.                 return message;
  69.             }
  70.            
  71.             // Gets the serial number
  72.             vds_ascii serialNumber[LENGTH_SERIAL_NUMBER + 1];
  73.             memset(serialNumber, 0, sizeof(serialNumber));
  74.             retCode = DPSDK_GetDigipassProperty(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, PROPERTY_SERIAL_NUMBER, serialNumber, sizeof(serialNumber), 0);
  75.             if (retCode != RETURN_CODE_SUCCESS)
  76.             {
  77.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot get serial number. Error code: %d", (int)retCode];
  78.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  79.                 return message;
  80.             }
  81.            
  82.             // Gets the sequence number
  83.             vds_byte sequenceNumber;
  84.             retCode = DPSDK_GetDigipassProperty(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, PROPERTY_SEQUENCE_NUMBER, &sequenceNumber, sizeof(sequenceNumber), 0);
  85.             if (retCode != RETURN_CODE_SUCCESS)
  86.             {
  87.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot get sequence number property. Error code: %d", (int)retCode];
  88.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  89.                 return message;
  90.             }
  91.            
  92.             // Sends the VASCO Notification Identifier
  93.             NSMutableString* request = [NSMutableString stringWithString:NETWORK_KEY_NOTIFICATION_REGISTRATION];
  94.             [request appendFormat:@"&%@=%s", NETWORK_KEY_SERIAL_NUMBER, serialNumber];
  95.             [request appendFormat:@"&%@=%d", NETWORK_KEY_SEQUENCE_NUMBER, sequenceNumber];
  96.             [request appendFormat:@"&%@=%s", NETWORK_KEY_VASCO_NOTIFICATION_IDENTIFIER, secureChannelMessage.rawData];
  97.             NSLog(@"Request content: %@", request);
  98.             NSDictionary* response = [Utils performNetworkRequest:@"/dp-gateway/registerNotif" withContent:request multiDevice:YES];
  99.             NSString* returnCode = [response valueForKey:NETWORK_KEY_RETCODE];
  100.             if (returnCode.intValue != 0)
  101.             {
  102.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot register VASCO notification ID. Error code: %@", returnCode];
  103.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  104.                 return message;
  105.             }
  106.            
  107.             // Stores the VASCO Notification Identifier
  108.             [storage putString:vascoNotificationIdentifier forKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER];
  109.             [storage writeWithFingerPrint:deviceFingerprintStorage andIterationNumber:ITERATION_COUNTER];
  110.         }
  111.     }
  112.     @catch (NSException* e)
  113.     {
  114.         [Utils displayAlertWithTitle:@"Register push notification failed." andMessage:e.reason];
  115.     }
  116.     @finally
  117.     {
  118.        
  119.         // Frees the memory
  120.         if (staticVector != NULL)
  121.         {
  122.             free(staticVector);
  123.         }
  124.         if (dynamicVector != NULL)
  125.         {
  126.             free(dynamicVector);
  127.         }
  128.        
  129.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement