예제 #1
0
        internal static void FromUnityAccessToken(
            string unityAccessToken,
            RepositorySpec repSpec,
            string projectPath)
        {
            CredentialsResponse response = PlasticScmRestApiClient.GetCredentials(
                PlasticWebApiUris.GetBaseUri(),
                unityAccessToken);

            if (response.Error != null)
            {
                UnityEngine.Debug.LogErrorFormat(
                    "Error getting credentials to download Cloud Project: {0} ({1})",
                    response.Error.Message,
                    response.Error.ErrorCode);

                return;
            }

            ClientConfigData configData = BuildClientConfigData(
                repSpec,
                projectPath,
                response);

            ClientConfig.Get().Save(configData);
        }
예제 #2
0
        /// <summary>
        /// Handles the registration response received from the coordinator.
        /// </summary>
        /// <remarks>
        /// Verifies the registration response message proofs, creates the credentials based on the issued MACs and
        /// finally updates the credentials pool by removing those credentials that were presented and by adding
        /// those that were issued.
        /// </remarks>
        /// <param name="registrationResponse">The registration response message received from the coordinator.</param>
        /// <param name="registrationValidationData">The state data required to validate the issued credentials and the proofs.</param>
        public IEnumerable <Credential> HandleResponse(
            CredentialsResponse registrationResponse,
            CredentialsResponseValidation registrationValidationData)
        {
            Guard.NotNull(nameof(registrationResponse), registrationResponse);
            Guard.NotNull(nameof(registrationValidationData), registrationValidationData);

            var issuedCredentialCount    = registrationResponse.IssuedCredentials.Count();
            var requestedCredentialCount = registrationValidationData.Requested.Count();

            if (issuedCredentialCount != NumberOfCredentials)
            {
                throw new WabiSabiCryptoException(
                          WabiSabiCryptoErrorCode.IssuedCredentialNumberMismatch,
                          $"{issuedCredentialCount} issued but {requestedCredentialCount} were requested.");
            }

            var credentials = registrationValidationData.Requested.Zip(registrationResponse.IssuedCredentials)
                              .Select(x => (Requested: x.First, Issued: x.Second))
                              .ToArray();

            var statements = credentials
                             .Select(x => ProofSystem.IssuerParametersStatement(CredentialIssuerParameters, x.Issued, x.Requested.Ma));

            var areCorrectlyIssued = ProofSystem.Verify(registrationValidationData.Transcript, statements, registrationResponse.Proofs);

            if (!areCorrectlyIssued)
            {
                throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.ClientReceivedInvalidProofs);
            }

            return(credentials.Select(x => new Credential(x.Requested.Value, x.Requested.Randomness, x.Issued)));
        }
예제 #3
0
        internal static void FromUnityAccessToken(
            string unityAccessToken,
            RepositorySpec repSpec,
            string projectPath)
        {
            CredentialsResponse response =
                PlasticScmRestApiClient.GetCredentials(unityAccessToken);

            if (response.Error != null)
            {
                UnityEngine.Debug.LogErrorFormat(
                    PlasticLocalization.GetString(PlasticLocalization.Name.ErrorGettingCredentialsCloudProject),
                    response.Error.Message,
                    response.Error.ErrorCode);

                return;
            }

            ClientConfigData configData = BuildClientConfigData(
                repSpec,
                projectPath,
                response);

            ClientConfig.Get().Save(configData);
        }
 public ConnectionConfirmationResponse(CredentialsResponse zeroAmountCredentials, CredentialsResponse zeroWeightCredentials, CredentialsResponse?realAmountCredentials = null, CredentialsResponse?realWeightCredentials = null)
 {
     ZeroAmountCredentials = zeroAmountCredentials;
     ZeroWeightCredentials = zeroWeightCredentials;
     RealAmountCredentials = realAmountCredentials;
     RealWeightCredentials = realWeightCredentials;
 }
예제 #5
0
 public PreparedCredentialsResponse(CredentialIssuer issuer, CredentialsResponse response, long delta, IEnumerable <GroupElement> serialNumbers)
 {
     _issuer        = issuer;
     _response      = response;
     _delta         = delta;
     _serialNumbers = serialNumbers;
     _committed     = false;
 }
예제 #6
0
        private CredentialsResponse Commit(CredentialsResponse response, long delta, IEnumerable <GroupElement> serialNumbers)
        {
            // Register the serial numbers to prevent credential reuse.
            foreach (var serialNumber in serialNumbers)
            {
                SerialNumbers.Add(serialNumber);
            }
            Balance += delta;

            return(response);
        }
예제 #7
0
        static ClientConfigData BuildClientConfigData(
            RepositorySpec repSpec,
            string projectPath,
            CredentialsResponse response)
        {
            SEIDWorkingMode workingMode = SEIDWorkingMode.LDAPWorkingMode;

            ClientConfigData configData = new ClientConfigData();

            configData.WorkspaceServer  = repSpec.Server;
            configData.CurrentWorkspace = projectPath;
            configData.WorkingMode      = workingMode.ToString();
            configData.SecurityConfig   = UserInfo.GetSecurityConfigStr(
                workingMode,
                response.Email,
                GetPassword(response.Token, response.Type));
            return(configData);
        }
예제 #8
0
            static ClientConfigData BuildClientConfigData(
                string serverName,
                string projectPath,
                CredentialsResponse response)
            {
                SEIDWorkingMode workingMode = GetWorkingMode(response.Type);

                ClientConfigData configData = new ClientConfigData();

                configData.WorkspaceServer  = serverName;
                configData.CurrentWorkspace = projectPath;
                configData.WorkingMode      = workingMode.ToString();
                configData.SecurityConfig   = UserInfo.GetSecurityConfigStr(
                    workingMode,
                    response.Email,
                    GetPassword(response.Token, response.Type));
                configData.LastRunningEdition = InstalledEdition.Get();
                return(configData);
            }
예제 #9
0
        internal CredentialsResponse GetCredentials(User user, string ambiente)
        {
            User resultUser = new User();
            CredentialsResponse response  = new CredentialsResponse();
            TPConnector         connector = InitializeConnector(ambiente);

            try
            {
                resultUser = connector.getCredentials(user);
                string[] securityD = resultUser.getApiKey().Split(' ');
                response.security   = securityD[1];
                response.success    = true;
                response.merchandid = resultUser.getMerchant();
                response.apikey     = resultUser.getApiKey();
            }
            catch (Exception ex)
            {
                response.success = false;
                response.message = ex.Message;
            }

            return(response);
        }
예제 #10
0
        public static void Main(string[] args)
        {
            OvhApiClient api = new OvhApiClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET", OvhInfra.Europe);

            CredentialsResponse response = api.RequestCredential(new[] {
                new AccessRule {
                    Method = "GET", Path = "/*"
                },
                new AccessRule {
                    Method = "PUT", Path = "/*"
                },
                new AccessRule {
                    Method = "POST", Path = "/*"
                },
                //new AccessRule{ Method = "DELETE", Path = "/*"},
            }).Result;

            api.ConsumerKey = "YOUR_CONSUMER_KEY";
            try {
                string[] billIds = api.GetMeBillNames(DateTime.Now.AddMonths(-5), DateTime.Now.AddMonths(-2)).Result;
                for (int i = 0; i < billIds.Length; i++)
                {
                    Bill    b = api.GetMeBill(billIds[i]).Result;
                    Payment p = api.GetMeBillPayment(billIds[i]).Result;

                    string[] billDetailIds = api.GetMeBillDetailNames(billIds[i]).Result;
                    for (int j = 0; j < billDetailIds.Length; j++)
                    {
                        BillDetail bd = api.GetMeBillDetails(b.BillId, billDetailIds[j]).Result;
                    }
                }

                long[] appIds = api.GetMeApiApplicationIds().Result;
                for (int i = 0; i < appIds.Length; i++)
                {
                    Application app = api.GetMeApiApplication(appIds[i]).Result;
                    Console.WriteLine(app.ApplicationKey);
                }

                long[] credsIds = api.GetMeApiCredentialIds().Result;
                for (int i = 0; i < credsIds.Length; i++)
                {
                    Application app  = api.GetMeApiCredentialApplication(credsIds[i]).Result;
                    Credential  cred = api.GetMeApiCredential(credsIds[i]).Result;
                    if (cred.Expiration < DateTime.Now)
                    {
                        api.DeleteMeApiCredential(credsIds[i]).Wait();
                    }
                }

                //var rfrf = api.CreateDomainRecord("daron.be",NamedResolutionFieldType.A,"10.0.0.1","test").Result;

//				long[] ids = api.GetDomainRecordIds("daron.be",NamedResolutionFieldType.A).Result;
//
//				foreach(long l in ids)
//				{
//					DomainRecordDetail detail = api.GetDomainRecord("daron.be",l).Result;
//					if(detail.SubDomain == "test")
//					{
//						DomainRecordDetail newRecord = api.UpdateDomainRecord("daron.be",detail.Id ,  "111.111.111.11","test").Result;
//
//						 api.DeleteDomainRecord("daron.be",l).Wait();
//					}
//				}
//
//				foreach(string server in api.GetDedicatedServers().Result) {
//					ServerInfos infos = api.GetDedicatedServerInfos(server).Result;
//					ServiceInfo sInfos = api.GetDedicatedServerServiceInfo(server).Result;
//					string[] ips = api.GetDedicatedServerIps(server).Result;
//					Mrtg[] mrtg = api.GetDedicatedServerMrtg(server, MrtgPeriod.Daily, MrtgType.TrafficUpload).Result;
//					mrtg = api.GetDedicatedServerMrtg(server, MrtgPeriod.Weekly, MrtgType.TrafficDownload).Result;
//					mrtg = api.GetDedicatedServerMrtg(server, MrtgPeriod.Monthly, MrtgType.ErrorsDownload).Result;
//					mrtg = api.GetDedicatedServerMrtg(server, MrtgPeriod.Yearly, MrtgType.ErrorsUpload).Result;
//					mrtg = api.GetDedicatedServerMrtg(server, MrtgPeriod.Hourly, MrtgType.PacketsDownload).Result;
//					mrtg = api.GetDedicatedServerMrtg(server, MrtgPeriod.Monthly, MrtgType.PacketsUpload).Result;
//				}
            } catch (AggregateException ex) {
                Console.WriteLine(ex.Message);
            }



            Console.ReadLine();
        }
예제 #11
0
        /// <summary>
        /// Process the <see cref="CredentialsRequest">credentials registration requests</see> and
        /// issues the credentials.
        /// </summary>
        /// <param name="registrationRequest">The request containing the credentials presentations, credential requests and the proofs.</param>
        /// <returns>The <see cref="CredentialsResponse">registration response</see> containing the requested credentials and the proofs.</returns>
        /// <exception cref="WabiSabiCryptoException">Error code: <see cref="WabiSabiCryptoErrorCode">WabiSabiErrorCode</see></exception>
        public CredentialsResponse HandleRequest(CredentialsRequest registrationRequest)
        {
            Guard.NotNull(nameof(registrationRequest), registrationRequest);

            var requested = registrationRequest.Requested ?? Enumerable.Empty <IssuanceRequest>();
            var presented = registrationRequest.Presented ?? Enumerable.Empty <CredentialPresentation>();

            var requestedCount = requested.Count();

            if (requestedCount != NumberOfCredentials)
            {
                throw new WabiSabiCryptoException(
                          WabiSabiCryptoErrorCode.InvalidNumberOfRequestedCredentials,
                          $"{NumberOfCredentials} credential requests were expected but {requestedCount} were received.");
            }

            var presentedCount = presented.Count();
            var requiredNumberOfPresentations = registrationRequest.IsNullRequest ? 0 : NumberOfCredentials;

            if (presentedCount != requiredNumberOfPresentations)
            {
                throw new WabiSabiCryptoException(
                          WabiSabiCryptoErrorCode.InvalidNumberOfPresentedCredentials,
                          $"{requiredNumberOfPresentations} credential presentations were expected but {presentedCount} were received.");
            }

            // Don't allow balance to go negative. In case this goes below zero
            // then there is a problem somewhere because this should not be possible.
            if (Balance + registrationRequest.Delta < 0)
            {
                throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.NegativeBalance);
            }

            // Check that the range proofs are of the appropriate bitwidth
            var rangeProofWidth = registrationRequest.IsNullRequest ? 0 : RangeProofWidth;
            var allRangeProofsAreCorrectSize = requested.All(x => x.BitCommitments.Count() == rangeProofWidth);

            if (!allRangeProofsAreCorrectSize)
            {
                throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.InvalidBitCommitment);
            }

            // Check all the serial numbers are unique. Note that this is checked separately from
            // ensuring that they haven't been used before, because even presenting a previously
            // unused credential more than once in the same request is still a double spend.
            if (registrationRequest.AreThereDuplicatedSerialNumbers)
            {
                throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.SerialNumberDuplicated);
            }

            var statements = new List <Statement>();

            foreach (var presentation in presented)
            {
                // Calculate Z using coordinator secret.
                var z = presentation.ComputeZ(CredentialIssuerSecretKey);

                // Add the credential presentation to the statements to be verified.
                statements.Add(ProofSystem.ShowCredentialStatement(presentation, z, CredentialIssuerParameters));

                // Check if the serial numbers have been used before. Note that
                // the serial numbers have not yet been verified at this point, but a
                // request with an invalid proof and a used serial number should also be
                // rejected.
                if (SerialNumbers.Contains(presentation.S))
                {
                    throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.SerialNumberAlreadyUsed, $"Serial number reused {presentation.S}");
                }
            }

            foreach (var credentialRequest in requested)
            {
                statements.Add(registrationRequest.IsNullRequest
                                        ? ProofSystem.ZeroProofStatement(credentialRequest.Ma)
                                        : ProofSystem.RangeProofStatement(credentialRequest.Ma, credentialRequest.BitCommitments, rangeProofWidth));
            }

            // Balance proof
            if (!registrationRequest.IsNullRequest)
            {
                var sumCa = presented.Select(x => x.Ca).Sum();
                var sumMa = requested.Select(x => x.Ma).Sum();

                // A positive Delta_a means the requested credential amounts are larger
                // than the presented ones (i.e. input registration, and a negative
                // balance correspond to output registration). The equation requires a
                // commitment to 0, so the sum of the presented attributes and the
                // negated requested attributes are tweaked by delta_a.
                var absAmountDelta = new Scalar((ulong)Math.Abs(registrationRequest.Delta));
                var deltaA         = registrationRequest.Delta < 0 ? absAmountDelta.Negate() : absAmountDelta;
                var balanceTweak   = deltaA * Generators.Gg;
                statements.Add(ProofSystem.BalanceProofStatement(balanceTweak + sumCa - sumMa));
            }

            var transcript = BuildTransnscript(registrationRequest.IsNullRequest);

            // Verify all statements.
            var areProofsValid = ProofSystem.Verify(transcript, statements, registrationRequest.Proofs);

            if (!areProofsValid)
            {
                throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.CoordinatorReceivedInvalidProofs);
            }

            // Issue credentials.
            var credentials = requested.Select(x => IssueCredential(x.Ma, RandomNumberGenerator.GetScalar())).ToArray();

            // Construct response.
            var proofs   = ProofSystem.Prove(transcript, credentials.Select(x => x.Knowledge), RandomNumberGenerator);
            var macs     = credentials.Select(x => x.Mac);
            var response = new CredentialsResponse(macs, proofs);

            // Register the serial numbers to prevent credential reuse.
            foreach (var presentation in presented)
            {
                SerialNumbers.Add(presentation.S);
            }
            Balance += registrationRequest.Delta;

            return(response);
        }
예제 #12
0
 public OutputRegistrationResponse(byte[] unsignedTransactionSecret, CredentialsResponse amountCredentials, CredentialsResponse weightCredentials)
 {
     UnsignedTransactionSecret = unsignedTransactionSecret;
     AmountCredentials         = amountCredentials;
     WeightCredentials         = weightCredentials;
 }
 public InputsRegistrationResponse(Guid aliceId, CredentialsResponse amountCredentials, CredentialsResponse weightCredentials)
 {
     AliceId           = aliceId;
     AmountCredentials = amountCredentials;
     WeightCredentials = weightCredentials;
 }
예제 #14
0
 public PhantomsForeverModule() : base("/phantomsforever")
 {
     Get("/OnlineConfigService.svc/GetOnlineConfig", args =>
     {
         return("[{\"Name\":\"SandboxUrl\",\"Values\":[\"prudp:\\/ address = lb - pdc - 81.165.113.171; port = 22700\"]}]");
     });
     Get("/Version/PDC-Live_Packages.txt", args =>
     {
         return("");
     });
     Get("/updater/UtcNow", args =>
     {
         return(DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"));
     });
     Get("/updater/GetValues/LauncherConfig@", args =>
     {
         var serializer = new JavaScriptSerializer();
         var config     = new List <Configuration>();
         config.Add(new Configuration()
         {
             Key   = "UtcNow",
             Value = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss")
         });
         config.Add(new Configuration()
         {
             Key   = "RequestStatus",
             Value = "OK"
         });
         return(serializer.Serialize(config));
     });
     Get("/updater/GetValues/LauncherConfig_DownloadType", args =>
     {
         return("");
     });
     Get("/updater/GetValues/eula_ubisoft", args =>
     {
         return("");
     });
     Get("/updater/GetValues/LauncherConfig_CanSeedInLobby", args =>
     {
         var serializer = new JavaScriptSerializer();
         var config     = new List <Configuration>();
         config.Add(new Configuration()
         {
             Key   = "LauncherConfig_CanSeedInLobby",
             Value = Convert.ToString(true)
         });
         config.Add(new Configuration()
         {
             Key   = "RequestStatus",
             Value = "OK"
         });
         return(serializer.Serialize(config));
     });
     Get("/LauncherWeb/main_*.html", args =>
     {
         return("");
     });
     Get("/redirect/uat.html", args =>
     {
         return("");
     });
     Post("loginservice/Login.svc/json/login", args =>
     {
         using (var sr = new StreamReader(this.Context.Request.Body))
         {
             var serializer = new JavaScriptSerializer();
             var response   = new CredentialsResponse()//TODO implement authentication
             {
                 Username = sr.ReadLine(),
                 Token    = new List <int>()
                 {
                     1, 1, 1, 1, 1, 1, 1
                 }
             };
             return(serializer.Serialize(response));
         }
     });
     Post("/grp-login/json/login", args =>
     {
         using (var sr = new StreamReader(this.Context.Request.Body))
         {
             var serializer = new JavaScriptSerializer();
             var response   = new CredentialsResponse()//TODO implement authentication
             {
                 Username = sr.ReadLine(),
                 Token    = new List <int>()
                 {
                     1, 1, 1, 1, 1, 1, 1
                 }
             };
             return(serializer.Serialize(response));
         }
     });
 }