Skip to content
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
.vscode
*.o
*.debhelper.log
obj-x86_64-linux-gnu
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.12)

project(ibmswtpm2 VERSION 1563 LANGUAGES C)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include (GNUInstallDirs)
include(TestBigEndian)

if(APPLE OR MSVC)
include(ConanAutoSetup)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(OpenSSL REQUIRED)
if(UNIX)
find_package(Threads REQUIRED)
endif()

add_subdirectory(src)
add_subdirectory(utils)
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,64 @@
This project is an implementation of the TCG TPM 2.0 specification. It is based on the TPM specification Parts 3 and 4 source code donated by Microsoft, with additional files to complete the implementation.

See the companion IBM TSS at https://sourceforge.net/projects/ibmtpm20tss/

# Building
## Dependencies
* For all platforms
* * cmake - http://cmake.org
* * openssl ( See conan instructions for Mac and Windows easy deps )
* Mac ( XCode and brew clang/gcc ) and Windows ( MSVC )
* * conan - http://conan.io

## Easy openssl dependency for Mac and Windows with Conan
* After install conan do:
```
mkdir build
cd build
conan profile new default --detect
conan install ..
```
On Windows Conan has preset binary dependencies for openssl 64 bits and MSVC 16 and up
If you get an error of non availability of openssl for your old MSVC build, you can execute
```
conan install .. --build *
```
This will rebuild the dependencies for your compiler

## Simple build instructions for Linux and Mac
Building is straightforward, as long you installed all dependencies:
```
mkdir build
cd build
cmake ..
make
```

## Simple build instructions for Windows Visual Studio
Build for Windows Visual Studio must be "almost" straightforward.
Builds are tested with MSVC
```
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
```

## Install
* Linux
On Linux, binary is installed in default sbin dir and an extra systemd service file is installed to start and stop the service.
No firewall exclusion files are included, so remember to open the required ports

* Mac and Windows
Install works, but only mac is guaranteed to end up in proper path

# Troubleshoot

## Windows has symbols / 32/64 bits mismatch
Only 64 bits compilations are tested with conan deps. If you installed openssl by your own, some possible issues:
* Your compiler is 64 bits and you have 32 bits deps, configure this way:
```
cmake -DCMAKE_BUILD_TYPE=Release -A win32 ..
```

## Mac You are using gcc or clang from Homebrew,ad Connan detected XCode Clang as default compiler
* Read profile section of Conan - https://docs.conan.io/en/latest/reference/profiles.html
16 changes: 16 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 1.0.{build}
image: Visual Studio 2019

install:
- cmd: echo "Downloading conan..."
- cmd: set PATH=%PATH%;%PYTHON%/Scripts/
- cmd: pip.exe install conan
- cmd: conan user # Create the conan data directory
- cmd: conan --version

build_script:
- cmd: mkdir build
- cmd: cd build
- cmd: conan install .. --build=missing
- cmd: cmake ..
- cmd: cmake --build . --config Release
2 changes: 2 additions & 0 deletions cmake/ConanAutoSetup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
5 changes: 5 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[requires]
openssl/1.1.1d

[generators]
cmake
4 changes: 4 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ibmswtpm2 (0.1.1563) unstable; urgency=low
* First cmake port release

-- Helio Chissini de Castro <helio@kde.org> Mon, 10 Feb 2020 20:20:00 +0100
19 changes: 19 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Source: ibmswtpm2
Maintainer: Helio Chissini de Castro <helio@kde.org>
Description: TPM2 Simulator
Priority: optional
Homepage: https://github.com/heliocastro/ibmswtpm2
Build-Depends: cmake (>= 3.0~),
libssl-dev (>= 1.1.0~),
debhelper-compat (= 12)
Section: Miscellaneous
Rules-Requires-Root: no
Standards-Version: 4.4.0

Package: tpm-server
Architecture: any
Section: Miscellaneous
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: This project is an implementation of the TCG TPM 2.0 specification.
It is based on the TPM specification Parts 3 and 4 source code
donated by Microsoft, with additional files to complete the implementation.
9 changes: 9 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/make -f

export DH_VERBOSE = 1

%:
dh $@

#override_dh_auto_install:
# dh_auto_install -- prefix=/usr
170 changes: 170 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
test_big_endian(BIG_ENDIAN)

add_executable(tpm_server
ACTCommands.c
ACT_spt.c
AlgorithmCap.c
AlgorithmTests.c
AsymmetricCommands.c
Attest_spt.c
AttestationCommands.c
AuditCommands.c
Bits.c
BnConvert.c
BnMath.c
BnMemory.c
Cancel.c
CapabilityCommands.c
Clock.c
ClockCommands.c
CommandAudit.c
CommandCodeAttributes.c
CommandDispatcher.c
ContextCommands.c
Context_spt.c
CryptDes.c
CryptCmac.c
CryptEccData.c
CryptEccKeyExchange.c
CryptEccMain.c
CryptEccSignature.c
CryptHash.c
CryptPrime.c
CryptPrimeSieve.c
CryptRand.c
CryptRsa.c
CryptSelfTest.c
CryptSmac.c
CryptSym.c
CryptUtil.c
DA.c
DebugHelpers.c
DictionaryCommands.c
DuplicationCommands.c
EACommands.c
EncryptDecrypt_spt.c
Entity.c
Entropy.c
EphemeralCommands.c
ExecCommand.c
Global.c
Handle.c
HashCommands.c
Hierarchy.c
HierarchyCommands.c
IoBuffers.c
IntegrityCommands.c
Locality.c
LocalityPlat.c
ManagementCommands.c
Manufacture.c
Marshal.c
MathOnByteBuffers.c
Memory.c
NVCommands.c
NVDynamic.c
NVMem.c
NVReserved.c
NV_spt.c
Object.c
ObjectCommands.c
Object_spt.c
PCR.c
PP.c
PPPlat.c
PlatformACT.c
PlatformData.c
Policy_spt.c
Power.c
PowerPlat.c
PrimeData.c
PropertyCap.c
RandomCommands.c
Response.c
ResponseCodeProcessing.c
RsaKeyCache.c
RunCommand.c
Session.c
SessionCommands.c
SessionProcess.c
SigningCommands.c
StartupCommands.c
SymmetricCommands.c
TPMCmdp.c
TPMCmds.c
TestingCommands.c
Ticket.c
Time.c
TpmAsn1.c
TpmFail.c
TpmSizeChecks.c
TpmToOsslDesSupport.c
TpmToOsslMath.c
TpmToOsslSupport.c
Unique.c
Unmarshal.c
Vendor_TCG_Test.c
X509_ECC.c
X509_RSA.c
X509_spt.c
ntc2lib.c
ntc2.c
$<$<BOOL:${UNIX}>:TcpServerPosix.c>
$<$<BOOL:${WIN32}>:TcpServer.c>
$<$<BOOL:${WIN32}>:applink.c>
)

target_compile_definitions(tpm_server
PRIVATE
# Unix defines
$<$<BOOL:${UNIX}>:_POSIX_>
$<$<BOOL:${UNIX}>:TPM_POSIX>
# Windows defines
$<$<PLATFORM_ID:Windows>:WIN32>
$<$<PLATFORM_ID:Windows>:TPM_WINDOWS>
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
$<$<AND:$<PLATFORM_ID:Windows>,$<CONFIG:Release>>:NO_FAIL_TRACE>
# Big endian
$<$<BOOL:${BIG_ENDIAN}>:BIG_ENDIAN_TPM=YES>
# Common
USE_BIT_FIELD_STRUCTURES=NO
TPM_NUVOTON
)

if(UNIX OR MINGW)
target_compile_options(tpm_server
PRIVATE
-Wall
-Werror
-Wmissing-declarations
-Wmissing-prototypes
-Wsign-compare
-Wnested-externs
$<$<STREQUAL:"${CMAKE_SIZEOF_VOID_P}","8">:-fno-strict-aliasing>
)
else(MSVC)
target_compile_options(tpm_server
PRIVATE
/W3
# Enable if you want warning as error
# /WX
)
endif()

target_include_directories(tpm_server
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(tpm_server
PRIVATE
OpenSSL::Crypto
$<$<BOOL:${UNIX}>:Threads::Threads>
$<$<BOOL:${WIN32}>:wsock32>
$<$<BOOL:${WIN32}>:ws2_32>
$<$<BOOL:${WIN32}>:crypt32>
)

install(TARGETS tpm_server
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
)
6 changes: 5 additions & 1 deletion src/CryptHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ typedef struct sequenceMethods {
SMAC_DATA_METHOD data;
SMAC_END_METHOD end;
} SMAC_METHODS;
#define SMAC_IMPLEMENTED (defined CC_MAC || defined CC_MAC_Start)
#if (defined CC_MAC || defined CC_MAC_Start)
#define SMAC_IMPLEMENTED 1
#else
#define SMAC_IMPLEMENTED 0
#endif

/* These definitions are here because the SMAC state is in the union of hash states. */

Expand Down
7 changes: 4 additions & 3 deletions src/Marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,10 @@ TPMS_ENC_SCHEME_OAEP_Marshal(TPMS_ENC_SCHEME_OAEP *source, BYTE **buffer, INT32
UINT16
TPMS_ENC_SCHEME_RSAES_Marshal(TPMS_ENC_SCHEME_RSAES *source, BYTE **buffer, INT32 *size)
{
source = source;
buffer = buffer;
size = size;
(void)source;
(void)buffer;
(void)size;

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/TcpServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ PlatformServer(
break;
case TPM_ACT_GET_SIGNALED:
{
UINT32 actHandle;
UINT32 actHandle = 0;
OK = ReadUINT32(s, &actHandle);
WriteUINT32(s, _rpc__ACT_GetSignaled(actHandle));
break;
Expand Down
2 changes: 1 addition & 1 deletion src/TcpServerPosix.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ PlatformServer(
break;
case TPM_ACT_GET_SIGNALED:
{
UINT32 actHandle;
UINT32 actHandle = 0;
ok = ReadUINT32(s, &actHandle);
WriteUINT32(s, _rpc__ACT_GetSignaled(actHandle));
break;
Expand Down
9 changes: 5 additions & 4 deletions src/Unmarshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ TPM_RC
TPMI_DH_SAVED_Unmarshal(TPMI_DH_SAVED *target, BYTE **buffer, INT32 *size, BOOL allowNull)
{
TPM_RC rc = TPM_RC_SUCCESS;
allowNull = allowNull;
(void)allowNull;

if (rc == TPM_RC_SUCCESS) {
rc = TPM_HANDLE_Unmarshal(target, buffer, size);
Expand Down Expand Up @@ -1466,9 +1466,10 @@ TPM_RC
TPMS_EMPTY_Unmarshal(TPMS_EMPTY *target, BYTE **buffer, INT32 *size)
{
TPM_RC rc = TPM_RC_SUCCESS;
target = target;
buffer = buffer;
size = size;
(void)target;
(void)buffer;
(void)size;

return rc;
}

Expand Down
Loading