예제 #1
0
        protected override OpResult _Store(PersonalCard _obj)
        {
            if (_obj == null)
            {
                return(OpResult.NotifyStoreAction(OpResult.ResultStatus.ObjectIsNull, _obj, "PersonalCard object cannot be created as it is null"));
            }

            RepositoryMgr.CardMgr.Store(_obj);
            _obj.PersonalCardID = _obj.CardRecordID;

            if (Exists(_obj))
            {
                ExecuteNonQuery(GetQuery_UpdateQuery(_obj));
                return(OpResult.NotifyStoreAction(OpResult.ResultStatus.Updated, _obj));
            }

            ExecuteNonQuery(GetQuery_InsertQuery(_obj));
            if (_obj.PersonalCardID == null)
            {
                _obj.PersonalCardID = DbMgr.GetLastInsertID();
            }
            _obj.FromDb = true;

            return(OpResult.NotifyStoreAction(OpResult.ResultStatus.Created, _obj));
        }
예제 #2
0
 public DropBoxLinkParams(string accessToken, string localFolderPath, PersonalCard card, string privateKeyPassword)
 {
     this.AccessToken        = accessToken;
     this.LocalFolderPath    = localFolderPath;
     this.Card               = card;
     this.PrivateKeyPassword = privateKeyPassword;
 }
예제 #3
0
        public async Task Confirm(string code)
        {
            var token = await this.request.Confirm(code);

            this.state = States.Confirmed;

            try
            {
                this.privateKeyResponse = await this.DownloadPrivateKey(token);
            }
            catch (VirgilPrivateServicesException e) when(e.ErrorCode == 40020)
            {
                throw new PrivateKeyNotFoundException();
            }

            this.state = States.PrivateKeyDownloaded;

            if (VirgilKeyPair.IsPrivateKeyEncrypted(this.privateKeyResponse.PrivateKey) &&

                !VirgilKeyPair.CheckPrivateKeyPassword(
                    this.privateKeyResponse.PrivateKey,
                    Encoding.UTF8.GetBytes(this.password))

                )
            {
                throw new WrongPrivateKeyPasswordException("Wrong password");
            }

            var card = new PersonalCard(this.recipientCard, new PrivateKey(this.privateKeyResponse.PrivateKey));

            this.aggregator.Publish(new CardLoaded(card, this.password));

            this.state = States.Finished;
        }
예제 #4
0
        private static Try<PersonalCard> BuildPersonalCard(ConfigureOptions options)
        {
            var result = new Try<PersonalCard>();

            string cardJson = null;
            CardModel cardModel = null;
            byte[] privateKeyBytes = null;
            PrivateKey privateKey = null;

            try
            {
                cardJson = File.ReadAllText(options.VirgilCardPath);
            }
            catch (Exception)
            {
                result.AddError("Can't read virgil card file");
            }

            try
            {
                if (cardJson != null)
                {
                    cardModel = JsonConvert.DeserializeObject<CardModel>(cardJson);
                }
            }
            catch (Exception)
            {
                result.AddError("Can't deserialize virgil card from file");
            }

            try
            {
                privateKeyBytes = File.ReadAllBytes(options.PrivateKeyPath);
            }
            catch (Exception)
            {
                result.AddError("Can't read virgil private card file");
            }

            try
            {
                if (privateKeyBytes != null)
                {
                    privateKey = new PrivateKey(privateKeyBytes);
                }
            }
            catch (Exception)
            {
                result.AddError("Private key file could not be parsed");
            }

            if (result.IsValid())
            {
                var pc = new PersonalCard(new RecipientCard(cardModel), privateKey);
                result.SetResult(pc);
            }

            return result;
        }
예제 #5
0
        public async Task Setup()
        {
            this.personalCard         = PersonalCard.Import(Settings.Default.PersonalCard);
            this.personalCardPassword = "******";
            var dropboxClient = new DropboxClientFactory("14c-HsvO9WUAAAAAAAABfMqXv6__GhRIZMYzFK1Dvd3zsTPD-oCbzYWzthLI8DAC").GetInstance();

            this.dropBoxCloudStorage = new DropBoxCloudStorage(dropboxClient, this.personalCard, this.personalCardPassword);
        }
예제 #6
0
        private DbDeleteStatement GetQuery_DeleteQuery(PersonalCard _obj)
        {
            DbDeleteStatement clause = DbMgr.CreateDeleteClause();

            clause.DeleteFrom("PersonalCards").Criteria.IsEqual("PersonalCards", "PersonalCardID", _obj.PersonalCardID);

            return(clause);
        }
예제 #7
0
        public DecryptFileOperation(LocalPath source, LocalPath target, PersonalCard personalCard, string password)
        {
            this.Title = "Decrypt " + source.AsRelativeToRoot();

            this.source = source;
            this.target = target;

            this.personalCard = personalCard;
            this.password     = password;
        }
예제 #8
0
 public StartSyncParams(
     PersonalCard personalCard,
     string password,
     DropboxCredentials dropboxCredentials,
     string sourceDir)
 {
     this.PersonalCard       = personalCard;
     this.Password           = password;
     this.DropboxCredentials = dropboxCredentials;
     this.SourceDir          = sourceDir;
 }
예제 #9
0
        public void StoreAccessData(PersonalCard card, string privateKeyPassword)
        {
            this.CurrentCard        = card;
            this.PrivateKeyPassword = privateKeyPassword;
            this.HasAccount         = true;

            var data = new StorageDto {
                PrivateKeyPassword = this.PrivateKeyPassword, PersonalCard = this.CurrentCard.Export()
            };

            var json = JsonConvert.SerializeObject(data);

            this.storageProvider.Save(json);
        }
        private async void SelectKey(object arg)
        {
            try
            {
                this.ClearErrors();
                this.IsBusy = true;

                var fileDto = this.SelectedCard;

                if (this.SelectedCard == null)
                {
                    this.RaiseErrorMessage("Please select card");
                    return;
                }

                var cardDto = await SDK.Domain.ServiceLocator.Services.Cards.Get(fileDto.card.id);

                var recipientCard = new RecipientCard(cardDto);
                var personalCard  = new PersonalCard(recipientCard, new PrivateKey(fileDto.private_key));
                if (personalCard.IsPrivateKeyEncrypted && !personalCard.CheckPrivateKeyPassword(this.Password))
                {
                    throw new WrongPrivateKeyPasswordException("Wrong password");
                }

                try
                {
                    var encrypt = personalCard.Encrypt("test");
                    personalCard.Decrypt(encrypt, this.Password);
                }
                catch
                {
                    throw new Exception("Virgil card is malformed");
                }

                this.aggregator.Publish(new CardLoaded(personalCard, this.Password));
                this.aggregator.Publish(new ConfirmationSuccessfull());
            }
            catch (WrongPrivateKeyPasswordException e)
            {
                this.AddErrorFor(nameof(this.Password), e.Message);
            }
            catch (Exception e)
            {
                this.RaiseErrorMessage(e.Message);
            }
            finally
            {
                this.IsBusy = false;
            }
        }
예제 #11
0
        public LocalFolderLink(string encryptedFolder, string decryptedFolder, PersonalCard personalCard, string privateKeyPassword)
        {
            this.personalCard       = personalCard;
            this.privateKeyPassword = privateKeyPassword;
            this.encryptedFolder    = new LocalFolder(new LocalFolderRoot(encryptedFolder), "Encrypted");
            this.decryptedFolder    = new LocalFolder(new LocalFolderRoot(decryptedFolder), "Decrypted");

            this.encryptedFolder.Subscribe(this);
            this.decryptedFolder.Subscribe(this);

            this.encryptedFolderWatcher = new LocalFolderWatcher(this.encryptedFolder);
            this.decryptedFolderWatcher = new LocalFolderWatcher(this.decryptedFolder);

            this.cancellationTokenSource = new CancellationTokenSource();
        }
        public async Task Confirm(string code)
        {
            var token = await this.request.Confirm(code);

            var card = await PersonalCard.Create(token, this.usePassword?this.password : null, new Dictionary <string, string>
            {
                ["CreatedWith"] = "Virgil.Disk"
            });

            if (this.uploadPrivateKey)
            {
                await card.UploadPrivateKey(this.password);
            }

            this.eventAggregator.Publish(new CardLoaded(card, this.password));
        }
        public void DecryptWithAnotherPassword(string anotherPassword)
        {
            if (VirgilKeyPair.IsPrivateKeyEncrypted(this.privateKeyResponse.PrivateKey) &&

                !VirgilKeyPair.CheckPrivateKeyPassword(
                    this.privateKeyResponse.PrivateKey,
                    Encoding.UTF8.GetBytes(anotherPassword))

                )
            {
                throw new WrongPrivateKeyPasswordException("Wrong password");
            }

            var card = new PersonalCard(this.recipientCard, new PrivateKey(this.privateKeyResponse.PrivateKey));

            this.aggregator.Publish(new CardLoaded(card, anotherPassword));
        }
예제 #14
0
        protected override OpResult _Delete(PersonalCard _obj)
        {
            if (_obj == null)
            {
                return(OpResult.NotifyDeleteAction(OpResult.ResultStatus.ObjectIsNull, _obj, "PersonalCard object cannot be deleted as it is null"));
            }

            if (Exists(_obj))
            {
                ExecuteNonQuery(GetQuery_DeleteQuery(_obj));

                RepositoryMgr.CardMgr.Delete(_obj);

                return(OpResult.NotifyDeleteAction(OpResult.ResultStatus.ExistsAndDeleted, _obj));
            }
            return(OpResult.NotifyDeleteAction(OpResult.ResultStatus.NotExists, _obj, "PersonalCard object cannot be deleted as it does not exist"));
        }
예제 #15
0
        public void Restore()
        {
            try
            {
                var json = this.storageProvider.Load();

                var data = JsonConvert.DeserializeObject <StorageDto>(json);

                this.PrivateKeyPassword = data.PrivateKeyPassword;
                this.CurrentCard        = PersonalCard.Import(data.PersonalCard);
                this.HasAccount         = true;
            }
            catch (Exception exception)
            {
                this.PrivateKeyPassword = null;
                this.CurrentCard        = null;
                this.HasAccount         = false;
                this.Exception          = exception;
            }
        }
예제 #16
0
 public CardLoaded(PersonalCard card, string password)
 {
     this.Card = card;
     this.PrivateKeyPassword = password;
 }
예제 #17
0
 public DropBoxCloudStorage(DropboxClient client, PersonalCard personalCard, string privateKeyPassword)
 {
     this.client             = client;
     this.credentials        = personalCard;
     this.privateKeyPassword = privateKeyPassword;
 }
예제 #18
0
        private DbInsertStatement GetQuery_InsertQuery(PersonalCard _obj)
        {
            Dictionary <string, DbFieldEntry> fields = GetFields(_obj);

            return(DbMgr.CreateInsertClause("PersonalCards", fields));
        }
예제 #19
0
 private DbUpdateStatement GetQuery_UpdateQuery(PersonalCard _obj)
 {
     return(DbMgr.CreateUpdateClause("PersonalCards", GetFields(_obj), "PersonalCardID", _obj.PersonalCardID));
 }