Esempio n. 1
0
        public void Asynchronous_Receive_CertificateSignError()
        {
            Exception receiveException = null;

            Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new SignThenEncryptMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Client.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            Server = new MessagingServer(Settings, Logger, LoggerFactory, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new SignThenEncryptMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Server.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            CollaborationRegistry.SetupFindAgreementForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i}_ChangedSignedCertificate.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });

            RunAsynchronousReceive(
                postValidation: () => {
                Assert.IsTrue(_startingCalled);
                Assert.IsFalse(_receivedCalled);
                Assert.IsTrue(_completedCalled);
                var error = MockLoggerProvider.FindEntry(EventIds.RemoteCertificate);
                Assert.IsTrue(error.Message
                              .Contains($"{TestCertificates.HelsenorgePrivateSigntature.Thumbprint}"));
                Assert.IsTrue(error.Message
                              .Contains($"{TestCertificates.HelsenorgePrivateSigntature.NotBefore}"));
                var signingException = receiveException as CertificateException;
                Assert.IsNotNull(signingException);
                Assert.IsNotNull(signingException.Payload);
            },
                wait: () => _completedCalled,
                received: (m) => { },
                messageModification: (m) => { },
                handledException: ((m, e) =>
            {
                Server.Stop(TimeSpan.FromSeconds(10));
                _handledExceptionCalled = true;
                _completedCalled = true;
                receiveException = e;
            }),
                messageProtected: true);
        }
Esempio n. 2
0
        public CollaborationSession StartCollaboration()
        {
            Logger.Info("Starting collaboration");

            lock (_locker)
            {
                SessionRegistry sreg = GetSessions();
                try
                {
                    _theSession = sreg.getSession();
                    Logger.Info("Session retrieved: " + OrbServices.GetSingleton().object_to_string(_theSession));
                }
                catch (TargetInvocationException e)
                {
                    if (e.InnerException is SessionDoesNotExist)
                    {
                        Logger.Warn("Session not found for entity " + (e.InnerException as SessionDoesNotExist).entity);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("Error trying to obtain session: " + e);
                    throw;
                }

                if (_theSession == null)
                {
                    try
                    {
                        CollaborationRegistry collab = GetCollabs();
                        _theSession = collab.createCollaborationSession();
                        sreg.registerSession(_theSession);
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Error creating the session (it will be destroyed): " + e);
                        if (_theSession != null)
                        {
                            _theSession.destroy();
                        }
                        throw;
                    }
                }
                UpdateActivation();
            }
            return(_theSession);
        }
Esempio n. 3
0
 public void ExitCollaboration()
 {
     lock (_locker)
     {
         try
         {
             DeactivateConsumer();
             DeactivateObserver();
             Logger.Info("Collaboration finished");
         }
         finally
         {
             _subsId     = 0;
             _obsId      = 0;
             _theSession = null;
             _consumer   = null;
             _observer   = null;
             _collabs    = null;
             _sessions   = null;
         }
     }
 }
Esempio n. 4
0
        private CollaborationRegistry GetCollabs()
        {
            bool find = _collabs == null;

            if (!find)
            {
                try
                {
                    find = !_context.ORB.non_existent(_collabs);
                }
                catch (Exception)
                {
                    find = true;
                }
            }
            if (find)
            {
                ServiceProperty[] serviceProperties = new ServiceProperty[1];
                string            collabsRegType    = Repository.GetRepositoryID(typeof(CollaborationRegistry));
                serviceProperties[0] =
                    new ServiceProperty("openbus.component.interface", collabsRegType);
                ServiceOfferDesc[] services = _context.OfferRegistry.findServices(serviceProperties);

                foreach (ServiceOfferDesc offerDesc in services)
                {
                    try
                    {
                        MarshalByRefObject obj =
                            offerDesc.service_ref.getFacet(collabsRegType);
                        if (obj == null)
                        {
                            continue;
                        }
                        _collabs = obj as CollaborationRegistry;
                        if (_collabs != null)
                        {
                            break; // found one
                        }
                    }
                    catch (Exception e)
                    {
                        NO_PERMISSION npe = null;
                        if (e is TargetInvocationException)
                        {
                            npe = e.InnerException as NO_PERMISSION;
                        }
                        // caso não seja uma NO_PERMISSION{NoLogin} descarta essa oferta.
                        if ((npe == null) && (!(e is NO_PERMISSION)))
                        {
                            continue;
                        }
                        npe = npe ?? e as NO_PERMISSION;
                        switch (npe.Minor)
                        {
                        case NoLoginCode.ConstVal:
                            throw;
                        }
                    }
                }
            }
            return(_collabs);
        }