Ejemplo n.º 1
0
        public async Task <IActionResult> SignPersonFaceVerification([FromBody] BiometricPersonDataForSignatureDto biometricPersonData)
        {
            byte[] assetId = _assetsService.GenerateAssetId(AttributeType.PassportPhoto, biometricPersonData.ImageSource);
            Guid   guid    = _dataAccessService.FindPersonGuid(assetId.ToHexString());

            if (guid == Guid.Empty)
            {
                return(BadRequest());
            }

            byte[] imageContent = Convert.FromBase64String(biometricPersonData.ImageTarget);
            byte[] auxBytes     = Convert.FromBase64String(biometricPersonData.AuxMessage);

            byte[] msg = new byte[assetId.Length + auxBytes?.Length ?? 0];

            Array.Copy(assetId, 0, msg, 0, assetId.Length);

            if ((auxBytes?.Length ?? 0) > 0)
            {
                Array.Copy(auxBytes, 0, msg, assetId.Length, auxBytes.Length);
            }

            Tuple <bool, double> res = await _facesService.VerifyPerson(_portalConfiguration.FacePersonGroupId, guid, imageContent).ConfigureAwait(false);

            if (res.Item1)
            {
                Tuple <byte[], byte[]> signRes = _facesService.Sign(msg);

                return(Ok(new BiometricSignedVerificationDto {
                    PublicKey = signRes.Item1.ToHexString(), Signature = signRes.Item2.ToHexString()
                }));
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SignPersonFaceVerification([FromBody] BiometricPersonDataForSignatureDto biometricPersonData)
        {
            byte[] imageSource = Convert.FromBase64String(biometricPersonData.ImageSource);
            byte[] imageTarget = Convert.FromBase64String(biometricPersonData.ImageTarget);

            byte[] assetId = await _assetsService.GenerateAssetId(AttributesSchemes.ATTR_SCHEME_NAME_PASSPORTPHOTO, biometricPersonData.ImageSource, null).ConfigureAwait(false);

            byte[] sourceImageCommitment = biometricPersonData.SourceImageCommitment.HexStringToByteArray();

            SurjectionProof surjectionProof = new SurjectionProof
            {
                AssetCommitments = new byte[][] { biometricPersonData.SourceImageProofCommitment.HexStringToByteArray() },
                Rs = new BorromeanRingSignature
                {
                    E = biometricPersonData.SourceImageProofSignatureE.HexStringToByteArray(),
                    S = new byte[][] { biometricPersonData.SourceImageProofSignatureS.HexStringToByteArray() }
                }
            };

            if (!ConfidentialAssetsHelper.VerifyIssuanceSurjectionProof(surjectionProof, sourceImageCommitment, new byte[][] { assetId }))
            {
                return(BadRequest("Surjection proofs validation failed"));
            }

            //byte[] auxBytes = null; // Convert.FromBase64String(biometricPersonData.AuxMessage);

            //byte[] msg = new byte[sourceImageCommitment.Length + auxBytes?.Length ?? 0];

            //Array.Copy(sourceImageCommitment, 0, msg, 0, sourceImageCommitment.Length);

            //if ((auxBytes?.Length ?? 0) > 0)
            //{
            //	Array.Copy(auxBytes, 0, msg, sourceImageCommitment.Length, auxBytes.Length);
            //}

            bool res = await _facesService.VerifyFaces(imageSource, imageTarget).ConfigureAwait(false);

            if (res)
            {
                Tuple <byte[], byte[]> signRes = _facesService.Sign(sourceImageCommitment);

                return(Ok(new BiometricSignedVerificationDto {
                    PublicKey = signRes.Item1.ToHexString(), Signature = signRes.Item2.ToHexString()
                }));
            }

            return(BadRequest());
        }
Ejemplo n.º 3
0
        public IActionResult SendOnboardingRequest([FromBody] UserAttributeTransferDto userAttributeTransfer)
        {
            ulong           accountId       = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture);
            UtxoPersistency utxoPersistency = _executionContextManager.ResolveUtxoExecutionServices(accountId);

            bool proceed = true;

            if (!string.IsNullOrEmpty(userAttributeTransfer.ImageContent) && !string.IsNullOrEmpty(userAttributeTransfer.Content))
            {
                string sourceImage = _dataAccessService.GetUserAssociatedAttributes(accountId).FirstOrDefault(t => t.Item1 == AttributeType.PassportPhoto)?.Item2;
                BiometricPersonDataForSignatureDto biometricPersonDataForSignature = new BiometricPersonDataForSignatureDto
                {
                    ImageSource = sourceImage,
                    ImageTarget = userAttributeTransfer.ImageContent
                };

                try
                {
                    BiometricSignedVerificationDto biometricSignedVerification = $"{Request.Scheme}://{Request.Host.ToUriComponent()}/biometric/".AppendPathSegment("SignPersonFaceVerification").PostJsonAsync(biometricPersonDataForSignature).ReceiveJson <BiometricSignedVerificationDto>().Result;
                }
                catch (FlurlHttpException)
                {
                    proceed = false;
                }
                //Tuple<bool, bool> faceRes = VerifyFaceImage(userAttributeTransfer.ImageContent, userAttributeTransfer.Content);

                proceed = true;                 // faceRes.Item1;
            }

            if (proceed)
            {
                SendOnboardingRequest(userAttributeTransfer, utxoPersistency.TransactionsService);

                return(Ok(true));
            }

            return(Ok(false));
        }
Ejemplo n.º 4
0
        public IActionResult SendEmployeeRequest([FromBody] UserAttributeTransferDto userAttributeTransfer)
        {
            ulong           accountId       = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture);
            UtxoPersistency utxoPersistency = _executionContextManager.ResolveUtxoExecutionServices(accountId);

            bool proceed = true;

            if (!string.IsNullOrEmpty(userAttributeTransfer.ImageContent) && !string.IsNullOrEmpty(userAttributeTransfer.Content))
            {
                string sourceImage = _dataAccessService.GetUserAssociatedAttributes(accountId).FirstOrDefault(t => t.Item1 == AttributeType.PassportPhoto)?.Item2;
                BiometricPersonDataForSignatureDto biometricPersonDataForSignature = new BiometricPersonDataForSignatureDto
                {
                    ImageSource = sourceImage,
                    ImageTarget = userAttributeTransfer.ImageContent
                };

                try
                {
                    BiometricSignedVerificationDto biometricSignedVerification = $"{Request.Scheme}://{Request.Host.ToUriComponent()}/biometric/".AppendPathSegment("SignPersonFaceVerification").PostJsonAsync(biometricPersonDataForSignature).ReceiveJson <BiometricSignedVerificationDto>().Result;
                }
                catch (FlurlHttpException)
                {
                    proceed = false;
                }
                //Tuple<bool, bool> faceRes = VerifyFaceImage(userAttributeTransfer.ImageContent, userAttributeTransfer.Content);

                proceed = true; // faceRes.Item1;
            }

            if (proceed)
            {
                SendEmployeeRequest(userAttributeTransfer, utxoPersistency.TransactionsService);

                string[] categoryEntries = userAttributeTransfer.ExtraInfo.Split("/");

                foreach (string categoryEntry in categoryEntries)
                {
                    string groupOwnerName = categoryEntry.Split("|")[0];
                    string groupName      = categoryEntry.Split("|")[1];

                    ulong groupRelationId = _dataAccessService.AddUserGroupRelation(accountId, groupOwnerName, userAttributeTransfer.Target, groupName);

                    if (groupRelationId > 0)
                    {
                        GroupRelationDto groupRelationDto = new GroupRelationDto
                        {
                            GroupRelationId = groupRelationId,
                            GroupOwnerName  = groupOwnerName,
                            GroupOwnerKey   = userAttributeTransfer.Target,
                            GroupName       = groupName
                        };

                        _idenitiesHubContext.Clients.Group(accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushGroupRelation", groupRelationDto);
                    }
                }


                return(Ok(true));
            }

            return(Ok(false));
        }