Exemple #1
0
        public ConsentManagementService(IDataAccessService dataAccessService, IAccountsService accountsService,
                                        IRelationsProofsValidationService relationsProofsValidationService, IConfigurationService configurationService,
                                        IHashCalculationsRepository hashCalculationsRepository, ILoggerService loggerService, IHubContext <ConsentManagementHub> hubContext)
        {
            _logger            = loggerService.GetLogger(nameof(ConsentManagementService));
            _dataAccessService = dataAccessService;
            _accountsService   = accountsService;
            _relationsProofsValidationService = relationsProofsValidationService;
            _hubContext         = hubContext;
            _azureConfiguration = configurationService.Get <IAzureConfiguration>();
            _hashCalculation    = hashCalculationsRepository.Create(Globals.DEFAULT_HASH);

            PipeIn = new ActionBlock <PacketBase>(async p =>
            {
                try
                {
                    if (p is GroupsRelationsProofs relationsProofs)
                    {
                        _logger.LogIfDebug(() => $"[{_accountId}]: checking relation proofs {JsonConvert.SerializeObject(relationsProofs, new ByteArrayJsonConverter())}");

                        UtxoPersistency utxoPersistency = _executionContextManager.ResolveUtxoExecutionServices(_accountId);
                        utxoPersistency.ClientCryptoService.DecodeEcdhTuple(relationsProofs.EcdhTuple, relationsProofs.TransactionPublicKey, out byte[] blindingFactor, out byte[] imageHash, out byte[] issuer, out byte[] sessionKey);
                        string keyImage = relationsProofs.KeyImage.ToString();

                        _proofsSessions.AddOrUpdate(keyImage, new ProofsSession {
                            SessionKey = sessionKey.ToHexString(), CreationTime = DateTime.UtcNow
                        }, (k, v) => v);

                        RelationProofsSession relationProofsSession = PopRelationProofSession(sessionKey.ToHexString());

                        _logger.LogIfDebug(() => $"{nameof(relationProofsSession)}={JsonConvert.SerializeObject(relationProofsSession, new ByteArrayJsonConverter())}");

                        RelationProofsValidationResults validationResults
                            = await _relationsProofsValidationService
                              .VerifyRelationProofs(relationsProofs, _clientCryptoService, relationProofsSession)
                              .ConfigureAwait(false);

                        await _hubContext.Clients.Group(sessionKey.ToHexString()).SendAsync("ValidationResults", validationResults).ConfigureAwait(false);
                    }
                    else if (p is TransitionCompromisedProofs compromisedProofs)
                    {
                        if (_proofsSessions.TryGetValue(compromisedProofs.CompromisedKeyImage.ToHexString(), out ProofsSession proofsSession))
                        {
                            await _hubContext.Clients.Group(proofsSession.SessionKey).SendAsync("ProofsCompromised", proofsSession).ConfigureAwait(false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error($"[{_accountId}]: failure during processing {p.GetType().Name}", ex);
                }
            });

            PipInNotifications = new ActionBlock <SynchronizerNotificationBase>(n =>
            {
            });
        }
        public IActionResult Authenticate([FromBody] AccountDto accountDto)
        {
            _logger.LogIfDebug(() => $"[{accountDto.AccountId}]: Started authentication of the account {JsonConvert.SerializeObject(accountDto)}");

            var accountDescriptor = _accountsService.Authenticate(accountDto.AccountId, accountDto.Password);

            if (accountDescriptor == null)
            {
                throw new AccountAuthenticationFailedException(accountDto.AccountId);
            }

            if (accountDescriptor.AccountType == AccountType.User)
            {
                _executionContextManager.InitializeUtxoExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey, accountDescriptor.SecretViewKey, accountDescriptor.PwdHash);
                var persistency = _executionContextManager.ResolveUtxoExecutionServices(accountDto.AccountId);
                if (!persistency.BindingKeySource.Task.IsCompleted)
                {
                    persistency.BindingKeySource.SetResult(ConfidentialAssetsHelper.PasswordHash(accountDto.Password));
                }
            }
            else
            {
                _executionContextManager.InitializeStateExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey);
            }

            var forLog = new
            {
                accountDescriptor.AccountId,
                accountDescriptor.AccountType,
                accountDescriptor.AccountInfo,
                SecretSpendKey = accountDescriptor.SecretSpendKey.ToHexString(),
                PublicSpendKey = accountDescriptor.PublicSpendKey.ToHexString(),
                SecretViewKey  = accountDescriptor.SecretViewKey.ToHexString(),
                PublicViewKey  = accountDescriptor.PublicViewKey.ToHexString()
            };

            _logger.LogIfDebug(() => $"[{accountDto.AccountId}]: Authenticated account {JsonConvert.SerializeObject(forLog)}");

            return(Ok(_translatorsRepository.GetInstance <AccountDescriptor, AccountDto>().Translate(accountDescriptor)));
        }
Exemple #3
0
        public IActionResult SendCompromisedProofs([FromBody] UnauthorizedUseDto unauthorizedUse)
        {
            ulong accountId = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture);

            UserRootAttribute rootAttribute = _dataAccessService.GetUserAttributes(accountId).FirstOrDefault();

            UtxoPersistency utxoPersistency = _executionContextManager.ResolveUtxoExecutionServices(accountId);

            byte[] target = unauthorizedUse.Target.HexStringToByteArray();
            byte[] compromisedKeyImage = unauthorizedUse.KeyImage.HexStringToByteArray();
            byte[] issuer  = rootAttribute.Source.HexStringToByteArray();
            byte[] assetId = rootAttribute.AssetId;
            byte[] originalBlindingFactor = rootAttribute.OriginalBlindingFactor;
            byte[] originalCommitment     = rootAttribute.OriginalCommitment;
            byte[] lastTransactionKey     = rootAttribute.LastTransactionKey;
            byte[] lastBlindingFactor     = rootAttribute.LastBlindingFactor;
            byte[] lastCommitment         = rootAttribute.LastCommitment;
            byte[] lastDestinationKey     = rootAttribute.LastDestinationKey;

            RequestInput requestInput = new RequestInput
            {
                AssetId = assetId,
                EligibilityBlindingFactor = originalBlindingFactor,
                EligibilityCommitment     = originalCommitment,
                Issuer = issuer,
                PrevAssetCommitment = lastCommitment,
                PrevBlindingFactor  = lastBlindingFactor,
                PrevDestinationKey  = lastDestinationKey,
                PrevTransactionKey  = lastTransactionKey,
                Target = target
            };

            OutputModel[] outputModels        = _gatewayService.GetOutputs(_portalConfiguration.RingSize + 1);
            byte[][]      issuanceCommitments = _gatewayService.GetIssuanceCommitments(issuer, _portalConfiguration.RingSize + 1);
            RequestResult requestResult       = utxoPersistency.TransactionsService.SendCompromisedProofs(requestInput, compromisedKeyImage, outputModels, issuanceCommitments).Result;

            return(Ok(requestResult.Result));
        }