Skip to content

Commit

Permalink
Merge pull request #20 from Pkcs11Interop/maintenance
Browse files Browse the repository at this point in the history
Maintenance cycle 2021
  • Loading branch information
jariq committed Sep 27, 2021
2 parents ff30332 + 89e9ea5 commit 26a4a5e
Show file tree
Hide file tree
Showing 39 changed files with 150 additions and 147 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ Pkcs11Interop.X509Store
=======================
**Easy to use PKCS#11 based X.509 certificate store**

[![Build Status](https://dev.azure.com/Pkcs11Interop/Pkcs11Interop.X509Store/_apis/build/status/Pkcs11Interop.Pkcs11Interop.X509Store?branchName=master)](https://dev.azure.com/Pkcs11Interop/Pkcs11Interop.X509Store/_build/latest?definitionId=1&branchName=master)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/Pkcs11Interop/Pkcs11Interop.X509Store/blob/master/LICENSE.md)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/l5hr66s6dnmajh0y/branch/master?svg=true)](https://ci.appveyor.com/project/pkcs11interop/pkcs11interop-x509store/branch/master)
[![NuGet](https://img.shields.io/badge/nuget-pkcs11interop.x509store-blue.svg)](https://www.nuget.org/packages/Pkcs11Interop.X509Store/)
[![Stack Overflow](https://img.shields.io/badge/stack-pkcs11interop-blue.svg)](https://stackoverflow.com/questions/tagged/pkcs11interop)
[![Twitter](https://img.shields.io/badge/twitter-p11interop-blue.svg)](https://twitter.com/p11interop)

**WARNING: Pkcs11Interop.X509Store is still in a very early stage of development and its API may fundamentally change with any subsequent release.**
Expand Down Expand Up @@ -37,7 +38,7 @@ Archives with the source code and binaries can be downloaded from [our releases

## License

Pkcs11Interop.X509Store is available under the terms of the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
Pkcs11Interop.X509Store is available under the terms of the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
[Human friendly license summary](https://tldrlegal.com/l/apache2) is available at tldrlegal.com but the [full license text](LICENSE.md) always prevails.

## Support
Expand All @@ -46,9 +47,9 @@ Pkcs11Interop.X509Store is still in a very early stage of development so if you

## Related projects

* [Pkcs11Interop](http://www.pkcs11interop.net/)
* [Pkcs11Interop](https://www.pkcs11interop.net/)
Managed .NET wrapper for unmanaged PKCS#11 libraries.
* [Pkcs11Admin](http://www.pkcs11admin.net/)
* [Pkcs11Admin](https://www.pkcs11admin.net/)
GUI tool for administration of PKCS#11 enabled devices based on Pkcs11Interop library.
* [PKCS11-LOGGER](https://github.com/Pkcs11Interop/pkcs11-logger)
PKCS#11 logging proxy module useful for debugging of PKCS#11 enabled applications.
Expand All @@ -57,5 +58,5 @@ Pkcs11Interop.X509Store is still in a very early stage of development so if you

## About

Pkcs11Interop.X509Store has been written for the Pkcs11Interop project by [Jaroslav Imrich](http://www.jimrich.sk).
Please visit project website - [pkcs11interop.net](http://www.pkcs11interop.net) - for more information.
Pkcs11Interop.X509Store has been written for the Pkcs11Interop project by [Jaroslav Imrich](https://www.jimrich.sk).
Please visit project website - [pkcs11interop.net](https://www.pkcs11interop.net) - for more information.
33 changes: 33 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 0.3-{build}

branches:
only:
- master

skip_tags: true

environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
Platform: net461
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
Platform: netstandard2.0
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
Platform: netstandard2.0
- APPVEYOR_BUILD_WORKER_IMAGE: macos
Platform: netstandard2.0

build_script:
- cmd: cd build && nuget-build.bat
- sh: dotnet --info && dotnet restore -p:Configuration=Release -p:Platform="Any CPU" -v normal ./src/ && dotnet build -p:Configuration=Release -p:Platform="Any CPU" -v normal ./src/

test_script:
- cmd: IF "%Platform%"=="net461" (nunit3-console .\src\Pkcs11Interop.X509Store.Tests\bin\Release\net48\Pkcs11Interop.X509Store.Tests.dll --result=myresults.xml;format=AppVeyor)
- cmd: IF "%Platform%"=="netstandard2.0" (cd .\src\Pkcs11Interop.X509Store.Tests\ && nuget install Appveyor.TestLogger && cd ..\..)
- cmd: IF "%Platform%"=="netstandard2.0" (dotnet vstest .\src\Pkcs11Interop.X509Store.Tests\bin\Release\netcoreapp3.1\Pkcs11Interop.X509Store.Tests.dll --Framework:".NETCoreApp,Version=v3.1" --TestAdapterPath:. --logger:Appveyor)
- sh: cd ./src/Pkcs11Interop.X509Store.Tests/ && nuget install -Source https://api.nuget.org/v3/index.json Appveyor.TestLogger && cd ../..
- sh: dotnet test -f netcoreapp3.1 --test-adapter-path:. --logger:Appveyor ./src/Pkcs11Interop.X509Store.Tests/

artifacts:
- path: build/nuget-unsigned/
name: Pkcs11Interop.X509Store
74 changes: 0 additions & 74 deletions azure-pipelines.yml

This file was deleted.

8 changes: 7 additions & 1 deletion build/nuget-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
set workingdir=%~dp0
set outputdir=%workingdir%nuget-unsigned

@rem Initialize build environment of Visual Studio 2017 Community/Professional/Enterprise
@rem Initialize build environment of Visual Studio 2017 or 2019 Community/Professional/Enterprise
@set tools=
@set tmptools="c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsMSBuildCmd.bat"
@if exist %tmptools% set tools=%tmptools%
@set tmptools="c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsMSBuildCmd.bat"
@if exist %tmptools% set tools=%tmptools%
@set tmptools="c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat"
@if exist %tmptools% set tools=%tmptools%
@set tmptools="c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsMSBuildCmd.bat"
@if exist %tmptools% set tools=%tmptools%
@set tmptools="c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsMSBuildCmd.bat"
@if exist %tmptools% set tools=%tmptools%
@set tmptools="c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsMSBuildCmd.bat"
@if exist %tmptools% set tools=%tmptools%
@if not defined tools goto :error
call %tools%
@echo on
Expand Down
10 changes: 3 additions & 7 deletions build/nuget-sign.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set SEVENZIP="c:\Program Files\7-Zip\7z.exe"
set SIGNTOOL="C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe"

@rem Define signing options
set CERTHASH=ef1bfeaa474bb078923831bf7732186673a5b5c9
set CERTHASH=d4ba72939a46bac6dd31dad895a9901ace0d56f6
set TSAURL=http://time.certum.pl/
set LIBNAME=Pkcs11Interop.X509Store
set LIBURL=https://www.pkcs11interop.net/
Expand All @@ -31,13 +31,8 @@ rmdir /S /Q package || goto :error
del /Q *.xml || goto :error
del /Q *.nupkg || goto :error

@rem Sign all assemblies using SHA1withRSA algorithm
%SIGNTOOL% sign /sha1 %CERTHASH% /fd sha1 /tr %TSAURL% /td sha1 /d %LIBNAME% /du %LIBURL% ^
lib\net461\Pkcs11Interop.X509Store.dll ^
lib\netstandard2.0\Pkcs11Interop.X509Store.dll || goto :error

@rem Sign all assemblies using SHA256withRSA algorithm
%SIGNTOOL% sign /sha1 %CERTHASH% /as /fd sha256 /tr %TSAURL% /td sha256 /d %LIBNAME% /du %LIBURL% ^
%SIGNTOOL% sign /sha1 %CERTHASH% /fd sha256 /tr %TSAURL% /td sha256 /d %LIBNAME% /du %LIBURL% ^
lib\net461\Pkcs11Interop.X509Store.dll ^
lib\netstandard2.0\Pkcs11Interop.X509Store.dll || goto :error

Expand All @@ -51,6 +46,7 @@ copy %inputdir%\*.snupkg . || goto :error
rmdir /S /Q lib || goto :error
del /Q *.nuspec || goto :error
del /Q *.txt || goto :error
del /Q *.png || goto :error

@echo *** SIGN SUCCESSFUL ***
@endlocal
Expand Down
2 changes: 1 addition & 1 deletion src/Pkcs11Interop.X509Store.Tests/CryptoObjects.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Pkcs11Interop.X509Store.Tests/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<TargetFrameworks>net48;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<RootNamespace>Net.Pkcs11Interop.X509Store.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Pkcs11Interop" Version="5.0.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.5.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Pkcs11Interop" Version="5.1.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.10" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Pkcs11Interop.X509Store.Tests/Pkcs11RsaProviderTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
25 changes: 21 additions & 4 deletions src/Pkcs11Interop.X509Store.Tests/SignedXmlTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
*/

using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Text;
Expand Down Expand Up @@ -47,14 +48,19 @@ public void MsdnSignedXmlTest()
// Get software based public key
RSA rsaPublicKey = cert.Info.ParsedCertificate.PublicKey.Key as RSA;

// Determine paths
string basePath = GetBasePath();
string plainXmlFilePath = Path.Combine(basePath, "Example.xml");
string signedXmlFilePath = Path.Combine(basePath, "SignedExample.xml");

// Create an XML file to sign
CreateSomeXml("Example.xml");
CreateSomeXml(plainXmlFilePath);

// Sign the XML that was just created and save it in a new file
SignXmlFile("Example.xml", "SignedExample.xml", rsaPrivateKey);
SignXmlFile(plainXmlFilePath, signedXmlFilePath, rsaPrivateKey);

// Verify the signature of the signed XML
bool result = VerifyXmlFile("SignedExample.xml", rsaPublicKey);
bool result = VerifyXmlFile(signedXmlFilePath, rsaPublicKey);

// Check the results of the signature verification
Assert.IsTrue(result);
Expand Down Expand Up @@ -159,5 +165,16 @@ public static void CreateSomeXml(string FileName)
document.WriteTo(xmltw);
xmltw.Close();
}

/// <summary>
/// Gets absolute path of directory where the test assembly is located
/// </summary>
/// <returns>Absolute path of directory where the test assembly is located</returns>
public static string GetBasePath()
{
string basePath = typeof(SoftHsm2Manager).Assembly.CodeBase;
basePath = new Uri(basePath).LocalPath;
return Path.GetDirectoryName(basePath);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
32 changes: 23 additions & 9 deletions src/Pkcs11Interop.X509Store.Tests/SoftHsm2/SoftHsm2Manager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 The Pkcs11Interop Project
* Copyright 2017-2021 The Pkcs11Interop Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,34 +78,48 @@ public static IPinProvider PinProvider

static SoftHsm2Manager()
{
// Determine base path
string basePath = typeof(SoftHsm2Manager).Assembly.CodeBase;
basePath = new Uri(basePath).LocalPath;
basePath = Path.GetDirectoryName(basePath);

// Create directory for SoftHSM2 tokens
if (!Directory.Exists($@"SoftHsm2{Path.DirectorySeparatorChar}tokens{Path.DirectorySeparatorChar}"))
Directory.CreateDirectory($@"SoftHsm2{Path.DirectorySeparatorChar}tokens{Path.DirectorySeparatorChar}");
string tokensDir = Path.Combine(basePath, "SoftHsm2", "tokens");
if (!Directory.Exists(tokensDir))
Directory.CreateDirectory(tokensDir);

// Determine path of configuration file
string configPath = Path.Combine(basePath, "SoftHsm2", "softhsm2.conf");

// Update contents of configuration file
string configContent = File.ReadAllText(configPath);
configContent = configContent.Replace("__TOKENDIR__", tokensDir);
File.WriteAllText(configPath, configContent);

// Setup environment variable with path to configuration file
EnvironmentHelper.SetEnvironmentVariable("SOFTHSM2_CONF", $@"SoftHsm2{Path.DirectorySeparatorChar}softhsm2.conf");
EnvironmentHelper.SetEnvironmentVariable("SOFTHSM2_CONF", configPath);

// Determine path to PKCS#11 library
if (Platform.IsWindows)
{
if (Platform.Uses64BitRuntime)
_libraryPath = $@"SoftHsm2\windows\softhsm2-x64.dll";
_libraryPath = Path.Combine(basePath, "SoftHsm2", "windows", "softhsm2-x64.dll");
else
_libraryPath = $@"SoftHsm2\windows\softhsm2.dll";
_libraryPath = Path.Combine(basePath, "SoftHsm2", "windows", "softhsm2.dll");
}
else if (Platform.IsLinux)
{
if (Platform.Uses64BitRuntime)
_libraryPath = $@"SoftHsm2/linux/libsofthsm2.so";
_libraryPath = Path.Combine(basePath, "SoftHsm2", "linux", "libsofthsm2.so");
else
throw new UnsupportedPlatformException("Pkcs11Interop.X509Store.Tests cannot be run on 32-bit Linux");
}
else if (Platform.IsMacOsX)
{
if (Platform.Uses64BitRuntime)
_libraryPath = $@"SoftHsm2/osx/libsofthsm2.so";
_libraryPath = Path.Combine(basePath, "SoftHsm2", "osx", "libsofthsm2.so");
else
throw new UnsupportedPlatformException("Pkcs11Interop.X509Store.Tests cannot be run on 32-bit OSX");
throw new UnsupportedPlatformException("Pkcs11Interop.X509Store.Tests cannot be run on 32-bit macOS");
}
else
{
Expand Down

0 comments on commit 26a4a5e

Please sign in to comment.