/// <summary>
        /// Read XAML formatted text into message types.
        /// </summary>
        /// <param name="contents"></param>
        public void ReadConfig(string contents)
        {
            Regex typeDetails = new Regex(@"(\w+)\s*=\s*""([\w\s]+)"""),
                  fieldReg = new Regex(@"<\s*Field\s+(.*?)\\\s*(Field\s*)?>", RegexOptions.Singleline);
            MatchCollection   detailMatches, fieldMatches;
            MessageFieldModel messageFieldModel;

            // Return if invalid
            if (null == contents)
            {
                return;
            }

            // Set general Type details
            if (typeDetails.IsMatch(contents))
            {
                detailMatches = typeDetails.Matches(contents);
                ReadProperties(detailMatches);
            }

            // Define fields for each field found
            if (fieldReg.IsMatch(contents))
            {
                fieldMatches = fieldReg.Matches(contents);
                foreach (Match fieldMatch in fieldMatches)
                {
                    messageFieldModel = new MessageFieldModel();
                    messageFieldModel.ReadConfig(fieldMatch.Groups[1].Value);

                    MessageFields.Add(messageFieldModel);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Destroys the uploadProgressMessage gameObject
 /// </summary>
 /// <param name="msgFields">Message Fiels of the uploadProgressMessage</param>
 public void DestroyUploadProgressMessage(MessageFields msgFields)
 {
     if (msgFields.gameObject != null)
     {
         Destroy(msgFields.gameObject);
     }
 }
예제 #3
0
    /// <summary>
    /// Uploads the files present in the folder selected by the user
    /// </summary>
    /// <param name="folderPath">Path of folder</param>
    /// <returns></returns>
    IEnumerator UploadFolderToAmazonS3(string folderPath)
    {
        bool          errorOccured   = false;
        string        errorMsg       = null;
        string        rootName       = FileBrowserHelpers.GetFilename(folderPath);
        List <string> uploadFileList = GetUploadFileList(folderPath, out long uploadSize);

        if (uploadSize > MaxUploadFileSize)
        {
            DisplayUploadErrorMessage("File size is too large. It must be less than 50MB.");
            yield break;
        }
        if (uploadFileList.Count > 1)
        {
            int           numberOfFiles = uploadFileList.Count;
            float         index         = 0;
            float         uploadPercentage;
            string        key, progress;
            MessageFields uploadMsgFields = DisplayUploadProgressMessage();
            foreach (string file in uploadFileList)
            {
                uploadPercentage = (index / numberOfFiles) * 100;
                progress         = "Progress : " + Mathf.Round(uploadPercentage).ToString() + "%";
                uploadMsgFields.MessageDetails("Upload Progress ...", progress);
                key = file.Substring(file.LastIndexOf(rootName));
                key = key.Replace("\\", "/");
                yield return(GetPreSignedRequest(key, file, false, (e, m) => { errorOccured = e; errorMsg = m; }));

                if (errorOccured)
                {
                    break;
                }
                index++;
            }

            DestroyUploadProgressMessage(uploadMsgFields);

            if (errorOccured)
            {
                DisplayUploadErrorMessage(errorMsg);
                yield break;
            }
            if (gltfUrl != null)
            {
                yield return(PushUrlToDatabase(gltfUrl));
            }
        }
        else if (uploadFileList.Count == 1)
        {
            string filePath = uploadFileList[0];
            string key      = filePath.Substring(filePath.LastIndexOf(rootName));
            key = key.Replace("\\", "/");
            yield return(GetPreSignedRequest(key, filePath, true, (e, m) => { }));
        }
        else
        {
            DisplayUploadErrorMessage("Folder is Empty.");
        }
    }
예제 #4
0
        /// <summary>
        /// Searches the current FieldCollection for the field in the same spot as messageField, then pulls it forward.
        /// </summary>
        /// <param name="messageField"></param>
        public MessageFieldModel PrioritizeField(MessageFieldModel messageField)
        {
            MessageFieldDetailsModel fieldDetails = messageField.MessageFieldDetails;
            MessageFieldModel        newField     = MessageFields.FindField(fieldDetails.WordNum, fieldDetails.BitStart);

            newField.ZIndex++;
            return(newField);
        }
예제 #5
0
 /// <summary>
 /// Displays a pop-up box while selected file is getting imported and the Viewer Scene is loaded
 /// </summary>
 void DisplayLoadingMessage()
 {
     _loadingMessage = UIManager.Instance.CreateMessageWindow();
     if (_loadingMessage != null)
     {
         MessageFields msgFields = _loadingMessage.GetComponent <MessageFields>();
         msgFields.MessageDetails("Loading...", "Importing selected object and starting AR Scene.");
     }
 }
예제 #6
0
    /// <summary>
    /// Used to display the progress of file upload
    /// </summary>
    /// <returns>Message Fields object that display the actual message, paasing it as it needs to be updated in a loop</returns>
    public MessageFields DisplayUploadProgressMessage()
    {
        GameObject uploadProgressMessage = UIManager.Instance.CreateMessageWindow();

        if (uploadProgressMessage != null)
        {
            MessageFields msgFields = uploadProgressMessage.GetComponent <MessageFields>();
            msgFields.MessageDetails("Upload Progress ...", "Progress : ");
            return(msgFields);
        }
        return(null);
    }
예제 #7
0
            public IPinGenerationResponse TranslatePinFromBdkToZpkEncryption(string bdk, string zpk, string keySerialNumber, string pinBlock, string accountNumber)
            {
                if (string.IsNullOrEmpty(bdk))
                {
                    throw new ArgumentNullException("bdk");
                }
                if (string.IsNullOrEmpty(zpk))
                {
                    throw new ArgumentNullException("zpk");
                }
                if (string.IsNullOrEmpty(keySerialNumber))
                {
                    throw new ArgumentNullException("keySerialNumber");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (accountNumber.Length > 18)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }
                string keyDescriptor = "605"; //"002";

                //configure Parameters
                var parameters = new List <string>()
                {
                    bdk,
                    zpk,
                    keyDescriptor,
                    keySerialNumber,
                    pinBlock,
                    ((int)PinBlockFormats.ANSI).ToString().PadLeft(2, '0'),
                    ((int)PinBlockFormats.ANSI).ToString().PadLeft(2, '0'),
                    accountNumber.PadLeft(12, '0')
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "encryptedPin", Length = 18
                });                                                                                  // the first digit should not be used   // _theHsm._encryptedPinLength });

                var hsmResponse = _theHsm.Send("G0", parameters, responseFormat);
                IPinGenerationResponse response = new PinGeneratorResponse();

                response.EncryptedPin = hsmResponse.Item("encryptedPin").Substring(2);

                return(response);
            }
예제 #8
0
            public IPinGenerationResponse TranslatePinFromOneZPKEncryptionToAnother(string SourceZPK, string DestinationZPK, string SourcePinBlock, PinBlockFormats pinBlockFormat, string accountNumber)
            {
                if (string.IsNullOrEmpty(SourceZPK))
                {
                    throw new ArgumentNullException("pinEncryptionKey");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (string.IsNullOrEmpty(DestinationZPK))
                {
                    throw new ArgumentNullException("zpk is empty");
                }
                if (string.IsNullOrEmpty(SourcePinBlock))
                {
                    throw new ArgumentNullException("Source Pin Block is empty");
                }

                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }

                //configure Parameters
                var parameters = new List <string>()
                {
                    SourceZPK,
                    DestinationZPK,
                    "12",
                    SourcePinBlock,
                    ((int)pinBlockFormat).ToString().PadLeft(2, '0'),
                    ((int)pinBlockFormat).ToString().PadLeft(2, '0'),
                    accountNumber.PadLeft(12, '0'),
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "encryptedPin", Length = 18
                });

                var hsmResponse = _theHsm.Send("CC", parameters, responseFormat);
                IPinGenerationResponse response = new PinGeneratorResponse();

                response.EncryptedPin = hsmResponse.Item("encryptedPin").Substring(0, 16);

                return(response);
            }
예제 #9
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="isInterchange"></param>
            /// <param name="pinEncryptionKey">zpk_lmk</param>
            /// <param name="pinVerificationKey">pvk</param>
            /// <param name="encryptedPinBlock">encrypted pin from the hsm</param>
            /// <param name="encryptedPinBlockFormat"></param>
            /// <param name="minPinLength">5</param>
            /// <param name="accountNumber">12 digit right most digit excluding the check digit</param>
            /// <param name="pinValidationData"></param>
            /// <param name="offset"></param>
            public void VerifyPIN(bool isInterchange, string pinEncryptionKey, string pinVerificationKey, string encryptedPinBlock, PinBlockFormats encryptedPinBlockFormat, int minPinLength, string accountNumber, string pinValidationData, string offset)
            {
                if (string.IsNullOrEmpty(pinVerificationKey))
                {
                    throw new ArgumentNullException("pinVerificationKey");
                }
                if (string.IsNullOrEmpty(pinEncryptionKey))
                {
                    throw new ArgumentNullException("pinEncryptionKey");
                }
                if (string.IsNullOrEmpty(encryptedPinBlock))
                {
                    throw new ArgumentNullException("encryptedPinBlock");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }
                if (pinValidationData.Length != 12)
                {
                    throw new ArgumentException("pinValidationData is not 12-digits");
                }

                //string decTable = new PinTranslation(new ThalesHsm()).TranslateDecimalizationTableFromOldToNewLMK();

                //configure Parameters
                var parameters = new List <string>()
                {
                    pinEncryptionKey,
                    pinVerificationKey,
                    "12", //(minPinLength+8).ToString().PadLeft(2,'0'),
                    encryptedPinBlock,
                    ((int)encryptedPinBlockFormat).ToString().PadLeft(2, '0'),
                    minPinLength.ToString().PadLeft(2, '0'),
                    accountNumber.PadLeft(12, '0'),
                    // decTable,
                    PinConfigurationManager.HsmConfig.DecimalisationTable,
                    pinValidationData,
                    offset
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                var hsmResponse = _theHsm.Send(isInterchange ? "EA" : "DA", parameters, responseFormat);
            }
예제 #10
0
        //public void OnAddWord(string a = "")
        //{
        //    if (NumWords >= maxWords) return;

        //    // Create a new field to fill in the spaces of the new word
        //    for (int i = 0; i < 16; ++i)
        //    {
        //        MessageFieldModel newField = new MessageFieldModel();
        //        newField.MessageFieldDetails.WordNum = NumWords;
        //        newField.MessageFieldDetails.BitStart = i;
        //        newField.MessageFieldDetails.BitLength = 1;

        //        MessageFields.Add(newField);
        //    }

        //    // Add to WordNumbers collection
        //    WordNumbers.Add(NumWords.ToString());

        //    // Increment field last
        //    ++NumWords;
        //}

        //public void OnSubtractWord(string a = "")
        //{
        //    if (NumWords <= 1) return;

        //    // Decrement field first
        //    --NumWords;

        //    // Remove from WordNumbers collection
        //    WordNumbers.Remove(NumWords.ToString());

        //    // Modify the collection by removing unwanted elements
        //    for (int i = 0; i < MessageFields.Count; ++i)
        //    {
        //        if (NumWords == MessageFields[i].MessageFieldDetails.WordNum)
        //        {
        //            MessageFields.Remove(MessageFields[i]);
        //            --i;
        //        }
        //    }
        //}

        public void AddWordFields()
        {
            // Create a new field to fill in the spaces of the new word
            for (int i = 0; i < 16; ++i)
            {
                MessageFieldModel newField = new MessageFieldModel();
                newField.MessageFieldDetails.WordNum   = NumWords;
                newField.MessageFieldDetails.BitStart  = i;
                newField.MessageFieldDetails.BitLength = 1;

                MessageFields.Add(newField);
            }
            NumWords++;
            UpdateMessageFields();
        }
예제 #11
0
        public void SubtractWordFields()
        {
            NumWords--;
            UpdateMessageFields();

            // Modify the collection by removing unwanted elements
            for (int i = 0; i < MessageFields.Count; ++i)
            {
                if (NumWords == MessageFields[i].MessageFieldDetails.WordNum)
                {
                    MessageFields.Remove(MessageFields[i]);
                    --i;
                }
            }
        }
예제 #12
0
    /// <summary>
    /// Display the WebAR link as hyperlink to the user
    /// </summary>
    /// <param name="url">WebAR link to be displayed</param>
    void DisplayARUrlMessage(string url)
    {
        GameObject arUrlMessage = UIManager.Instance.CreateMessageWindow();

        if (arUrlMessage != null)
        {
            MessageFields msgFields = arUrlMessage.GetComponent <MessageFields>();
            msgFields.MessageDetails("WebAR URL", "Copy and Paste the below URL in a Web Browser.\n" + "<link=" + url + "><color=blue><u><i>" + url + "</i></color></u></link>", "OK");
            Transform okTrans = arUrlMessage.transform.Find("Done");
            if (okTrans != null)
            {
                Button okButton = okTrans.gameObject.GetComponent <Button>();
                okButton.onClick.AddListener(() => { Destroy(arUrlMessage); });
            }
        }
    }
예제 #13
0
        /// <summary>
        /// Displays the  error that occurred while importing the gltf object
        /// </summary>
        /// <param name="msg">Error Message to be displyed</param>
        private void GLTFImportErrorMessage(string msg)
        {
            GameObject GLTFImportErrorMessage = UIManager.Instance.CreateMessageWindow();

            if (GLTFImportErrorMessage != null)
            {
                MessageFields msgFields = GLTFImportErrorMessage.GetComponent <MessageFields>();
                msgFields.MessageDetails("GLTF Import Error!", msg, "OK");
                Transform okTrans = GLTFImportErrorMessage.transform.Find("Done");
                if (okTrans != null)
                {
                    Button okButton = okTrans.gameObject.GetComponent <Button>();
                    okButton.onClick.AddListener(() => { Destroy(GLTFImportErrorMessage); });
                }
            }
        }
예제 #14
0
    /// <summary>
    /// Displays the error message occured during file upload
    /// </summary>
    /// <param name="errorMessage">Error Message to be displayed</param>
    public void DisplayUploadErrorMessage(string errorMessage)
    {
        GameObject uploadErrorMessage = UIManager.Instance.CreateMessageWindow();

        if (uploadErrorMessage != null)
        {
            MessageFields msgFields = uploadErrorMessage.GetComponent <MessageFields>();
            msgFields.MessageDetails("Upload File Error!", errorMessage, "OK");
            Transform okTrans = uploadErrorMessage.transform.Find("Done");
            if (okTrans != null)
            {
                Button okButton = okTrans.gameObject.GetComponent <Button>();
                okButton.onClick.AddListener(() => { Destroy(uploadErrorMessage); });
            }
        }
    }
예제 #15
0
    /// <summary>
    /// Error message shown as pop-up if the selected file type is not supported for importing
    /// </summary>
    void DisplayFileErrorMessage()
    {
        GameObject fileErrorMessage = UIManager.Instance.CreateMessageWindow();

        if (fileErrorMessage != null)
        {
            MessageFields msgFields = fileErrorMessage.GetComponent <MessageFields>();
            msgFields.MessageDetails("File Type Error!", "Selected File type cannot be loaded, please select \".obj\" or \".gltf\" files.", "OK");
            Transform okTrans = fileErrorMessage.transform.Find("Done");
            if (okTrans != null)
            {
                Button okButton = okTrans.gameObject.GetComponent <Button>();
                okButton.onClick.AddListener(() => { Destroy(fileErrorMessage); });
            }
        }
    }
예제 #16
0
    /// <summary>
    /// Uploads a single file to the server. Not used in case of upload to AmazonS3
    /// Note - As the backend server supports only upload to AmazonS3 this is never called
    /// </summary>
    /// <param name="uploadFilePath">Path of file to be uploaded</param>
    /// <param name="deleteTempFile">Path of temporary Zip file</param>
    /// <returns></returns>
    private IEnumerator UploadFileToServer(string uploadFilePath, bool deleteTempFile)
    {
        List <IMultipartFormSection> formData = new List <IMultipartFormSection>();
        string fileName = FileBrowserHelpers.GetFilename(uploadFilePath);

        byte[] fileData = FileBrowserHelpers.ReadBytesFromFile(uploadFilePath);
        formData.Add(new MultipartFormFileSection("Object", fileData, fileName, "application/octet-stream"));

        using (UnityWebRequest uwr = UnityWebRequest.Post(amazonS3ServerBackend + "/fileupload", formData))
        {
            uwr.SendWebRequest();

            MessageFields uploadMsgFields = DisplayUploadProgressMessage();
            StartCoroutine(CheckUploadConnection(uwr));
            while (!uwr.isDone)
            {
                string progress = "Progress : " + Mathf.Round(uwr.uploadProgress * 100).ToString() + "%";
                uploadMsgFields.MessageDetails("Upload Progress ...", progress);
                if (uwr.isNetworkError || uwr.isHttpError)
                {
                    yield break;
                }
                yield return(null);
            }

            if (uwr.result != UnityWebRequest.Result.Success)
            {
                DestroyUploadProgressMessage(uploadMsgFields);
                if (deleteTempFile && FileBrowserHelpers.FileExists(uploadFilePath))
                {
                    FileBrowserHelpers.DeleteFile(uploadFilePath);
                    Debug.Log("Temp File deleted after Error");
                }
                DisplayUploadErrorMessage(uwr.error);
            }
            else
            {
                DestroyUploadProgressMessage(uploadMsgFields);
                if (deleteTempFile && FileBrowserHelpers.FileExists(uploadFilePath))
                {
                    FileBrowserHelpers.DeleteFile(uploadFilePath);
                    Debug.Log("Temp File deleted");
                }
            }
        }
    }
예제 #17
0
            public IGeneratePinOffsetResponse GeneratePVV(string encryptedPin, string accountNumber, string cardPan)
            {
                if (string.IsNullOrEmpty(encryptedPin))
                {
                    throw new ArgumentNullException("encryptedPin");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }
                //string pinValidationData = cardPan.Substring(0, cardPan.Length - 6); //AHMED
                string pinValidationData = cardPan.Substring(0, 10);

                pinValidationData = string.Format("{0}N{1}", pinValidationData, cardPan.Last());
                //configure Parameters
                var parameters = new List <string>()
                {
                    PinConfigurationManager.HsmConfig.PinVerificationKeyPVV,
                    encryptedPin,
                    accountNumber.PadLeft(12, '0'),
                    "0",  //minPinLength.ToString().PadLeft(2,'0'),

                    // PinConfigurationManager.HsmConfig.DecimalisationTable,
                    // pinValidationData
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "offset", Length = 4
                });

                var hsmResponse = _theHsm.Send("DG", parameters, responseFormat);

                IGeneratePinOffsetResponse response = new GeneratePinOffsetResponse();

                response.Offset = hsmResponse.Item("offset");

                return(response);
            }
예제 #18
0
        public MessageQueryStringBuilder SetFields(MessageFields fields)
        {
            _fieldsAction = () =>
            {
                var sb        = new StringBuilder();
                var allFields = fields.GetFlagEnumValues()
                                .ToList();

                if (fields.HasFlag(MessageFields.Messages))
                {
                    sb.Append("messages");//TODO: dependent on MessageRequestAction.. (eg. get vs list)
                }
                else
                {
                    var messageFields = allFields
                                        .Where(f => MessageFields.Messages.HasFlag(f))
                                        .Select(f => f.GetAttribute <StringValueAttribute, MessageFields>())
                                        .Where(att => att != null)
                                        .Select(att => att.Text)
                                        .ToList();

                    sb.Append("messages(").Append(string.Join(",", messageFields)).Append(")");
                }

                var otherFields = allFields
                                  .Where(f => f == MessageFields.ResultSizeEstimate || f == MessageFields.NextPageToken)
                                  .Select(f => f.GetAttribute <StringValueAttribute, MessageFields>())
                                  .Where(att => att != null)
                                  .Select(att => att.Text)
                                  .ToList();

                if (otherFields.Any())
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(",");
                    }

                    sb.Append(string.Join(",", otherFields));
                }

                SetParameter("fields", sb.ToString());
            };

            return(this);
        }
예제 #19
0
            public IGeneratePinOffsetResponse GeneratePinOffsetFromPinBlock(string encryptedPinBlock, string accountNumber, PinBlockFormats encryptedPinBlockFormat)
            {
                if (string.IsNullOrEmpty(encryptedPinBlock))
                {
                    throw new ArgumentNullException("encryptedPin");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }

                //configure Parameters
                var parameters = new List <string>()
                {
                    "001",
                    PinConfigurationManager.HsmConfig.ZPK_LMK,
                    PinConfigurationManager.HsmConfig.PinVerificationKey,
                    encryptedPinBlock,
                    ((int)encryptedPinBlockFormat).ToString().PadLeft(2, '0'),
                    "04",
                    accountNumber.PadLeft(12, '0'),
                    PinConfigurationManager.HsmConfig.DecimalisationTable,
                    PinConfigurationManager.HsmConfig.PinValidationData
                }; //5145851169N5

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "offset", Length = 12
                });

                var hsmResponse = _theHsm.Send("BK", parameters, responseFormat);

                IGeneratePinOffsetResponse response = new GeneratePinOffsetResponse();

                response.Offset = hsmResponse.Item("offset");

                return(response);
            }
예제 #20
0
            public IPinGenerationResponse TranslatePinFromEncryptionUnderInterchangeKeyToLMKEncryption(string zpk, string EncryptedPin, PinBlockFormats pinBlockFormat, string accountNumber)
            {
                if (string.IsNullOrEmpty(EncryptedPin))
                {
                    throw new ArgumentNullException("pinEncryptionKey");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (string.IsNullOrEmpty(zpk))
                {
                    throw new ArgumentNullException("zpk is empty");
                }

                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }

                //configure Parameters
                var parameters = new List <string>()
                {
                    zpk,
                    EncryptedPin,
                    ((int)pinBlockFormat).ToString().PadLeft(2, '0'),
                    accountNumber.PadLeft(12, '0'),
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "encryptedPin", Length = _theHsm._encryptedPinLength
                });

                var hsmResponse = _theHsm.Send("JE", parameters, responseFormat);
                IPinGenerationResponse response = new PinGeneratorResponse();

                response.EncryptedPin = hsmResponse.Item("encryptedPin");

                return(response);
            }
예제 #21
0
            public string TranslateDecimalizationTableFromOldToNewLMK()
            {
                var parameters = new List <string>()
                {
                    PinConfigurationManager.HsmConfig.DecimalisationTable
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "decimalisationtable", Length = 16
                });

                var    hsmResponse = _theHsm.Send("LO", parameters, responseFormat);
                string response    = hsmResponse.Item("decimalisationtable");

                return(response);
            }
예제 #22
0
            public ITranslatePinEncryptionKeyResponse TranslateFromExchangeKeyToStorageKey(string exchangeKey, string pinEncryptionKey, KeyScheme?exchangeKeyScheme, KeyScheme?storageKeyScheme)
            {
                //configure Parameters
                var parameters = new List <string>()
                {
                    exchangeKey,
                    pinEncryptionKey
                };

                if (exchangeKeyScheme.HasValue || storageKeyScheme.HasValue)
                {
                    parameters.Add(";");
                    parameters.Add(exchangeKeyScheme.HasValue ? ((char)exchangeKeyScheme.Value).ToString() : ((char)storageKeyScheme.Value).ToString());
                    parameters.Add(storageKeyScheme.HasValue ? ((char)storageKeyScheme.Value).ToString() : ((char)exchangeKeyScheme.Value).ToString());
                    parameters.Add("1");
                }

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.AddRange(new List <MessageField>()
                {
                    new MessageField()
                    {
                        Name = "zpk_lmk", Length = pinEncryptionKey.Length
                    },
                    new MessageField()
                    {
                        Name = "checkValue", Length = 6
                    }
                });

                var hsmResponse = _theHsm.Send("FA", parameters, responseFormat);

                ITranslatePinEncryptionKeyResponse response = new TranslatePinEncryptionKeyResponse();

                response.TranslatedPinEncryptionKey = hsmResponse.Item("zpk_lmk");
                response.KeyCheckValue = hsmResponse.Item("checkValue");

                return(response);
            }
예제 #23
0
            public IPinGenerationResponse DeriveEncryptedPin(string pan)
            {
                if (string.IsNullOrEmpty(pan))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (pan.Length < 16)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }
                string accountNumber = pan.Substring(pan.Length - 13, 12);

                //configure Parameters
                var parameters = new List <string>()
                {
                    PinConfigurationManager.HsmConfig.PinVerificationKeyPVV,
                    "0000FFFFFFFF", //Default Pin offset
                    "04",           //minPinLength.ToString().PadLeft(2,'0'),
                    accountNumber.PadLeft(12, '0'),
                    PinConfigurationManager.HsmConfig.DecimalisationTable,
                    "P", //PinConfigurationManager.HsmConfig.PinValidationData
                    pan.Length == 19 ? pan.PadRight(20, 'F') : pan
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "encryptedPin", Length = _theHsm._encryptedPinLength
                });

                var hsmResponse = _theHsm.Send("EE", parameters, responseFormat);

                IPinGenerationResponse response = new PinGeneratorResponse();

                response.EncryptedPin = hsmResponse.Item("encryptedPin");

                return(response);
            }
예제 #24
0
            public IGenerateCVVResponse GenerateCvv(string pan, string expiryDate, string cardVerificationKey, string serviceCode)
            {
                if (string.IsNullOrEmpty(pan))
                {
                    throw new ArgumentNullException("pan");
                }
                if (pan.Length < 16 || pan.Length > 19)
                {
                    throw new ArgumentException("pan is shorter than 16-digits or greater that 19-digits");
                }
                //string serviceCode = "000"; // to be printed behind the card


                //configure Parameters
                var parameters = new List <string>()
                {
                    cardVerificationKey,
                    pan,
                    ";",
                    expiryDate,
                    serviceCode
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "cvv", Length = 3
                });

                var hsmResponse = _theHsm.Send("CW", parameters, responseFormat);

                IGenerateCVVResponse response = new GenerateCVVResponse();

                response.Cvv = hsmResponse.Item("cvv");

                return(response);
            }
예제 #25
0
    /// <summary>
    /// If user clicks the WebAR button in the Options screen
    /// </summary>
    public void OnOptionWebAR()
    {
        GameObject webARWindow = CreateMessageWindow();
        if (webARWindow != null)
        {
            MessageFields msgFieds = webARWindow.GetComponent<MessageFields>();
            msgFieds.MessageDetails("Web AR", "Select a glTF/glb file or a Folder/Zip containing a gltf/glb file to generate Web URL\nNote : Selected File/Folder will be uploaded to remote server to generate the URL.", "Browse", "Cancel");
            Transform browseTrans = webARWindow.transform.Find("Done");
            if (browseTrans != null)
            {
                Button browse = browseTrans.gameObject.GetComponent<Button>();
                browse.onClick.AddListener(() => { Destroy(webARWindow); StartCoroutine(GameManager.Instance.DisplayWebARLoadCoroutine()); });
            }

            Transform cancelTrans = webARWindow.transform.Find("Cancel");
            if (cancelTrans != null)
            {
                Button cancel = cancelTrans.gameObject.GetComponent<Button>();
                cancel.onClick.AddListener(() => Destroy(webARWindow));
            }
        }
    }
예제 #26
0
            public IPinGenerationResponse GenerateRandomPin(string accountNumber, int?pinLength)
            {
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }

                //configure Parameters
                var parameters = new List <string>()
                {
                    accountNumber.PadLeft(12, '0')
                };

                if (pinLength.HasValue)
                {
                    parameters.Add(pinLength.Value.ToString().PadLeft(2, '0'));
                }

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "encryptedPin", Length = _theHsm._encryptedPinLength
                });

                var hsmResponse = _theHsm.Send("JA", parameters, responseFormat);

                IPinGenerationResponse response = new PinGeneratorResponse();

                response.EncryptedPin = hsmResponse.Item("encryptedPin");

                return(response);
            }
예제 #27
0
            public IPinGenerationResponse EncryptClearPin(string clearPin, string accountNumber)
            {
                if (string.IsNullOrEmpty(clearPin))
                {
                    throw new ArgumentNullException("clearPin");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }
                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }

                //configure Parameters
                var parameters = new List <string>()
                {
                    clearPin.PadRight(_theHsm._encryptedPinLength, 'F'),
                    accountNumber.PadLeft(12, '0')
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "encryptedPin", Length = _theHsm._encryptedPinLength
                });

                var hsmResponse = _theHsm.Send("BA", parameters, responseFormat);

                IPinGenerationResponse response = new PinGeneratorResponse();

                response.EncryptedPin = hsmResponse.Item("encryptedPin");

                return(response);
            }
예제 #28
0
    /// <summary>
    /// If user clicks the Viewer button in the Options screen
    /// </summary>
    public void OnOptionViewer()
    {
        GameObject viewerWindow = CreateMessageWindow();
        if (viewerWindow != null)
        {
            MessageFields msgFields = viewerWindow.GetComponent<MessageFields>();
            msgFields.MessageDetails("AR Viewer", "Click on \"Browse\" and select a 3D file to view in AR", "Browse", "Cancel");
            Transform browseTrans = viewerWindow.transform.Find("Done");
            if (browseTrans != null)
            {
                Button browse = browseTrans.gameObject.GetComponent<Button>();
                browse.onClick.AddListener(() => { Destroy(viewerWindow); StartCoroutine(GameManager.Instance.DisplayLoadCoroutine()); });
            }

            Transform cancelTrans = viewerWindow.transform.Find("Cancel");
            if(cancelTrans != null)
            {
                Button cancel = cancelTrans.gameObject.GetComponent<Button>();
                cancel.onClick.AddListener(() => Destroy(viewerWindow));
            }
        }

    }
예제 #29
0
            public string DecryptAnEncrypted(string EncryptedPin, string accountNumber)
            {
                if (string.IsNullOrEmpty(EncryptedPin))
                {
                    throw new ArgumentNullException("pinEncryptionKey");
                }
                if (string.IsNullOrEmpty(accountNumber))
                {
                    throw new ArgumentNullException("accountNumber");
                }

                if (accountNumber.Length > 12)
                {
                    throw new ArgumentException("accountNumber is longer than 12-digits");
                }

                //configure Parameters
                var parameters = new List <string>()
                {
                    accountNumber.PadLeft(12, '0'),
                    EncryptedPin
                };

                //configure Response Format
                var responseFormat = new MessageFields();

                responseFormat.Fields.Add(new MessageField()
                {
                    Name = "Pin", Length = 4
                });                                                                        // _theHsm._encryptedPinLength });

                var    hsmResponse = _theHsm.Send("NG", parameters, responseFormat);
                string response    = hsmResponse.Item("Pin");

                return(response);
            }
예제 #30
0
        public static void Parse(Message msg, MessageFields fields,
                                 ref MessageKeyValuePairs KVPairs, out string result)
        {
            foreach (MessageField fld in fields.Fields)
            {
                fld.Skip = false;
            }
            int fldIdx = 0;

            while (fldIdx <= fields.Fields.Count - 1)
            {
                MessageField fld = fields.Fields[fldIdx];

                int repetitions = 1;
                if (!String.IsNullOrEmpty(fld.Repetitions))
                {
                    int  Num;
                    bool isNum = int.TryParse(fld.Repetitions, out Num);
                    if (isNum)
                    {
                        repetitions = Convert.ToInt32(fld.Repetitions);
                    }
                    else
                    {
                        repetitions = Convert.ToInt32(KVPairs.Item(fld.Repetitions));
                    }

                    if (fld.StaticRepetitions)
                    {
                        int nextNonStaticRepField = fldIdx + 1;
                        while (nextNonStaticRepField <= fields.Fields.Count - 1 && fields.Fields[nextNonStaticRepField].StaticRepetitions)
                        {
                            nextNonStaticRepField++;
                        }

                        List <MessageField> dynamicFields = new List <MessageField>();
                        for (int i = fldIdx; i < nextNonStaticRepField; i++)
                        {
                            dynamicFields.Add(fields.Fields[i]);
                        }

                        for (int i = fldIdx; i < nextNonStaticRepField; i++)
                        {
                            fields.Fields.RemoveAt(fldIdx);
                        }

                        int           insertPos = fldIdx;
                        List <string> fieldList = new List <string>();
                        for (int i = 1; i < repetitions; i++)
                        {
                            for (int j = 0; j < dynamicFields.Count - 1; j++)
                            {
                                MessageField newFld = dynamicFields[j].Clone();
                                newFld.Repetitions       = "";
                                newFld.StaticRepetitions = false;
                                if (!fieldList.Contains(newFld.Name))
                                {
                                    fieldList.Add(newFld.Name);
                                }

                                //Save the ORIGINAL field name.
                                newFld.Name = newFld.Name + " #" + i.ToString();


                                if (fieldList.Contains(newFld.DependentField))
                                {
                                    newFld.DependentField = newFld.DependentField + " #" + i.ToString();
                                }

                                if (fieldList.Contains(newFld.DynamicLength))
                                {
                                    newFld.DynamicLength = newFld.DynamicLength + " #" + i.ToString();
                                }

                                fields.Fields.Insert(insertPos, newFld);

                                insertPos++;
                            }
                        }

                        repetitions = 1;

                        fld = fields.Fields[fldIdx];
                    }
                }

                for (int j = 0; j < repetitions; j++)
                {
                    if (((!fld.Skip) &&
                         (!String.IsNullOrEmpty(fld.DependentField) && KVPairs.ContainsKey(fld.DependentField)) &&
                         (fld.DependentValue.Count == 0 || fld.DependentValue.Contains(KVPairs.Item(fld.DependentField)))) ||
                        (String.IsNullOrEmpty(fld.DependentField)) ||
                        (!String.IsNullOrEmpty(fld.DependentField) && !KVPairs.ContainsKey(fld.DependentField) && fld.DependentValue.Count == 0))
                    {
                        string val = "";

                        if (fld.SkipUntilValid)
                        {
                            try
                            {
                                do
                                {
                                    val = msg.MessageData.Substring(msg.CurrentIndex, fld.Length);
                                    if (fld.ValidValues.Contains(val))
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        msg.AdvanceIndex(1);
                                    }
                                }while (fld.ValidValues.Contains(val));
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                if (fld.AllowNotFoundValid)
                                {
                                    val = "";
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                        }
                        else if (fld.ParseUntilValue != "")
                        {
                            string tempVal = "";
                            do
                            {
                                val = msg.MessageData.Substring(msg.CurrentIndex, 1);
                                if (fld.ParseUntilValue == val)
                                {
                                    msg.DecreaseIndex(1);
                                    break;
                                }
                                else
                                {
                                    tempVal += val;
                                    msg.AdvanceIndex(1);
                                }
                            }while (true);
                            val = tempVal;
                        }
                        else
                        {
                            if (fld.DynamicLength != "")
                            {
                                foreach (MessageField scannedFld in fields.Fields)
                                {
                                    if (scannedFld.Name == fld.DynamicLength)
                                    {
                                        if (scannedFld.MessageFieldType == MessageFieldTypes.Hexadecimal)
                                        {
                                            fld.Length = Convert.ToInt32(KVPairs.Item(fld.DynamicLength), 16);
                                        }
                                        else
                                        {
                                            fld.Length = Convert.ToInt32(KVPairs.Item(fld.DynamicLength));
                                        }
                                    }
                                }
                            }
                            if (fld.Length != 0)
                            {
                                if ((fld.MessageFieldType != MessageFieldTypes.Binary))
                                {
                                    val = msg.MessageData.Substring(msg.CurrentIndex, fld.Length);
                                }
                                else
                                {
                                    val = msg.MessageData.Substring(msg.CurrentIndex, fld.Length * 2);
                                }
                            }
                            else
                            {
                                val = msg.MessageData.Substring(msg.CurrentIndex, msg.CharsLeft());
                            }
                        }
                        if (fld.OptionValues.Count == 0 || fld.OptionValues.Contains(val))
                        {
                            try
                            {
                                if (fld.ValidValues.Count > 0 || !fld.ValidValues.Contains(val))
                                {
                                    Log.Logger.MinorDebug(String.Format("Invalid value detected for field [{0}].", fld.Name));
                                    Log.Logger.MinorDebug(String.Format("Received [{0}] but can be one of [{1}]. ", val, GetCommaSeparetedListWithValues(fld.ValidValues)));
                                    throw new Exception(String.Format("Invalid value [{0}] for field [{1}].", val, fld.Name));
                                }
                                switch (fld.MessageFieldType)
                                {
                                case MessageFieldTypes.Hexadecimal:
                                case MessageFieldTypes.Binary:
                                    if (!Utility.IsHexString(val))
                                    {
                                        Log.Logger.MinorDebug(String.Format("Invalid value detected for field [{0}].", fld.Name));
                                        Log.Logger.MinorDebug(String.Format("Received [{0}] but expected a hexadecimal value.", val));
                                        throw new Exception(String.Format("Invalid value [{0}] for field [{1}].", val, fld.Name));
                                    }
                                    break;

                                case MessageFieldTypes.Numeric:
                                    int  Num;
                                    bool isNum = int.TryParse(fld.Repetitions, out Num);
                                    if (!isNum)
                                    {
                                        Log.Logger.MinorDebug(String.Format("Invalid value detected for field [{0}].", fld.Name));
                                        Log.Logger.MinorDebug(String.Format("Received [{0}] but expected a numeric value.", val));
                                        throw new Exception(String.Format("Invalid value [{0}] for field [{1}].", val, fld.Name));
                                    }
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (fld.RejectionCode != "")
                                {
                                    result = fld.RejectionCode;
                                }
                                else
                                {
                                    throw ex;
                                }
                            }

                            if (repetitions == 1)
                            {
                                KVPairs.Add(fld.Name, val);
                            }
                            else
                            {
                                KVPairs.Add(fld.Name + " #" + j.ToString(), val);
                            }

                            if (fld.MessageFieldType != MessageFieldTypes.Binary)
                            {
                                msg.AdvanceIndex(fld.Length);
                            }
                            else
                            {
                                msg.AdvanceIndex(fld.Length * 2);
                            }

                            if (j == repetitions)
                            {
                                fld.Skip = true;
                            }

                            if (fld.DependentField != "")
                            {
                                for (int z = fldIdx + 1; z < fields.Fields.Count - 1; z++)
                                {
                                    if (fields.Fields[z].DependentField == fld.DependentField && fields.Fields[z].ExclusiveDependency)
                                    {
                                        fields.Fields[z].Skip = true;
                                    }
                                }
                            }
                        }
                    }
                    if (msg.CharsLeft() == 0)
                    {
                        break;
                    }
                }
                if (msg.CharsLeft() == 0)
                {
                    break;
                }
                fldIdx += 1;
            }
            result = ErrorCodes.ER_00_NO_ERROR;
        }