Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Dotnet 8 and use new preview UA .Net Package #10

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions GDSwithREST.Domain/Entities/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ public Application()
public string ServerCapabilities { get; set; } = null!;
public byte[] Certificate { get; set; } = Array.Empty<byte>();
public byte[]? HttpsCertificate { get; set; }
public int? TrustListId { get; set; }
public int? HttpsTrustListId { get; set; }

public CertificateStore HttpsTrustList { get; set; } = null!;
public CertificateStore TrustList { get; set; } = null!;
public string? TrustListId { get; set; }
public string? HttpsTrustListId { get; set; }
public ICollection<ApplicationName> ApplicationNames { get; set; }
public ICollection<CertificateRequest> CertificateRequests { get; set; }
public ICollection<ServerEndpoint> ServerEndpoints { get; set; }
Expand Down
18 changes: 0 additions & 18 deletions GDSwithREST.Domain/Entities/CertificateStore.cs

This file was deleted.

6 changes: 3 additions & 3 deletions GDSwithREST.Domain/GDSwithREST.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Gds.Server.Common" Version="1.4.372.106" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Gds.Server.Common" Version="1.5.374.26-preview" />
</ItemGroup>

</Project>
14 changes: 0 additions & 14 deletions GDSwithREST.Domain/Repositories/ICertificateStoreRepository.cs

This file was deleted.

60 changes: 44 additions & 16 deletions GDSwithREST.Domain/Services/ApplicationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,43 +577,71 @@ public override bool GetApplicationCertificate(

public override bool SetApplicationTrustLists(
NodeId applicationId,
string trustListId,
string httpsTrustListId
string certificateTypeId,
string trustListId
)
{
using var scope = _serviceScopeFactory.CreateScope();
var applicationRepository = scope.ServiceProvider.GetRequiredService<IApplicationRepository>();
var certificateStoreRepository = scope.ServiceProvider.GetRequiredService<ICertificateStoreRepository>();

Guid id = GetNodeIdGuid(applicationId);
var application = applicationRepository.GetApplicationById(id).Result;

if (application == null)
if (application == null || string.IsNullOrEmpty(trustListId))
{
return false;
}

application.TrustListId = null;
application.HttpsTrustListId = null;

if (trustListId != null)
if(certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.ApplicationCertificateType))
{
application.TrustListId = trustListId;
}
if(certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.HttpsCertificateType))
{
var certificateStore = certificateStoreRepository.GetCertificateStoreByPath(httpsTrustListId);
application.HttpsTrustListId = trustListId;
}

applicationRepository.SaveChanges();

if (certificateStore != null)
return true;
}

public override bool GetApplicationTrustLists(
NodeId applicationId,
string certificateTypeId,
out string trustListId
)
{
trustListId = null!;
using var scope = _serviceScopeFactory.CreateScope();
var applicationRepository = scope.ServiceProvider.GetRequiredService<IApplicationRepository>();

Guid id = GetNodeIdGuid(applicationId);
var application = applicationRepository.GetApplicationById(id).Result;

if (application == null)
{
return false;
}

if (certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.ApplicationCertificateType))
{
if(string.IsNullOrEmpty(application.TrustListId))
{
application.TrustListId = certificateStore.Id;
return false;
}
trustListId = application.TrustListId;
return true;
}

if (httpsTrustListId != null)
if (certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.HttpsCertificateType))
{
var certificateStore = certificateStoreRepository.GetCertificateStoreByPath(httpsTrustListId);

if (certificateStore != null)
if (string.IsNullOrEmpty(application.HttpsTrustListId))
{
application.HttpsTrustListId = certificateStore.Id;
return false;
}
trustListId = application.HttpsTrustListId;
return true;
}

applicationRepository.SaveChanges();
Expand Down
12 changes: 8 additions & 4 deletions GDSwithREST.Domain/Services/CertificateGroupService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Opc.Ua;
using Opc.Ua.Gds.Server;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;

namespace GDSwithREST.Domain.Services
Expand All @@ -10,9 +11,10 @@ public class CertificateGroupService : CertificateGroup, ICertificateGroupServic

public override CertificateGroupService Create(
string storePath,
CertificateGroupConfiguration certificateGroupConfiguration)
CertificateGroupConfiguration certificateGroupConfiguration,
[Optional] string trustedIssuerCertificatesStorePath)
{
var cg = new CertificateGroupService(storePath, certificateGroupConfiguration);
var cg = new CertificateGroupService(storePath, certificateGroupConfiguration, trustedIssuerCertificatesStorePath);
CertificateGroups.Add(cg);
return cg;
}
Expand All @@ -21,10 +23,12 @@ public CertificateGroupService() : base() { }

protected CertificateGroupService(
string authoritiesStorePath,
CertificateGroupConfiguration certificateGroupConfiguration
CertificateGroupConfiguration certificateGroupConfiguration,
[Optional] string trustedIssuerCertificatesStorePath
)
: base(authoritiesStorePath,
certificateGroupConfiguration)
certificateGroupConfiguration,
trustedIssuerCertificatesStorePath)
{ }

public async Task<X509Certificate2Collection> GetTrustList()
Expand Down
15 changes: 7 additions & 8 deletions GDSwithREST.Domain/Services/GdsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using Opc.Ua.Configuration;
using Opc.Ua.Gds.Server;
using Opc.Ua.Gds.Server.Database;
using Opc.Ua.Gds.Server.Database.Linq;
using static Org.BouncyCastle.Math.EC.ECCurve;
using Opc.Ua.Server.UserDatabase;

namespace GDSwithREST.Domain.Services
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public async Task StartServer(CancellationToken stoppingToken)
// get the DatabaseStorePath configuration parameter.
GlobalDiscoveryServerConfiguration gdsConfiguration = _applicationInstance.ApplicationConfiguration.ParseExtension<GlobalDiscoveryServerConfiguration>();
string usersDatabaseStorePath = Utils.ReplaceSpecialFolderNames(gdsConfiguration.UsersDatabaseStorePath);
var usersDatabase = JsonUsersDatabase.Load(usersDatabaseStorePath);
var usersDatabase = JsonUserDatabase.Load(usersDatabaseStorePath);
//await _certificateGroup.Init();
var gdsServer = new GlobalDiscoverySampleServer(
_applications,
Expand All @@ -61,12 +60,12 @@ public async Task StartServer(CancellationToken stoppingToken)
//start GDS
await _applicationInstance.Start(gdsServer);

//trust GDS CA
var defaultCertificateGroup = _certificateGroups.CertificateGroups.SingleOrDefault(cg => cg.Id.Identifier is (uint)CertificateGroupType.DefaultApplicationGroup);
if (defaultCertificateGroup is null)
throw new Exception("Failed to initialze GDS CA Certifcate");
////trust GDS CA
//var defaultCertificateGroup = _certificateGroups.CertificateGroups.SingleOrDefault(cg => cg.Id.Identifier is (uint)CertificateGroupType.DefaultApplicationGroup);
//if (defaultCertificateGroup is null)
// throw new Exception("Failed to initialze GDS CA Certifcate");

await _applicationInstance.AddOwnCertificateToTrustedStoreAsync(defaultCertificateGroup.Certificate, stoppingToken);
//await _applicationInstance.AddOwnCertificateToTrustedStoreAsync(defaultCertificateGroup.Certificate, stoppingToken);

var endpoints = _applicationInstance.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct();

Expand Down
14 changes: 7 additions & 7 deletions GDSwithREST.Infrastructure/GDSwithREST.Infrastructure.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 0 additions & 31 deletions GDSwithREST.Infrastructure/GdsDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public GdsDbContext(DbContextOptions<GdsDbContext> options)
public virtual DbSet<ApplicationName> ApplicationNames { get; set; }
public virtual DbSet<Application> Applications { get; set; }
public virtual DbSet<CertificateRequest> CertificateRequests { get; set; }
public virtual DbSet<CertificateStore> CertificateStores { get; set; }
public virtual DbSet<ServerEndpoint> ServerEndpoints { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Expand Down Expand Up @@ -52,12 +51,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Application>(entity =>
{
entity.HasIndex(e => e.HttpsTrustListId)
.HasDatabaseName("IX_FK_Applications_HttpsTrustListId");

entity.HasIndex(e => e.TrustListId)
.HasDatabaseName("IX_FK_Applications_TrustListId");

entity.Property(e => e.HttpsTrustListId).IsRequired(false);

entity.Property(e => e.TrustListId).IsRequired(false);
Expand All @@ -78,17 +71,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

entity.Property(e => e.ServerCapabilities).HasMaxLength(500);

entity.HasOne(d => d.HttpsTrustList)
.WithMany(p => p.ApplicationsHttpsTrustList)
.HasForeignKey(d => d.HttpsTrustListId)
.HasConstraintName("FK_Applications_HttpsTrustListId")
.OnDelete(DeleteBehavior.ClientSetNull);

entity.HasOne(d => d.TrustList)
.WithMany(p => p.ApplicationsTrustList)
.HasForeignKey(d => d.TrustListId)
.HasConstraintName("FK_Applications_TrustListId")
.OnDelete(DeleteBehavior.ClientSetNull);
});

modelBuilder.Entity<CertificateRequest>(entity =>
Expand Down Expand Up @@ -122,19 +104,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasConstraintName("FK_CertificateRequests_Applications");
});

modelBuilder.Entity<CertificateStore>(entity =>
{
entity.Property(e => e.Id).HasColumnName("ID");

entity.Property(e => e.AuthorityId)
.HasMaxLength(50)
.IsRequired(false);

entity.Property(e => e.Path)
.IsRequired()
.HasMaxLength(256);
});

modelBuilder.Entity<ServerEndpoint>(entity =>
{
entity.HasIndex(e => e.ApplicationId)
Expand Down
Loading
Loading