From bbb1f3ed9168b1334ae42fb3031259c1ec3eace7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Aas=20Sja=CC=8Afjell?= Date: Mon, 5 Dec 2016 08:37:47 +0100 Subject: [PATCH 1/6] =?UTF-8?q?F=C3=B8rste=20fors=C3=B8k=20p=C3=A5=20en=20?= =?UTF-8?q?resourceUtility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Med enkel test som ser at det fungerer med string replacement --- .../Difi.Felles.Utility.Resources.csproj | 21 +++ .../Language/Data/en-us.Designer.cs | 72 ++++++++++ .../Language/Data/en-us.resx | 124 +++++++++++++++++ .../Language/Data/nb-no.Designer.cs | 81 +++++++++++ .../Language/Data/nb-no.resx | 126 ++++++++++++++++++ .../Language/Language.cs | 8 ++ .../Language/LanguageResource.cs | 40 ++++++ .../Language/LanguageResourceEnum.cs | 7 + .../Difi.Felles.Utility.Tester.csproj | 1 + .../LanguageResourceTests.cs | 24 ++++ .../Extensions/X509Certificate2Extensions.cs | 4 +- 11 files changed, 507 insertions(+), 1 deletion(-) create mode 100755 Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs create mode 100755 Difi.Felles.Utility.Resources/Language/Data/en-us.resx create mode 100755 Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs create mode 100755 Difi.Felles.Utility.Resources/Language/Data/nb-no.resx create mode 100755 Difi.Felles.Utility.Resources/Language/Language.cs create mode 100755 Difi.Felles.Utility.Resources/Language/LanguageResource.cs create mode 100755 Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs create mode 100755 Difi.Felles.Utility.Tester/LanguageResourceTests.cs diff --git a/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj b/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj index 765a7a8..84e3294 100755 --- a/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj +++ b/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj @@ -55,7 +55,20 @@ Properties\SharedAssemblyInfo.cs + + + + nb-no.resx + True + True + + + True + True + en-us.resx + + @@ -90,6 +103,14 @@ + + ResXFileCodeGenerator + nb-no.Designer.cs + + + ResXFileCodeGenerator + en-us.Designer.cs + Designer diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs new file mode 100755 index 0000000..63cf697 --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Difi.Felles.Utility.Resources.Language.Data { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class en_us { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal en_us() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Difi.Felles.Utility.Resources.Language.Data.en-us", typeof(en_us).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to It has a value. + /// + internal static string MyString { + get { + return ResourceManager.GetString("MyString", resourceCulture); + } + } + } +} diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx new file mode 100755 index 0000000..431446d --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + It has a value + What he said? + + \ No newline at end of file diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs new file mode 100755 index 0000000..57d4dff --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Difi.Felles.Utility.Resources.Language.Data { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class nb_no { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal nb_no() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Difi.Felles.Utility.Resources.Language.Data.nb-no", typeof(nb_no).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Sertifikat med Subject '{0:certificateSubject}' og Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo}. + /// + internal static string CertificateShortDescription { + get { + return ResourceManager.GetString("CertificateShortDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + internal static string String1 { + get { + return ResourceManager.GetString("String1", resourceCulture); + } + } + } +} diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx new file mode 100755 index 0000000..16add4f --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Sertifikat med Subject '{0:certificateSubject}' og Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo} + + + + + \ No newline at end of file diff --git a/Difi.Felles.Utility.Resources/Language/Language.cs b/Difi.Felles.Utility.Resources/Language/Language.cs new file mode 100755 index 0000000..b4bb3d1 --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/Language.cs @@ -0,0 +1,8 @@ +namespace Difi.Felles.Utility.Resources.Language +{ + public enum Language + { + English, + Norwegian + } +} diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs new file mode 100755 index 0000000..c4f1873 --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs @@ -0,0 +1,40 @@ +using System.Reflection; +using System.Resources; + +namespace Difi.Felles.Utility.Resources.Language +{ + public class LanguageResource + { + private static readonly string ResourceBasePath = "Difi.Felles.Utility.Resources.Language.Data"; + private static readonly string EnUs = $"{ResourceBasePath}.en-us"; + private static readonly string NbNo = $"{ResourceBasePath}.nb-no"; + private static readonly ResourceManager NorwegianResourceManager = new ResourceManager(NbNo, Assembly.GetExecutingAssembly()); + private static readonly ResourceManager EnglishResourceManager = new ResourceManager(EnUs, Assembly.GetExecutingAssembly()); + + private static Resources.Language.Language _currentLanguage = Resources.Language.Language.Norwegian; + public static Resources.Language.Language CurrentLanguage + { + get + { + return _currentLanguage; + } + set + { + _currentLanguage = value; + ResourceManager = CurrentLanguage == Resources.Language.Language.Norwegian + ? NorwegianResourceManager + : EnglishResourceManager; + } + } + + public static ResourceManager ResourceManager { get; private set; } = NorwegianResourceManager; + + public static string GetLanguageResource(LanguageResourceEnum languageResourceEnum) + { + var name = languageResourceEnum.ToString(); + return ResourceManager.GetString(name); + } + + + } +} diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs b/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs new file mode 100755 index 0000000..5765a31 --- /dev/null +++ b/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs @@ -0,0 +1,7 @@ +namespace Difi.Felles.Utility.Resources.Language +{ + public enum LanguageResourceEnum + { + CertificateShortDescription, + } +} diff --git a/Difi.Felles.Utility.Tester/Difi.Felles.Utility.Tester.csproj b/Difi.Felles.Utility.Tester/Difi.Felles.Utility.Tester.csproj index 79ae180..c12fe65 100755 --- a/Difi.Felles.Utility.Tester/Difi.Felles.Utility.Tester.csproj +++ b/Difi.Felles.Utility.Tester/Difi.Felles.Utility.Tester.csproj @@ -82,6 +82,7 @@ Properties\SharedAssemblyInfo.cs + diff --git a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs new file mode 100755 index 0000000..6f259d2 --- /dev/null +++ b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs @@ -0,0 +1,24 @@ +using Difi.Felles.Utility.Extensions; +using Difi.Felles.Utility.Resources.Certificate; +using Difi.Felles.Utility.Resources.Language; +using Xunit; + +namespace Difi.Felles.Utility.Tester +{ + public class LanguageResourceTests + { + public class GetResourceMethod + { + [Fact] + public void Get_resource_with_placeholders() + { + LanguageResource.CurrentLanguage = Language.Norwegian; + var certificate = CertificateResource.UnitTests.GetPostenCertificate(); + + var certDescr = certificate.ToShortString("Extrainfo"); + + Assert.True(certDescr.Contains(certificate.Subject)); + } + } + } +} diff --git a/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs b/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs index 3e6c6a8..8abc18a 100755 --- a/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs +++ b/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs @@ -1,4 +1,5 @@ using System.Security.Cryptography.X509Certificates; +using Difi.Felles.Utility.Resources.Language; namespace Difi.Felles.Utility.Extensions { @@ -6,7 +7,8 @@ public static class X509Certificate2Extensions { public static string ToShortString(this X509Certificate2 certificate, string extraInfo = "") { - return $"Sertifikat med Subject '{certificate.Subject}' og Thumbprint '{certificate.Thumbprint}' {extraInfo}"; + var shortStringWithPlaceholders = LanguageResource.GetLanguageResource(LanguageResourceEnum.CertificateShortDescription); + return string.Format(shortStringWithPlaceholders, certificate.Subject, certificate.Thumbprint, extraInfo); } } } \ No newline at end of file From 6d4cbc7f10fbc1d9bec21c855ae8428b74638b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Aas=20Sja=CC=8Afjell?= Date: Mon, 5 Dec 2016 13:10:52 +0100 Subject: [PATCH 2/6] Legger inn ressurser for norske tekster --- .../Language/Data/en-us.Designer.cs | 33 ++++++- .../Language/Data/en-us.resx | 14 ++- .../Language/Data/nb-no.Designer.cs | 90 ++++++++++++++++++- .../Language/Data/nb-no.resx | 34 ++++++- .../Language/LanguageResource.cs | 24 +++-- .../Language/LanguageResourceEnum.cs | 15 ++++ .../LanguageResourceTests.cs | 11 +++ .../CertificateChainValidator.cs | 22 +++-- Difi.Felles.Utility/CertificateValidator.cs | 22 +++-- .../Extensions/X509Certificate2Extensions.cs | 5 +- .../Validation/XmlValidationRunner.cs | 14 +-- 11 files changed, 244 insertions(+), 40 deletions(-) diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs index 63cf697..b7900e2 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs @@ -61,11 +61,38 @@ internal en_us() { } /// - /// Looks up a localized string similar to It has a value. + /// Looks up a localized string similar to . /// - internal static string MyString { + internal static string CertificateShortDescription { get { - return ResourceManager.GetString("MyString", resourceCulture); + return ResourceManager.GetString("CertificateShortDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The 'PrefixList' attribute is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NMTOKENS' - The attribute value cannot be empty.. + /// + internal static string ToleratedPrefixListError { + get { + return ResourceManager.GetString("ToleratedPrefixListError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard.. + /// + internal static string ToleratedXsdIdError { + get { + return ResourceManager.GetString("ToleratedXsdIdError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + internal static string UsedExternalCertificateResult { + get { + return ResourceManager.GetString("UsedExternalCertificateResult", resourceCulture); } } } diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx index 431446d..6dc4267 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx @@ -117,8 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - It has a value - What he said? + + + + + The 'PrefixList' attribute is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NMTOKENS' - The attribute value cannot be empty. + + + It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard. + + + \ No newline at end of file diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs index 57d4dff..6b35f10 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs @@ -60,6 +60,60 @@ internal nb_no() { } } + /// + /// Looks up a localized string similar to gikk ut {0:expirationDateString}.. + /// + internal static string CertificateExpiredResult { + get { + return ResourceManager.GetString("CertificateExpiredResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to har følgende feil i sertifikatkjeden: {0:prettyChainErrorStatuses}. + /// + internal static string CertificateInvalidChainResult { + get { + return ResourceManager.GetString("CertificateInvalidChainResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sertifikat var null! Sjekk at sertifikatet blir lastet korrekt.. + /// + internal static string CertificateIsNull { + get { + return ResourceManager.GetString("CertificateIsNull", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to aktiveres ikke før {0:effectiveDateString}. + /// + internal static string CertificateNotActivatedResult { + get { + return ResourceManager.GetString("CertificateNotActivatedResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sertifikatet er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides.. + /// + internal static string CertificateNotIssuedToOrganization { + get { + return ResourceManager.GetString("CertificateNotIssuedToOrganization", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et sertifikat utstedt av en gyldig sertifikatutsteder.. + /// + internal static string CertificateSelfSignedErrorResult { + get { + return ResourceManager.GetString("CertificateSelfSignedErrorResult", resourceCulture); + } + } + /// /// Looks up a localized string similar to Sertifikat med Subject '{0:certificateSubject}' og Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo}. /// @@ -70,11 +124,41 @@ internal static string CertificateShortDescription { } /// - /// Looks up a localized string similar to . + /// Looks up a localized string similar to Validering av {0:certificateShortDescription} feilet. + ///Dette skjer fordi kjeden ble bygd med følgende sertifikater: + ///{1:chainAsString}, men kun følgende er godkjent for å bygge kjeden: + ///{2:validatorCertificatesAsString}. Dette skjer som oftest om sertifikater blir hentet fra Certificate Store på Windows, og det tillates ikke under validering. Det er kun gyldig å bygge en kjede med sertifikatene som blir sendt inn i validatoren.. + /// + internal static string CertificateUsedExternalResult { + get { + return ResourceManager.GetString("CertificateUsedExternalResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to er et gyldig sertifikat.. + /// + internal static string CertificateValidResult { + get { + return ResourceManager.GetString("CertificateValidResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Attributtet PrefixList er ugyldig - Verdien er ugyldig i henhold til datatypen http://www.w3.org/2001/XMLSchema:NMTOKENS - Attributtverdien kan ikke være tom.. + /// + internal static string ToleratedPrefixListError { + get { + return ResourceManager.GetString("ToleratedPrefixListError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Det er en feil hvis det finnes et medlem av attributtet som bruker en typedefinisjon med typen xs:ID eller avledet fra xs:ID og et annet attributt med typen xs:ID tilsvarer et attributtjokertegn.. /// - internal static string String1 { + internal static string ToleratedXsdIdError { get { - return ResourceManager.GetString("String1", resourceCulture); + return ResourceManager.GetString("ToleratedXsdIdError", resourceCulture); } } } diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx index 16add4f..3181cd0 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx @@ -117,10 +117,40 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + gikk ut {0:expirationDateString}. + + + har følgende feil i sertifikatkjeden: {0:prettyChainErrorStatuses} + + + Sertifikat var null! Sjekk at sertifikatet blir lastet korrekt. + + + aktiveres ikke før {0:effectiveDateString} + + + Sertifikatet er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides. + + + er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et sertifikat utstedt av en gyldig sertifikatutsteder. + Sertifikat med Subject '{0:certificateSubject}' og Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo} - - + + Validering av {0:certificateShortDescription} feilet. +Dette skjer fordi kjeden ble bygd med følgende sertifikater: +{1:chainAsString}, men kun følgende er godkjent for å bygge kjeden: +{2:validatorCertificatesAsString}. Dette skjer som oftest om sertifikater blir hentet fra Certificate Store på Windows, og det tillates ikke under validering. Det er kun gyldig å bygge en kjede med sertifikatene som blir sendt inn i validatoren. + + + er et gyldig sertifikat. + + + Attributtet PrefixList er ugyldig - Verdien er ugyldig i henhold til datatypen http://www.w3.org/2001/XMLSchema:NMTOKENS - Attributtverdien kan ikke være tom. + + + Det er en feil hvis det finnes et medlem av attributtet som bruker en typedefinisjon med typen xs:ID eller avledet fra xs:ID og et annet attributt med typen xs:ID tilsvarer et attributtjokertegn. \ No newline at end of file diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs index c4f1873..df2f599 100755 --- a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs +++ b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs @@ -5,14 +5,14 @@ namespace Difi.Felles.Utility.Resources.Language { public class LanguageResource { - private static readonly string ResourceBasePath = "Difi.Felles.Utility.Resources.Language.Data"; + private const string ResourceBasePath = "Difi.Felles.Utility.Resources.Language.Data"; private static readonly string EnUs = $"{ResourceBasePath}.en-us"; private static readonly string NbNo = $"{ResourceBasePath}.nb-no"; private static readonly ResourceManager NorwegianResourceManager = new ResourceManager(NbNo, Assembly.GetExecutingAssembly()); private static readonly ResourceManager EnglishResourceManager = new ResourceManager(EnUs, Assembly.GetExecutingAssembly()); - private static Resources.Language.Language _currentLanguage = Resources.Language.Language.Norwegian; - public static Resources.Language.Language CurrentLanguage + private static Language _currentLanguage = Language.Norwegian; + public static Language CurrentLanguage { get { @@ -21,7 +21,7 @@ public static Resources.Language.Language CurrentLanguage set { _currentLanguage = value; - ResourceManager = CurrentLanguage == Resources.Language.Language.Norwegian + ResourceManager = CurrentLanguage == Language.Norwegian ? NorwegianResourceManager : EnglishResourceManager; } @@ -29,12 +29,24 @@ public static Resources.Language.Language CurrentLanguage public static ResourceManager ResourceManager { get; private set; } = NorwegianResourceManager; - public static string GetLanguageResource(LanguageResourceEnum languageResourceEnum) + public static string GetResource(LanguageResourceEnum languageResourceEnum) { var name = languageResourceEnum.ToString(); return ResourceManager.GetString(name); } - + public static string GetResource(LanguageResourceEnum languageResourceEnum, Language temporaryLanguage) + { + var preLanguage = CurrentLanguage; + + CurrentLanguage = temporaryLanguage; + var resource = GetResource(languageResourceEnum); + CurrentLanguage = preLanguage; + + return resource; + + } + + } } diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs b/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs index 5765a31..4a4d64a 100755 --- a/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs +++ b/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs @@ -2,6 +2,21 @@ { public enum LanguageResourceEnum { + //X509Certificate2Extensions CertificateShortDescription, + + //XSD Validation + ToleratedXsdIdError, + ToleratedPrefixListError, + + //Certificate Validation + CertificateUsedExternalResult, + CertificateInvalidChainResult, + CertificateValidResult, + CertificateSelfSignedErrorResult, + CertificateIsNull, + CertificateNotIssuedToOrganization, + CertificateNotActivatedResult, + CertificateExpiredResult } } diff --git a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs index 6f259d2..25732d9 100755 --- a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs +++ b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs @@ -19,6 +19,17 @@ public void Get_resource_with_placeholders() Assert.True(certDescr.Contains(certificate.Subject)); } + + [Fact] + public void Get_resource_with_temporary_language() + { + LanguageResource.CurrentLanguage = Language.Norwegian; + var resource = LanguageResource.GetResource(LanguageResourceEnum.ToleratedPrefixListError, Language.English); + + Assert.True(resource.Contains("The 'PrefixList' attribute is invalid")); + Assert.Equal(Language.Norwegian, LanguageResource.CurrentLanguage); + } + } } } diff --git a/Difi.Felles.Utility/CertificateChainValidator.cs b/Difi.Felles.Utility/CertificateChainValidator.cs index 9c77381..0ef9536 100755 --- a/Difi.Felles.Utility/CertificateChainValidator.cs +++ b/Difi.Felles.Utility/CertificateChainValidator.cs @@ -2,6 +2,8 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using Difi.Felles.Utility.Extensions; +using static Difi.Felles.Utility.Resources.Language.LanguageResource; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceEnum; namespace Difi.Felles.Utility { @@ -139,11 +141,12 @@ private CertificateValidationResult ValidateThatUsingOnlyValidatorCertificates(X private static CertificateValidationResult UsedExternalCertificatesResult(X509Certificate2 certificate, string chainAsString, string validatorCertificatesAsString) { - return new CertificateValidationResult(CertificateValidationType.InvalidChain, - $"Validering av '{certificate.ToShortString()}' feilet. {Environment.NewLine}" + - $"Dette skjer fordi kjeden ble bygd med følgende sertifikater: {Environment.NewLine}{chainAsString}, " + - $"men kun følgende er godkjent for å bygge kjeden: {Environment.NewLine}{validatorCertificatesAsString}. Dette skjer som oftest om sertifikater blir hentet fra Certificate Store på Windows, " + - "og det tillates ikke under validering. Det er kun gyldig å bygge en kjede med de sertifikatene sendt inn til validatoren."); + var externalCertificatesUsedMessage = + string.Format( + GetResource(CertificateUsedExternalResult), + certificate.ToShortString(), chainAsString, validatorCertificatesAsString); + + return new CertificateValidationResult(CertificateValidationType.InvalidChain, externalCertificatesUsedMessage); } private static bool IsSameCertificate(X509Certificate2 certificate1, X509Certificate2 certificate2) @@ -192,17 +195,20 @@ private static CertificateValidationResult Validate(X509Certificate2 certificate private static CertificateValidationResult InvalidChainResult(X509Certificate2 certificate, params X509ChainStatus[] x509ChainStatuses) { - return new CertificateValidationResult(CertificateValidationType.InvalidChain, certificate.ToShortString($"har følgende feil i sertifikatkjeden: {GetPrettyChainErrorStatuses(x509ChainStatuses)}")); + var invalidChainResult = string.Format(GetResource(CertificateInvalidChainResult), GetPrettyChainErrorStatuses(x509ChainStatuses)); + return new CertificateValidationResult(CertificateValidationType.InvalidChain, certificate.ToShortString(invalidChainResult)); } private static CertificateValidationResult ValidResult(X509Certificate2 certificate) { - return new CertificateValidationResult(CertificateValidationType.Valid, certificate.ToShortString("er et gyldig sertifikat.")); + var validChainResult = GetResource(CertificateValidResult); + return new CertificateValidationResult(CertificateValidationType.Valid, certificate.ToShortString(validChainResult)); } private static CertificateValidationResult SelfSignedErrorResult(X509Certificate2 certificate) { - return new CertificateValidationResult(CertificateValidationType.InvalidChain, certificate.ToShortString("er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et sertifikat utstedt av en gyldig sertifikatutsteder.")); + var selfSignedErrorResult = GetResource(CertificateSelfSignedErrorResult); + return new CertificateValidationResult(CertificateValidationType.InvalidChain, certificate.ToShortString(selfSignedErrorResult)); } private static string GetPrettyChainErrorStatuses(X509ChainStatus[] chainStatuses) diff --git a/Difi.Felles.Utility/CertificateValidator.cs b/Difi.Felles.Utility/CertificateValidator.cs index 504e246..2c0710d 100755 --- a/Difi.Felles.Utility/CertificateValidator.cs +++ b/Difi.Felles.Utility/CertificateValidator.cs @@ -1,11 +1,14 @@ using System; using System.Security.Cryptography.X509Certificates; using Difi.Felles.Utility.Extensions; +using static Difi.Felles.Utility.Resources.Language.LanguageResource; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceEnum; namespace Difi.Felles.Utility { public class CertificateValidator { + [Obsolete("Use ValidateCertificate(X509Certificate, string) instead and use CertificateValidationResult to get result of validation")] public static bool IsValidCertificate(X509Certificate2 certificate, string certificateOrganizationNumber) { return ValidateCertificate(certificate, certificateOrganizationNumber).Type == CertificateValidationType.Valid; @@ -51,35 +54,40 @@ public static CertificateValidationResult ValidateCertificate(X509Certificate2 c private static CertificateValidationResult NoCertificateResult() { - return new CertificateValidationResult(CertificateValidationType.InvalidCertificate, "Sertifikat var null! Sjekk at sertifikatet blir lastet korrekt."); + var nullCertificateResult = GetResource(CertificateIsNull); + return new CertificateValidationResult(CertificateValidationType.InvalidCertificate, nullCertificateResult); } private static CertificateValidationResult NotIssuedToOrganizationResult(string certificateOrganizationNumber) { - return new CertificateValidationResult(CertificateValidationType.InvalidCertificate, - $"Sertifikatet er ikke utstedt til organisasjonsnummer '{certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet " + - "eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides."); + var notIssuedToOrganizationResult = string.Format(GetResource(CertificateNotIssuedToOrganization), certificateOrganizationNumber); + return new CertificateValidationResult( + CertificateValidationType.InvalidCertificate, + notIssuedToOrganizationResult); } private static CertificateValidationResult NotActivatedResult(X509Certificate2 certificate) { + var notActivatedResult = string.Format(GetResource(CertificateNotActivatedResult), certificate.GetEffectiveDateString()); return new CertificateValidationResult( CertificateValidationType.InvalidCertificate, - certificate.ToShortString($"aktiveres ikke før {certificate.GetEffectiveDateString()}")); + certificate.ToShortString(notActivatedResult)); } private static CertificateValidationResult ExpiredResult(X509Certificate2 certificate) { + var expiredResult = string.Format(GetResource(CertificateExpiredResult), certificate.GetExpirationDateString()); return new CertificateValidationResult( CertificateValidationType.InvalidCertificate, - certificate.ToShortString($"gikk ut {certificate.GetExpirationDateString()}.")); + certificate.ToShortString(expiredResult)); } private static CertificateValidationResult ValidResult(X509Certificate2 certificate) { + var validResult = GetResource(CertificateValidResult); return new CertificateValidationResult( CertificateValidationType.Valid, - certificate.ToShortString("er et gyldig sertifikat.")); + certificate.ToShortString(validResult)); } private static bool IsIssuedToOrganizationNumber(X509Certificate certificate, string certificateOrganizationNumber) diff --git a/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs b/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs index 8abc18a..cc914de 100755 --- a/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs +++ b/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs @@ -1,5 +1,6 @@ using System.Security.Cryptography.X509Certificates; -using Difi.Felles.Utility.Resources.Language; +using static Difi.Felles.Utility.Resources.Language.LanguageResource; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceEnum; namespace Difi.Felles.Utility.Extensions { @@ -7,7 +8,7 @@ public static class X509Certificate2Extensions { public static string ToShortString(this X509Certificate2 certificate, string extraInfo = "") { - var shortStringWithPlaceholders = LanguageResource.GetLanguageResource(LanguageResourceEnum.CertificateShortDescription); + var shortStringWithPlaceholders = GetResource(CertificateShortDescription); return string.Format(shortStringWithPlaceholders, certificate.Subject, certificate.Thumbprint, extraInfo); } } diff --git a/Difi.Felles.Utility/Validation/XmlValidationRunner.cs b/Difi.Felles.Utility/Validation/XmlValidationRunner.cs index 31a6314..15e85d4 100755 --- a/Difi.Felles.Utility/Validation/XmlValidationRunner.cs +++ b/Difi.Felles.Utility/Validation/XmlValidationRunner.cs @@ -3,17 +3,19 @@ using System.Text; using System.Xml; using System.Xml.Schema; +using Difi.Felles.Utility.Resources.Language; namespace Difi.Felles.Utility.Validation { internal class XmlValidationRunner { - private const string ToleratedXsdIdErrorEnUs = "It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard."; - private const string ToleratedXsdIdErrorNbNo = "Det er en feil hvis det finnes et medlem av attributtet som bruker en typedefinisjon med typen xs:ID eller avledet fra xs:ID og et annet attributt med typen xs:ID tilsvarer et attributtjokertegn."; - private const string ToleratedPrefixListErrorEnUs = "The 'PrefixList' attribute is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NMTOKENS' - The attribute value cannot be empty."; - private const string ToleratedPrefixListErrorNbNo = "Attributtet PrefixList er ugyldig - Verdien er ugyldig i henhold til datatypen http://www.w3.org/2001/XMLSchema:NMTOKENS - Attributtverdien kan ikke være tom."; - - internal static readonly List ToleratedErrors = new List {ToleratedXsdIdErrorEnUs, ToleratedXsdIdErrorNbNo, ToleratedPrefixListErrorEnUs, ToleratedPrefixListErrorNbNo}; + internal static readonly List ToleratedErrors = new List + { + LanguageResource.GetResource(LanguageResourceEnum.ToleratedXsdIdError, Language.Norwegian), + LanguageResource.GetResource(LanguageResourceEnum.ToleratedXsdIdError, Language.English), + LanguageResource.GetResource(LanguageResourceEnum.ToleratedPrefixListError, Language.Norwegian), + LanguageResource.GetResource(LanguageResourceEnum.ToleratedPrefixListError, Language.English), + }; internal XmlValidationRunner(XmlSchemaSet xmlSchemaSet) { From 681d7804aad01e0dfa2b8ef5d11cad2986ca4fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Aas=20Sja=CC=8Afjell?= Date: Mon, 5 Dec 2016 13:56:08 +0100 Subject: [PATCH 3/6] Legger til engelske oversettelser --- .../Language/Data/en-us.Designer.cs | 86 ++++++++++++++++--- .../Language/Data/en-us.resx | 32 ++++++- .../Language/Data/nb-no.Designer.cs | 2 +- .../Language/Data/nb-no.resx | 2 +- 4 files changed, 106 insertions(+), 16 deletions(-) diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs index b7900e2..4ebbecb 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs @@ -61,7 +61,61 @@ internal en_us() { } /// - /// Looks up a localized string similar to . + /// Looks up a localized string similar to expired on {0:expirationDateString}.. + /// + internal static string CertificateExpiredResult { + get { + return ResourceManager.GetString("CertificateExpiredResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to has the following certificate chain errors: {0:prettyChainErrorStatuses}. + /// + internal static string CertificateInvalidChainResult { + get { + return ResourceManager.GetString("CertificateInvalidChainResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The certificate is null! Please check that the certificate is loaded correctly.. + /// + internal static string CertificateIsNull { + get { + return ResourceManager.GetString("CertificateIsNull", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to is not active until {0:effectiveDateString}. + /// + internal static string CertificateNotActivatedResult { + get { + return ResourceManager.GetString("CertificateNotActivatedResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The certificate is not issued to organization number '{0:certificateOrganizationNumber}'. This occurs if the certificate is issued to a different organization or if it isn't an organizational certificate. An organizational certificate can be aquired from Buypass or Commfides. + /// + internal static string CertificateNotIssuedToOrganization { + get { + return ResourceManager.GetString("CertificateNotIssuedToOrganization", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to is invalid because the chain length is 1. This means that the certificate is self signed. An organizational certificate issued by a valid certificate issuer is required. An organizational certificate can be aquired from Buypass or Commfides. + /// + internal static string CertificateSelfSignedErrorResult { + get { + return ResourceManager.GetString("CertificateSelfSignedErrorResult", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Certtificate with Subject '{0:certificateSubject}' and Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo}. /// internal static string CertificateShortDescription { get { @@ -70,29 +124,41 @@ internal static string CertificateShortDescription { } /// - /// Looks up a localized string similar to The 'PrefixList' attribute is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NMTOKENS' - The attribute value cannot be empty.. + /// Looks up a localized string similar to Validation of {0:certificateShortDescription} failed. + ///This happened because the chain was built with the following certificates: + ///{1:chainAsString}, but only the following are allowed to build the chain: + ///{2:validatorCertificatesAsString}. This usually happens if the certificate is retrieved from Windows Certificate Store and this is not allowed during validation. The chain can only be built using the validator certificates.. /// - internal static string ToleratedPrefixListError { + internal static string CertificateUsedExternalResult { get { - return ResourceManager.GetString("ToleratedPrefixListError", resourceCulture); + return ResourceManager.GetString("CertificateUsedExternalResult", resourceCulture); } } /// - /// Looks up a localized string similar to It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard.. + /// Looks up a localized string similar to is a valid certificate.. /// - internal static string ToleratedXsdIdError { + internal static string CertificateValidResult { get { - return ResourceManager.GetString("ToleratedXsdIdError", resourceCulture); + return ResourceManager.GetString("CertificateValidResult", resourceCulture); } } /// - /// Looks up a localized string similar to . + /// Looks up a localized string similar to The 'PrefixList' attribute is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NMTOKENS' - The attribute value cannot be empty.. /// - internal static string UsedExternalCertificateResult { + internal static string ToleratedPrefixListError { get { - return ResourceManager.GetString("UsedExternalCertificateResult", resourceCulture); + return ResourceManager.GetString("ToleratedPrefixListError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard.. + /// + internal static string ToleratedXsdIdError { + get { + return ResourceManager.GetString("ToleratedXsdIdError", resourceCulture); } } } diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx index 6dc4267..8286414 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx @@ -117,8 +117,35 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + expired on {0:expirationDateString}. + + + has the following certificate chain errors: {0:prettyChainErrorStatuses} + + + The certificate is null! Please check that the certificate is loaded correctly. + + + is not active until {0:effectiveDateString} + + + The certificate is not issued to organization number '{0:certificateOrganizationNumber}'. This occurs if the certificate is issued to a different organization or if it isn't an organizational certificate. An organizational certificate can be aquired from Buypass or Commfides + + + is invalid because the chain length is 1. This means that the certificate is self signed. An organizational certificate issued by a valid certificate issuer is required. An organizational certificate can be aquired from Buypass or Commfides + - + Certtificate with Subject '{0:certificateSubject}' and Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo} + + + Validation of {0:certificateShortDescription} failed. +This happened because the chain was built with the following certificates: +{1:chainAsString}, but only the following are allowed to build the chain: +{2:validatorCertificatesAsString}. This usually happens if the certificate is retrieved from Windows Certificate Store and this is not allowed during validation. The chain can only be built using the validator certificates. + + + is a valid certificate. The 'PrefixList' attribute is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NMTOKENS' - The attribute value cannot be empty. @@ -126,7 +153,4 @@ It is an error if there is a member of the attribute uses of a type definition with type xs:ID or derived from xs:ID and another attribute with type xs:ID matches an attribute wildcard. - - - \ No newline at end of file diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs index 6b35f10..d83e001 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs @@ -106,7 +106,7 @@ internal static string CertificateNotIssuedToOrganization { } /// - /// Looks up a localized string similar to er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et sertifikat utstedt av en gyldig sertifikatutsteder.. + /// Looks up a localized string similar to er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et virksomhetssertifikat utstedt av en gyldig sertifikatutsteder. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides.. /// internal static string CertificateSelfSignedErrorResult { get { diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx index 3181cd0..045fd37 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx @@ -133,7 +133,7 @@ Sertifikatet er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides. - er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et sertifikat utstedt av en gyldig sertifikatutsteder. + er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et virksomhetssertifikat utstedt av en gyldig sertifikatutsteder. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides. Sertifikat med Subject '{0:certificateSubject}' og Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo} From b1f2d40378cd435c12226ef71b216edcdbcf29e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Aas=20Sja=CC=8Afjell?= Date: Mon, 5 Dec 2016 14:40:25 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Finpuss=20p=C3=A5=20noen=20tekster=20for=20?= =?UTF-8?q?mer=20info=20og=20bedre=20leselighet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Language/Data/en-us.Designer.cs | 4 ++-- Difi.Felles.Utility.Resources/Language/Data/en-us.resx | 4 ++-- .../Language/Data/nb-no.Designer.cs | 4 ++-- Difi.Felles.Utility.Resources/Language/Data/nb-no.resx | 4 ++-- Difi.Felles.Utility.Tester/CertificateValidatorTests.cs | 8 ++++++-- Difi.Felles.Utility/CertificateValidator.cs | 6 +++--- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs index 4ebbecb..126d497 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.Designer.cs @@ -97,7 +97,7 @@ internal static string CertificateNotActivatedResult { } /// - /// Looks up a localized string similar to The certificate is not issued to organization number '{0:certificateOrganizationNumber}'. This occurs if the certificate is issued to a different organization or if it isn't an organizational certificate. An organizational certificate can be aquired from Buypass or Commfides. + /// Looks up a localized string similar to is not issued to organization number '{0:certificateOrganizationNumber}'. This occurs if the certificate is issued to a different organization or if it isn't an organizational certificate. An organizational certificate can be aquired from Buypass or Commfides.. /// internal static string CertificateNotIssuedToOrganization { get { @@ -115,7 +115,7 @@ internal static string CertificateSelfSignedErrorResult { } /// - /// Looks up a localized string similar to Certtificate with Subject '{0:certificateSubject}' and Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo}. + /// Looks up a localized string similar to Certificate with Subject '{0:certificateSubject}' and Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo}. /// internal static string CertificateShortDescription { get { diff --git a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx index 8286414..d2f0a0f 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/en-us.resx +++ b/Difi.Felles.Utility.Resources/Language/Data/en-us.resx @@ -130,13 +130,13 @@ is not active until {0:effectiveDateString} - The certificate is not issued to organization number '{0:certificateOrganizationNumber}'. This occurs if the certificate is issued to a different organization or if it isn't an organizational certificate. An organizational certificate can be aquired from Buypass or Commfides + is not issued to organization number '{0:certificateOrganizationNumber}'. This occurs if the certificate is issued to a different organization or if it isn't an organizational certificate. An organizational certificate can be aquired from Buypass or Commfides. is invalid because the chain length is 1. This means that the certificate is self signed. An organizational certificate issued by a valid certificate issuer is required. An organizational certificate can be aquired from Buypass or Commfides - Certtificate with Subject '{0:certificateSubject}' and Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo} + Certificate with Subject '{0:certificateSubject}' and Thumbprint '{1:certificateThumbprint}' {2:certificateExtraInfo} Validation of {0:certificateShortDescription} failed. diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs index d83e001..54fc368 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.Designer.cs @@ -79,7 +79,7 @@ internal static string CertificateInvalidChainResult { } /// - /// Looks up a localized string similar to Sertifikat var null! Sjekk at sertifikatet blir lastet korrekt.. + /// Looks up a localized string similar to Sertifikatet var null! Sjekk at sertifikatet blir lastet korrekt.. /// internal static string CertificateIsNull { get { @@ -97,7 +97,7 @@ internal static string CertificateNotActivatedResult { } /// - /// Looks up a localized string similar to Sertifikatet er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides.. + /// Looks up a localized string similar to er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides.. /// internal static string CertificateNotIssuedToOrganization { get { diff --git a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx index 045fd37..650874b 100755 --- a/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx +++ b/Difi.Felles.Utility.Resources/Language/Data/nb-no.resx @@ -124,13 +124,13 @@ har følgende feil i sertifikatkjeden: {0:prettyChainErrorStatuses} - Sertifikat var null! Sjekk at sertifikatet blir lastet korrekt. + Sertifikatet var null! Sjekk at sertifikatet blir lastet korrekt. aktiveres ikke før {0:effectiveDateString} - Sertifikatet er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides. + er ikke utstedt til organisasjonsnummer '{0:certificateOrganizationNumber}'. Dette vil skje om sertifikatet er utstedt til en annen virksomhet eller hvis det ikke er et virksomhetssertifikat. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides. er ugyldig, fordi lengden på kjeden er 1, noe som betyr at sertifikatet er selvsignert. Det må brukes et virksomhetssertifikat utstedt av en gyldig sertifikatutsteder. Virksomhetssertifikat kan skaffes fra Buypass eller Commfides. diff --git a/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs b/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs index b0f81c3..9e83e93 100755 --- a/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs +++ b/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs @@ -1,4 +1,5 @@ using Difi.Felles.Utility.Resources.Certificate; +using Difi.Felles.Utility.Resources.Language; using Difi.Felles.Utility.Utilities; using Xunit; @@ -19,11 +20,12 @@ public void Returns_fail_if_certificate_error() //Assert Assert.Equal(CertificateValidationType.InvalidCertificate, result.Type); - Assert.NotNull(result.Message); + Assert.Contains("gikk ut", result.Message); + } [Fact] - public void Returns_fail_if_invalid_certificate_chain() + public void Returns_fail_if_self_signed_certificate() { //Arrange var funksjoneltTestmiljøSertifikater = CertificateChainUtility.FunksjoneltTestmiljøSertifikater(); @@ -33,6 +35,7 @@ public void Returns_fail_if_invalid_certificate_chain() //Assert Assert.Equal(CertificateValidationType.InvalidChain, result.Type); + Assert.Contains("er ugyldig, fordi lengden på kjeden er 1", result.Message); } [Fact] @@ -46,6 +49,7 @@ public void Returns_ok_if_valid_certificate_and_chain() //Assert Assert.Equal(CertificateValidationType.Valid, result.Type); + Assert.Contains("er et gyldig sertifikat", result.Message); } } diff --git a/Difi.Felles.Utility/CertificateValidator.cs b/Difi.Felles.Utility/CertificateValidator.cs index 2c0710d..f8d4948 100755 --- a/Difi.Felles.Utility/CertificateValidator.cs +++ b/Difi.Felles.Utility/CertificateValidator.cs @@ -36,7 +36,7 @@ public static CertificateValidationResult ValidateCertificate(X509Certificate2 c if (!IsIssuedToOrganizationNumber(certificate, certificateOrganizationNumber)) { - return NotIssuedToOrganizationResult(certificateOrganizationNumber); + return NotIssuedToOrganizationResult(certificate, certificateOrganizationNumber); } if (!IsActivatedCertificate(certificate)) @@ -58,12 +58,12 @@ private static CertificateValidationResult NoCertificateResult() return new CertificateValidationResult(CertificateValidationType.InvalidCertificate, nullCertificateResult); } - private static CertificateValidationResult NotIssuedToOrganizationResult(string certificateOrganizationNumber) + private static CertificateValidationResult NotIssuedToOrganizationResult(X509Certificate2 certificate, string certificateOrganizationNumber) { var notIssuedToOrganizationResult = string.Format(GetResource(CertificateNotIssuedToOrganization), certificateOrganizationNumber); return new CertificateValidationResult( CertificateValidationType.InvalidCertificate, - notIssuedToOrganizationResult); + certificate.ToShortString(notIssuedToOrganizationResult)); } private static CertificateValidationResult NotActivatedResult(X509Certificate2 certificate) From 32702e4764ec6a58fb8fbc425022a1a040affdb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Aas=20Sja=CC=8Afjell?= Date: Tue, 6 Dec 2016 09:09:31 +0100 Subject: [PATCH 5/6] Rydder opp LanguageResource etter PR --- .../Difi.Felles.Utility.Resources.csproj | 2 +- .../Language/LanguageResource.cs | 49 +++++++------------ ...ResourceEnum.cs => LanguageResourceKey.cs} | 2 +- .../CertificateChainValidatorTests.cs | 2 + .../LanguageResourceTests.cs | 2 +- .../CertificateChainValidator.cs | 2 +- Difi.Felles.Utility/CertificateValidator.cs | 2 +- .../Exceptions/SecurityException.cs | 1 + .../Extensions/X509Certificate2Extensions.cs | 2 +- .../Validation/XmlValidationRunner.cs | 10 ++-- SharedAssemblyInfo.cs | 7 ++- 11 files changed, 37 insertions(+), 44 deletions(-) rename Difi.Felles.Utility.Resources/Language/{LanguageResourceEnum.cs => LanguageResourceKey.cs} (93%) diff --git a/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj b/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj index 84e3294..1a07e48 100755 --- a/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj +++ b/Difi.Felles.Utility.Resources/Difi.Felles.Utility.Resources.csproj @@ -56,7 +56,7 @@ - + nb-no.resx diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs index df2f599..895db37 100755 --- a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs +++ b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs @@ -1,5 +1,7 @@ -using System.Reflection; +using System; +using System.Reflection; using System.Resources; +using Difi.Felles.Utility.Resources.Language.Data; namespace Difi.Felles.Utility.Resources.Language { @@ -11,42 +13,29 @@ public class LanguageResource private static readonly ResourceManager NorwegianResourceManager = new ResourceManager(NbNo, Assembly.GetExecutingAssembly()); private static readonly ResourceManager EnglishResourceManager = new ResourceManager(EnUs, Assembly.GetExecutingAssembly()); - private static Language _currentLanguage = Language.Norwegian; - public static Language CurrentLanguage + public static Language CurrentLanguage { get; set; } = Language.Norwegian; + + public static string GetResource(LanguageResourceKey key) { - get - { - return _currentLanguage; - } - set - { - _currentLanguage = value; - ResourceManager = CurrentLanguage == Language.Norwegian - ? NorwegianResourceManager - : EnglishResourceManager; - } + return GetResource(key, CurrentLanguage); } - public static ResourceManager ResourceManager { get; private set; } = NorwegianResourceManager; - - public static string GetResource(LanguageResourceEnum languageResourceEnum) + public static string GetResource(LanguageResourceKey key, Language language) { - var name = languageResourceEnum.ToString(); - return ResourceManager.GetString(name); + return GetManagerForLanguage(language).GetString(key.ToString()); } - public static string GetResource(LanguageResourceEnum languageResourceEnum, Language temporaryLanguage) + private static ResourceManager GetManagerForLanguage(Language language) { - var preLanguage = CurrentLanguage; - - CurrentLanguage = temporaryLanguage; - var resource = GetResource(languageResourceEnum); - CurrentLanguage = preLanguage; - - return resource; - + switch (language) + { + case Language.English: + return EnglishResourceManager; + case Language.Norwegian: + return NorwegianResourceManager; + default: + throw new ArgumentOutOfRangeException(nameof(language), language, null); + } } - - } } diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs b/Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs similarity index 93% rename from Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs rename to Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs index 4a4d64a..b8d09b8 100755 --- a/Difi.Felles.Utility.Resources/Language/LanguageResourceEnum.cs +++ b/Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs @@ -1,6 +1,6 @@ namespace Difi.Felles.Utility.Resources.Language { - public enum LanguageResourceEnum + public enum LanguageResourceKey { //X509Certificate2Extensions CertificateShortDescription, diff --git a/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs b/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs index f15b0d7..8d0f527 100755 --- a/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs +++ b/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs @@ -1,4 +1,5 @@ using Difi.Felles.Utility.Resources.Certificate; +using Difi.Felles.Utility.Resources.Language; using Difi.Felles.Utility.Utilities; using Xunit; @@ -11,6 +12,7 @@ public class ValidateCertificateChain : CertificateChainValidatorTests [Fact] public void Fails_with_self_signed_certificate() { + //Arrange var selfSignedCertificate = CertificateResource.UnitTests.GetEnhetstesterSelvsignertSertifikat(); var certificateChainValidator = new CertificateChainValidator(CertificateChainUtility.ProduksjonsSertifikater()); diff --git a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs index 25732d9..ced8be6 100755 --- a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs +++ b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs @@ -24,7 +24,7 @@ public void Get_resource_with_placeholders() public void Get_resource_with_temporary_language() { LanguageResource.CurrentLanguage = Language.Norwegian; - var resource = LanguageResource.GetResource(LanguageResourceEnum.ToleratedPrefixListError, Language.English); + var resource = LanguageResource.GetResource(LanguageResourceKey.ToleratedPrefixListError, Language.English); Assert.True(resource.Contains("The 'PrefixList' attribute is invalid")); Assert.Equal(Language.Norwegian, LanguageResource.CurrentLanguage); diff --git a/Difi.Felles.Utility/CertificateChainValidator.cs b/Difi.Felles.Utility/CertificateChainValidator.cs index 0ef9536..1966dd1 100755 --- a/Difi.Felles.Utility/CertificateChainValidator.cs +++ b/Difi.Felles.Utility/CertificateChainValidator.cs @@ -3,7 +3,7 @@ using System.Security.Cryptography.X509Certificates; using Difi.Felles.Utility.Extensions; using static Difi.Felles.Utility.Resources.Language.LanguageResource; -using static Difi.Felles.Utility.Resources.Language.LanguageResourceEnum; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceKey; namespace Difi.Felles.Utility { diff --git a/Difi.Felles.Utility/CertificateValidator.cs b/Difi.Felles.Utility/CertificateValidator.cs index f8d4948..890af90 100755 --- a/Difi.Felles.Utility/CertificateValidator.cs +++ b/Difi.Felles.Utility/CertificateValidator.cs @@ -2,7 +2,7 @@ using System.Security.Cryptography.X509Certificates; using Difi.Felles.Utility.Extensions; using static Difi.Felles.Utility.Resources.Language.LanguageResource; -using static Difi.Felles.Utility.Resources.Language.LanguageResourceEnum; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceKey; namespace Difi.Felles.Utility { diff --git a/Difi.Felles.Utility/Exceptions/SecurityException.cs b/Difi.Felles.Utility/Exceptions/SecurityException.cs index 24cbdb6..6895c41 100755 --- a/Difi.Felles.Utility/Exceptions/SecurityException.cs +++ b/Difi.Felles.Utility/Exceptions/SecurityException.cs @@ -2,6 +2,7 @@ namespace Difi.Felles.Utility.Exceptions { + [Obsolete("No reason to have a common SecurityException as it creates implicit library dependencies.")] public class SecurityException : DifiException { public SecurityException() diff --git a/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs b/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs index cc914de..f6e5c85 100755 --- a/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs +++ b/Difi.Felles.Utility/Extensions/X509Certificate2Extensions.cs @@ -1,6 +1,6 @@ using System.Security.Cryptography.X509Certificates; using static Difi.Felles.Utility.Resources.Language.LanguageResource; -using static Difi.Felles.Utility.Resources.Language.LanguageResourceEnum; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceKey; namespace Difi.Felles.Utility.Extensions { diff --git a/Difi.Felles.Utility/Validation/XmlValidationRunner.cs b/Difi.Felles.Utility/Validation/XmlValidationRunner.cs index 15e85d4..ead6f50 100755 --- a/Difi.Felles.Utility/Validation/XmlValidationRunner.cs +++ b/Difi.Felles.Utility/Validation/XmlValidationRunner.cs @@ -4,6 +4,8 @@ using System.Xml; using System.Xml.Schema; using Difi.Felles.Utility.Resources.Language; +using static Difi.Felles.Utility.Resources.Language.LanguageResource; +using static Difi.Felles.Utility.Resources.Language.LanguageResourceKey; namespace Difi.Felles.Utility.Validation { @@ -11,10 +13,10 @@ internal class XmlValidationRunner { internal static readonly List ToleratedErrors = new List { - LanguageResource.GetResource(LanguageResourceEnum.ToleratedXsdIdError, Language.Norwegian), - LanguageResource.GetResource(LanguageResourceEnum.ToleratedXsdIdError, Language.English), - LanguageResource.GetResource(LanguageResourceEnum.ToleratedPrefixListError, Language.Norwegian), - LanguageResource.GetResource(LanguageResourceEnum.ToleratedPrefixListError, Language.English), + GetResource(ToleratedXsdIdError, Language.Norwegian), + GetResource(ToleratedXsdIdError, Language.English), + GetResource(ToleratedPrefixListError, Language.Norwegian), + GetResource(ToleratedPrefixListError, Language.English), }; internal XmlValidationRunner(XmlSchemaSet xmlSchemaSet) diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index 81027dc..0b1eebc 100755 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -1,12 +1,11 @@ using System.Reflection; -using System.Runtime.CompilerServices; [assembly: AssemblyCompany("Direktoratet for forvaltning og IKT (Difi)")] [assembly: AssemblyTrademark("Direktoratet for forvaltning og IKT (Difi)")] [assembly: AssemblyProduct("Difi Felles Utility")] [assembly: AssemblyDescription("Bibliotek brukt av Difi i klientbiblioteker")] -[assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("1.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0")] +[assembly: AssemblyVersion("1.1.0")] +[assembly: AssemblyFileVersion("1.1.0")] +[assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyCopyright("© 2015-2016 Direktoratet for forvaltning og IKT (Difi)")] [assembly: AssemblyCulture("")] From ddc0bce65b1768c2279b7939a58bb83b8c5f769f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Aas=20Sja=CC=8Afjell?= Date: Tue, 6 Dec 2016 09:13:21 +0100 Subject: [PATCH 6/6] R# opprydding --- Difi.Felles.Utility.Resources/Language/LanguageResource.cs | 3 +-- Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs | 4 ++-- Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs | 2 -- Difi.Felles.Utility.Tester/CertificateValidatorTests.cs | 2 -- Difi.Felles.Utility.Tester/LanguageResourceTests.cs | 3 +-- Difi.Felles.Utility/CertificateChainValidator.cs | 2 +- Difi.Felles.Utility/CertificateValidator.cs | 2 +- Difi.Felles.Utility/Validation/XmlValidationRunner.cs | 2 +- SharedAssemblyInfo.cs | 2 +- 9 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs index 895db37..5b5a35f 100755 --- a/Difi.Felles.Utility.Resources/Language/LanguageResource.cs +++ b/Difi.Felles.Utility.Resources/Language/LanguageResource.cs @@ -1,7 +1,6 @@ using System; using System.Reflection; using System.Resources; -using Difi.Felles.Utility.Resources.Language.Data; namespace Difi.Felles.Utility.Resources.Language { @@ -38,4 +37,4 @@ private static ResourceManager GetManagerForLanguage(Language language) } } } -} +} \ No newline at end of file diff --git a/Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs b/Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs index b8d09b8..ada9853 100755 --- a/Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs +++ b/Difi.Felles.Utility.Resources/Language/LanguageResourceKey.cs @@ -4,7 +4,7 @@ public enum LanguageResourceKey { //X509Certificate2Extensions CertificateShortDescription, - + //XSD Validation ToleratedXsdIdError, ToleratedPrefixListError, @@ -19,4 +19,4 @@ public enum LanguageResourceKey CertificateNotActivatedResult, CertificateExpiredResult } -} +} \ No newline at end of file diff --git a/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs b/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs index 8d0f527..f15b0d7 100755 --- a/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs +++ b/Difi.Felles.Utility.Tester/CertificateChainValidatorTests.cs @@ -1,5 +1,4 @@ using Difi.Felles.Utility.Resources.Certificate; -using Difi.Felles.Utility.Resources.Language; using Difi.Felles.Utility.Utilities; using Xunit; @@ -12,7 +11,6 @@ public class ValidateCertificateChain : CertificateChainValidatorTests [Fact] public void Fails_with_self_signed_certificate() { - //Arrange var selfSignedCertificate = CertificateResource.UnitTests.GetEnhetstesterSelvsignertSertifikat(); var certificateChainValidator = new CertificateChainValidator(CertificateChainUtility.ProduksjonsSertifikater()); diff --git a/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs b/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs index 9e83e93..9094932 100755 --- a/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs +++ b/Difi.Felles.Utility.Tester/CertificateValidatorTests.cs @@ -1,5 +1,4 @@ using Difi.Felles.Utility.Resources.Certificate; -using Difi.Felles.Utility.Resources.Language; using Difi.Felles.Utility.Utilities; using Xunit; @@ -21,7 +20,6 @@ public void Returns_fail_if_certificate_error() //Assert Assert.Equal(CertificateValidationType.InvalidCertificate, result.Type); Assert.Contains("gikk ut", result.Message); - } [Fact] diff --git a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs index ced8be6..4b90824 100755 --- a/Difi.Felles.Utility.Tester/LanguageResourceTests.cs +++ b/Difi.Felles.Utility.Tester/LanguageResourceTests.cs @@ -29,7 +29,6 @@ public void Get_resource_with_temporary_language() Assert.True(resource.Contains("The 'PrefixList' attribute is invalid")); Assert.Equal(Language.Norwegian, LanguageResource.CurrentLanguage); } - } } -} +} \ No newline at end of file diff --git a/Difi.Felles.Utility/CertificateChainValidator.cs b/Difi.Felles.Utility/CertificateChainValidator.cs index 1966dd1..5631137 100755 --- a/Difi.Felles.Utility/CertificateChainValidator.cs +++ b/Difi.Felles.Utility/CertificateChainValidator.cs @@ -143,7 +143,7 @@ private static CertificateValidationResult UsedExternalCertificatesResult(X509Ce { var externalCertificatesUsedMessage = string.Format( - GetResource(CertificateUsedExternalResult), + GetResource(CertificateUsedExternalResult), certificate.ToShortString(), chainAsString, validatorCertificatesAsString); return new CertificateValidationResult(CertificateValidationType.InvalidChain, externalCertificatesUsedMessage); diff --git a/Difi.Felles.Utility/CertificateValidator.cs b/Difi.Felles.Utility/CertificateValidator.cs index 890af90..4eea477 100755 --- a/Difi.Felles.Utility/CertificateValidator.cs +++ b/Difi.Felles.Utility/CertificateValidator.cs @@ -62,7 +62,7 @@ private static CertificateValidationResult NotIssuedToOrganizationResult(X509Cer { var notIssuedToOrganizationResult = string.Format(GetResource(CertificateNotIssuedToOrganization), certificateOrganizationNumber); return new CertificateValidationResult( - CertificateValidationType.InvalidCertificate, + CertificateValidationType.InvalidCertificate, certificate.ToShortString(notIssuedToOrganizationResult)); } diff --git a/Difi.Felles.Utility/Validation/XmlValidationRunner.cs b/Difi.Felles.Utility/Validation/XmlValidationRunner.cs index ead6f50..a959b0f 100755 --- a/Difi.Felles.Utility/Validation/XmlValidationRunner.cs +++ b/Difi.Felles.Utility/Validation/XmlValidationRunner.cs @@ -16,7 +16,7 @@ internal class XmlValidationRunner GetResource(ToleratedXsdIdError, Language.Norwegian), GetResource(ToleratedXsdIdError, Language.English), GetResource(ToleratedPrefixListError, Language.Norwegian), - GetResource(ToleratedPrefixListError, Language.English), + GetResource(ToleratedPrefixListError, Language.English) }; internal XmlValidationRunner(XmlSchemaSet xmlSchemaSet) diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index 0b1eebc..778f456 100755 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -8,4 +8,4 @@ [assembly: AssemblyFileVersion("1.1.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyCopyright("© 2015-2016 Direktoratet for forvaltning og IKT (Difi)")] -[assembly: AssemblyCulture("")] +[assembly: AssemblyCulture("")] \ No newline at end of file