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

feat add windows compilation support #54

Open
wants to merge 29 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
62808c7
feat add windows support
agrandville Jun 29, 2021
8b52bc6
fix cmake minimal version
agrandville Jun 29, 2021
37b6ada
fix build set version
agrandville Jun 29, 2021
0bfde54
fix disable appveyor remote desktop
agrandville Jun 29, 2021
6306bc6
fix static cast size_t to CK_ULONG
agrandville Jun 29, 2021
7dc0df0
feat add Win64 compilation support
agrandville Jun 29, 2021
e6db92d
fix appveyor error 'version already exists'
agrandville Jun 29, 2021
9a83334
fix windows CMake generator name
agrandville Jun 29, 2021
223a83b
fix downgrade to Visual Studio 14 2015
agrandville Jun 29, 2021
e0f7c14
doc add windows compilation notes
agrandville Jun 29, 2021
ed359d6
feat publish github release
agrandville Jun 30, 2021
1e143db
fix change artifact zip path
agrandville Jun 30, 2021
762c472
fix change artifact zip path
agrandville Jun 30, 2021
c229b27
Update .appveyor.yml
agrandville Jun 30, 2021
8ad94de
Update CMakeLists.txt
agrandville Jun 30, 2021
ae4eb73
Update .appveyor.yml
agrandville Jun 30, 2021
292cb09
Update .appveyor.yml
agrandville Jun 30, 2021
172a6dc
Update .appveyor.yml
agrandville Jun 30, 2021
83838a4
feat release appVeyor builds
agrandville Jun 30, 2021
c75abcb
feat disable appveyor RDP on finish
agrandville Jun 30, 2021
8322301
fix PR regression
agrandville Jun 30, 2021
92fa357
fix merge win32/cryptoki.h with pkcs11-env.h
agrandville Jun 30, 2021
38dd4a7
fix remove getopt source
agrandville Jul 1, 2021
6644bdc
Import pristine copy of NetBSD getopt code
agrandville Jul 1, 2021
524e6aa
fix windows portability
agrandville Jul 1, 2021
2decd75
fix update getopt build
agrandville Jul 1, 2021
f5a1536
fix remove unnecessary include
agrandville Jul 1, 2021
71f3f71
fix remove unnecessary GTest libraries
agrandville Jul 1, 2021
0c8badc
fix remove appveyor RDP on finish
agrandville Jul 1, 2021
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
35 changes: 35 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 0.0.0-{build}
configuration: Release
platform:
- x86
#- x64
cache:
- C:/Tools/vcpkg/installed/
environment:
APPVEYOR_SAVE_CACHE_ON_ERROR: true
matrix:
- GENERATOR: "Visual Studio 14 2015"
TARGET: x86-windows
- GENERATOR: "Visual Studio 14 2015 Win64"
TARGET: x64-windows
install:
# Update vcpkg
- cd c:\tools\vcpkg
- cmd: git fetch
- cmd: git checkout 2021.05.12
- cmd: bootstrap-vcpkg.bat
- cmd: vcpkg install gtest:x86-windows
- cmd: vcpkg install gtest:x64-windows
- cmd: vcpkg update
- cmd: vcpkg upgrade --no-dry-run
build_script:
- cmd: if exist "C:\projects\pkcs11test\build" rd /s /q C:\projects\pkcs11test\build
- cmd: mkdir C:\projects\pkcs11test\build
- cmd: cd C:\projects\pkcs11test\build
- cmd: vcpkg integrate install
- cmd: cmake .. -G "%GENERATOR%" -DVCPKG_TARGET_TRIPLET=%TARGET% -DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake
- cmd: cmake --build . --config RelWithDebInfo
- cmd: ctest -C RelWithDebInfo --progress --verbose
- cmd: cmake -DCMAKE_INSTALL_PREFIX=out/ -DCMAKE_INSTALL_CONFIG_NAME=RelWithDebInfo -P cmake_install.cmake
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
agrandville marked this conversation as resolved.
Show resolved Hide resolved
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(p11test)


set(SOURCES cipher.cc
describe.cc
digest.cc
dual.cc
globals.cc
hmac.cc
init.cc
key.cc
keypair.cc
login.cc
object.cc
pkcs11-describe.cc
pkcs11test.cc
rng.cc
session.cc
sign.cc
slot.cc
tookan.cc
)

if(MSVC)
list(APPEND INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/win32)

list(APPEND SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/third_party/win32/getopt.cpp)

endif()

list(APPEND INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/pkcs11)


find_package(GTest CONFIG REQUIRED COMPONENTS CXX_LIB)
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIRS} )

if(${VCPKG_TARGET_TRIPLET} MATCHES ".*windows-static$")
message(FATAL_ERROR "GTest library doesn't support static linking for now")
# switch to MultiThreaded runtime library (MT) vs MultiThreaded DLL (MD)
set_property(TARGET ${PROJECT_NAME} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()



install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)

#get_cmake_property(_variableNames VARIABLES)
#list (SORT _variableNames)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
38 changes: 38 additions & 0 deletions NOTES.WIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Building pkcs11test for Windows

This document describes process of building both 32-bit and 64-bit versions of pkcs11test on 64-bit Windows machine.

## Required software

- [Visual Studio](https://visualstudio.microsoft.com/vs/community/) (Community)
- [C/C++ dependency manager from Microsoft](https://vcpkg.io/)
- [CMake](https://cmake.org/)

## Prepare working directories

set P11TEST_HOME=C:\Projects\pkcs11test
set VCPKG_HOME=C:\Projects\vcpkg

## Build GTest

cd %VCPKG_HOME%
bootstrap-vcpkg.bat
vcpkg install gtest:x86-windows
vcpkg install gtest:x64-windows
vcpkg integrate install

## Build pkcs11test
git clone https://github.com/google/pkcs11test.git %P11TEST_HOME%
## x86
mkdir %P11TEST_HOME%\tmp
cd %P11TEST_HOME%\tmp
cmake .. -A Win32 -DCMAKE_TOOLCHAIN_FILE=%VCPKG_HOME%/scripts/buildsystems/vcpkg.cmake
cmake --build . --config RelWithDebInfo
cmake -DCMAKE_INSTALL_PREFIX=%P11TEST_HOME%\out32 -DCMAKE_INSTALL_CONFIG_NAME=RelWithDebInfo -P cmake_install.cmake

## x64
mkdir %P11TEST_HOME%\tmp
cd %P11TEST_HOME%\tmp
cmake .. -A x64 -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_TOOLCHAIN_FILE=%VCPKG_HOME%/scripts/buildsystems/vcpkg.cmake
cmake --build . --config RelWithDebInfo
cmake -DCMAKE_INSTALL_PREFIX=%P11TEST_HOME%\out64 -DCMAKE_INSTALL_CONFIG_NAME=RelWithDebInfo -P cmake_install.cmake
4 changes: 2 additions & 2 deletions cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ TEST_F(ReadOnlySessionTest, CreateSecretKeyAttributes) {
{CKA_DECRYPT, (CK_VOID_PTR)&g_ck_true, sizeof(CK_BBOOL)},
{CKA_CLASS, &key_class, sizeof(key_class)},
{CKA_KEY_TYPE, (CK_VOID_PTR)&key_type, sizeof(key_type)},
{CKA_VALUE, (CK_VOID_PTR)key.data(), key.size()},
{CKA_VALUE, (CK_VOID_PTR)key.data(), static_cast<CK_ULONG>(key.size())},
};
CK_OBJECT_HANDLE key_object;
ASSERT_CKR_OK(g_fns->C_CreateObject(session_, attrs.data(), attrs.size(), &key_object));
Expand Down Expand Up @@ -626,7 +626,7 @@ TEST_F(ReadOnlySessionTest, SecretKeyTestVectors) {
{CKA_DECRYPT, (CK_VOID_PTR)&g_ck_true, sizeof(CK_BBOOL)},
{CKA_CLASS, &key_class, sizeof(key_class)},
{CKA_KEY_TYPE, (CK_VOID_PTR)&key_type, sizeof(key_type)},
{CKA_VALUE, (CK_VOID_PTR)key.data(), key.size()},
{CKA_VALUE, (CK_VOID_PTR)key.data(), static_cast<CK_ULONG>(key.size())},
};
CK_OBJECT_HANDLE key_object;
ASSERT_CKR_OK(g_fns->C_CreateObject(session_, attrs.data(), attrs.size(), &key_object));
Expand Down
7 changes: 7 additions & 0 deletions digest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#include <cstdlib>
#include "pkcs11test.h"


#ifdef _WIN32
#include <windows.h>
#include <stdlib.h>
#endif
agrandville marked this conversation as resolved.
Show resolved Hide resolved


#include <map>
#include <sstream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion hmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ TEST_F(ReadOnlySessionTest, HmacTestVectors) {
{CKA_VERIFY, (CK_VOID_PTR)&g_ck_true, sizeof(CK_BBOOL)},
{CKA_CLASS, &key_class, sizeof(key_class)},
{CKA_KEY_TYPE, (CK_VOID_PTR)&key_type, sizeof(key_type)},
{CKA_VALUE, (CK_VOID_PTR)key.data(), key.size()},
{CKA_VALUE, (CK_VOID_PTR)key.data(), static_cast<CK_ULONG>(key.size())},
};
CK_OBJECT_HANDLE key_object;
ASSERT_CKR_OK(g_fns->C_CreateObject(session_, attrs.data(), attrs.size(), &key_object));
Expand Down
20 changes: 10 additions & 10 deletions keypair.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ TEST_F(ReadOnlySessionTest, CreateKeyPairObjects) {
{CKA_PRIVATE, (CK_VOID_PTR)&g_ck_false, sizeof(CK_BBOOL)},
{CKA_CLASS, &public_key_class, sizeof(public_key_class)},
{CKA_KEY_TYPE, (CK_VOID_PTR)&key_type, sizeof(key_type)},
{CKA_PUBLIC_EXPONENT, (CK_VOID_PTR)public_exponent.data(), public_exponent.size()},
{CKA_MODULUS, (CK_VOID_PTR)public_modulus.data(), public_modulus.size()},
{CKA_PUBLIC_EXPONENT, (CK_VOID_PTR)public_exponent.data(), static_cast<CK_ULONG>(public_exponent.size())},
{CKA_MODULUS, (CK_VOID_PTR)public_modulus.data(), static_cast<CK_ULONG>(public_modulus.size())},
};
EXPECT_CKR_OK(g_fns->C_CreateObject(session_,
public_attrs.data(),
Expand All @@ -254,34 +254,34 @@ TEST_F(ReadOnlySessionTest, CreateKeyPairObjects) {
{CKA_PRIVATE, (CK_VOID_PTR)&g_ck_false, sizeof(CK_BBOOL)},
{CKA_CLASS, &private_key_class, sizeof(private_key_class)},
{CKA_KEY_TYPE, (CK_VOID_PTR)&key_type, sizeof(key_type)},
{CKA_PUBLIC_EXPONENT, (CK_VOID_PTR)public_exponent.data(), public_exponent.size()},
{CKA_PRIVATE_EXPONENT, (CK_BYTE_PTR)private_exponent.data(), private_exponent.size()},
{CKA_MODULUS, (CK_VOID_PTR)public_modulus.data(), public_modulus.size()},
{CKA_PUBLIC_EXPONENT, (CK_VOID_PTR)public_exponent.data(), static_cast<CK_ULONG>(public_exponent.size())},
{CKA_PRIVATE_EXPONENT, (CK_BYTE_PTR)private_exponent.data(), static_cast<CK_ULONG>(private_exponent.size())},
{CKA_MODULUS, (CK_VOID_PTR)public_modulus.data(), static_cast<CK_ULONG>(public_modulus.size())},
};
string prime1data;
if (!keydata.prime1.empty()) {
prime1data = hex_decode(keydata.prime1);
private_attrs.push_back({CKA_PRIME_1, (CK_BYTE_PTR)prime1data.data(), prime1data.size()});
private_attrs.push_back({CKA_PRIME_1, (CK_BYTE_PTR)prime1data.data(), static_cast<CK_ULONG>(prime1data.size())});
}
string prime2data;
if (!keydata.prime2.empty()) {
prime2data = hex_decode(keydata.prime2);
private_attrs.push_back({CKA_PRIME_2, (CK_BYTE_PTR)prime2data.data(), prime2data.size()});
private_attrs.push_back({CKA_PRIME_2, (CK_BYTE_PTR)prime2data.data(), static_cast<CK_ULONG>(prime2data.size())});
}
string exponent1data;
if (!keydata.exponent1.empty()) {
exponent1data = hex_decode(keydata.exponent1);
private_attrs.push_back({CKA_EXPONENT_1, (CK_BYTE_PTR)exponent1data.data(), exponent1data.size()});
private_attrs.push_back({CKA_EXPONENT_1, (CK_BYTE_PTR)exponent1data.data(),static_cast<CK_ULONG>(exponent1data.size())});
}
string exponent2data;
if (!keydata.exponent2.empty()) {
exponent2data = hex_decode(keydata.exponent2);
private_attrs.push_back({CKA_EXPONENT_2, (CK_BYTE_PTR)exponent2data.data(), exponent2data.size()});
private_attrs.push_back({CKA_EXPONENT_2, (CK_BYTE_PTR)exponent2data.data(), static_cast<CK_ULONG>(exponent2data.size())});
}
string coefficientdata;
if (!keydata.coefficient.empty()) {
coefficientdata = hex_decode(keydata.coefficient);
private_attrs.push_back({CKA_COEFFICIENT, (CK_BYTE_PTR)coefficientdata.data(), coefficientdata.size()});
private_attrs.push_back({CKA_COEFFICIENT, (CK_BYTE_PTR)coefficientdata.data(), static_cast<CK_ULONG>(coefficientdata.size())});
}
EXPECT_CKR_OK(g_fns->C_CreateObject(session_,
private_attrs.data(),
Expand Down
4 changes: 4 additions & 0 deletions pkcs11-env.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifdef _WIN32
#include "cryptoki.h"
#else
/* From 2.1 of [PKCS11-base-v2.40]: Cryptoki structures SHALL be packed with 1-byte alignment. */
#if defined(STRICT_P11)
# pragma pack(push, 1)
Expand All @@ -28,6 +31,7 @@
#ifndef NULL_PTR
#define NULL_PTR 0
#endif
#endif //_WIN32

#include <pkcs11.h>

Expand Down
Loading