Example #1
0
    public static IEnumerator LogBasesStream(MentalState m, Expression e, ProofType pt = Proof, float timeout = -1)
    {
        var result = new ProofBases();
        var done   = new Container <bool>(false);

        var startTime    = Time.time;
        var proofRoutine = m.StreamProofs(result, e, done, pt);

        m.StartCoroutine(proofRoutine);

        var waitingString    = "waiting for '" + e + "' to be proved...";
        var foundResult      = "found partial result. go to LogBasesStream() to see it.";
        var isProvedByString = "'" + e + "'" + " is proved by: ";

        while (!done.Item)
        {
            if (startTime + timeout >= Time.time)
            {
                m.StopCoroutine(proofRoutine);
                break;
            }
            // Log(waitingString);
            if (!result.IsEmpty())
            {
                // Log(foundResult);
                // Log(isProvedByString + result);
            }
            yield return(null);
        }
        Log(isProvedByString + result);
        yield break;
    }
Example #2
0
 public Proof(
     ProofType type,
     ProofType proofId,
     BankAccount bankAccount)
 {
     Id          = GetUniqueIdentifier();
     Type        = type;
     ProofId     = proofId;
     BankAccount = bankAccount;
 }
Example #3
0
        /// <summary>
        /// Constructor.  Use this constructor when the verifier does not known integerB.
        /// </summary>
        /// <param name="crypto">Crypto parameters</param>
        /// <param name="closedIntegerA">Value of pedersen commitment to integer A</param>
        /// <param name="rangeProofType">relation between integerA and integerB</param>
        /// <param name="closedIntegerB">Value of pedersen commitment to integer B</param>
        /// <param name="minRange">Minimum value of integerA and integerB</param>
        /// <param name="maxRange">Maximum value of integerA and integerB</param>
        public VerifierRangeProofParameters(CryptoParameters crypto, GroupElement closedIntegerA, ProofType rangeProofType, GroupElement closedIntegerB, int minRange, int maxRange)
            : base(crypto)
        {
            this.setVerifierParameters(new GroupElement[] { closedIntegerA, closedIntegerB });

            this.RangeProofType  = rangeProofType;
            this.IntegerBIsKnown = false;
            this.MinValue        = minRange;
            this.MaxValue        = maxRange;
        }
        private async Task <AuthResponse> handleAuthRequest(AuthRequest authRequest, ProofType type)
        {
            AuthResponse response = new AuthResponse();

            if (authRequest.user != null)
            {
                var user = (await userRepository.Lookup(authRequest.user)).FirstOrDefault();
                if (user == null)
                {
                    throw new NoSuchUserException();
                }
                if (authRequest.profile != null)
                {
                    var userLookup = new UserLookup();
                    userLookup.id            = user.Id;
                    authRequest.profile.user = userLookup;
                }
            }
            var profile = (await profileRepository.Lookup(authRequest.profile)).FirstOrDefault();

            if (profile == null)
            {
                switch (type)
                {
                case ProofType.ProofType_NickEmail:
                    throw new NickInvalidException();

                case ProofType.ProofType_Unique:
                    throw new UniqueNickInvalidException();

                default:
                    throw new AuthInvalidCredentialsException();
                }
            }

            UserLookup lookup = new UserLookup();

            lookup.id    = profile.Userid;
            profile.User = profile.User ?? (await userRepository.Lookup(lookup)).FirstOrDefault();

            String client_proof = GetPasswordProof(profile, authRequest, type, true);

            if (!client_proof.Equals(authRequest.client_response))
            {
                throw new AuthInvalidCredentialsException();
            }

            response.server_response = GetPasswordProof(profile, authRequest, type, false);
            response.profile         = profile;
            response.user            = profile.User;
            response.session         = await generateSessionKey(profile);

            response.success = true;
            return(response);
        }
Example #5
0
        public IActionResult Update(string id, ProofType item)
        {
            var items = _service.Get(id);

            if (items == null)
            {
                return(NotFound());
            }

            _service.Update(id, item);

            return(NoContent());
        }
Example #6
0
        /// <summary>
        /// Constructor. Use this constructor when the Verifier knows the value of integerB.
        /// </summary>
        /// <param name="crypto">Crypto parameters</param>
        /// <param name="closedIntegerA">Committed value being compared.</param>
        /// <param name="integerB">Verifier known constant being compared</param>
        /// <param name="maxRange">Maximum value of committed value in closedCommitment. Used to determine length of bit decomposition.</param>
        /// <param name="minRange">Minimum value of committed value in closedCommitment. Used to determine length of bit decomposition.</param>
        /// <param name="proofType">Relatation between committed value in closedCommitment and integer ( less than, greater than, etc).</param>
        public VerifierRangeProofParameters(CryptoParameters crypto, GroupElement closedIntegerA, ProofType rangeProofType, int integerB, int minRange, int maxRange)
            : base(crypto)
        {
            GroupElement closedIntegerB = this.G.Exponentiate(this.FieldZq.GetElement(integerB));

            this.setVerifierParameters(new GroupElement[] { closedIntegerA, closedIntegerB });

            this.RangeProofType  = rangeProofType;
            this.IntegerBIsKnown = true;
            this.IntegerB        = integerB;
            this.MinValue        = minRange;
            this.MaxValue        = maxRange;
        }
Example #7
0
 /// <summary>
 /// Constructor. Use this constructor when the verifier DOES NOT know the value
 /// of IntegerB.
 /// </summary>
 /// <param name="crypto">Crypto parameters.</param>
 /// <param name="openIntegerA">Pedersen Commitment to integerA.</param>
 /// <param name="rangeProofType">Type of range proof.</param>
 /// <param name="openIntegerB">Pedersen Commitment to integerB.</param>
 /// <param name="minRange">Minimum value for integerA and integerB.</param>
 /// <param name="maxRange">Maximum value for integerA and integerB.</param>
 public ProverRangeProofParameters(
     CryptoParameters crypto,
     PedersenCommitment openIntegerA,
     ProofType rangeProofType,
     PedersenCommitment openIntegerB,
     int minRange,
     int maxRange) : base(crypto)
 {
     this.setProverParameters(new PedersenCommitment[] { openIntegerA, openIntegerB });
     this.IntegerBIsKnown = false;
     this.RangeProofType  = rangeProofType;
     this.MinValue        = minRange;
     this.MaxValue        = maxRange;
 }
Example #8
0
        /// <summary>
        /// Constructor. Use this constructor when the verifier knows the value
        /// of IntegerB.
        /// </summary>
        /// <param name="crypto">Crypto parameters.</param>
        /// <param name="openIntegerA">Pedersen Commitment to integerA.</param>
        /// <param name="rangeProofType">Type of range proof.</param>
        /// <param name="integerB">integerB.</param>
        /// <param name="minRange">Minimum value for integerA and integerB.</param>
        /// <param name="maxRange">Maximum value for integerA and integerB.</param>

        public ProverRangeProofParameters(
            CryptoParameters crypto,
            PedersenCommitment openIntegerA,
            ProofType rangeProofType,
            int integerB,
            int minRange,
            int maxRange) : base(crypto)
        {
            PedersenCommitment openIntegerB = new PedersenCommitment(this.G, this.H, this.FieldZq.GetElement((uint)integerB), this.FieldZq.Zero, this.Group);

            this.setProverParameters(new PedersenCommitment[] { openIntegerA, openIntegerB });

            this.IntegerBIsKnown = true;
            this.IntegerB        = integerB;
            this.RangeProofType  = rangeProofType;
            this.MinValue        = minRange;
            this.MaxValue        = maxRange;
        }
Example #9
0
        public ActionResult <ProofType> Create(ProofType items)
        {
            _service.Create(items);

            return(CreatedAtRoute("GetProofType", new { id = items.Id.ToString() }, items));
        }
Example #10
0
 public void Remove(ProofType itemIn)
 {
     _collection.DeleteOne(item => item.Id == item.Id);
 }
Example #11
0
 public void Update(string id, ProofType itemIn)
 {
     _collection.ReplaceOne(item => item.Id == id, itemIn);
 }
Example #12
0
 public ProofType Create(ProofType itemIn)
 {
     _collection.InsertOne(itemIn);
     return(itemIn);
 }
Example #13
0
        private String GetPasswordProof(Profile profile, AuthRequest request, ProofType type, bool client_to_server)
        {
            List <String> challenges = new List <String>();
            StringBuilder sb         = new StringBuilder();
            string        password   = null;

            if (profile != null && profile.User != null)
            {
                password = profile.User.Password;
            }
            switch (type)
            {
            case ProofType.ProofType_NickEmail:
                if (profile.User.Partnercode != CoreWeb.Models.User.PARTNERID_GAMESPY)
                {
                    sb.Append(profile.User.Partnercode.ToString());
                    sb.Append("@");
                    sb.Append(profile.Nick);
                    sb.Append("@");
                    sb.Append(profile.User.Email);
                }
                else
                {
                    sb.Append(profile.Nick);
                    sb.Append("@");
                    sb.Append(profile.User.Email);
                }
                break;

            case ProofType.ProofType_Unique:
                if (profile.User.Partnercode != CoreWeb.Models.User.PARTNERID_GAMESPY)
                {
                    sb.Append(profile.User.Partnercode.ToString());
                    sb.Append("@");
                    sb.Append(profile.Uniquenick);
                }
                else
                {
                    sb.Append(profile.Uniquenick);
                }
                break;

            case ProofType.ProofType_PreAuth:
                password = request.client_response;
                sb.Append(request.auth_token);
                break;

            case ProofType.ProofType_LoginTicket:
                password = request.login_ticket;
                sb.Append(request.login_ticket);
                break;
            }
            if (client_to_server)
            {
                challenges.Add(request.client_challenge);
                challenges.Add(request.server_challenge);
            }
            else
            {
                challenges.Add(request.server_challenge);
                challenges.Add(request.client_challenge);
            }
            return(GetProofString(sb.ToString(), challenges, password));
        }