From deb3f120ca57edd86efac6360227e353b8ce1b25 Mon Sep 17 00:00:00 2001 From: Erich Barnstedt Date: Fri, 23 Jun 2017 15:52:41 +0200 Subject: [PATCH] Small cleanup of cert factory I/F, removing implicit default parameters. --- .../ApplicationInstance.cs | 8 ++- .../Samples/NetCoreConsoleClient/Program.cs | 11 +++- .../Certificates/CertificateFactory.cs | 51 ++----------------- 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs b/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs index bdea696f8b..3d4a94dfb7 100644 --- a/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs +++ b/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs @@ -1251,12 +1251,18 @@ namespace Opc.Ua.Configuration X509Certificate2 certificate = CertificateFactory.CreateCertificate( id.StoreType, id.StorePath, + null, configuration.ApplicationUri, configuration.ApplicationName, id.SubjectName, serverDomainNames, minimumKeySize, - lifeTimeInMonths + DateTime.UtcNow - TimeSpan.FromDays(1), + lifeTimeInMonths, + CertificateFactory.defaultHashSize, + false, + null, + null ); id.Certificate = certificate; diff --git a/SampleApplications/Samples/NetCoreConsoleClient/Program.cs b/SampleApplications/Samples/NetCoreConsoleClient/Program.cs index c7158523cf..4c569be180 100644 --- a/SampleApplications/Samples/NetCoreConsoleClient/Program.cs +++ b/SampleApplications/Samples/NetCoreConsoleClient/Program.cs @@ -95,9 +95,18 @@ namespace NetCoreConsoleClient X509Certificate2 certificate = CertificateFactory.CreateCertificate( config.SecurityConfiguration.ApplicationCertificate.StoreType, config.SecurityConfiguration.ApplicationCertificate.StorePath, + null, config.ApplicationUri, config.ApplicationName, - config.SecurityConfiguration.ApplicationCertificate.SubjectName + config.SecurityConfiguration.ApplicationCertificate.SubjectName, + null, + CertificateFactory.defaultKeySize, + DateTime.UtcNow - TimeSpan.FromDays(1), + CertificateFactory.defaultLifeTime, + CertificateFactory.defaultHashSize, + false, + null, + null ); config.SecurityConfiguration.ApplicationCertificate.Certificate = certificate; diff --git a/Stack/Opc.Ua.Core/Security/Certificates/CertificateFactory.cs b/Stack/Opc.Ua.Core/Security/Certificates/CertificateFactory.cs index 2427e97885..9ea9d28dbd 100644 --- a/Stack/Opc.Ua.Core/Security/Certificates/CertificateFactory.cs +++ b/Stack/Opc.Ua.Core/Security/Certificates/CertificateFactory.cs @@ -154,48 +154,6 @@ public class CertificateFactory return certificate; } - /// - /// Creates a self signed application instance certificate. - /// - /// Type of certificate store (Directory) . - /// The store path (syntax depends on storeType). - /// The application uri (created if not specified). - /// Name of the application (optional if subjectName is specified). - /// The subject used to create the certificate (optional if applicationName is specified). - /// The domain names that can be used to access the server machine (defaults to local computer name if not specified). - /// Size of the key (1024, 2048 or 4096). - /// The lifetime of the key in months. - /// The hash size in bits. - /// The certificate with a private key. - public static X509Certificate2 CreateCertificate( - string storeType, - string storePath, - string applicationUri, - string applicationName, - string subjectName = null, - IList serverDomainNames = null, - ushort keySize = defaultKeySize, - ushort lifetimeInMonths = defaultLifeTime, - ushort hashSizeInBits = defaultHashSize - ) - { - return CreateCertificate( - storeType, - storePath, - null, - applicationUri, - applicationName, - subjectName, - serverDomainNames, - keySize, - DateTime.UtcNow - TimeSpan.FromDays(1), - lifetimeInMonths, - hashSizeInBits, - false, - null - ); - } - /// /// Creates a self signed application instance certificate. /// @@ -227,7 +185,7 @@ public class CertificateFactory ushort hashSizeInBits, bool isCA, X509Certificate2 issuerCAKeyCert, - byte[] publicKey = null) + byte[] publicKey) { if (issuerCAKeyCert != null) { @@ -244,8 +202,7 @@ public class CertificateFactory ref subjectName, ref domainNames, ref keySize, - ref lifetimeInMonths, - isCA); + ref lifetimeInMonths); using (var cfrg = new CertificateFactoryRandomGenerator()) { @@ -459,6 +416,7 @@ public class CertificateFactory return certificate; } #endregion + #region Private Methods /// /// Sets the parameters to suitable defaults. @@ -469,8 +427,7 @@ public class CertificateFactory ref string subjectName, ref IList domainNames, ref ushort keySize, - ref ushort lifetimeInMonths, - bool isCA) + ref ushort lifetimeInMonths) { // enforce recommended keysize unless lower value is enforced. if (keySize < 1024)