Skip to content

Commit 3c30b43

Browse files
committed
Merge branch 'oda'
* oda: Misc Doxygen updates Move ODA types required by EMV context to separate header Use crypto_memcmp_s() for hash validation during ODA Implement validation of certification expiration dates Implement --oda option for emv-tool Fix --debug-source option parsing for emv-tool Implement remaining part of Combined DDA/Application Cryptogram Generation (CDA) Refactor ODA abstraction to cache data needed for Transaction Data Hash Code Implement initial EMV Card Action Analysis Implement helper functions for GENERATE APPLICATION CRYPTOGRAM in TTL and TAL Update Signed Dynamic Application Data retrieval for CDA Remember currently retrieved ICC public key Remember currently selected Offline Data Authentication (ODA) method Implement initial part of Combined DDA/Application Cryptogram Generation (CDA) Implement remaining part of Dynamic Data Authentication (DDA) Implement helper functions for INTERNAL AUTHENTICATE in TTL and TAL Implement Signed Dynamic Application Data retrieval and validation Validate configuration fields for ODA in high-level EMV abstraction Move cached fields to EMV processing context Let most ODA functions use EMV processing context Populate Unpredictable Number (field 9F37) Add error for missing terminal data during Offline Data Authentication (ODA) Implement initial part of Dynamic Data Authentication (DDA) Refactor EMV RSA abstraction Implement Static Data Authentication (SDA) Add initial Offline Data Authentication (ODA) abstraction Implement ICC public key retrieval Implement Signed Static Application Data retrieval Implement issuer public key retrieval and validation Implement CAPK validation Update Github Actions workflow for MbedTLS Add OpenEMV common crypto abstraction as a submodule Add more CAPKs Move CAPK static data to separate header Add initial CAPK abstraction
2 parents ceb2007 + b848b54 commit 3c30b43

37 files changed

+6835
-198
lines changed

.github/workflows/fedora-build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
steps:
2727
- name: Install build tools and dependencies
28-
run: sudo dnf -y install git cmake gcc g++ boost-devel iso-codes-devel json-c-devel
28+
run: sudo dnf -y install git cmake gcc g++ mbedtls-devel boost-devel iso-codes-devel json-c-devel
2929

3030
- name: Install PCSCLite
3131
if: contains(matrix.deps, 'pcsclite')
@@ -77,7 +77,7 @@ jobs:
7777
steps:
7878
- name: Install build tools and dependencies
7979
run: |
80-
sudo dnf -y install git gh cmake gcc g++ boost-devel iso-codes-devel json-c-devel pcsc-lite-devel bash-completion-devel doxygen rpm-build qt5-qtbase-devel
80+
sudo dnf -y install git gh cmake gcc g++ mbedtls-devel boost-devel iso-codes-devel json-c-devel pcsc-lite-devel bash-completion-devel doxygen rpm-build qt5-qtbase-devel
8181
8282
- name: Checkout
8383
uses: actions/checkout@v4

.github/workflows/macos-build.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##############################################################################
2-
# Copyright 2022-2024 Leon Lynch
2+
# Copyright 2022-2025 Leon Lynch
33
#
44
# This file is licensed under the terms of the LGPL v2.1 license.
55
# See LICENSE file.
@@ -32,9 +32,13 @@ jobs:
3232
brew install iso-codes
3333
brew install json-c
3434
35-
- name: Install argp-standalone using brew
35+
- name: Install MbedTLS and argp-standalone using brew
36+
# Homebrew doesn't support universal binaries so only install dependencies for arch-specific builds
3637
if: ${{ matrix.fetch_deps == 'NO' }}
37-
run: brew install argp-standalone
38+
run: |
39+
brew install mbedtls
40+
brew install argp-standalone
41+
echo "CMAKE_REQUIRE_FIND_PACKAGE_MbedTLS=YES" >> $GITHUB_ENV
3842
3943
- name: Install PCSCLite using brew
4044
if: contains(matrix.deps, 'pcsclite')
@@ -67,6 +71,8 @@ jobs:
6771
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.osx_arch }}" \
6872
-DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" \
6973
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} \
74+
-DFETCH_MBEDTLS=${{ matrix.fetch_deps }} \
75+
-DCMAKE_REQUIRE_FIND_PACKAGE_MbedTLS=${{ env.CMAKE_REQUIRE_FIND_PACKAGE_MbedTLS }} \
7076
-DFETCH_ARGP=${{ matrix.fetch_deps }} \
7177
-DBUILD_EMV_DECODE=YES \
7278
-DBUILD_EMV_TOOL=${{ matrix.build_emv_tool }} \
@@ -114,6 +120,7 @@ jobs:
114120
cmake -B build \
115121
-DCMAKE_OSX_ARCHITECTURES="x86_64" \
116122
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
123+
-DFETCH_MBEDTLS=YES \
117124
-DFETCH_ARGP=YES \
118125
-DBUILD_EMV_DECODE=YES \
119126
-DBUILD_EMV_TOOL=YES \

.github/workflows/ubuntu-build.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install dependencies
3030
run: |
3131
sudo apt-get update
32-
sudo apt-get install -y libboost-locale-dev iso-codes libjson-c-dev
32+
sudo apt-get install -y libmbedtls-dev libboost-locale-dev iso-codes libjson-c-dev
3333
3434
- name: Install PCSCLite
3535
if: contains(matrix.deps, 'pcsclite')
@@ -80,7 +80,7 @@ jobs:
8080
8181
- name: Install dependencies
8282
run: |
83-
apt-get install -y libboost-locale-dev iso-codes libjson-c-dev libpcsclite-dev bash-completion doxygen qtbase5-dev
83+
apt-get install -y libmbedtls-dev libboost-locale-dev iso-codes libjson-c-dev libpcsclite-dev bash-completion doxygen qtbase5-dev
8484
8585
- name: Checkout
8686
uses: actions/checkout@v4
@@ -148,7 +148,7 @@ jobs:
148148
- name: Install dependencies
149149
run: |
150150
sudo apt-get update
151-
sudo apt-get install -y libboost-locale-dev iso-codes libjson-c-dev libpcsclite-dev doxygen qtbase5-dev
151+
sudo apt-get install -y libmbedtls-dev libboost-locale-dev iso-codes libjson-c-dev libpcsclite-dev doxygen qtbase5-dev
152152
153153
- name: Checkout
154154
uses: actions/checkout@v4

.github/workflows/windows-build.yaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- { sys: mingw64, env: x86_64, build_type: "Release", lib_type: "static", shared_libs: "NO", deps: "none", build_emv_tool: NO, build_emv_viewer: NO }
21-
- { sys: mingw64, env: x86_64, build_type: "Debug", lib_type: "dll", shared_libs: "YES", deps: "qt6", build_emv_tool: YES, build_emv_viewer: YES }
22-
- { sys: mingw64, env: x86_64, build_type: "Release", lib_type: "static", shared_libs: "NO", deps: "qt5", build_emv_tool: YES, build_emv_viewer: YES }
23-
- { sys: ucrt64, env: ucrt-x86_64, build_type: "Debug", lib_type: "static", shared_libs: "NO", deps: "qt5", build_emv_tool: YES, build_emv_viewer: YES }
24-
- { sys: ucrt64, env: ucrt-x86_64, build_type: "Release", lib_type: "dll", shared_libs: "YES", deps: "qt6", build_emv_tool: YES, build_emv_viewer: YES }
20+
- { sys: mingw64, env: x86_64, build_type: "Release", lib_type: "static", shared_libs: "NO", deps: "none", fetch_deps: NO, build_emv_tool: NO, build_emv_viewer: NO }
21+
- { sys: mingw64, env: x86_64, build_type: "Debug", lib_type: "dll", shared_libs: "YES", deps: "qt6", fetch_deps: NO, build_emv_tool: YES, build_emv_viewer: YES }
22+
- { sys: mingw64, env: x86_64, build_type: "Release", lib_type: "static", shared_libs: "NO", deps: "qt5", fetch_deps: YES, build_emv_tool: YES, build_emv_viewer: YES }
23+
- { sys: ucrt64, env: ucrt-x86_64, build_type: "Debug", lib_type: "static", shared_libs: "NO", deps: "qt5", fetch_deps: NO, build_emv_tool: YES, build_emv_viewer: YES }
24+
- { sys: ucrt64, env: ucrt-x86_64, build_type: "Release", lib_type: "dll", shared_libs: "YES", deps: "qt6", fetch_deps: YES, build_emv_tool: YES, build_emv_viewer: YES }
2525
# NOTE: Only test Qt6 for clang64 because Qt5's windeployqt does not support clang64
26-
- { sys: clang64, env: clang-x86_64, build_type: "Debug", lib_type: "static", shared_libs: "NO", deps: "qt6", build_emv_tool: YES, build_emv_viewer: YES }
27-
- { sys: clang64, env: clang-x86_64, build_type: "Release", lib_type: "dll", shared_libs: "YES", deps: "qt6", build_emv_tool: YES, build_emv_viewer: YES }
26+
- { sys: clang64, env: clang-x86_64, build_type: "Debug", lib_type: "static", shared_libs: "NO", deps: "qt6", fetch_deps: NO, build_emv_tool: YES, build_emv_viewer: YES }
27+
- { sys: clang64, env: clang-x86_64, build_type: "Release", lib_type: "dll", shared_libs: "YES", deps: "qt6", fetch_deps: YES, build_emv_tool: YES, build_emv_viewer: YES }
2828

2929
name: Windows MSYS2 ${{matrix.sys}} build (${{ matrix.lib_type }}/${{ matrix.build_type }}/${{ matrix.deps }})
3030

@@ -54,6 +54,12 @@ jobs:
5454
mingw-w64-${{matrix.env}}-json-c
5555
mingw-w64-${{matrix.env}}-gettext
5656
57+
- name: Install MbedTLS
58+
if: ${{ matrix.fetch_deps == 'NO' }}
59+
run: |
60+
pacman --noconfirm -S --needed mingw-w64-${{matrix.env}}-mbedtls
61+
echo "CMAKE_REQUIRE_FIND_PACKAGE_MbedTLS=YES" >> $GITHUB_ENV
62+
5763
- name: Install Qt5
5864
if: contains(matrix.deps, 'qt5')
5965
run: |
@@ -75,6 +81,8 @@ jobs:
7581
cmake -G Ninja -B build \
7682
-DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" \
7783
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} \
84+
-DFETCH_MBEDTLS=${{ matrix.fetch_deps }} \
85+
-DCMAKE_REQUIRE_FIND_PACKAGE_MbedTLS=${{ env.CMAKE_REQUIRE_FIND_PACKAGE_MbedTLS }} \
7886
-DFETCH_ARGP=YES \
7987
-DBUILD_EMV_DECODE=YES \
8088
-DBUILD_EMV_TOOL=${{ matrix.build_emv_tool }} \
@@ -154,6 +162,7 @@ jobs:
154162
-DCMAKE_C_COMPILER="${{ env.TOOLCHAIN_PATH }}/gcc.exe" \
155163
-DCMAKE_CXX_COMPILER="${{ env.TOOLCHAIN_PATH }}/g++.exe" \
156164
-DBUILD_SHARED_LIBS=YES \
165+
-DFETCH_MBEDTLS=YES \
157166
-DFETCH_ARGP=YES \
158167
-DBUILD_EMV_DECODE=YES \
159168
-DBUILD_EMV_TOOL=YES \

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "mcc-codes"]
22
path = mcc-codes
33
url = https://github.com/greggles/mcc-codes.git
4+
[submodule "crypto"]
5+
path = crypto
6+
url = https://github.com/openemv/crypto.git

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ if(EMV_UTILS_IS_TOP_LEVEL)
8383
include(CTest)
8484
endif()
8585

86+
# Allow parent scope to provide crypto targets when not building shared libs
87+
if(EMV_UTILS_IS_TOP_LEVEL OR BUILD_SHARED_LIBS)
88+
list(APPEND CRYPTO_TESTS crypto_sha crypto_rsa)
89+
add_subdirectory(crypto)
90+
add_subdirectory(crypto/test)
91+
elseif (NOT TARGET crypto_mem OR
92+
NOT TARGET crypto_rand OR
93+
NOT TARGET crypto_sha OR
94+
NOT TARGET crypto_rsa)
95+
message(FATAL_ERROR "Parent project must provide crypto libraries for static builds")
96+
endif()
97+
8698
include(FindPackageHandleStandardArgs) # Provides find_package() messages
8799
include(GNUInstallDirs) # Provides CMAKE_INSTALL_* variables and good defaults for install()
88100

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Dependencies
8484

8585
This project also makes use of sub-projects that must be provided as git
8686
submodules using `git clone --recurse-submodules`:
87+
* [OpenEMV common crypto abstraction](https://github.com/openemv/crypto)
8788
* [mcc-codes](https://github.com/greggles/mcc-codes)
8889

8990
Build
@@ -336,6 +337,10 @@ See [LICENSE](https://github.com/openemv/emv-utils/blob/master/LICENSE) and
336337
[LICENSE.gpl](https://github.com/openemv/emv-utils/blob/master/viewer/LICENSE.gpl)
337338
files.
338339

340+
This project includes [crypto](https://github.com/openemv/crypto) as a git
341+
submodule and it is licensed under the terms of the MIT license. See
342+
[LICENSE](https://github.com/openemv/crypto/blob/master/LICENSE) file.
343+
339344
This project includes [mcc-codes](https://github.com/greggles/mcc-codes) as a
340345
git submodule and it is licensed under the terms of The Unlicense license. See
341346
[LICENSE](https://github.com/greggles/mcc-codes/blob/main/LICENSE.txt) file.

crypto

Submodule crypto added at f3d2108

src/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ add_library(emv
280280
emv_ttl.c
281281
emv_app.c
282282
emv_tal.c
283+
emv_capk.c
284+
emv_rsa.c
285+
emv_oda.c
286+
emv_date.c
283287
)
284288
set(emv_HEADERS # PUBLIC_HEADER property requires a list instead of individual entries
285289
emv.h
@@ -291,6 +295,11 @@ set(emv_HEADERS # PUBLIC_HEADER property requires a list instead of individual e
291295
emv_ttl.h
292296
emv_app.h
293297
emv_tal.h
298+
emv_capk.h
299+
emv_rsa.h
300+
emv_oda.h
301+
emv_oda_types.h
302+
emv_date.h
294303
)
295304
set(emv_HEADERS ${emv_HEADERS} PARENT_SCOPE) # Doxygen generator requires a list of headers
296305
add_library(emv::emv ALIAS emv)
@@ -301,6 +310,10 @@ target_link_libraries(emv
301310
PRIVATE
302311
iso7816
303312
iso8859
313+
crypto_mem
314+
crypto_rand
315+
crypto_sha
316+
crypto_rsa
304317
)
305318
# The EMV_PKGCONFIG_REQ_PRIV and EMV_PKGCONFIG_LIBS_PRIV variables are set
306319
# for the parent scope to facilitate the generation of pkgconfig files.
@@ -323,6 +336,10 @@ target_include_directories(emv
323336
install(
324337
TARGETS
325338
emv
339+
crypto_mem
340+
crypto_rand
341+
crypto_sha
342+
crypto_rsa
326343
EXPORT emvUtilsTargets # For use by install(EXPORT) command
327344
PUBLIC_HEADER
328345
DESTINATION "include/emv"

0 commit comments

Comments
 (0)