Advertisement
neetrath

Untitled

Aug 27th, 2018
244
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.        
  30.         [Utils displayAlertWithTitle:@"Information" andMessage:[NSString stringWithFormat:@"mustBeSent: %d", mustBeSent]];
  31.         [Utils displayAlertWithTitle:@"Information" andMessage:[NSString stringWithFormat:@"alreadyActivated: %d", alreadyActivated]];
  32.        
  33.         if (mustBeSent && alreadyActivated)
  34.         {
  35.            
  36.             // Loads the static vector from the storage
  37.             NSData* nsStaticVector = [storage getBytesForKey:STORAGE_KEY_STATIC_VECTOR];
  38.             vds_int32 staticVectorLength = (vds_int32) nsStaticVector.length;
  39.             staticVector = (vds_byte*) malloc(sizeof(vds_byte) * staticVectorLength);
  40.             [nsStaticVector getBytes:staticVector length:staticVectorLength];
  41.            
  42.             // Loads the dynamic vector from the storage
  43.             NSData* nsDynamicVector = [storage getBytesForKey:STORAGE_KEY_DYNAMIC_VECTOR];
  44.             vds_int32 dynamicVectorFromStorageLength = (vds_int32) nsDynamicVector.length;
  45.             vds_byte* dynamicVectorFromStorage = (vds_byte*) malloc(sizeof(vds_byte) * dynamicVectorFromStorageLength);
  46.             [nsDynamicVector getBytes:dynamicVectorFromStorage length:dynamicVectorFromStorageLength];
  47.            
  48.             // Allocates the dynamic vector with a correct length
  49.             // Indeed, if the DIGIPASS SDK is updated, the dynamic vector length can increase
  50.             int dynamicVectorLength;
  51.             vds_int32 dynamicVectorLengthNew = dynamicVectorLength;
  52.             vds_int32 retCode = DPSDK_GetDynamicVectorLength(staticVector, staticVectorLength, &dynamicVectorLengthNew);
  53.             if(retCode != RETURN_CODE_SUCCESS){
  54.                 [Utils displayAlertWithTitle:@"DynamicVectorLength ERROR" andMessage:[NSString stringWithFormat:@"Retcode: %d", retCode]];
  55.                 return @"DynamicVectorLength ERROR";
  56.             }
  57.             dynamicVectorLength = dynamicVectorLengthNew;
  58.             vds_byte* dynamicVector = (vds_byte*) malloc(sizeof(vds_byte) * dynamicVectorLength);
  59.             memset(dynamicVector, 0, dynamicVectorLength);
  60.             memcpy(dynamicVector, dynamicVectorFromStorage, dynamicVectorFromStorageLength);
  61.             free(dynamicVectorFromStorage);
  62.            
  63.             // Encrypts the VASCO Notification Identifier
  64.             SecureChannelMessage secureChannelMessage;
  65.             memset(&secureChannelMessage, 0, sizeof(SecureChannelMessage));
  66.             retCode = DPSDK_GenerateSecureChannelInformationMessage(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, (vds_ascii*) vascoNotificationIdentifier.UTF8String,
  67.                                                                     SECURE_CHANNEL_MESSAGE_PROTECTION_HMAC_AESCTR, fingerprintDigipass, &secureChannelMessage);
  68.             if (retCode != RETURN_CODE_SUCCESS)
  69.             {
  70.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot encrypt message. Error code: %d", (int)retCode];
  71.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  72.                 return message;
  73.             }
  74.            
  75.             // Gets the serial number
  76.             vds_ascii serialNumber[LENGTH_SERIAL_NUMBER + 1];
  77.             memset(serialNumber, 0, sizeof(serialNumber));
  78.             retCode = DPSDK_GetDigipassProperty(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, PROPERTY_SERIAL_NUMBER, serialNumber, sizeof(serialNumber), 0);
  79.             if (retCode != RETURN_CODE_SUCCESS)
  80.             {
  81.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot get serial number. Error code: %d", (int)retCode];
  82.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  83.                 return message;
  84.             }
  85.            
  86.             // Gets the sequence number
  87.             vds_byte sequenceNumber;
  88.             retCode = DPSDK_GetDigipassProperty(staticVector, staticVectorLength, dynamicVector, dynamicVectorLength, PROPERTY_SEQUENCE_NUMBER, &sequenceNumber, sizeof(sequenceNumber), 0);
  89.             if (retCode != RETURN_CODE_SUCCESS)
  90.             {
  91.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot get sequence number property. Error code: %d", (int)retCode];
  92.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  93.                 return message;
  94.             }
  95.            
  96.             // Sends the VASCO Notification Identifier
  97.             NSMutableString* request = [NSMutableString stringWithString:NETWORK_KEY_NOTIFICATION_REGISTRATION];
  98.             [request appendFormat:@"&%@=%s", NETWORK_KEY_SERIAL_NUMBER, serialNumber];
  99.             [request appendFormat:@"&%@=%d", NETWORK_KEY_SEQUENCE_NUMBER, sequenceNumber];
  100.             [request appendFormat:@"&%@=%s", NETWORK_KEY_VASCO_NOTIFICATION_IDENTIFIER, secureChannelMessage.rawData];
  101.             NSLog(@"Request content: %@", request);
  102.             NSDictionary* response = [Utils performNetworkRequest:@"/dp-gateway/registerNotif" withContent:request multiDevice:YES];
  103.             NSString* returnCode = [response valueForKey:NETWORK_KEY_RETCODE];
  104.             if (returnCode.intValue != 0)
  105.             {
  106.                 NSString* message = [NSString stringWithFormat:@"Failed to register push notification. Cannot register VASCO notification ID. Error code: %@", returnCode];
  107.                 [Utils displayAlertWithTitle:@"Register push notification failed" andMessage:message];
  108.                 return message;
  109.             }
  110.            
  111.             // Stores the VASCO Notification Identifier
  112.             [storage putString:vascoNotificationIdentifier forKey:STORAGE_KEY_VASCO_NOTIFICATION_IDENTIFIER];
  113.             [storage writeWithFingerPrint:deviceFingerprintStorage andIterationNumber:ITERATION_COUNTER];
  114.         }
  115.     }
  116.     @catch (NSException* e)
  117.     {
  118.         [Utils displayAlertWithTitle:@"Register push notification failed." andMessage:e.reason];
  119.     }
  120.     @finally
  121.     {
  122.        
  123.         // Frees the memory
  124.         if (staticVector != NULL)
  125.         {
  126.             free(staticVector);
  127.         }
  128.         if (dynamicVector != NULL)
  129.         {
  130.             free(dynamicVector);
  131.         }
  132.        
  133.     }
  134.     [Utils displayAlertWithTitle:@"Information" andMessage: @"Register for push notification successful"];
  135.     return @"";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement