Пример #1
0
        private IActionResult GetServiceProviderActionType(IUtxoClientCryptoService clientCryptoService, string actionDecoded)
        {
            ulong accountId = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture);

            UriBuilder uriBuilder = new UriBuilder(actionDecoded);
            string     actionType = uriBuilder.Uri.ParseQueryString()["actionType"];

            string registrationKey;

            byte[]            targetBytes   = uriBuilder.Uri.ParseQueryString()["publicKey"]?.HexStringToByteArray();
            UserRootAttribute rootAttribute = _dataAccessService.GetUserAttributes(accountId).FirstOrDefault();

            if (actionType == "0") // Login and register
            {
                clientCryptoService.GetBoundedCommitment(rootAttribute.AssetId, targetBytes, out byte[] blindingFactor, out byte[] assetCommitment);
                registrationKey = assetCommitment.ToHexString();
                NameValueCollection queryParams = uriBuilder.Uri.ParseQueryString();
                queryParams["registrationKey"] = registrationKey;
                uriBuilder.Query = queryParams.ToString();
            }
            else if (actionType == "1") // employee registration
            {
                registrationKey = rootAttribute.AssetId.ToHexString();
                NameValueCollection queryParams = uriBuilder.Uri.ParseQueryString();
                queryParams["registrationKey"] = registrationKey;
                uriBuilder.Query = queryParams.ToString();
            }
            else if (actionType == "2")             // document sign
            {
            }

            ServiceProviderActionAndValidationsDto serviceProviderActionAndValidations = uriBuilder.Uri.ToString().GetJsonAsync <ServiceProviderActionAndValidationsDto>().Result;

            string validationsExpression = string.Empty;

            if ((serviceProviderActionAndValidations.Validations?.Count ?? 0) > 0)
            {
                validationsExpression = ":" + serviceProviderActionAndValidations.Validations.JoinStrings("|");
            }

            if (actionType == "2")
            {
                return(Ok(new { Action = "6", ActionInfo = $"{serviceProviderActionAndValidations.PublicKey}:{serviceProviderActionAndValidations.SessionKey}:{serviceProviderActionAndValidations.ExtraInfo}{validationsExpression}" }));
            }
            else
            {
                if (serviceProviderActionAndValidations.IsRegistered)
                {
                    return(Ok(new { Action = actionType == "0" ? "3" : "5", ActionInfo = $"{serviceProviderActionAndValidations.PublicKey}:{serviceProviderActionAndValidations.SessionKey}:{serviceProviderActionAndValidations.ExtraInfo}{validationsExpression}" }));
                }
                else
                {
                    return(Ok(new { Action = actionType == "0" ? "2" : "4", ActionInfo = $"{serviceProviderActionAndValidations.PublicKey}:{serviceProviderActionAndValidations.SessionKey}:{serviceProviderActionAndValidations.ExtraInfo}{validationsExpression}" }));
                }
            }
        }
Пример #2
0
        private void NotifyAttributeUpdate(UserRootAttribute userAttribute)
        {
            UserAttributeDto userAttributeDto = new UserAttributeDto
            {
                SchemeName  = userAttribute.SchemeName,
                Source      = userAttribute.Source,
                Content     = userAttribute.Content,
                Validated   = false,
                IsOverriden = true
            };

            _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushUserAttributeUpdate", userAttributeDto);
        }
Пример #3
0
 private static UserAttributeDto GetUserAttributeDto(UserRootAttribute c)
 {
     return(new UserAttributeDto
     {
         AttributeType = Enum.GetName(typeof(AttributeType), c.AttributeType),
         Content = c.Content,
         OriginalBlindingFactor = c.OriginalBlindingFactor.ToHexString(),
         OriginalCommitment = c.OriginalCommitment.ToHexString(),
         OriginatingCommitment = c.IssuanceCommitment.ToHexString(),
         LastBlindingFactor = c.LastBlindingFactor.ToHexString(),
         LastCommitment = c.LastCommitment.ToHexString(),
         AssetId = c.AssetId.ToHexString(),
         Validated = !string.IsNullOrEmpty(c.Content),
         Source = c.Source,
         LastDestinationKey = c.LastDestinationKey.ToHexString(),
         LastTransactionKey = c.LastTransactionKey.ToHexString(),
         IsOverriden = c.IsOverriden
     });
 }
Пример #4
0
        private void NotifyAttributeUpdate(UserRootAttribute userAttribute)
        {
            UserAttributeDto userAttributeDto = new UserAttributeDto
            {
                AttributeType          = ((AttributeType)userAttribute.AttributeType).ToString(),
                Source                 = userAttribute.Source,
                AssetId                = userAttribute.AssetId.ToHexString(),
                OriginalCommitment     = userAttribute.OriginalCommitment.ToHexString(),
                OriginatingCommitment  = userAttribute.IssuanceCommitment.ToHexString(),
                LastCommitment         = userAttribute.LastCommitment.ToHexString(),
                Content                = userAttribute.Content,
                LastBlindingFactor     = userAttribute.LastBlindingFactor.ToHexString(),
                LastDestinationKey     = userAttribute.LastDestinationKey.ToHexString(),
                LastTransactionKey     = userAttribute.LastTransactionKey.ToHexString(),
                OriginalBlindingFactor = userAttribute.OriginalBlindingFactor.ToHexString(),
                Validated              = false,
                IsOverriden            = true
            };

            _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushUserAttributeUpdate", userAttributeDto);
        }
Пример #5
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));
        }
Пример #6
0
        public UserIdentitiesUpdater(long accountId, IUtxoClientCryptoService clientCryptoService,
                                     IAssetsService assetsService, IDataAccessService dataAccessService,
                                     IHubContext <IdentitiesHub> idenitiesHubContext, IRelationsProofsValidationService relationsProofsValidationService,
                                     ISchemeResolverService schemeResolverService, ILoggerService loggerService, CancellationToken cancellationToken)
        {
            _accountId           = accountId;
            _clientCryptoService = clientCryptoService;
            _assetsService       = assetsService;
            _dataAccessService   = dataAccessService;
            _idenitiesHubContext = idenitiesHubContext;
            _relationsProofsValidationService = relationsProofsValidationService;
            _schemeResolverService            = schemeResolverService;
            _cancellationToken = cancellationToken;

            _cancellationToken.Register(() =>
            {
                PipeIn?.Complete();
                PipInNotifications?.Complete();
            });

            _logger = loggerService.GetLogger(nameof(UserIdentitiesUpdater));
            PipeIn  = new ActionBlock <PacketBase>(async p =>
            {
                try
                {
                    if (p is TransferAssetToUtxo packet)
                    {
                        _logger.LogIfDebug(() => $"[{_accountId}]: Processing {nameof(TransferAssetToUtxo)}");
                        UserRootAttribute userRootAttribute = _dataAccessService.GetRootAttributeByOriginalCommitment(_accountId, packet.TransferredAsset.AssetCommitment);
                        if (userRootAttribute != null)
                        {
                            _clientCryptoService.DecodeEcdhTuple(packet.TransferredAsset.EcdhTuple, packet.TransactionPublicKey, out byte[] blindingFactor, out byte[] assetId);
                            await _assetsService.GetAttributeSchemeName(assetId, packet.Signer.ToString()).ContinueWith(t =>
                            {
                                if (t.IsCompleted && !t.IsFaulted)
                                {
                                    _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture))
                                    .SendAsync("PushAttribute",
                                               new UserAttributeDto
                                    {
                                        SchemeName  = t.Result,
                                        Source      = packet.Signer.ToString(),
                                        Content     = userRootAttribute.Content,
                                        Validated   = true,
                                        IsOverriden = false
                                    });
                                }
                            }, TaskScheduler.Current).ConfigureAwait(false);

                            await ObtainRelations(packet, assetId).ConfigureAwait(false);

                            await ObtainRegistrations(packet, assetId).ConfigureAwait(false);
                        }
                        else
                        {
                            _logger.Error($"[{_accountId}]: No Root Attribute found by commitment {packet.TransferredAsset.AssetCommitment.ToHexString()}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error($"Failure during processing {nameof(PipeIn)}, packet {p?.GetType().Name}", ex);
                }
            });

            PipInNotifications = new ActionBlock <SynchronizerNotificationBase>(n =>
            {
                try
                {
                    _logger.LogIfDebug(() => $"[{_accountId}]: notification {n.GetType().Name} {JsonConvert.SerializeObject(n, new ByteArrayJsonConverter())}");

                    ProcessEligibilityCommitmentsDisabled(n);

                    NotifyUserAttributeLastUpdate(n);

                    NotifyCompromisedKeyImage(n);
                }
                catch (Exception ex)
                {
                    _logger.Error($"Failure during processing {nameof(PipInNotifications)}, notification {n?.GetType().Name}", ex);
                }
            });
        }