Esempio n. 1
0
        public virtual String EncryptCredential(
            X509Certificate2 certificate, string domain, string username, string password, string administrativePassword)
        {
            var credential = new Credential() { Domain = domain, UserName = username, Password = password, AdministrativePassword = administrativePassword };

            var certificateInBytes = CryptoProviderProxy.EncryptCredential(credential, certificate);
            
            return System.Text.Encoding.Default.GetString(certificateInBytes);
        }
Esempio n. 2
0
        public ModSicService CreateModSicServiceToSendCollect(
            string fakeClientRequestID, string fakeServiceRequestID)
        {
            var fakeRequestInfo1 = new RequestInfo() { ClientRequestId = fakeClientRequestID, ServiceRequestId = fakeServiceRequestID };
            var fakeRequestInfo2 = new RequestInfo() { ClientRequestId = fakeServiceRequestID, ServiceRequestId = fakeClientRequestID };
            var fakeSendCollectResult = new SendRequestResult() { Requests = new RequestInfo[] { fakeRequestInfo1, fakeRequestInfo2 } };
            var fakeCertificate = new FileContentLoader().GetFileContentBytes(GetType().Assembly, "CollectService.pfx");
            var fakeCredentials = new Credential();
            var mocks = new MockRepository();
            
            var api = mocks.DynamicMock<ModSicConnection>(new string[] { "", "", "", "" });
            Expect.Call(
                api.SendCollect(FAKE_TARGET_ADDRESS, fakeCredentials, FAKE_OVAL_DEFINITIONS, null, null))
                       .IgnoreArguments()
                    .Return(fakeSendCollectResult);
            Expect.Call(
                api.GetCertificate())
                    .Return(fakeCertificate);
            mocks.ReplayAll();

            return new ModSicService(api);
        }
Esempio n. 3
0
 public virtual byte[] EncryptCredential(Credential credential, X509Certificate2 certificate)
 {
     return
         new CollectServiceCryptoProvider()
             .EncryptCredentialBasedOnCertificateOfServer(credential, certificate);
 }
Esempio n. 4
0
        private String EncryptCredentials(Credential credentials)
        {
            var certificateInBytes = this.GetCertificate();
            var encryptedBytes = 
                new CollectServiceCryptoProvider()
                    .EncryptCredentialBasedOnCertificateOfServer(
                        credentials, 
                        new X509Certificate2(certificateInBytes, this.CertificatePassword));

            return System.Text.Encoding.Default.GetString(encryptedBytes);
        }
Esempio n. 5
0
        private Request CreateRequest(string targetAddress, Credential credentials, string externalVariables, Dictionary<string, string> targetParameters = null)
        {
            var encrytedCredentials = this.EncryptCredentials(credentials);

            var newRequest = new Request()
            {
                Address = targetAddress,
                Credential = encrytedCredentials,
                DefinitionId = Guid.NewGuid().ToString(),
                ExternalVariables = externalVariables,
                RequestId = Guid.NewGuid().ToString(),
                TargetParameters = targetParameters
            };
            return newRequest;
        }
Esempio n. 6
0
 /// <summary>
 /// It requests a new collection to modSIC Server.
 /// </summary>
 /// <param name="targetAddress">The target IP address or hostname.</param>
 /// <param name="targetCredentials">The target encrypted and serialized credentials.</param>
 /// <param name="ovalDefinitions">The Oval Definitions document.</param>
 /// <param name="externalVariables">The optional Oval Variables document.</param>
 /// <returns><see cref="http://modsic.codeplex.com/wikipage?title=Contract&referringTitle=Documentation#sendRequestResult"/></returns>
 public virtual SendRequestResult SendCollect(
     string targetAddress, Credential targetCredentials, string ovalDefinitions, string externalVariables = null, Dictionary<string, string> targetParameters = null)
 {
     var newRequest = CreateRequest(targetAddress, targetCredentials, externalVariables, targetParameters);
     var package = CreatePackage(ovalDefinitions, newRequest);
     var token = LogonModSic();
     try
     {
         return ModSicProxyService.SendRequest(package, token);
     }
     finally
     {
         ModSicProxyService.Logout(token);
     }
 }
Esempio n. 7
0
        private String RequestCollectionSynchronous(string address, Credential credentials, string ovalDefinitions, out string collectRequestId, string externalVariables = null, Dictionary<string, string> targetParameters = null)
        {
            collectRequestId = null;

            var requestResult = modSicConnection.SendCollect(address, credentials, ovalDefinitions, externalVariables, targetParameters);
            if (requestResult.HasErrors)
            {
                view.ShowErrorMessage(requestResult.Message);
                return null;
            }

            collectRequestId = requestResult.Requests.First().ServiceRequestId;
            view.ShowCollectionIdMessage(collectRequestId);
            view.ShowCollectingDataMessage(address);

            while (true)
            {
                Sleep(10);

                var statusString = this.IsCollectionInExecution(collectRequestId);
                if (string.IsNullOrEmpty(statusString))
                {
                    view.ShowCollectionFinishedMessage();
                    view.ShowGetDocumentsMessage();
                    return modSicConnection.GetOvalResults(collectRequestId);
                }
            }
        }
Esempio n. 8
0
        public virtual String SendCollectSynchronous(
            string targetAddres,
            Credential credentials, 
            string ovalDefinitions,
            out string collectRequestID,
            int poolingIntervalInSecs = 30,
            string externalVariables = null,
            Dictionary<string, string> targetParameters = null)
        {
            var sendCollectResult =
                TryToRequestCollect(targetAddres, credentials, ovalDefinitions, externalVariables, targetParameters);

            collectRequestID = sendCollectResult.First().Value;

            Console.WriteLine("Collect was requested successfully.");
            Console.WriteLine("Request Collect ID generated by modSIC: {0}", collectRequestID);
            Console.WriteLine("Collecting data on {0}...", targetAddres);
            
            var progressThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.Progress));
            progressThread.Start();
            try
            {
                string lastReschedStr = "";
                while (true)
                {
                    if (poolingIntervalInSecs > 0)
                        System.Threading.Thread.Sleep(poolingIntervalInSecs * 1000);

                    var statusString = this.IsCollectInExecution(collectRequestID);
                    if (string.IsNullOrEmpty(statusString))
                    {
                        progressThread.Abort();
                        Console.WriteLine("The collect has finished.");
                        Console.WriteLine("Trying to get Oval Results...");
                        progressThread = new Thread(new ThreadStart(this.Progress));
                        progressThread.Start();
                        var retVal = _modSicConnection.GetOvalResults(collectRequestID);
                        progressThread.Abort();
                        //Console.Write("\b");
                        return retVal;
                    }

                    var reschedString = "(" + CollectRequestStatus.Open.ToString() + ") ";
                    var foundResched = statusString.IndexOf(reschedString);
                    if (foundResched >= 0)
                    {
                        statusString = statusString.Substring(foundResched + reschedString.Length);
                        if (statusString != lastReschedStr)
                        {
                            Console.WriteLine("Rescheduled. " + statusString);
                            lastReschedStr = statusString;
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(lastReschedStr))
                        {
                            Console.WriteLine("Collect resumed.");
                        }
                        lastReschedStr = "";
                    }
                }
            }
            finally
            {
                progressThread.Abort();
            }
        }
Esempio n. 9
0
 public virtual Dictionary<String, String> SendCollect(
     string targetAddres, Credential credentials, string ovalDefinitions, string externalVariables = null, Dictionary<string, string> targetParameters = null)
 {
     return TryToRequestCollect(targetAddres, credentials, ovalDefinitions, externalVariables, targetParameters);
 }
Esempio n. 10
0
        private Dictionary<String, String> TryToRequestCollect(
            string targetAddres, Credential credentials, string ovalDefinitions, string externalVariables = null, Dictionary<string, string> targetParameters = null)
        {
            SendRequestResult requestResult = null;
            try
            {
                requestResult = _modSicConnection.SendCollect(targetAddres, credentials, ovalDefinitions, externalVariables, targetParameters);
            }
            catch (Exception ex)
            {
                throw new ModSicCallingException(ex.Message);
            }

            if (requestResult.HasErrors)
                throw new ModSicCallingException(requestResult.Message);

            return requestResult.Requests.ToDictionary(r => r.ClientRequestId, r => r.ServiceRequestId);
        }
Esempio n. 11
0
        public void Should_be_possible_to_request_collect_sync()
        {
            var mockModSicApi = ModSicServiceMocker.CreateModSicServiceToSendCollectAndWaitItsCompletion();
            var collectRequestID = string.Empty;
            var fakeCredential = new Credential();
            var requestCollectResult =
                new ModSicService(mockModSicApi)
                    .SendCollectSynchronous(
                        FakeTargetAddress, fakeCredential, FakeDefinitions, out collectRequestID, 0, null, null);

            Assert.IsFalse(String.IsNullOrEmpty(requestCollectResult), "The result of send collect syncronous cannot be null.");
            mockModSicApi.AssertWasCalled(api => api.SendCollect(FakeTargetAddress, fakeCredential, FakeDefinitions, null, null));
            mockModSicApi.AssertWasCalled(api => api.GetCollectionsInExecution(), api => api.Repeat.Times(6));
            mockModSicApi.AssertWasCalled(api => api.GetOvalResults(ModSicServiceMocker.FAKE_COLLECT_REQUEST_ID));
            Assert.AreEqual(ModSicServiceMocker.FAKE_OVAL_RESULTS, requestCollectResult, "Unexpected Oval Results was returned.");
        }