示例#1
0
        public void Should_Decrypt_Identity_Card_Element_Document()
        {
            Update       update       = _classFixture.Entity;
            PassportData passportData = update.Message.PassportData;

            RSA key = EncryptionKey.ReadAsRsa();

            IDecrypter  decrypter             = new Decrypter();
            Credentials credentials           = decrypter.DecryptCredentials(passportData.Credentials, key);
            EncryptedPassportElement idCardEl = Assert.Single(passportData.Data, el => el.Type == "identity_card");

            IdDocumentData documentData = decrypter.DecryptData <IdDocumentData>(
                idCardEl.Data,
                credentials.SecureData.IdentityCard.Data
                );

            Assert.NotEmpty(documentData.DocumentNo);
            if (string.IsNullOrEmpty(documentData.ExpiryDate))
            {
                Assert.Null(documentData.Expiry);
            }
            else
            {
                Assert.NotNull(documentData.Expiry);
            }
        }
        public async Task Should_Decrypt_Front_Side_File()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            RSA                      key          = EncryptionKey.ReadAsRsa();
            EncryptedPassportElement element      = passportData.Data.Single();
            IDecrypter               decrypter    = new Decrypter();
            Credentials              credentials  = decrypter.DecryptCredentials(passportData.Credentials, key);

            File   encryptedFileInfo;
            string decryptedFilePath = System.IO.Path.GetTempFileName();

            using (System.IO.Stream decryptedFile = System.IO.File.OpenWrite(decryptedFilePath))
            {
                encryptedFileInfo = await BotClient.DownloadAndDecryptPassportFileAsync(
                    element.FrontSide,
                    credentials.SecureData.DriverLicense.FrontSide,
                    decryptedFile
                    );
            }

            _output.WriteLine("Front side JPEG file is written to \"{0}\".", decryptedFilePath);

            Assert.NotEmpty(encryptedFileInfo.FilePath);
            Assert.NotEmpty(encryptedFileInfo.FileId);
            Assert.InRange(encryptedFileInfo.FileSize, 1_000, 50_000_000);
        }
示例#3
0
        public void Should_Decrypt_Personal_Details_Element()
        {
            PassportData passportData = GetPassportData();

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials =
                decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.RsaPrivateKey);

            EncryptedPassportElement element = Assert.Single(passportData.Data, el => el.Type == "personal_details");

            PersonalDetails personalDetails = decrypter.DecryptData <PersonalDetails>(
                encryptedData: element.Data,
                dataCredentials: credentials.SecureData.PersonalDetails.Data
                );

            Assert.Equal("Poulad", personalDetails.FirstName);
            Assert.Equal("Ashrafpour", personalDetails.LastName);
            Assert.Equal("پولاد", personalDetails.FirstNameNative);
            Assert.Equal("اشرف پور", personalDetails.LastNameNative);
            Assert.Empty(personalDetails.MiddleName);
            Assert.Empty(personalDetails.MiddleNameNative);
            Assert.Equal("male", personalDetails.Gender);
            Assert.Equal(PassportEnums.Gender.Male, personalDetails.Gender);
            Assert.Equal("US", personalDetails.CountryCode);          // U.S.A
            Assert.Equal("IR", personalDetails.ResidenceCountryCode); // Iran
            Assert.Equal("30.07.1990", personalDetails.BirthDate);
            Assert.InRange(personalDetails.Birthdate, new DateTime(1990, 7, 30), new DateTime(1990, 7, 30, 1, 0, 0));
        }
        public void Should_Decrypt_Data()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            EncryptedPassportElement element      = passportData.Data.Single();

            RSA         key         = EncryptionKey.ReadAsRsa();
            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            PersonalDetails personalDetails = decrypter.DecryptData <PersonalDetails>(
                element.Data,
                credentials.SecureData.PersonalDetails.Data
                );

            Assert.NotNull(personalDetails);
            Assert.NotEmpty(personalDetails.FirstName);
            Assert.NotEmpty(personalDetails.Gender);
            Assert.NotEmpty(personalDetails.CountryCode);
            Assert.Equal(2, personalDetails.CountryCode.Length);
            Assert.NotEmpty(personalDetails.ResidenceCountryCode);
            Assert.Equal(2, personalDetails.ResidenceCountryCode.Length);
            Assert.NotEmpty(personalDetails.BirthDate);
            Assert.InRange(personalDetails.Birthdate, new DateTime(1900, 1, 1), DateTime.Today);
        }
示例#5
0
        public async Task Should_decrypt_utility_bill_element_translation()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            RSA                      key          = EncryptionKey.ReadAsRsa();
            EncryptedPassportElement billElement  = Assert.Single(passportData.Data, el => el.Type == "utility_bill");

            PassportFile translationFile = Assert.Single(billElement.Translation);

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            FileCredentials fileCredentials = Assert.Single(credentials.SecureData.UtilityBill.Translation);

            File encryptedFileInfo;

            using (System.IO.Stream decryptedFile = new System.IO.MemoryStream())
            {
                encryptedFileInfo = await BotClient.DownloadAndDecryptPassportFileAsync(
                    translationFile,
                    fileCredentials,
                    decryptedFile
                    );

                Assert.InRange(decryptedFile.Length, translationFile.FileSize - 256, translationFile.FileSize + 256);
            }

            Assert.NotEmpty(encryptedFileInfo.FilePath);
            Assert.NotEmpty(encryptedFileInfo.FileId);
            Assert.InRange(encryptedFileInfo.FileSize, 1_000, 50_000_000);
        }
示例#6
0
        public async Task Should_Decrypt_Identity_Card_Element_Selfie()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            RSA                      key          = EncryptionKey.ReadAsRsa();
            EncryptedPassportElement idCardEl     = Assert.Single(passportData.Data, el => el.Type == "identity_card");

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            byte[] encryptedContent;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream(idCardEl.Selfie.FileSize))
            {
                await BotClient.GetInfoAndDownloadFileAsync(
                    idCardEl.Selfie.FileId,
                    stream
                    );

                encryptedContent = stream.ToArray();
            }

            byte[] content = decrypter.DecryptFile(
                encryptedContent,
                credentials.SecureData.IdentityCard.Selfie
                );

            Assert.NotEmpty(content);
        }
示例#7
0
        public async Task Should_Decrypt_Identity_Card_Element_Reverse_Side()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            RSA                      key          = EncryptionKey.ReadAsRsa();
            EncryptedPassportElement idCardEl     = Assert.Single(passportData.Data, el => el.Type == "identity_card");

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            string botToken    = ConfigurationProvider.TestConfigurations.ApiToken;
            File   encFileInfo = await BotClient.GetFileAsync(idCardEl.ReverseSide.FileId);

            HttpClient http = new HttpClient();

            System.IO.Stream encFileStream = await http.GetStreamAsync(
                $"https://api.telegram.org/file/bot{botToken}/{encFileInfo.FilePath}"
                );

            string destFilePath = System.IO.Path.GetTempFileName();

            using (encFileStream)
                using (System.IO.Stream reverseSideFile = System.IO.File.OpenWrite(destFilePath))
                {
                    await decrypter.DecryptFileAsync(
                        encFileStream,
                        credentials.SecureData.IdentityCard.ReverseSide,
                        reverseSideFile
                        );

                    Assert.InRange(reverseSideFile.Length, encFileInfo.FileSize - 256, encFileInfo.FileSize + 256);
                }

            _output.WriteLine("Reverse side photo is written to file \"{0}\".", destFilePath);
        }
        public void Should_validate_passport_message()
        {
            Update       update       = _classFixture.Entity;
            PassportData passportData = update.Message.PassportData;

            EncryptedPassportElement phoneElement = Assert.Single(passportData.Data, el => el.Type == "phone_number");

            Assert.NotNull(phoneElement);
            Assert.Equal(PassportEnums.Scope.PhoneNumber, phoneElement.Type);
            Assert.NotEmpty(phoneElement.PhoneNumber);
            Assert.True(long.TryParse(phoneElement.PhoneNumber, out _));
            Assert.NotEmpty(phoneElement.Hash);

            EncryptedPassportElement emailElement = Assert.Single(passportData.Data, el => el.Type == "email");

            Assert.NotNull(emailElement);
            Assert.Equal(PassportEnums.Scope.Email, emailElement.Type);
            Assert.NotEmpty(emailElement.Email);
            Assert.NotEmpty(emailElement.Hash);

            Assert.NotNull(passportData.Credentials);
            Assert.NotEmpty(passportData.Credentials.Data);
            Assert.NotEmpty(passportData.Credentials.Hash);
            Assert.NotEmpty(passportData.Credentials.Secret);
        }
示例#9
0
        public void Should_Validate_Passport_Message()
        {
            Update       update       = _classFixture.Entity;
            PassportData passportData = update.Message.PassportData;

            #region identity card element validation

            EncryptedPassportElement idCardEl = Assert.Single(passportData.Data, el => el.Type == "identity_card");
            Assert.NotNull(idCardEl);
            Assert.Equal(PassportEnums.Scope.IdentityCard, idCardEl.Type);

            Assert.NotEmpty(idCardEl.Data);
            Assert.NotEmpty(idCardEl.Hash);

            Assert.NotNull(idCardEl.FrontSide);
            Assert.NotEmpty(idCardEl.FrontSide.FileId);
            Assert.InRange(idCardEl.FrontSide.FileDate, new DateTime(2018, 6, 1), DateTime.UtcNow);

            Assert.NotNull(idCardEl.ReverseSide);
            Assert.NotEmpty(idCardEl.ReverseSide.FileId);
            Assert.InRange(idCardEl.ReverseSide.FileDate, new DateTime(2018, 6, 1), DateTime.UtcNow);

            Assert.NotNull(idCardEl.Selfie);
            Assert.NotEmpty(idCardEl.Selfie.FileId);
            Assert.InRange(idCardEl.Selfie.FileDate, new DateTime(2018, 6, 1), DateTime.UtcNow);

            #endregion

            #region utility bill element validation

            EncryptedPassportElement billElement = Assert.Single(passportData.Data, el => el.Type == "utility_bill");
            Assert.NotNull(billElement);
            Assert.Equal(PassportEnums.Scope.UtilityBill, billElement.Type);

            Assert.NotEmpty(billElement.Hash);
            Assert.Null(billElement.Data);

            PassportFile billScanFile = Assert.Single(billElement.Files);
            Assert.NotNull(billScanFile);
            Assert.NotEmpty(billScanFile.FileId);
            Assert.InRange(billScanFile.FileDate, new DateTime(2018, 6, 1), DateTime.UtcNow);

            PassportFile billTranslationFile = Assert.Single(billElement.Files);
            Assert.NotNull(billTranslationFile);
            Assert.NotEmpty(billTranslationFile.FileId);
            Assert.InRange(billTranslationFile.FileDate, new DateTime(2018, 6, 1), DateTime.UtcNow);

            #endregion

            Assert.NotNull(passportData.Credentials);
            Assert.NotEmpty(passportData.Credentials.Data);
            Assert.NotEmpty(passportData.Credentials.Hash);
            Assert.NotEmpty(passportData.Credentials.Secret);
        }
        public void Should_Validate_Passport_Update()
        {
            Update       update       = _classFixture.Entity;
            PassportData passportData = update.Message.PassportData;

            EncryptedPassportElement encryptedElement = Assert.Single(passportData.Data);

            Assert.Equal("personal_details", encryptedElement.Type);
            Assert.Equal(PassportEnums.Scope.PersonalDetails, encryptedElement.Type);
            Assert.NotEmpty(encryptedElement.Data);
            Assert.NotEmpty(encryptedElement.Hash);

            Assert.NotNull(passportData.Credentials);
            Assert.NotEmpty(passportData.Credentials.Data);
            Assert.NotEmpty(passportData.Credentials.Hash);
            Assert.NotEmpty(passportData.Credentials.Secret);
        }
        public async Task Should_Decrypt_Translation_File()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            RSA                      key          = EncryptionKey.ReadAsRsa();
            EncryptedPassportElement element      = passportData.Data.Single();

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            for (int i = 0; i < element.Translation.Length; i++)
            {
                PassportFile    passportFile    = element.Translation[i];
                FileCredentials fileCredentials = credentials.SecureData.DriverLicense.Translation[i];

                byte[] encryptedContent;
                {
                    File encryptedFileInfo = await BotClient.GetFileAsync(passportFile.FileId);

                    Assert.NotEmpty(encryptedFileInfo.FilePath);
                    Assert.NotEmpty(encryptedFileInfo.FileId);
                    Assert.InRange(encryptedFileInfo.FileSize, 1_000, 50_000_000);

                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(encryptedFileInfo.FileSize))
                    {
                        await BotClient.DownloadFileAsync(encryptedFileInfo.FilePath, stream);

                        encryptedContent = stream.ToArray();
                    }
                }

                byte[] translationContent = decrypter.DecryptFile(
                    encryptedContent,
                    fileCredentials
                    );

                Assert.NotEmpty(translationContent);

                string decryptedFilePath = System.IO.Path.GetTempFileName();
                await System.IO.File.WriteAllBytesAsync(decryptedFilePath, translationContent);

                _output.WriteLine("Translation JPEG file is written to \"{0}\".", decryptedFilePath);
            }
        }
        public async Task Should_Decrypt_Utility_Bill_Element_Translation()
        {
            PassportData             passportData = GetPassportData();
            EncryptedPassportElement billElement  = Assert.Single(passportData.Data, el => el.Type == "utility_bill");

            Assert.NotNull(billElement.Translation);
            PassportFile translationFile = Assert.Single(billElement.Translation);

            Assert.Equal("DgADAQADOwADGV9BRP4b7RLGAtUKAg", translationFile.FileId);
            Assert.InRange(translationFile.FileDate, new DateTime(2018, 8, 30), new DateTime(2018, 8, 31));
            Assert.Equal(0, translationFile.FileSize);

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials =
                decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.RsaPrivateKey);

            FileCredentials translationFileCredentials = Assert.Single(credentials.SecureData.UtilityBill.Translation);

            byte[] encryptedContent = await System.IO.File.ReadAllBytesAsync("Files/utility_bill-translation.jpg.enc");

            byte[] content = decrypter.DecryptFile(
                encryptedContent,
                translationFileCredentials
                );

            Assert.NotEmpty(content);

            await System.IO.File.WriteAllBytesAsync("Files/utility_bill-translation.jpg", content);

            using (System.IO.MemoryStream
                   encryptedFileStream = new System.IO.MemoryStream(encryptedContent),
                   decryptedFileStream = new System.IO.MemoryStream()
                   )
            {
                await decrypter.DecryptFileAsync(
                    encryptedFileStream,
                    translationFileCredentials,
                    decryptedFileStream
                    );

                Assert.Equal(content, decryptedFileStream.ToArray());
            }
        }
        public void Should_Decrypt_Element_Document()
        {
            PassportData passportData = GetPassportData();

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials =
                decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.RsaPrivateKey);

            EncryptedPassportElement idCardEl = Assert.Single(passportData.Data, el => el.Type == "identity_card");

            IdDocumentData documentData = decrypter.DecryptData <IdDocumentData>(
                idCardEl.Data,
                credentials.SecureData.IdentityCard.Data
                );

            Assert.Equal("9999R", documentData.DocumentNo);
            Assert.Empty(documentData.ExpiryDate);
            Assert.Null(documentData.Expiry);
        }
        public void Should_Validate_Passport_Update()
        {
            Update       update       = _classFixture.Entity;
            PassportData passportData = update.Message.PassportData;

            EncryptedPassportElement encryptedElement = Assert.Single(passportData.Data);

            Assert.NotNull(encryptedElement);
            Assert.Equal("driver_license", encryptedElement.Type);
            Assert.Equal(PassportEnums.Scope.DriverLicense, encryptedElement.Type);

            Assert.NotEmpty(encryptedElement.Data);
            Assert.NotEmpty(encryptedElement.Hash);

            Assert.NotNull(encryptedElement.FrontSide);
            Assert.NotEmpty(encryptedElement.FrontSide.FileId);
            Assert.InRange(encryptedElement.FrontSide.FileSize, 1_000, 50_000_000);

            Assert.NotNull(encryptedElement.ReverseSide);
            Assert.NotEmpty(encryptedElement.ReverseSide.FileId);
            Assert.InRange(encryptedElement.ReverseSide.FileSize, 1_000, 50_000_000);

            Assert.NotNull(encryptedElement.Selfie);
            Assert.NotEmpty(encryptedElement.Selfie.FileId);
            Assert.InRange(encryptedElement.Selfie.FileSize, 1_000, 50_000_000);

            Assert.NotNull(encryptedElement.Translation);
            Assert.NotEmpty(encryptedElement.Translation);
            Assert.All(encryptedElement.Translation, Assert.NotNull);
            Assert.All(
                encryptedElement.Translation,
                translation => Assert.NotEmpty(translation.FileId)
                );
            Assert.All(
                encryptedElement.Translation,
                translation => Assert.InRange(translation.FileSize, 1_000, 50_000_000)
                );

            Assert.NotNull(passportData.Credentials);
            Assert.NotEmpty(passportData.Credentials.Data);
            Assert.NotEmpty(passportData.Credentials.Hash);
            Assert.NotEmpty(passportData.Credentials.Secret);
        }
        public async Task Should_Decrypt_Selfie_File()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            RSA                      key          = EncryptionKey.ReadAsRsa();
            EncryptedPassportElement element      = passportData.Data.Single();
            IDecrypter               decrypter    = new Decrypter();
            Credentials              credentials  = decrypter.DecryptCredentials(passportData.Credentials, key);

            byte[] encryptedContent;
            {
                File encryptedFileInfo = await BotClient.GetFileAsync(element.Selfie.FileId);

                Assert.NotEmpty(encryptedFileInfo.FilePath);
                Assert.NotEmpty(encryptedFileInfo.FileId);
                Assert.InRange(encryptedFileInfo.FileSize, 1_000, 50_000_000);

                using (System.IO.MemoryStream stream = new System.IO.MemoryStream(encryptedFileInfo.FileSize))
                {
                    await BotClient.DownloadFileAsync(encryptedFileInfo.FilePath, stream);

                    encryptedContent = stream.ToArray();
                }
            }

            byte[] selfieContent = decrypter.DecryptFile(
                encryptedContent,
                credentials.SecureData.DriverLicense.Selfie
                );

            Assert.NotEmpty(selfieContent);

            using (System.IO.Stream stream = new System.IO.MemoryStream(selfieContent))
            {
                await BotClient.SendPhotoAsync(
                    _fixture.SupergroupChat,
                    stream,
                    "selfie with driver license",
                    replyToMessageId : update.Message.MessageId
                    );
            }
        }
示例#16
0
        public void Should_Decrypt_Document_Data()
        {
            PassportData passportData = GetPassportData();

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials =
                decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.RsaPrivateKey);

            EncryptedPassportElement licenseEl = Assert.Single(passportData.Data, el => el.Type == "driver_license");

            IdDocumentData licenseDoc = decrypter.DecryptData <IdDocumentData>(
                encryptedData: licenseEl.Data,
                dataCredentials: credentials.SecureData.DriverLicense.Data
                );

            Assert.Equal("G544-061", licenseDoc.DocumentNo);
            Assert.Equal("26.11.2022", licenseDoc.ExpiryDate);
            Assert.NotNull(licenseDoc.Expiry);
            Assert.InRange(licenseDoc.Expiry.Value, new DateTime(2022, 11, 26), new DateTime(2022, 11, 26, 0, 0, 1));
        }
        public void Should_Decrypt_Data()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            EncryptedPassportElement element      = passportData.Data.Single();

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.ReadAsRsa());

            ResidentialAddress residentialAddress = decrypter.DecryptData <ResidentialAddress>(
                element.Data,
                credentials.SecureData.Address.Data
                );

            Assert.NotNull(residentialAddress);
            Assert.NotEmpty(residentialAddress.StreetLine1);
            Assert.NotEmpty(residentialAddress.City);
            Assert.NotEmpty(residentialAddress.PostCode);
            Assert.Equal(2, residentialAddress.CountryCode.Length);
        }
        public async Task Should_Decrypt_Identity_Card_Element_Reverse_Side()
        {
            PassportData             passportData = GetPassportData();
            EncryptedPassportElement idCardEl     = Assert.Single(passportData.Data, el => el.Type == "identity_card");

            Assert.NotNull(idCardEl.ReverseSide);
            Assert.Equal("DgADAQADKAADNfRARK9jbzh5AAFqvAI", idCardEl.ReverseSide.FileId);
            Assert.InRange(idCardEl.ReverseSide.FileDate, new DateTime(2018, 8, 30), new DateTime(2018, 8, 31));
            Assert.Equal(0, idCardEl.ReverseSide.FileSize);

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials =
                decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.RsaPrivateKey);

            byte[] encryptedContent =
                await System.IO.File.ReadAllBytesAsync("Files/identity_card-reverse_side.jpg.enc");

            byte[] content = decrypter.DecryptFile(
                encryptedContent,
                credentials.SecureData.IdentityCard.ReverseSide
                );

            Assert.NotEmpty(content);

            await System.IO.File.WriteAllBytesAsync("Files/identity_card-reverse_side.jpg", encryptedContent);

            using (System.IO.MemoryStream
                   encryptedFileStream = new System.IO.MemoryStream(encryptedContent),
                   decryptedFileStream = new System.IO.MemoryStream()
                   )
            {
                await decrypter.DecryptFileAsync(
                    encryptedFileStream,
                    credentials.SecureData.IdentityCard.ReverseSide,
                    decryptedFileStream
                    );

                Assert.Equal(content, decryptedFileStream.ToArray());
            }
        }
        static async Task DecryptPassportDataAsync(Message message)
        {
            IDecrypter decrypter = new Decrypter();

            // Step 1: Decrypt credentials
            Credentials credentials = decrypter.DecryptCredentials(
                message.PassportData.Credentials,
                GetRsaPrivateKey()
                );

            // Step 2: Validate nonce
            if (credentials.Nonce != "Test nonce for this demo")
            {
                throw new Exception($"Invalid nonce: \"{credentials.Nonce}\".");
            }

            // Step 3: Decrypt residential address using credentials
            EncryptedPassportElement addressElement = message.PassportData.Data.Single(
                el => el.Type == PassportEnums.Scope.Address
                );
            ResidentialAddress address = decrypter.DecryptData <ResidentialAddress>(
                encryptedData: addressElement.Data,
                dataCredentials: credentials.SecureData.Address.Data
                );

            // Step 4: Get phone number
            string phoneNumber = message.PassportData.Data.Single(
                el => el.Type == PassportEnums.Scope.PhoneNumber
                ).PhoneNumber;

            await _botClient.SendTextMessageAsync(
                message.From.Id,
                "Your 🏠 address is:\n" +
                $"{address.StreetLine1}\n" +
                $"{address.City}, {address.CountryCode}\n" +
                $"{address.PostCode}\n\n" +
                $"📱 {phoneNumber}"
                );
        }
示例#20
0
        public void Should_decrypt_address_element()
        {
            PassportData passportData = GetPassportData();

            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials =
                decrypter.DecryptCredentials(passportData.Credentials, EncryptionKey.RsaPrivateKey);

            EncryptedPassportElement addressEl = Assert.Single(passportData.Data, el => el.Type == "address");

            ResidentialAddress residentialAddress = decrypter.DecryptData <ResidentialAddress>(
                encryptedData: addressEl.Data,
                dataCredentials: credentials.SecureData.Address.Data
                );

            Assert.Equal("123 Maple Street", residentialAddress.StreetLine1);
            Assert.Equal("Unit 4", residentialAddress.StreetLine2);
            Assert.Equal("A1A 1A1", residentialAddress.PostCode);
            Assert.Equal("Toronto", residentialAddress.City);
            Assert.Equal("Ontario", residentialAddress.State);
            Assert.Equal("CA", residentialAddress.CountryCode);
        }
        public void Should_Decrypt_Credentials()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            EncryptedPassportElement element      = passportData.Data.Single();

            RSA key = EncryptionKey.ReadAsRsa();

            IDecrypter decrypter = new Decrypter();

            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            Assert.NotNull(credentials);
            Assert.Equal("Test nonce for driver license", credentials.Nonce);
            Assert.NotNull(credentials.SecureData);

            // decryption of document data in 'driver_license' element requires accompanying DataCredentials
            Assert.NotNull(credentials.SecureData.DriverLicense);
            Assert.NotNull(credentials.SecureData.DriverLicense.Data);
            Assert.NotEmpty(credentials.SecureData.DriverLicense.Data.Secret);
            Assert.NotEmpty(credentials.SecureData.DriverLicense.Data.DataHash);

            // decryption of front side file in 'driver_license' element requires accompanying FileCredentials
            Assert.NotNull(credentials.SecureData.DriverLicense.FrontSide);
            Assert.NotEmpty(credentials.SecureData.DriverLicense.FrontSide.Secret);
            Assert.NotEmpty(credentials.SecureData.DriverLicense.FrontSide.FileHash);

            // decryption of optional selfie file in 'driver_license' element requires accompanying FileCredentials
            Assert.NotNull(credentials.SecureData.DriverLicense.Selfie);
            Assert.NotEmpty(credentials.SecureData.DriverLicense.Selfie.Secret);
            Assert.NotEmpty(credentials.SecureData.DriverLicense.Selfie.FileHash);

            // decryption of optional translation file in 'driver_license' element requires accompanying FileCredentials
            Assert.Equal(
                element.Translation.Length,
                credentials.SecureData.DriverLicense.Translation.Length
                );
        }
        public void Should_Decrypt_Document_Data()
        {
            Update                   update       = _classFixture.Entity;
            PassportData             passportData = update.Message.PassportData;
            EncryptedPassportElement element      = passportData.Data.Single();
            RSA         key         = EncryptionKey.ReadAsRsa();
            IDecrypter  decrypter   = new Decrypter();
            Credentials credentials = decrypter.DecryptCredentials(passportData.Credentials, key);

            IdDocumentData licenseDoc = decrypter.DecryptData <IdDocumentData>(
                encryptedData: element.Data,
                dataCredentials: credentials.SecureData.DriverLicense.Data
                );

            Assert.NotEmpty(licenseDoc.DocumentNo);
            if (string.IsNullOrEmpty(licenseDoc.ExpiryDate))
            {
                Assert.Null(licenseDoc.Expiry);
            }
            else
            {
                Assert.NotNull(licenseDoc.Expiry);
            }
        }