Exemplo n.º 1
0
        private void Apply(TerminalPolicyVersionCreated @event)
        {
            var versionPeriod = ValidityPeriod.Between(@event.VersionFrom, @event.VersionTo);

            var draft = new PolicyVersion
                        (
                @event.VersionNumber,
                PolicyStatus.Terminated,
                PolicyVersionStatus.Draft,
                ValidityPeriod.Between(@event.CoverFrom, @event.CoverTo),
                versionPeriod,
                @event.Covers
                .Select(c =>
                        new PolicyCover
                        (
                            c.Code,
                            ValidityPeriod.Between(c.CoverFrom, c.CoverTo),
                            new UnitPrice(c.Price, c.PriceUnit)
                        )
                        )
                .ToList()
                        );

            versions.Add(draft);
        }
Exemplo n.º 2
0
 public InitialPolicyVersionCreated(
     string policyNumber,
     string productCode,
     ValidityPeriod coverPeriod,
     DateTime purchaseDate,
     Person policyHolder,
     Car car,
     IEnumerable <PolicyCover> covers)
 {
     PolicyNumber = policyNumber;
     PolicyStatus = PolicyStatus.Active;
     ProductCode  = productCode;
     CoverFrom    = coverPeriod.ValidFrom;
     CoverTo      = coverPeriod.ValidTo;
     PurchaseDate = purchaseDate;
     PolicyHolder = new PersonData(policyHolder.FirstName, policyHolder.LastName, policyHolder.TaxId);
     Car          = new CarData(car.Make, car.PlateNumber, car.ProductionYear);
     Covers       = covers
                    .Select(c => new PolicyCoverData
                            (
                                c.CoverCode,
                                c.CoverPeriod.ValidFrom,
                                c.CoverPeriod.ValidTo,
                                c.Amount,
                                c.Price.Price,
                                c.Price.PricePeriod
                            )
                            )
                    .ToList();
 }
Exemplo n.º 3
0
            public override IDeepCopyable CopyTo(IDeepCopyable other)
            {
                var dest = other as MedicationOrderDispenseRequestComponent;

                if (dest != null)
                {
                    base.CopyTo(dest);
                    if (Medication != null)
                    {
                        dest.Medication = (Hl7.Fhir.Model.Element)Medication.DeepCopy();
                    }
                    if (ValidityPeriod != null)
                    {
                        dest.ValidityPeriod = (Hl7.Fhir.Model.Period)ValidityPeriod.DeepCopy();
                    }
                    if (NumberOfRepeatsAllowedElement != null)
                    {
                        dest.NumberOfRepeatsAllowedElement = (Hl7.Fhir.Model.PositiveInt)NumberOfRepeatsAllowedElement.DeepCopy();
                    }
                    if (Quantity != null)
                    {
                        dest.Quantity = (Hl7.Fhir.Model.SimpleQuantity)Quantity.DeepCopy();
                    }
                    if (ExpectedSupplyDuration != null)
                    {
                        dest.ExpectedSupplyDuration = (Hl7.Fhir.Model.Duration)ExpectedSupplyDuration.DeepCopy();
                    }
                    return(dest);
                }
                else
                {
                    throw new ArgumentException("Can only copy to an object of the same type", "other");
                }
            }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        protected virtual void loadProfile(XDocument profile)
        {
            XElement baseInfo = profile.Element("OSCA").Element("Profile");

            // Extract the base information
            Name                = baseInfo.Element("name").Value;
            Description         = baseInfo.Element("description").Value;
            Version             = baseInfo.Element("version").Value;
            CertificateLifetime = new ValidityPeriod(baseInfo.Element("lifetime"));

            if (baseInfo.Element("renewOverlap") != null)
            {
                RenewOverlapPeriod = new ValidityPeriod(baseInfo.Element("renewOverlap"));
            }
            else
            {
                RenewOverlapPeriod = new ValidityPeriod(ValidityPeriod.Unit.Hours, 0);
            }

            // Populate the list of Extensions
            IEnumerable <XElement> exts = baseInfo.Element("Extensions").Elements("Extension");

            foreach (XElement ext in exts)
            {
                extensions.Add(ProfileExtensionFactory.GetExtension(ext));
            }
        }
        private X509Certificate2 NewDeviceChainedCertificate(
            DistinguishedName distinguishedName,
            ValidityPeriod validityPeriod,
            string dnsName,
            OidCollection enhancedKeyUsages,
            X509Certificate2 parentCertificateAuthority)
        {
            BasicConstraints basicConstraints = new BasicConstraints()
            {
                CertificateAuthority    = false,
                HasPathLengthConstraint = false,
                PathLengthConstraint    = 0,
                Critical = true
            };
            SubjectAlternativeName subjectAlternativeName = new SubjectAlternativeName()
            {
                DnsName = new List <string>()
                {
                    dnsName
                }
            };
            X509KeyUsageFlags x509KeyUsageFlags = X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature;

            return(this._createCertificates.NewRsaChainedCertificate(distinguishedName, basicConstraints, validityPeriod, subjectAlternativeName, parentCertificateAuthority, enhancedKeyUsages, x509KeyUsageFlags, new RsaConfiguration()));
        }
Exemplo n.º 6
0
        public X509Certificate2 NewRsaSelfSignedCertificate(
            DistinguishedName distinguishedName,
            BasicConstraints basicConstraints,
            ValidityPeriod validityPeriod,
            SubjectAlternativeName subjectAlternativeName,
            OidCollection enhancedKeyUsages,
            X509KeyUsageFlags x509KeyUsageFlags,
            RsaConfiguration rsaConfiguration)
        {
            using var rsa = RSA.Create(rsaConfiguration.KeySize); // 1024, 2048 or 4096
            var request = new CertificateRequest(
                _certificateUtility.CreateIssuerOrSubject(distinguishedName),
                rsa,
                rsaConfiguration.HashAlgorithmName,
                rsaConfiguration.RSASignaturePadding);

            X509Certificate2 generatedCertificate = SelfSignedConfiguration(
                basicConstraints,
                validityPeriod,
                subjectAlternativeName,
                enhancedKeyUsages,
                x509KeyUsageFlags,
                request);

            return(generatedCertificate);
        }
            public override ErrorList Validate()
            {
                var result = new ErrorList();

                result.AddRange(base.Validate());

                if (Medication != null)
                {
                    result.AddRange(Medication.Validate());
                }
                if (ValidityPeriod != null)
                {
                    result.AddRange(ValidityPeriod.Validate());
                }
                if (NumberOfRepeatsAllowedElement != null)
                {
                    result.AddRange(NumberOfRepeatsAllowedElement.Validate());
                }
                if (Quantity != null)
                {
                    result.AddRange(Quantity.Validate());
                }
                if (ExpectedSupplyDuration != null)
                {
                    result.AddRange(ExpectedSupplyDuration.Validate());
                }

                return(result);
            }
Exemplo n.º 8
0
        /// <summary>
        /// Create a Self signed certificate with all options which can also be used as a root certificate
        /// </summary>
        /// <param name="distinguishedName">Distinguished Name used for the subject and the issuer properties</param>
        /// <param name="validityPeriod">Valid from, Valid to certificate properties</param>
        /// <param name="subjectAlternativeName">SAN but only DnsNames can be added as a list + Email property</param>
        /// <param name="enhancedKeyUsages">Defines how the certificate key can be used.
        ///  new Oid("1.3.6.1.5.5.7.3.1")  // TLS Server auth
        ///  new Oid("1.3.6.1.5.5.7.3.2")  // TLS Client auth
        ///  new Oid("1.3.6.1.5.5.7.3.3")  // Code signing
        ///  new Oid("1.3.6.1.5.5.7.3.4")  // Email
        ///  new Oid("1.3.6.1.5.5.7.3.8")  // Timestamping
        /// </param>
        /// <param name="x509KeyUsageFlags">Defines how the certificate key can be used.
        ///  None             No key usage parameters.
        ///  EncipherOnly     The key can be used for encryption only.
        ///  CrlSign          The key can be used to sign a certificate revocation list (CRL).
        ///  KeyCertSign      The key can be used to sign certificates.
        ///  KeyAgreement     The key can be used to determine key agreement, such as a key created using the Diffie-Hellman key agreement algorithm.
        ///  DataEncipherment The key can be used for data encryption.
        ///  KeyEncipherment  The key can be used for key encryption.
        ///  NonRepudiation   The key can be used for authentication.
        ///  DecipherOnly     The key can be used for decryption only.
        ///  </param>
        /// <returns>Self signed certificate</returns>
        public X509Certificate2 NewECDsaSelfSignedCertificate(
            DistinguishedName distinguishedName,
            BasicConstraints basicConstraints,
            ValidityPeriod validityPeriod,
            SubjectAlternativeName subjectAlternativeName,
            OidCollection enhancedKeyUsages,
            X509KeyUsageFlags x509KeyUsageFlags,
            ECDsaConfiguration eCDsaConfiguration)
        {
            using var ecdsa = ECDsa.Create("ECDsa");
            ecdsa.KeySize   = eCDsaConfiguration.KeySize;
            var request = new CertificateRequest(
                _certificateUtility.CreateIssuerOrSubject(distinguishedName),
                ecdsa,
                eCDsaConfiguration.HashAlgorithmName);

            X509Certificate2 generatedCertificate = SelfSignedConfiguration(
                basicConstraints,
                validityPeriod,
                subjectAlternativeName,
                enhancedKeyUsages,
                x509KeyUsageFlags,
                request);

            return(generatedCertificate);
        }
        public X509Certificate2 NewIntermediateChainedCertificate(
            DistinguishedName distinguishedName,
            ValidityPeriod validityPeriod,
            int pathLengthConstraint,
            string dnsName,
            X509Certificate2 parentCertificateAuthority)
        {
            OidCollection enhancedKeyUsages = new OidCollection()
            {
                new Oid("1.3.6.1.5.5.7.3.2"),
                new Oid("1.3.6.1.5.5.7.3.1")
            };
            BasicConstraints basicConstraints = new BasicConstraints()
            {
                CertificateAuthority    = true,
                HasPathLengthConstraint = true,
                PathLengthConstraint    = pathLengthConstraint,
                Critical = true
            };
            SubjectAlternativeName subjectAlternativeName = new SubjectAlternativeName()
            {
                DnsName = new List <string>()
                {
                    dnsName
                }
            };
            X509KeyUsageFlags x509KeyUsageFlags = X509KeyUsageFlags.KeyCertSign;

            return(this._createCertificates.NewRsaChainedCertificate(distinguishedName, basicConstraints, validityPeriod, subjectAlternativeName, parentCertificateAuthority, enhancedKeyUsages, x509KeyUsageFlags, new RsaConfiguration()));
        }
        public X509Certificate2 NewClientSelfSignedCertificate(
            DistinguishedName distinguishedName,
            ValidityPeriod validityPeriod,
            string dnsName)
        {
            OidCollection enhancedKeyUsages = new OidCollection()
            {
                new Oid("1.3.6.1.5.5.7.3.2")
            };
            BasicConstraints basicConstraints = new BasicConstraints()
            {
                CertificateAuthority    = false,
                HasPathLengthConstraint = false,
                PathLengthConstraint    = 0,
                Critical = true
            };
            SubjectAlternativeName subjectAlternativeName = new SubjectAlternativeName()
            {
                DnsName = new List <string>()
                {
                    dnsName
                }
            };
            X509KeyUsageFlags x509KeyUsageFlags = X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature;

            return(this._createCertificates.NewECDsaSelfSignedCertificate(distinguishedName, basicConstraints, validityPeriod, subjectAlternativeName, enhancedKeyUsages, x509KeyUsageFlags, new ECDsaConfiguration()));
        }
Exemplo n.º 11
0
 public PolicyCover(string coverCode, ValidityPeriod coverPeriod, UnitPrice price)
 {
     CoverCode   = coverCode;
     CoverPeriod = coverPeriod;
     Price       = price;
     Amount      = CalculateAmount();
 }
Exemplo n.º 12
0
 public static DateTime AddValidityPeriod(
     this DateTime date,
     ValidityPeriod validityPeriod) => date
 .AddDays(validityPeriod.Days)
 .AddMonths(validityPeriod.Months)
 .AddYears(validityPeriod.Years)
 .AddDays(-1);
Exemplo n.º 13
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var to                  = To.Get(context);
            var from                = From.Get(context);
            var body                = Body.Get(context);
            var mediaurls           = MediaUrls.Get(context);
            var accountsid          = AccountSid.Get(context);
            var messagingservicesid = MessagingServiceSid.Get(context);
            var applicationsid      = ApplicationSid.Get(context);
            var statuscallback      = StatusCallback.Get(context);
            var providefeedback     = ProvideFeedback.Get(context);
            var maxprice            = MaxPrice.Get(context);
            var validityperiod      = ValidityPeriod.Get(context);
            var smartencoded        = SmartEncoded.Get(context);

            var message = await MessageWrappers.SendMessageAsync(objectContainer.Get <ITwilioRestClient>(), from, to, body, mediaurls, maxprice, validityperiod, smartencoded, accountsid, applicationsid, messagingservicesid, providefeedback, statuscallback);

            // Outputs
            return((ctx) => {
                Message.Set(ctx, message);
            });
        }
        /// <summary>
        /// Create a Self signed certificate with all options which can also be used as a root certificate
        /// </summary>
        /// <param name="distinguishedName">Distinguished Name used for the subject and the issuer properties</param>
        /// <param name="validityPeriod">Valid from, Valid to certificate properties</param>
        /// <param name="subjectAlternativeName">SAN but only DnsNames can be added as a list + Email property</param>
        /// <param name="enhancedKeyUsages">Defines how the certificate key can be used.
        ///  new Oid("1.3.6.1.5.5.7.3.1")  // TLS Server auth
        ///  new Oid("1.3.6.1.5.5.7.3.2")  // TLS Client auth
        ///  new Oid("1.3.6.1.5.5.7.3.3")  // Code signing
        ///  new Oid("1.3.6.1.5.5.7.3.4")  // Email
        ///  new Oid("1.3.6.1.5.5.7.3.8")  // Timestamping
        /// </param>
        /// <param name="x509KeyUsageFlags">Defines how the certificate key can be used.
        ///  None             No key usage parameters.
        ///  EncipherOnly     The key can be used for encryption only.
        ///  CrlSign          The key can be used to sign a certificate revocation list (CRL).
        ///  KeyCertSign      The key can be used to sign certificates.
        ///  KeyAgreement     The key can be used to determine key agreement, such as a key created using the Diffie-Hellman key agreement algorithm.
        ///  DataEncipherment The key can be used for data encryption.
        ///  KeyEncipherment  The key can be used for key encryption.
        ///  NonRepudiation   The key can be used for authentication.
        ///  DecipherOnly     The key can be used for decryption only.
        ///  </param>
        /// <returns>Self signed certificate</returns>
        public X509Certificate2 NewSelfSignedCertificate(
            DistinguishedName distinguishedName,
            BasicConstraints basicConstraints,
            ValidityPeriod validityPeriod,
            SubjectAlternativeName subjectAlternativeName,
            OidCollection enhancedKeyUsages,
            X509KeyUsageFlags x509KeyUsageFlags)
        {
            using var ecdsa = ECDsa.Create("ECDsa");

            ecdsa.KeySize = 256;
            var request = new CertificateRequest(
                _certificateUtility.CreateIssuerOrSubject(distinguishedName),
                ecdsa,
                HashAlgorithmName.SHA256);

            _certificateUtility.AddBasicConstraints(request, basicConstraints);
            _certificateUtility.AddExtendedKeyUsages(request, x509KeyUsageFlags);
            _certificateUtility.AddSubjectAlternativeName(request, subjectAlternativeName);

            request.CertificateExtensions.Add(
                new X509EnhancedKeyUsageExtension(enhancedKeyUsages, false));

            request.CertificateExtensions.Add(
                new X509SubjectKeyIdentifierExtension(request.PublicKey, false));

            var notbefore = validityPeriod.ValidFrom.AddDays(-1);
            var notafter  = validityPeriod.ValidTo;
            X509Certificate2 generatedCertificate = request.CreateSelfSigned(notbefore, notafter);

            return(generatedCertificate);
        }
Exemplo n.º 15
0
        public void ExtendCoverage(DateTime effectiveDateOfChange, CoverPrice newCover)
        {
            if (Terminated())
            {
                throw new ApplicationException("Cannot annex terminated policy");
            }

            var versionAtDate = versions.EffectiveAt(effectiveDateOfChange);

            if (versionAtDate == null || !versionAtDate.CoversDate(effectiveDateOfChange))
            {
                throw new ApplicationException("Policy does not cover annex date");
            }

            if (versionAtDate.ContainsCover(newCover.CoverCode))
            {
                throw new ApplicationException("This cover is already present");
            }

            var newVersionNumber = versions.Count + 1;
            var versionPeriod    = ValidityPeriod.Between(effectiveDateOfChange, versionAtDate.CoverPeriod.ValidTo);
            var newCoverage      = PolicyCover.ForPrice(newCover, versionPeriod);

            ApplyChange
            (
                new CoverageExtendedPolicyVersionCreated
                (
                    newVersionNumber,
                    versionAtDate.VersionNumber,
                    versionPeriod,
                    newCoverage
                )
            );
        }
Exemplo n.º 16
0
 public static PolicyCover ForPrice(CoverPrice coverPrice, ValidityPeriod coverPeriod)
 {
     return(new PolicyCover
            (
                coverPrice.CoverCode,
                coverPeriod,
                new UnitPrice(coverPrice.Price, coverPrice.CoverPeriod)
            ));
 }
 public PolicyVersion CreateDraftCopy(int newVersionNumber, ValidityPeriod versionPeriod)
 {
     return(new PolicyVersion
            (
                newVersionNumber,
                PolicyStatus.Active,
                PolicyVersionStatus.Draft,
                CoverPeriod,
                versionPeriod,
                new List <PolicyCover>(covers)
            ));
 }
        public X509Certificate2 NewServerChainedCertificate(
            DistinguishedName distinguishedName,
            ValidityPeriod validityPeriod,
            string dnsName,
            X509Certificate2 parentCertificateAuthority)
        {
            OidCollection enhancedKeyUsages = new OidCollection()
            {
                new Oid("1.3.6.1.5.5.7.3.1")
            };

            return(this.NewDeviceChainedCertificate(distinguishedName, validityPeriod, dnsName, enhancedKeyUsages, parentCertificateAuthority));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Create an client chained certificate for Client and Server TLS Auth
        /// </summary>
        /// <param name="distinguishedName">Distinguished Name used for the subject and the issuer properties</param>
        /// <param name="validityPeriod">Valid from, Valid to certificate properties</param>
        /// <param name="dnsName">Dns name use the certificate validation</param>
        /// <param name="parentCertificateAuthority"> Parent cert to create the chain from</param>
        /// <returns>X509Certificate2 client chained certificate</returns>
        public X509Certificate2 NewServerChainedCertificate(
            DistinguishedName distinguishedName,
            ValidityPeriod validityPeriod,
            string dnsName,
            X509Certificate2 parentCertificateAuthority)
        {
            var enhancedKeyUsages = new OidCollection {
                OidLookup.ServerAuthentication
            };

            return(NewDeviceChainedCertificate(distinguishedName,
                                               validityPeriod, dnsName, enhancedKeyUsages, parentCertificateAuthority));
        }
        /// <summary>
        /// Create an server chained certificate for Client and Server TLS Auth
        /// </summary>
        /// <param name="distinguishedName">Distinguished Name used for the subject and the issuer properties</param>
        /// <param name="validityPeriod">Valid from, Valid to certificate properties</param>
        /// <param name="dnsName">Dns name use the certificate validation</param>
        /// <param name="parentCertificateAuthority"> Parent cert to create the chain from</param>
        /// <returns>X509Certificate2 server chained certificate</returns>
        public X509Certificate2 NewClientChainedCertificate(
           DistinguishedName distinguishedName,
           ValidityPeriod validityPeriod,
           string dnsName,
           X509Certificate2 parentCertificateAuthority)
        {
            var enhancedKeyUsages = new OidCollection {
                new Oid("1.3.6.1.5.5.7.3.2"), // TLS Client auth
            };

            return NewDeviceChainedCertificate(distinguishedName,
                validityPeriod, dnsName, enhancedKeyUsages, parentCertificateAuthority);
        }
        public void AddCover(string coverCode, UnitPrice price, ValidityPeriod coverPeriod)
        {
            if (VersionStatus != PolicyVersionStatus.Draft)
            {
                throw new ApplicationException("Cannot modify non draft version");
            }

            //check if not already present??

            //TODO: check dates

            this.covers.Add(new PolicyCover(coverCode, coverPeriod, price));
        }
Exemplo n.º 22
0
        private void Apply(CoverageExtendedPolicyVersionCreated @event)
        {
            var versionPeriod = ValidityPeriod.Between(@event.VersionFrom, @event.VersionTo);
            var draft         = versions.WithNumber(@event.BaseVersionNumber)
                                .CreateDraftCopy(@event.VersionNumber, versionPeriod);

            draft.AddCover
            (
                @event.NewCover.Code,
                new UnitPrice(@event.NewCover.Price, @event.NewCover.PriceUnit),
                ValidityPeriod.Between(@event.NewCover.CoverFrom, @event.NewCover.CoverTo)
            );
            versions.Add(draft);
        }
Exemplo n.º 23
0
 public CoverageExtendedPolicyVersionCreated
 (
     int versionNumber,
     int baseVersionNumber,
     ValidityPeriod versionPeriod,
     PolicyCoverData newCover
 )
 {
     VersionNumber     = versionNumber;
     BaseVersionNumber = baseVersionNumber;
     VersionFrom       = versionPeriod.ValidFrom;
     VersionTo         = versionPeriod.ValidTo;
     NewCover          = newCover;
 }
 public PolicyVersion(
     int versionNumber,
     PolicyStatus policyStatus,
     PolicyVersionStatus versionStatus,
     ValidityPeriod coverPeriod,
     ValidityPeriod versionPeriod,
     IEnumerable <PolicyCover> policyCovers)
 {
     VersionNumber = versionNumber;
     PolicyStatus  = policyStatus;
     VersionStatus = versionStatus;
     CoverPeriod   = coverPeriod;
     VersionPeriod = versionPeriod;
     covers.AddRange(policyCovers);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Issue a certificate based on a PKCS#10 certificate request and validity period
        /// </summary>
        /// <param name="Request">DER encoded PKCS#10 certificate request</param>
        /// <param name="Validity">Validity period for certificate</param>
        /// <returns>Requested certificate</returns>
        /// <exception cref="ArgumentException">Invalid signature algorithm in request</exception>
        public X509Certificate IssueCertificate(byte[] Request, ValidityPeriod Validity)
        {
            Pkcs10CertificationRequest p10;

            try
            {
                p10 = new Pkcs10CertificationRequest(Request);
            }
            catch (Exception ex)
            {
                logEvent(LogEvent.EventType.Error, "Certificate issue fail: " + ex.Message);
                throw new Exception("Certificate issue failed", ex);
            }
            return(IssueCertificate(p10, Validity));
        }
        /// <summary>
        /// Create an device chained certificate for Client and Server TLS Auth using RSA algorithm
        ///
        /// The device certificate (also called a leaf certificate) must have the Subject Name set to the Device ID that was used when registering the IoT device in the Azure IoT Hub. This setting is required for authentication.
        /// </summary>
        /// <param name="distinguishedName">Distinguished Name used for the subject and the issuer properties</param>
        /// <param name="validityPeriod">Valid from, Valid to certificate properties</param>
        /// <param name="dnsName">Dns name use the certificate validation</param>
        /// <param name="parentCertificateAuthority"> Parent cert to create the chain from</param>
        /// <returns>X509Certificate2 device chained certificate</returns>
        public X509Certificate2 NewRsaDeviceChainedCertificate(
            DistinguishedName distinguishedName,
            ValidityPeriod validityPeriod,
            string dnsName,
            X509Certificate2 parentCertificateAuthority,
            RsaConfiguration rsaConfiguration = null)
        {
            var enhancedKeyUsages = new OidCollection {
                OidLookup.ClientAuthentication,
                OidLookup.ServerAuthentication
            };

            return(NewRsaDeviceChainedCertificate(distinguishedName,
                                                  validityPeriod, dnsName, enhancedKeyUsages, parentCertificateAuthority,
                                                  rsaConfiguration));
        }
Exemplo n.º 27
0
        private Policy(Guid policyId, Offer.Offer offer, DateTime purchaseDate, DateTime policyStartDate)
        {
            if (offer.Converted())
            {
                throw new ApplicationException("Offer already converted");
            }

            if (offer.Rejected())
            {
                throw new ApplicationException("Offer already rejected");
            }

            if (offer.Expired(purchaseDate))
            {
                throw new ApplicationException("Offer expired");
            }


            if (offer.Expired(policyStartDate))
            {
                throw new ApplicationException("Offer not valid at policy start date");
            }

            var policyNumber = Guid.NewGuid().ToString();
            var coverPeriod  = ValidityPeriod.Between
                               (
                policyStartDate,
                policyStartDate.Add(offer.CoverPeriod)
                               );
            var covers = offer.Covers
                         .Select(c => PolicyCover.ForPrice(c, coverPeriod))
                         .ToList();

            Id = policyId;
            ApplyChange(
                new InitialPolicyVersionCreated
                (
                    policyNumber,
                    offer.ProductCode,
                    coverPeriod,
                    purchaseDate,
                    offer.Customer,
                    offer.Car,
                    covers
                )
                );
        }
Exemplo n.º 28
0
        private void butSubmit_Click(object sender, EventArgs e)
        {
            // Get the profile
            string profileFile;

            if (cbProfile.Checked)
            {
                if (lbProfiles.Text == "none")
                {
                    MessageBox.Show("Profile not selected", "OSCA - Issue Certificate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                profileFile = caInfo.Profiles[lbProfiles.SelectedIndex - 1].file;

                // Issue cert
                try
                {
                    cert = caInfo.IssueCertificate(parser.Request, new Profile(profileFile));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("There was a problem: " + ex.Message, "OSCA - Issue Certificate", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    butCancel_Click(null, null);
                }
            }
            else
            {
                profileFile = null;
                if ((tbValidPeriod.Text == "") || (Convert.ToInt32(tbValidPeriod.Text) < 1))
                {
                    MessageBox.Show("Invalid certificate validity period", "OSCA - Issue Certificate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                ValidityPeriod validity = new ValidityPeriod(lbValidUnits.Text, Convert.ToInt32(tbValidPeriod.Text));

                //Issue cert
                try
                {
                    cert = caInfo.IssueCertificate(parser.Request, validity);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("There was a problem: " + ex.Message, "OSCA - Issue Certificate", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    butCancel_Click(null, null);
                }
            }
        }
Exemplo n.º 29
0
        public void CanExtendCoverageWithMiddleDayOfPolicy()
        {
            var product = ProductsTestData.StandardCarInsurance();
            var policy  = PolicyTestData.StandardOneYearPolicy(new DateTime(2019, 1, 1));

            var newCover = product.CoverWithCode("AC");

            policy.ExtendCoverage
            (
                new DateTime(2019, 7, 1),
                new CoverPrice(Guid.NewGuid(), newCover, Money.Euro(100), TimeSpan.FromDays(365))
            );

            var resultingEvents = policy.GetUncommittedChanges();

            //assert state
            policy
            .Should()
            .HaveVersions(2);

            policy.Versions.WithNumber(1).Should()
            .BeActive()
            .HaveActivePolicyStatus()
            .HaveTotalPremiumEqualTo(Money.Euro(500));

            policy.Versions.WithNumber(2)
            .Should()
            .BeDraft()
            .HaveActivePolicyStatus()
            .CoverPeriod(new DateTime(2019, 1, 1), new DateTime(2020, 1, 1))
            .HaveTotalPremiumEqualTo(Money.Euro(550.41));


            //assert events
            resultingEvents
            .Should()
            .BeSingle()
            .ContainEvent(
                new CoverageExtendedPolicyVersionCreated
                (
                    2,
                    1,
                    ValidityPeriod.Between(new DateTime(2019, 7, 1), new DateTime(2020, 1, 1)),
                    new PolicyCoverData("AC", new DateTime(2019, 7, 1), new DateTime(2020, 1, 1), Money.Euro(50.41), Money.Euro(100), TimeSpan.FromDays(365))
                )
                );
        }
Exemplo n.º 30
0
        /// <summary>
        /// Issue a certificate based on a PKCS#10 certificate request object and validity period
        /// </summary>
        /// <param name="Request">PKCS#10 certificate request</param>
        /// <param name="Validity">Validity period for certificate</param>
        /// <returns>Requested certificate</returns>
        /// <exception cref="ArgumentException">Invalid signature algorithm in request</exception>
        public X509Certificate IssueCertificate(Pkcs10CertificationRequest Request, ValidityPeriod Validity)
        {
            X509Certificate cert = null;

            try
            {
                cert = issueCertificate(Request, null, DateTime.Now.ToUniversalTime(), Validity.NotAfter(DateTime.Now).ToUniversalTime());
                logEvent(LogEvent.EventType.IssueCert, "Certificate issued. Serial: " + cert.SerialNumber.ToString());
            }
            catch (Exception ex)
            {
                logEvent(LogEvent.EventType.Error, "Certificate issue fail: " + ex.Message);
                throw new Exception("Certificate issue failed", ex);
            }

            return(cert);
        }