Skip to content

Commit

Permalink
feat: add support for bitstring statuslist
Browse files Browse the repository at this point in the history
Refs: #80
  • Loading branch information
Phil91 committed Nov 11, 2024
1 parent 1c89bc1 commit 3247656
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 75 deletions.
2 changes: 2 additions & 0 deletions charts/dim/templates/cronjob-processes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ spec:
value: "{{ .Values.processesworker.provisioning.encryptionConfigs.index0.cipherMode }}"
- name: "DIM__ENCRYPTIONCONFIGS__0__PADDINGMODE"
value: "{{ .Values.processesworker.provisioning.encryptionConfigs.index0.paddingMode }}"
- name: "DIM__STATUSLISTTYPE"
value: "{{ .Values.processesworker.dim.statusListType }}"
- name: "PROVISIONING__CLIENTID"
value: "{{ .Values.processesworker.provisioning.clientId }}"
- name: "PROVISIONING__CLIENTSECRET"
Expand Down
3 changes: 3 additions & 0 deletions charts/dim/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ processesworker:
memory: 300M
dim:
applicationName: ""
# -- Sets the type of the status list which will be created for the issuer wallet
# -- valid types are: StatusList2021, BitstringStatusList
statusListType: "BitstringStatusList"
provisioning:
clientId: ""
clientSecret: ""
Expand Down
11 changes: 6 additions & 5 deletions src/clients/Dim.Clients/Api/Dim/DimClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Dim.Clients.Api.Dim.Models;
using Dim.Clients.Extensions;
using Dim.Clients.Token;
using Dim.DbAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions;
using System.Net.Http.Json;
Expand Down Expand Up @@ -61,7 +62,7 @@ public async Task<CompanyData> GetCompanyData(BasicAuthSettings dimAuth, string
}
}

public async Task<string> GetStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, CancellationToken cancellationToken)
public async Task<string> GetStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, StatusListType statusListType, CancellationToken cancellationToken)
{
var client = await basicAuthTokenService.GetBasicAuthorizedClient<DimClient>(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
var result = await client.GetAsync($"{dimBaseUrl}/api/v2.0.0/companyIdentities/{companyId}/revocationLists", cancellationToken)
Expand All @@ -76,23 +77,23 @@ public async Task<string> GetStatusList(BasicAuthSettings dimAuth, string dimBas
var response = await result.Content
.ReadFromJsonAsync<StatusListListResponse>(JsonSerializerExtensions.Options, cancellationToken)
.ConfigureAwait(ConfigureAwaitOptions.None);
if (response?.Data == null || !response.Data.Any(x => x.RemainingSpace > 0))
if (response?.Data == null || !response.Data.Where(x => x.Type == statusListType.ToString()).Any(x => x.RemainingSpace > 0))
{
throw new ConflictException("There is no status list with remaining space, please create a new one.");
}

return response.Data.First(x => x.RemainingSpace > 0).StatusListCredential;
return response.Data.First(x => x.RemainingSpace > 0 && x.Type == statusListType.ToString()).StatusListCredential;
}
catch (JsonException je)
{
throw new ServiceException(je.Message);
}
}

public async Task<string> CreateStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, CancellationToken cancellationToken)
public async Task<string> CreateStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, StatusListType statusListType, CancellationToken cancellationToken)
{
var client = await basicAuthTokenService.GetBasicAuthorizedClient<DimClient>(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
var data = new CreateStatusListRequest(new CreateStatusListPaypload(new CreateStatusList("StatusList2021", DateTimeOffset.UtcNow.ToString("yyyyMMdd"), "New revocation list", 2097152)));
var data = new CreateStatusListRequest(new CreateStatusListPaypload(new CreateStatusList(statusListType.ToString(), DateTimeOffset.UtcNow.ToString("yyyyMMdd"), "New revocation list", 2097152)));
var result = await client.PostAsJsonAsync($"{dimBaseUrl}/api/v2.0.0/companyIdentities/{companyId}/revocationLists", data, JsonSerializerExtensions.Options, cancellationToken)
.CatchingIntoServiceExceptionFor("assign-application", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE,
async m =>
Expand Down
5 changes: 3 additions & 2 deletions src/clients/Dim.Clients/Api/Dim/IDimClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

using Dim.Clients.Api.Dim.Models;
using Dim.Clients.Token;
using Dim.DbAccess.Models;

namespace Dim.Clients.Api.Dim;

public interface IDimClient
{
Task<CompanyData> GetCompanyData(BasicAuthSettings dimAuth, string dimBaseUrl, string tenantName, string application, CancellationToken cancellationToken);
Task<string> GetStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, CancellationToken cancellationToken);
Task<string> CreateStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, CancellationToken cancellationToken);
Task<string> GetStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, StatusListType statusListType, CancellationToken cancellationToken);
Task<string> CreateStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, StatusListType statusListType, CancellationToken cancellationToken);
}
1 change: 0 additions & 1 deletion src/clients/Dim.Clients/Api/Div/IProvisioningClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
********************************************************************************/

using Dim.Clients.Api.Div.Models;
using Dim.Clients.Token;

namespace Dim.Clients.Api.Div;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Dim.Clients.Api.Div.Models;
Expand Down
4 changes: 0 additions & 4 deletions src/clients/Dim.Clients/Api/Div/ProvisioningClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions;
using System;
using System.Linq;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Dim.Clients.Api.Div;

Expand Down
4 changes: 4 additions & 0 deletions src/clients/Dim.Clients/Dim.Clients.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions" Version="2.13.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\database\Dim.DbAccess\Dim.DbAccess.csproj" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions src/clients/Dim.Clients/Token/IBasicAuthTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Dim.Clients.Token;

public interface IBasicAuthTokenService
Expand Down
27 changes: 27 additions & 0 deletions src/database/Dim.DbAccess/Models/StatusListType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/********************************************************************************
* Copyright (c) 2024 BMW Group AG
* Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

namespace Dim.DbAccess.Models;

public enum StatusListType
{
StatusList2021 = 1,
BitstringStatusList = 2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Dim.DbAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Validation;
using System.ComponentModel.DataAnnotations;
Expand All @@ -35,4 +36,7 @@ public class DimHandlerSettings
[Required]
[DistinctValues("x => x.Index")]
public IEnumerable<EncryptionModeConfig> EncryptionConfigs { get; set; } = null!;

[Required]
public StatusListType StatusListType { get; set; }
}
2 changes: 1 addition & 1 deletion src/processes/DimProcess.Library/DimProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public class DimProcessHandler(
ClientId = clientId,
ClientSecret = secret
};
await dimClient.CreateStatusList(dimAuth, baseUrl, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
await dimClient.CreateStatusList(dimAuth, baseUrl, companyId.Value, _settings.StatusListType, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

return new ValueTuple<IEnumerable<ProcessStepTypeId>?, ProcessStepStatusId, bool, string?>(
Enumerable.Repeat(ProcessStepTypeId.SEND_CALLBACK, 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

using Dim.Clients.Api.Div;
using Dim.Clients.Api.Div.Models;
using Dim.Clients.Token;
using Dim.DbAccess;
using Dim.DbAccess.Extensions;
using Dim.DbAccess.Repositories;
Expand Down
23 changes: 12 additions & 11 deletions src/processes/Processes.Worker/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@
"DimDb": "Server=placeholder;Database=placeholder;Port=5432;User Id=placeholder;Password=placeholder;Ssl Mode=Disable;"
},
"Dim": {
"ApplicationName": ""
"ApplicationName": "",
"EncryptionConfigIndex": 0,
"EncryptionConfigs": [
{
"Index": 0,
"EncryptionKey": "",
"CipherMode": "",
"PaddingMode": ""
}
],
"StatusListType": ""
},
"Processes": {
"LockExpirySeconds": 300
Expand All @@ -34,16 +44,7 @@
"ClientSecret": "",
"TokenAddress": "",
"BaseUrl": "",
"GrantType": "",
"EncryptionConfigIndex": 0,
"EncryptionConfigs": [
{
"Index": 0,
"EncryptionKey": "",
"CipherMode": "",
"PaddingMode": ""
}
]
"GrantType": ""
},
"Callback": {
"Username": "",
Expand Down
8 changes: 4 additions & 4 deletions src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task StartSetupDim(string companyName, string bpn, string didDocume
await dimRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task<string> GetStatusList(string bpn, CancellationToken cancellationToken)
public async Task<string> GetStatusList(string bpn, StatusListType statusListType, CancellationToken cancellationToken)
{
var (exists, companyId, baseUrl, walletData) = await dimRepositories.GetInstance<ITenantRepository>().GetCompanyAndWalletDataForBpn(bpn).ConfigureAwait(ConfigureAwaitOptions.None);
var (tokenAddress, clientId, clientSecret, initializationVector, encryptionMode) = walletData.ValidateData();
Expand Down Expand Up @@ -90,10 +90,10 @@ public async Task<string> GetStatusList(string bpn, CancellationToken cancellati
ClientId = clientId,
ClientSecret = secret
};
return await dimClient.GetStatusList(dimAuth, baseUrl, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
return await dimClient.GetStatusList(dimAuth, baseUrl, companyId.Value, statusListType, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task<string> CreateStatusList(string bpn, CancellationToken cancellationToken)
public async Task<string> CreateStatusList(string bpn, StatusListType statusListType, CancellationToken cancellationToken)
{
var (exists, companyId, baseUrl, walletData) = await dimRepositories.GetInstance<ITenantRepository>().GetCompanyAndWalletDataForBpn(bpn).ConfigureAwait(ConfigureAwaitOptions.None);
var (tokenAddress, clientId, clientSecret, initializationVector, encryptionMode) = walletData.ValidateData();
Expand Down Expand Up @@ -121,7 +121,7 @@ public async Task<string> CreateStatusList(string bpn, CancellationToken cancell
ClientId = clientId,
ClientSecret = secret
};
return await dimClient.CreateStatusList(dimAuth, baseUrl, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
return await dimClient.CreateStatusList(dimAuth, baseUrl, companyId.Value, statusListType, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task CreateTechnicalUser(string bpn, TechnicalUserData technicalUserData)
Expand Down
4 changes: 2 additions & 2 deletions src/web/Dim.Web/BusinessLogic/IDimBusinessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace Dim.Web.BusinessLogic;
public interface IDimBusinessLogic : ITransient
{
Task StartSetupDim(string companyName, string bpn, string didDocumentLocation, bool isIssuer);
Task<string> GetStatusList(string bpn, CancellationToken cancellationToken);
Task<string> CreateStatusList(string bpn, CancellationToken cancellationToken);
Task<string> GetStatusList(string bpn, StatusListType statusListType, CancellationToken cancellationToken);
Task<string> CreateStatusList(string bpn, StatusListType statusListType, CancellationToken cancellationToken);
Task CreateTechnicalUser(string bpn, TechnicalUserData technicalUserData);
Task DeleteTechnicalUser(string bpn, TechnicalUserData technicalUserData);
Task<ProcessData> GetSetupProcess(string bpn, string companyName);
Expand Down
22 changes: 13 additions & 9 deletions src/web/Dim.Web/Controllers/DimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class DimController
public static RouteGroupBuilder MapDimApi(this RouteGroupBuilder group)
{
var dim = group.MapGroup("/dim");
const string BpnDescription = "bpn of the company";

dim.MapPost("setup-dim", ([FromQuery] string companyName, [FromQuery] string bpn, [FromQuery] string didDocumentLocation, IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.StartSetupDim(companyName, bpn, didDocumentLocation, false))
.WithSwaggerDescription("Creates a holder wallet",
Expand All @@ -53,31 +54,34 @@ public static RouteGroupBuilder MapDimApi(this RouteGroupBuilder group)
.RequireAuthorization(r => r.RequireRole("setup_wallet"))
.Produces(StatusCodes.Status201Created);

dim.MapGet("status-list", ([FromQuery] string bpn, CancellationToken cancellationToken, [FromServices] IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.GetStatusList(bpn, cancellationToken))
dim.MapGet("status-list", ([AsParameters] GetStatusListParameters parameters, CancellationToken cancellationToken, [FromServices] IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.GetStatusList(parameters.Bpn, parameters.StatusListType, cancellationToken))
.WithSwaggerDescription("Gets the status list for the given company",
"Example: GET: api/dim/status-list/{bpn}",
"id of the dim company")
"Example: GET: api/dim/status-list/{bpn}/{statusListType}",
"id of the dim company",
"The type of the statuslist to receive")
.RequireAuthorization(r => r.RequireRole("view_status_list"))
.Produces(StatusCodes.Status200OK, responseType: typeof(string), contentType: Constants.JsonContentType);

dim.MapPost("status-list", ([FromQuery] string bpn, CancellationToken cancellationToken, [FromServices] IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.CreateStatusList(bpn, cancellationToken))
dim.MapPost("status-list", ([AsParameters] CreateStatusListParameters parameters, CancellationToken cancellationToken, [FromServices] IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.CreateStatusList(parameters.Bpn, parameters.StatusListType, cancellationToken))
.WithSwaggerDescription("Creates a status list for the given company",
"Example: Post: api/dim/status-list/{bpn}",
"bpn of the company")
BpnDescription,
"The type of the statuslist that should be created")
.RequireAuthorization(r => r.RequireRole("create_status_list"))
.AllowAnonymous()
.Produces(StatusCodes.Status200OK, responseType: typeof(string), contentType: Constants.JsonContentType);

dim.MapPost("technical-user/{bpn}", ([FromRoute] string bpn, [FromBody] TechnicalUserData technicalUserData, [FromServices] IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.CreateTechnicalUser(bpn, technicalUserData))
.WithSwaggerDescription("Creates a technical user for the dim of the given bpn",
"Example: Post: api/dim/technical-user/{bpn}",
"bpn of the company")
BpnDescription)
.RequireAuthorization(r => r.RequireRole("create_technical_user"))
.Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType);

dim.MapPost("technical-user/{bpn}/delete", ([FromRoute] string bpn, [FromBody] TechnicalUserData technicalUserData, [FromServices] IDimBusinessLogic dimBusinessLogic) => dimBusinessLogic.DeleteTechnicalUser(bpn, technicalUserData))
.WithSwaggerDescription("Deletes a technical user with the given name of the given bpn",
"Example: Post: api/dim/technical-user/{bpn}/delete",
"bpn of the company")
BpnDescription)
.RequireAuthorization(r => r.RequireRole("delete_technical_user"))
.Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType);

Expand All @@ -89,7 +93,7 @@ public static RouteGroupBuilder MapDimApi(this RouteGroupBuilder group)
)
.WithSwaggerDescription("Gets the wallet creation process id for the given bpn and companyName",
"Example: Post: api/dim/process/setup?bpn={bpn}&companyName={companyName}",
"bpn of the company",
BpnDescription,
"name of the company")
.RequireAuthorization(r => r.RequireRole("get_process"))
.Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType);
Expand All @@ -103,7 +107,7 @@ public static RouteGroupBuilder MapDimApi(this RouteGroupBuilder group)
)
.WithSwaggerDescription("Gets the technical user creation process id for the given technicalUserName",
"Example: Post: api/dim/process/technical-user?bpn={bpn}&companyName={companyName}&technicalUserName={technicalUserName}",
"bpn of the company",
BpnDescription,
"name of the company",
"name of the techincal user to get the process for")
.RequireAuthorization(r => r.RequireRole("get_process"))
Expand Down
33 changes: 33 additions & 0 deletions src/web/Dim.Web/Models/CreateStatusListParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************************************************************************
* Copyright (c) 2024 BMW Group AG
* Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Dim.DbAccess.Models;
using Microsoft.AspNetCore.Mvc;

namespace Dim.Web.Models;

public struct CreateStatusListParameters
{
[FromQuery]
public string Bpn { get; set; }

[FromQuery]
public StatusListType StatusListType { get; set; }
}
Loading

0 comments on commit 3247656

Please sign in to comment.