public void Decorate_But_Not_Recreate_PushConfiguration() { // Arrange var smpResponse = new SmpConfiguration { Url = "http://some/url" }; var push = new PushConfiguration { TlsConfiguration = new TlsConfiguration { CertificateType = TlsCertificateChoiceType.PrivateKeyCertificate, ClientCertificateInformation = new ClientCertificateReference() } }; var fixture = new SendingProcessingMode { PushConfiguration = push }; // Act SendingProcessingMode result = ExerciseDecorate(fixture, smpResponse); // Assert Assert.Same(push, result.PushConfiguration); Assert.Equal(smpResponse.Url, push.Protocol.Url); Assert.Same( push.TlsConfiguration.ClientCertificateInformation, result.PushConfiguration.TlsConfiguration.ClientCertificateInformation); }
public void Decorate_Not_Recreate_CollaborationInfo() { // Arrange var smpResponse = new SmpConfiguration(); var collaboration = new CollaborationInfo { AgreementReference = new AgreementReference { Value = "http://eu.europe.org/agreements" } }; var fixture = new SendingProcessingMode { MessagePackaging = new SendMessagePackaging { CollaborationInfo = collaboration } }; // Act SendingProcessingMode result = ExerciseDecorate(fixture, smpResponse); // Assert Assert.Same(collaboration, result.MessagePackaging.CollaborationInfo); Assert.Equal( collaboration.AgreementReference.Value, result.MessagePackaging.CollaborationInfo.AgreementReference.Value); }
private static void OverrideEntireEncryption(SendingProcessingMode pmode, SmpConfiguration smpResponse) { Logger.Trace($"Override SendingPMode.Encryption with {{IsEnabled={smpResponse.EncryptionEnabled}}}"); Logger.Trace( "Override SendingPMode.Encryption with {{" + $"Algorithm={smpResponse.EncryptAlgorithm}, " + $"AlgorithmKeySize={smpResponse.EncryptAlgorithmKeySize}}}"); Logger.Trace("Override SendingPMode.Encryption with {{CertificateType=PublicKeyCertificate}}"); Logger.Trace( "Override SendingPMode.Encryption.KeyTransport Algorithms with {{" + $"Digest={smpResponse.EncryptKeyDigestAlgorithm}, " + $"Mgf={smpResponse.EncryptKeyMgfAlorithm}, " + $"Transport={smpResponse.EncryptKeyTransportAlgorithm}}}"); pmode.Security = pmode.Security ?? new Model.PMode.Security(); pmode.Security.Encryption = pmode.Security.Encryption ?? new Encryption(); pmode.Security.Encryption.IsEnabled = smpResponse.EncryptionEnabled; pmode.Security.Encryption.Algorithm = smpResponse.EncryptAlgorithm; pmode.Security.Encryption.AlgorithmKeySize = smpResponse.EncryptAlgorithmKeySize; pmode.Security.Encryption.CertificateType = PublicKeyCertificateChoiceType.PublicKeyCertificate; pmode.Security.Encryption.EncryptionCertificateInformation = new PublicKeyCertificate { Certificate = TryConvertToBase64String(smpResponse.EncryptPublicKeyCertificate) }; pmode.Security.Encryption.KeyTransport = pmode.Security.Encryption.KeyTransport ?? new KeyEncryption(); pmode.Security.Encryption.KeyTransport.DigestAlgorithm = smpResponse.EncryptKeyDigestAlgorithm; pmode.Security.Encryption.KeyTransport.MgfAlgorithm = smpResponse.EncryptKeyMgfAlorithm; pmode.Security.Encryption.KeyTransport.TransportAlgorithm = smpResponse.EncryptKeyTransportAlgorithm; }
private SmpConfiguration FindSmpResponseForToParty(Model.Core.Party party) { using (DatastoreContext context = _createDatastore()) { string primaryPartyType = party.PartyIds .FirstOrNothing() .SelectMany(x => x.Type) .GetOrElse(() => null); SmpConfiguration foundConfiguration = context.SmpConfigurations .FirstOrDefault( sc => sc.PartyRole == party.Role && sc.ToPartyId == party.PrimaryPartyId && sc.PartyType == primaryPartyType); if (foundConfiguration == null) { throw new ConfigurationErrorsException( "No SMP Response found for the given " + $"'Role': {party.Role}, 'PartyId': {party.PrimaryPartyId}, and 'PartyType': {primaryPartyType}"); } return(foundConfiguration); } }
private void InsertSmpResponse(SmpConfiguration smpConfiguration) { using (DatastoreContext context = GetDataStoreContext()) { context.SmpConfigurations.Add(smpConfiguration); context.SaveChanges(); } }
public void InsertSmpConfiguration(SmpConfiguration config) { using (var context = new DatastoreContext(_configuration)) { context.SmpConfigurations.Add(config); context.SaveChanges(); } }
private SendingProcessingMode ExerciseDecorate(SendingProcessingMode pmode, SmpConfiguration smpResponse) { var doc = new XmlDocument(); doc.LoadXml(AS4XmlSerializer.ToString(smpResponse)); var sut = new LocalDynamicDiscoveryProfile(GetDataStoreContext); return(sut.DecoratePModeWithSmpMetaData(pmode, doc).CompletedSendingPMode); }
private void InsertSmpConfiguration(SmpConfiguration smpConfig) { PollingAt(Path.GetFullPath(@".\database"), "*.db"); // Wait for migrations to complete on datastore Thread.Sleep(TimeSpan.FromSeconds(5)); var spy = new DatastoreSpy(AS4Component.GetConfiguration()); spy.InsertSmpConfiguration(smpConfig); }
private static void OverrideToParty(SendingProcessingMode pmode, SmpConfiguration smpResponse) { Logger.Trace( "Override SendingPMode.MessagingPackaging.ToParty with {{" + $"Role={smpResponse.PartyRole}, " + $"PartyId={smpResponse.ToPartyId}}}"); pmode.MessagePackaging = pmode.MessagePackaging ?? new SendMessagePackaging(); pmode.MessagePackaging.PartyInfo = pmode.MessagePackaging.PartyInfo ?? new PartyInfo(); pmode.MessagePackaging.PartyInfo.ToParty = new Party(smpResponse.PartyRole, new PartyId(smpResponse.ToPartyId)); }
public void Dont_Touch_Signing_During_Decoration() { // Arrange var smpResponse = new SmpConfiguration { EncryptionEnabled = true }; var fixture = new SendingProcessingMode { Security = { Signing = { IsEnabled = true } } }; // Act SendingProcessingMode result = ExerciseDecorate(fixture, smpResponse); // Assert Assert.Same(fixture.Security.Signing, result.Security.Signing); Assert.True(result.Security.Signing.IsEnabled); }
public void DecorateMandatoryInfoToSendingPMode() { // Arrange var smpResponse = new SmpConfiguration { PartyRole = "role", Url = "http://some/url" }; var doc = new XmlDocument(); doc.LoadXml(AS4XmlSerializer.ToString(smpResponse)); var pmode = new SendingProcessingMode(); var sut = new LocalDynamicDiscoveryProfile(GetDataStoreContext); // Act SendingProcessingMode actual = sut.DecoratePModeWithSmpMetaData(pmode, doc).CompletedSendingPMode; // Assert Assert.Equal(smpResponse.Url, actual.PushConfiguration.Protocol.Url); }
public async Task RetrieveSmpResponseFromDatastore() { // Arrange var fixture = new Party("role", new PartyId(Guid.NewGuid().ToString(), "type")); var expected = new SmpConfiguration { PartyRole = fixture.Role, ToPartyId = fixture.PrimaryPartyId, PartyType = "type" }; InsertSmpResponse(expected); var sut = new LocalDynamicDiscoveryProfile(GetDataStoreContext); // Act XmlDocument actualDoc = await sut.RetrieveSmpMetaDataAsync(fixture, properties : null); // Assert var actual = AS4XmlSerializer.FromString <SmpConfiguration>(actualDoc.OuterXml); Assert.Equal(expected.ToPartyId, actual.ToPartyId); }
/// <summary> /// Retrieves the SMP meta data <see cref="XmlDocument" /> for a given <paramref name="party" /> using a given /// <paramref name="properties" />. /// </summary> /// <param name="party">The party identifier to select the right SMP meta-data.</param> /// <param name="properties">The information properties specified in the <see cref="SendingProcessingMode"/> for this profile.</param> public Task <XmlDocument> RetrieveSmpMetaDataAsync(Model.Core.Party party, IDictionary <string, string> properties) { if (party == null) { throw new ArgumentNullException(nameof(party)); } if (party.PrimaryPartyId == null || party.PartyIds.FirstOrDefault()?.Type == null || party.Role == null) { throw new InvalidOperationException( "Given invalid 'ToParty', requires 'Role', 'PartyId', and 'PartyType'"); } SmpConfiguration configuration = FindSmpResponseForToParty(party); string xml = AS4XmlSerializer.ToString(configuration); var document = new XmlDocument(); document.LoadXml(xml); return(Task.FromResult(document)); }
private void InsertEnabledEncryptionForHolodeck(string url) { var smpConfig = new SmpConfiguration { TlsEnabled = false, EncryptionEnabled = true, PartyRole = HolodeckPartyRole, ToPartyId = "org:eu:europa:as4:example", PartyType = "org:eu:europa:as4:example", Url = url, Action = "StoreMessage", ServiceType = "org:holodeckb2b:services", ServiceValue = "Test", FinalRecipient = "org:eu:europa:as4:example", EncryptAlgorithm = Encryption.Default.Algorithm, EncryptPublicKeyCertificate = Properties.Resources.AccessPointB_PublicCert, EncryptAlgorithmKeySize = Encryption.Default.AlgorithmKeySize, EncryptKeyDigestAlgorithm = KeyEncryption.Default.DigestAlgorithm, EncryptKeyMgfAlorithm = KeyEncryption.Default.MgfAlgorithm, EncryptKeyTransportAlgorithm = KeyEncryption.Default.TransportAlgorithm }; InsertSmpConfiguration(smpConfig); }
private void InsertSmpConfigurationForAS4Component(string url, bool enableEncryption) { var smpConfig = new SmpConfiguration { TlsEnabled = false, EncryptionEnabled = enableEncryption, PartyRole = HolodeckPartyRole, ToPartyId = HolodeckBId, PartyType = HolodeckBId, Url = url, Action = Constants.Namespaces.TestAction, ServiceType = Constants.Namespaces.TestService, ServiceValue = Constants.Namespaces.TestService, FinalRecipient = HolodeckBId, EncryptAlgorithm = Encryption.Default.Algorithm, EncryptPublicKeyCertificate = Properties.Resources.AccessPointB_PublicCert, EncryptAlgorithmKeySize = Encryption.Default.AlgorithmKeySize, EncryptKeyDigestAlgorithm = KeyEncryption.Default.DigestAlgorithm, EncryptKeyMgfAlorithm = KeyEncryption.Default.MgfAlgorithm, EncryptKeyTransportAlgorithm = KeyEncryption.Default.TransportAlgorithm }; InsertSmpConfiguration(smpConfig); }
private static void AddFinalRecipientToMessageProperties(SendingProcessingMode pmode, SmpConfiguration smpResponse) { pmode.MessagePackaging = pmode.MessagePackaging ?? new SendMessagePackaging(); pmode.MessagePackaging.MessageProperties = pmode.MessagePackaging.MessageProperties ?? new List <MessageProperty>(); pmode.MessagePackaging.MessageProperties.Add( new MessageProperty { Name = "finalRecipient", Value = smpResponse.FinalRecipient }); }
private static void OverrideCollaborationServiceAction(SendingProcessingMode pmode, SmpConfiguration smpResponse) { Logger.Trace( "Override SendingPMode.MessagingPackaing.CollaborationInfo with {{" + $"ServiceType={smpResponse.ServiceType}, " + $"ServiceValue={smpResponse.ServiceValue}, " + $"Action={smpResponse.Action}}}"); pmode.MessagePackaging = pmode.MessagePackaging ?? new SendMessagePackaging(); pmode.MessagePackaging.CollaborationInfo = pmode.MessagePackaging.CollaborationInfo ?? new CollaborationInfo(); pmode.MessagePackaging.CollaborationInfo.Action = smpResponse.Action; pmode.MessagePackaging.CollaborationInfo.Service = new Service { Type = smpResponse.ServiceType, Value = smpResponse.ServiceValue }; }
private static void OverridePushProtocolUrlWithTlsEnabling(SendingProcessingMode pmode, SmpConfiguration smpResponse) { Logger.Debug($"Decorate SendingPMode {pmode.Id} with SMP from local store"); Logger.Trace( "Override SendingPMode.PushConfiguration with {{" + $"Protocol.Url={smpResponse.Url}, " + $"TlsConfiguration.IsEnabled={smpResponse.TlsEnabled}}}"); pmode.PushConfiguration = pmode.PushConfiguration ?? new PushConfiguration(); pmode.PushConfiguration.Protocol = pmode.PushConfiguration.Protocol ?? new Protocol(); pmode.PushConfiguration.Protocol.Url = smpResponse.Url; pmode.PushConfiguration.TlsConfiguration = pmode.PushConfiguration.TlsConfiguration ?? new TlsConfiguration(); pmode.PushConfiguration.TlsConfiguration.IsEnabled = smpResponse.TlsEnabled; }