Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/coverity-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x # SDK Version to use.
dotnet-version: 10.0.x # SDK Version to use.

- name: Cache Nuget packages
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-build-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x # SDK Version to use.
dotnet-version: 10.0.x # SDK Version to use.

- name: Cache Nuget packages
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x # SDK Version to use.
dotnet-version: 10.0.x # SDK Version to use.

- name: Cache Nuget packages
uses: actions/cache@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x # SDK Version to use.
dotnet-version: 10.0.x # SDK Version to use.

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.1
Expand All @@ -45,4 +45,4 @@ jobs:
run: msbuild src/WebEid.Security.sln /t:Build /p:Configuration=Release

- name: Test
run: vstest.console.exe src/WebEid.Security.Tests/bin/Release/net8.0/WebEID.Security.Tests.dll
run: vstest.console.exe src/WebEid.Security.Tests/bin/Release/net10.0/WebEID.Security.Tests.dll
3 changes: 2 additions & 1 deletion .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x # SDK Version to use.
dotnet-version: 10.0.x # SDK Version to use.

- name: Set up JDK 21
uses: actions/setup-java@v4
Expand Down Expand Up @@ -71,5 +71,6 @@ jobs:
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"web-eid_web-eid-authtoken-validation-dotnet" /o:"web-eid" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" /d:sonar.verbose=true /d:sonar.token="$env:SONAR_TOKEN" /d:sonar.host.url="https://sonarcloud.io"
dotnet build --configuration Release --no-restore src/WebEid.Security.sln
dotnet format src/WebEid.Security.sln --verify-no-changes --no-restore
dotnet test src/WebEid.Security.sln --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover --results-directory "TestResults"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="$env:SONAR_TOKEN"
308 changes: 274 additions & 34 deletions README.md

Large diffs are not rendered by default.

77 changes: 60 additions & 17 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Web eID ASP.NET example

![European Regional Development Fund](https://github.com/open-eid/DigiDoc4-Client/blob/master/client/images/EL_Regionaalarengu_Fond.png)
<img src="src/WebEid.AspNetCore.Example/wwwroot/img/eu-fund-flags.jpg" width="300" alt="European Regional Development Fund">

This project is an example ASP.NET web application that shows how to implement strong authentication and digital signing with electronic ID smart cards using Web eID.

More information about the Web eID project is available on the project [website](https://web-eid.eu/).

The ASP.NET web application makes use of the following technologies:

- ASP.NET MVC,
- the Web eID authentication token validation library [_web-eid-authtoken-validation-dotnet_](https://github.com/web-eid/web-eid-authtoken-validation-dotnet),
- the Web eID JavaScript library [_web-eid.js_](https://github.com/web-eid/web-eid.js),
- the digital signing library [_libdigidocpp_](https://github.com/open-eid/libdigidocpp/tree/master/examples/DigiDocCSharp).

## Quickstart

Complete the steps below to run the example application in order to test authentication and digital signing with Web eID.
Expand Down Expand Up @@ -91,8 +84,8 @@ Set up the `libdigidocpp` library as follows:

1. Install the _libdigidocpp-4.0.0.8301.x64.msi_ package or higher. The installation packages are available from [https://github.com/open-eid/libdigidocpp/releases](https://github.com/open-eid/libdigidocpp/releases).
2. Copy the C# source files from the `libdigidocpp` installation folder `include\digidocpp_csharp` to the `src\WebEid.AspNetCore.Example\DigiDoc` folder.
3. Copy all files from the `libdigidocpp` installation folder to the example application build output folder `bin\Debug\net8.0` (after building, see next step).
* Windows: Also copy folder `schema` from `libdigidocpp` installation folder to the example application build output folder `bin\Debug\net8.0`
3. Copy all files from the `libdigidocpp` installation folder to the example application build output folder `bin\Debug\net10.0` (after building, see next step).
* Windows: Also copy folder `schema` from `libdigidocpp` installation folder to the example application build output folder `bin\Debug\net10.0`
4. When running in the `Development` profile, create an empty file named `EE_T.xml` for TSL cache as described in the [_Using test TSL lists_](https://github.com/open-eid/libdigidocpp/wiki/Using-test-TSL-lists#preconditions) section of the `libdigidocpp` wiki.

#### For Ubuntu Linux
Expand Down Expand Up @@ -123,7 +116,7 @@ Set up the `libdigidocpp` library as follows:

1. Install the *libdigidocpp_4.0.0.1460.pkg* package or higher. The installation packages are available from [https://github.com/open-eid/libdigidocpp/releases](https://github.com/open-eid/libdigidocpp/releases).
2. Copy the C# source files from `/Library/libdigidocpp/include/digidocpp_csharp` directory to `src/WebEid.AspNetCore.Example/DigiDoc` directory.
3. Go to `bin/Debug/net8.0` directory and create symbolic link to `/Library/libdigidocpp/lib/libdigidoc_csharp.dylib` library:
3. Go to `bin/Debug/net10.0` directory and create symbolic link to `/Library/libdigidocpp/lib/libdigidoc_csharp.dylib` library:
```cmd
ln -s /Library/libdigidocpp/lib/libdigidoc_csharp.dylib
```
Expand All @@ -132,7 +125,7 @@ Further information is available in the [libdigidocpp example C# application sou

### 5. Build the application

You need to have the [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) installed for building the application package.
You need to have the [.NET 10.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/10.0) installed for building the application package.
Build the application by running the following command in a terminal window under the `src` directory:

```cmd
Expand Down Expand Up @@ -160,7 +153,32 @@ This will activate the `https` profile in the `launchSettings.json` and launch t
When the application has started, open your preferred web browser on the address defined in `launchSettings.json` on the `applicationUrl` field at `https` profile and follow instructions on the front page.
By default the address is https://localhost:44391.

## Overview of the source code
## Table of contents

* [Quickstart](#quickstart)
* [Setup for Development](#setup-for-development)
* [Overview of the project](#overview-of-the-project)
+ [Overview of the source code](#overview-of-the-source-code)
+ [Requesting the signing certificate in a separate step](#requesting-the-signing-certificate-in-a-separate-step)
* [More information](#more-information)
+ [Frequently asked questions](#frequently-asked-questions)
- [Why do I get the `System.ApplicationException: Failed to verify OCSP Responder certificate` error during signing?](#why-do-i-get-the-systemapplicationexception-failed-to-verify-ocsp-responder-certificate-error-during-signing)
* [Building and running example web application with Docker on Ubuntu Linux](#building-and-running-example-web-application-with-docker-on-ubuntu-linux)
+ [Prerequisites](#prerequisites)
+ [Building the application](#building-the-application)
+ [Building the Docker image](#building-the-docker-image)
* [Running the Docker container with HTTPS support](#running-the-docker-container-with-https-support)

## Overview of the project

The ASP.NET web application makes use of the following technologies:

- ASP.NET MVC,
- the Web eID authentication token validation library [_web-eid-authtoken-validation-dotnet_](https://github.com/web-eid/web-eid-authtoken-validation-dotnet),
- the Web eID JavaScript library [_web-eid.js_](https://github.com/web-eid/web-eid.js),
- the digital signing library [_libdigidocpp_](https://github.com/open-eid/libdigidocpp/tree/master/examples/DigiDocCSharp).

### Overview of the source code

The `src\WebEid.AspNetCore.Example` directory contains the ASP.NET application source code and resources. The subdirectories therein have the following purpose:
- `wwwroot`: web server static content, including CSS and JavaScript files,
Expand All @@ -170,8 +188,23 @@ The `src\WebEid.AspNetCore.Example` directory contains the ASP.NET application s
- logging in,
- digital signing,
- `DigiDoc`: contains the C# binding files of the `libdigidocpp` library; these files must be copied from the `libdigidocpp` installation directory `\include\digidocpp_csharp`,
- `Dto`: data transfer objects used by the Web API endpoints,
- `Pages`: Razor pages,
- `Signing`: Web eID signing service implementation that uses `libdigidocpp`.
- `Services`: helper services for cleaning up signing containers and for building the mobile authentication and signing request URIs,
- `Signing`: Web eID signing service implementation that uses `libdigidocpp`,
- `SigningService`: prepares signing containers and finalizes signatures,
- `MobileSigningService`: orchestrates the mobile signing flow (builds mobile signing requests/responses) and supports requesting the signing certificate in a separate step when enabled by configuration,
- `Options`: strongly-typed configuration classes for mobile Web eID settings such as `BaseRequestUri` and `RequestSigningCert` (when set to false, initiates a separate signing-certificate flow to demo requesting the certificate without prior authentication, as the signing certificate normally comes from the authentication flow).

### Requesting the signing certificate in a separate step

In some deployments, the signing certificate is not reused from the authentication flow. Instead, it is retrieved directly from the user’s ID-card during the signing process itself.

This approach is useful when the signing process is performed without a prior authentication step. For example, in a mobile flow, the user may start signing directly without authenticating beforehand. In such cases, the signing certificate must be requested separately from the user’s ID-card before the signature can be created.

When this mode is enabled in the configuration, the backend issues a separate request for the signing certificate using the `MobileSigningService`. The service communicates with the client to obtain the certificate before the signing container is prepared, ensuring that the correct certificate chain is available for the signature.

This behavior is controlled by the `RequestSigningCert` flag in the `appsettings.json` configuration files (`appsettings.json`, `appsettings.Development.json`). When the flag is set to **false**, the application explicitly requests the signing certificate during the signing process, demonstrating the separate signing certificate retrieval flow. When set to **true**, the signing uses the signing certificate that was already obtained during authentication, and no additional request is made.

## More information

Expand All @@ -192,7 +225,7 @@ then please follow these steps in this chapter to build a Docker image in Ubuntu

Before you begin, ensure you have the following installed on your system:

- .NET SDK 8.0
- .NET SDK 10.0
- libdigidocpp-csharp

You can install them using the following commands:
Expand All @@ -205,7 +238,7 @@ sudo apt update
```
then install the packages
```sh
sudo apt install dotnet-sdk-8.0 libdigidocpp-csharp
sudo apt install dotnet-sdk-10.0 libdigidocpp-csharp
```
Add a NuGet package source for web-eid-authtoken-validation-dotnet library:

Expand Down Expand Up @@ -238,7 +271,7 @@ To build the application, follow these steps:

4. Update the `OriginUrl` in the `appsettings.json` to match your production environment. Please replace https://localhost:8443 with your actual domain name where you intend to run the application:
```sh
sed -i 's#"OriginUrl": "https://localhost:44391"#"OriginUrl": "https://localhost:8443"#' WebEid.AspNetCore.Example/bin/Release/net8.0/publish/appsettings.json
sed -i 's#"OriginUrl": "https://localhost:44391"#"OriginUrl": "https://example.com"#' WebEid.AspNetCore.Example/bin/Release/net10.0/publish/appsettings.json
```

### Building the Docker image
Expand Down Expand Up @@ -299,3 +332,13 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions
By default, this middleware is already enabled in the application.

A Docker Compose configuration file `docker-compose.yml` is available in the `src` directory for running the Docker image `web-eid-asp-dotnet-example` on port 8480 behind a reverse proxy.

# Code formatting

The project uses `.editorconfig` for .NET code formatting rules.

To format the library code, run:

```bash
dotnet format example/src/WebEid.AspNetCore.Example.sln --no-restore
```
2 changes: 1 addition & 1 deletion example/src/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
LICENSE
README.md

!WebEid.AspNetCore.Example/bin/Release/net8.0/publish/
!WebEid.AspNetCore.Example/bin/Release/net10.0/publish/
Loading
Loading