From 3b32f754a417f5ec4d723958073b4cfba690a68a Mon Sep 17 00:00:00 2001
From: Anton
Date: Sat, 30 Nov 2024 18:30:29 +0400
Subject: [PATCH] Add PIV smart card keyfile encryption
---
.github/workflows/build-macos.yml | 124 +++
.github/workflows/main.yml | 128 +++
.gitignore | 10 +
README.md | 2 +
doc/html/Bluekeys.html | 42 +
doc/html/Keyfiles.html | 9 +
doc/html/Security Tokens & Smart Cards.html | 7 +-
src/Build/Include/Makefile.inc | 36 +-
src/Common/EMVCard.h | 4 +-
src/Common/EMVToken.h | 2 +-
src/Common/Language.xml | 12 +-
src/Common/MockSecurityToken.cpp | 69 ++
src/Common/MockSecurityToken.h | 49 +
src/Common/SecurityToken.cpp | 383 +++++++-
src/Common/SecurityToken.h | 160 +++-
src/Core/Core.h | 24 +-
src/Core/Core.make | 12 +-
src/Core/CoreBase.cpp | 18 +-
src/Core/CoreBase.h | 8 +-
src/Core/CoreTest.cpp | 955 ++++++++++++++++++++
src/Core/MountOptions.cpp | 7 +
src/Core/MountOptions.h | 6 +-
src/Core/Unix/CoreServiceProxy.h | 7 +-
src/Core/Unix/CoreUnix.cpp | 2 +
src/Core/VolumeCreator.cpp | 2 +-
src/Core/VolumeCreator.h | 1 +
src/Driver/Fuse/FuseService.h | 5 +-
src/Main/CommandLineInterface.cpp | 11 +
src/Main/CommandLineInterface.h | 1 +
src/Main/Forms/ChangePasswordDialog.cpp | 24 +-
src/Main/Forms/ChangePasswordDialog.h | 2 +-
src/Main/Forms/Forms.cpp | 92 +-
src/Main/Forms/Forms.h | 32 +-
src/Main/Forms/KeyfileGeneratorDialog.cpp | 35 +-
src/Main/Forms/KeyfileGeneratorDialog.h | 1 +
src/Main/Forms/MainFrame.cpp | 12 +
src/Main/Forms/MainFrame.h | 1 +
src/Main/Forms/MountOptionsDialog.cpp | 6 +-
src/Main/Forms/SecurityTokenKeysDialog.cpp | 105 +++
src/Main/Forms/SecurityTokenKeysDialog.h | 54 ++
src/Main/Forms/VolumeCreationWizard.cpp | 12 +-
src/Main/Forms/VolumeCreationWizard.h | 1 +
src/Main/Forms/VolumePasswordPanel.cpp | 44 +-
src/Main/Forms/VolumePasswordPanel.h | 6 +-
src/Main/Forms/VolumePasswordWizardPage.cpp | 4 +-
src/Main/Forms/VolumePasswordWizardPage.h | 4 +-
src/Main/GraphicUserInterface.cpp | 59 +-
src/Main/GraphicUserInterface.h | 3 +-
src/Main/Main.make | 7 +-
src/Main/TextUserInterface.cpp | 46 +-
src/Main/TextUserInterface.h | 3 +-
src/Main/Unix/Main.cpp | 2 +
src/Main/UserInterface.cpp | 5 +-
src/Main/UserInterface.h | 2 +-
src/Makefile | 27 +-
src/Platform/Buffer.cpp | 4 +
src/Platform/Buffer.h | 2 +-
src/Platform/FilesystemPath.h | 1 +
src/Platform/Finally.h | 11 +
src/Platform/PipelineStream.cpp | 62 ++
src/Platform/PipelineStream.h | 40 +
src/Platform/PipelineStreamTest.cpp | 173 ++++
src/Platform/Platform.make | 4 +
src/Platform/Unix/FilesystemPath.cpp | 9 +
src/Testing/SampleTest.cpp | 46 +
src/Testing/SampleTest.h | 15 +
src/Testing/Testing.cpp | 94 ++
src/Testing/Testing.h | 130 +++
src/Testing/Testing.make | 6 +
src/Volume/Keyfile.cpp | 205 ++++-
src/Volume/Keyfile.h | 14 +-
src/Volume/Volume.cpp | 14 +-
src/Volume/Volume.h | 4 +-
src/Volume/Volume.make | 5 +-
74 files changed, 3303 insertions(+), 221 deletions(-)
create mode 100644 .github/workflows/build-macos.yml
create mode 100644 .github/workflows/main.yml
create mode 100644 doc/html/Bluekeys.html
create mode 100644 src/Common/MockSecurityToken.cpp
create mode 100644 src/Common/MockSecurityToken.h
create mode 100644 src/Core/CoreTest.cpp
create mode 100644 src/Main/Forms/SecurityTokenKeysDialog.cpp
create mode 100644 src/Main/Forms/SecurityTokenKeysDialog.h
create mode 100644 src/Platform/PipelineStream.cpp
create mode 100644 src/Platform/PipelineStream.h
create mode 100644 src/Platform/PipelineStreamTest.cpp
create mode 100644 src/Testing/SampleTest.cpp
create mode 100644 src/Testing/SampleTest.h
create mode 100644 src/Testing/Testing.cpp
create mode 100644 src/Testing/Testing.h
create mode 100644 src/Testing/Testing.make
diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml
new file mode 100644
index 0000000000..d7b9570329
--- /dev/null
+++ b/.github/workflows/build-macos.yml
@@ -0,0 +1,124 @@
+name: Build and test macOS
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+ create:
+ tags:
+ - '*'
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+env:
+ WX_BUILD_DIR: ${{ github.workspace }}/wxbuild
+ WX_ROOT: ${{ github.workspace }}/wxsrc
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+ # This workflow contains a single job called "build"
+ build:
+ # The type of runner that the job will run on
+ runs-on: ${{matrix.runner}}
+ strategy:
+ matrix:
+ runner: [macos-13]
+
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v2
+
+ - name: Download Packages
+ uses: carlosperate/download-file-action@v1.0.3
+ id: download-packages
+ with:
+ file-url: 'http://s.sudre.free.fr/Software/files/Packages.dmg'
+ file-name: 'Packages.dmg'
+ location: '.'
+
+ - name: Download macFUSE
+ uses: carlosperate/download-file-action@v1.0.3
+ id: download-macfuse
+ with:
+ file-url: 'https://github.com/osxfuse/osxfuse/releases/download/macfuse-4.5.0/macfuse-4.5.0.dmg'
+ file-name: 'macfuse.dmg'
+ location: '.'
+
+ - name: Download pkg-config
+ uses: carlosperate/download-file-action@v1.0.3
+ id: download-pkg-config
+ with:
+ file-url: 'https://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz'
+ file-name: pkg-config-0.28.tar.gz
+ location: '.'
+
+ - name: Mount Packages
+ run: sudo hdiutil attach Packages.dmg
+
+ - name: Mount macFUSE
+ run: sudo hdiutil attach macfuse.dmg
+
+ - name: List Volumes directory context
+ run: ls -latr /Volumes || true
+
+ - name: Install Packages
+ run: sudo installer -pkg "/Volumes/Packages 1.2.10/Install Packages.pkg" -target /
+
+ - name: Install macFUSE
+ run: sudo installer -pkg "/Volumes/macFUSE/Install macFUSE.pkg" -target /
+
+ - name: Build and install pkg-config
+ run: tar xvf pkg-config-0.28.tar.gz && cd pkg-config-0.28 && ./configure && make && sudo make install
+
+ - name: Install yasm
+ run: brew install yasm
+
+ - uses: actions/cache@v2
+ name: Cache/restore wxWidgets
+ id: cache-wxwidgets
+ with:
+ path: |
+ ${{ env.WX_ROOT }}
+ ${{ env.WX_BUILD_DIR }}
+ key: wxwidgets
+
+ - uses: maxim-lobanov/setup-xcode@v1
+ with:
+ xcode-version: latest-stable
+
+ - uses: actions/checkout@v2
+ name: Checkout wxWidgets
+ with:
+ repository: 'wxWidgets/wxWidgets'
+ ref: 'v3.2.5'
+ path: ${{ env.WX_ROOT }}
+ submodules: 'recursive'
+
+ - name: Show Xcode used
+ run: |
+ SDK_VERSION=$(xcrun --show-sdk-version); xcrun --show-sdk-path; xcrun --sdk macosx${SDK_VERSION} --show-sdk-path
+
+ - name: Build wxWidgets
+ if: steps.cache-wxwidgets.outputs.cache-hit != 'true'
+ run: |
+ ls -l ${{env.WX_ROOT}}
+ (cd src && make WXSTATIC=FULL WX_ROOT=${{env.WX_ROOT}} WX_BUILD_DIR=${{env.WX_BUILD_DIR}} wxbuild); cat ${{ env.WX_BUILD_DIR }}/config.log
+
+ - name: Build Veracrypt
+ run: cd src && make LOCAL_DEVELOPMENT_BUILD=true WXSTATIC=FULL WX_ROOT=${{env.WX_ROOT}} WX_BUILD_DIR=${{env.WX_BUILD_DIR}} && make LOCAL_DEVELOPMENT_BUILD=true WXSTATIC=1 package
+
+ - name: Show directory structure
+ run: |
+ ls -R .
+ ls -l src || true
+
+ - name: Release
+ uses: softprops/action-gh-release@v1
+ if: startsWith(github.ref, 'refs/tags/')
+ with:
+ files: '**/VeraCrypt*.dmg'
+
+
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000000..c906c367bf
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,128 @@
+# This is a basic workflow to help you get started with Actions
+
+name: CI
+
+# Controls when the workflow will run
+on:
+ # Triggers the workflow on push or pull request events but only for the master branch
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+ create:
+ tags:
+ - '*'
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+env:
+ WX_BUILD_DIR: ${{ github.workspace }}/wxbuild
+ WX_ROOT: ${{ github.workspace }}/wxsrc
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+ # This workflow contains a single job called "build"
+ build:
+ # The type of runner that the job will run on
+ runs-on: ${{matrix.runner}}
+ strategy:
+ matrix:
+ runner: [macos-13]
+
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v2
+
+ - name: Download Packages
+ uses: carlosperate/download-file-action@v1.0.3
+ id: download-packages
+ with:
+ file-url: 'http://s.sudre.free.fr/Software/files/Packages.dmg'
+ file-name: 'Packages.dmg'
+ location: '.'
+
+ - name: Download macFUSE
+ uses: carlosperate/download-file-action@v1.0.3
+ id: download-macfuse
+ with:
+ file-url: 'https://github.com/osxfuse/osxfuse/releases/download/macfuse-4.5.0/macfuse-4.5.0.dmg'
+ file-name: 'macfuse.dmg'
+ location: '.'
+
+ - name: Download pkg-config
+ uses: carlosperate/download-file-action@v1.0.3
+ id: download-pkg-config
+ with:
+ file-url: 'https://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz'
+ file-name: pkg-config-0.28.tar.gz
+ location: '.'
+
+ - name: Mount Packages
+ run: sudo hdiutil attach Packages.dmg
+
+ - name: Mount macFUSE
+ run: sudo hdiutil attach macfuse.dmg
+
+ - name: List Volumes directory context
+ run: ls -latr /Volumes || true
+
+ - name: Install Packages
+ run: sudo installer -pkg "/Volumes/Packages 1.2.10/Install Packages.pkg" -target /
+
+ - name: Install macFUSE
+ run: sudo installer -pkg "/Volumes/macFUSE/Install macFUSE.pkg" -target /
+
+ - name: Build and install pkg-config
+ run: tar xvf pkg-config-0.28.tar.gz && cd pkg-config-0.28 && ./configure && make && sudo make install
+
+ - name: Install yasm
+ run: brew install yasm
+
+ - uses: actions/cache@v2
+ name: Cache/restore wxWidgets
+ id: cache-wxwidgets
+ with:
+ path: |
+ ${{ env.WX_ROOT }}
+ ${{ env.WX_BUILD_DIR }}
+ key: wxwidgets
+
+ - uses: maxim-lobanov/setup-xcode@v1
+ with:
+ xcode-version: latest-stable
+
+ - uses: actions/checkout@v2
+ name: Checkout wxWidgets
+ with:
+ repository: 'wxWidgets/wxWidgets'
+ ref: 'v3.2.5'
+ path: ${{ env.WX_ROOT }}
+ submodules: 'recursive'
+
+ - name: Show Xcode used
+ run: |
+ SDK_VERSION=$(xcrun --show-sdk-version); xcrun --show-sdk-path; xcrun --sdk macosx${SDK_VERSION} --show-sdk-path
+
+ - name: Build wxWidgets
+ if: steps.cache-wxwidgets.outputs.cache-hit != 'true'
+ run: |
+ ls -l ${{env.WX_ROOT}}
+ (cd src && make WXSTATIC=FULL WX_ROOT=${{env.WX_ROOT}} WX_BUILD_DIR=${{env.WX_BUILD_DIR}} wxbuild); cat ${{ env.WX_BUILD_DIR }}/config.log
+
+ - name: Build Veracrypt
+ run: cd src && make LOCAL_DEVELOPMENT_BUILD=true WXSTATIC=FULL WX_ROOT=${{env.WX_ROOT}} WX_BUILD_DIR=${{env.WX_BUILD_DIR}} && make LOCAL_DEVELOPMENT_BUILD=true WXSTATIC=1 package
+
+ - name: Show directory structure
+ run: |
+ ls -R .
+ ls -l src || true
+
+ - name: Release
+ uses: softprops/action-gh-release@v1
+ if: startsWith(github.ref, 'refs/tags/')
+ with:
+ files: '**/VeraCrypt*.dmg'
+
+
diff --git a/.gitignore b/.gitignore
index 412edcca9d..80f85c7e51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,16 @@
# For those using Visual Studio Code for development
.vscode/
+# Testing artifacts
+Tests/**/*.raw
+Tests/**/*.vol
+Tests/**/*.bin
+Tests/**/*.dmg
+Tests/**/*.vc
+Tests/**/*.key
+**/*Testing
+!src/Testing
+
# CLion
.idea/
diff --git a/README.md b/README.md
index 21f46ca757..dd00947aa9 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+![build](./actions/workflows/build-macos.yml/badge.svg)
+
This archive contains the source code of VeraCrypt.
It is based on the original TrueCrypt 7.1a with security enhancements and modifications.
diff --git a/doc/html/Bluekeys.html b/doc/html/Bluekeys.html
new file mode 100644
index 0000000000..e0ba6c9a2e
--- /dev/null
+++ b/doc/html/Bluekeys.html
@@ -0,0 +1,42 @@
+
+
+
+
+VeraCrypt - Free Open source disk encryption with strong security for the Paranoid
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Bluekeys
+
+Security Tokens and Smart Cards, which support encryption (e.g. there are assymetric cryptography key on the card), can be used to issue blue key.
+Blue key is just an ordinary keyfile encrypted using key stored on the smart card. Because usually it is not possible to extract the key from the smart card,
+such a file could not be used independently from the card to decrypt the volume.
Please note that security tokens and smart cards are currently not
+supported for Pre-Boot authentication of system encryption.
+
\ No newline at end of file
diff --git a/doc/html/Keyfiles.html b/doc/html/Keyfiles.html
index 04dd3463a4..f5d8c823c6 100644
--- a/doc/html/Keyfiles.html
+++ b/doc/html/Keyfiles.html
@@ -80,6 +80,15 @@ Keyfiles
smart cards protected by multiple PIN codes (which can be entered
either using a hardware PIN pad or via the VeraCrypt GUI).
+ Optionally, keyfiles can be encrypted using PKCS-11 compliant security
+ tokens and smart cards. This provides additional level of security:
+ knowing the keyfile content is not enough, you also need a
+ security token or smart card. See chapter
+ Bluekeys .
+
EMV-compliant smart cards' data can be used as keyfile, see chapter
Security Tokens & Smart Cards
-VeraCrypt supports security (or cryptographic) tokens and smart cards that can be accessed using the PKCS #11 (2.0 or later) protocol [23]. For more information, please see the section
+VeraCrypt supports security (or cryptographic) tokens and smart cards that can be accessed using the PKCS #11 (2.0 or later) protocol [23]. There are two way these devices can be used with VeraCrypt.
+
+Keyfiles
+
As an additional encryption layer. For more infromation, please see Bluekeys
+.Please note that security tokens and smart cards are currently not supported for Pre-Boot authentication of system encryption.