Skip to content

Commit 769da2b

Browse files
committed
Add callback to ask online validation confirmation
IB-7865 Signed-off-by: Raul Metsma <[email protected]>
1 parent 14e2f1f commit 769da2b

21 files changed

+144
-77
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
container: ${{ matrix.container }}
106106
strategy:
107107
matrix:
108-
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:23.04', 'ubuntu:23.10']
108+
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:23.10']
109109
env:
110110
DEBIAN_FRONTEND: noninteractive
111111
DEBFULLNAME: github-actions

examples/DigiDocCSharp/DigiDocCSharp.csproj

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,34 @@
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
5+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
86
<ProjectGuid>{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}</ProjectGuid>
97
<OutputType>Exe</OutputType>
108
<AppDesignerFolder>Properties</AppDesignerFolder>
119
<RootNamespace>DigiDocCSharp</RootNamespace>
1210
<AssemblyName>DigiDocCSharp</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14-
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1512
<FileAlignment>512</FileAlignment>
1613
</PropertyGroup>
17-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18-
<PlatformTarget>x86</PlatformTarget>
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
15+
<PlatformTarget>AnyCPU</PlatformTarget>
1916
<DebugSymbols>true</DebugSymbols>
2017
<DebugType>full</DebugType>
21-
<Optimize>false</Optimize>
2218
<OutputPath>bin\Debug\</OutputPath>
2319
<DefineConstants>DEBUG;TRACE</DefineConstants>
2420
<ErrorReport>prompt</ErrorReport>
25-
<WarningLevel>4</WarningLevel>
2621
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
22+
<Prefer32Bit>false</Prefer32Bit>
2723
</PropertyGroup>
28-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
29-
<PlatformTarget>x86</PlatformTarget>
24+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
25+
<PlatformTarget>AnyCPU</PlatformTarget>
3026
<DebugType>pdbonly</DebugType>
3127
<Optimize>true</Optimize>
3228
<OutputPath>bin\Release\</OutputPath>
3329
<DefineConstants>TRACE</DefineConstants>
3430
<ErrorReport>prompt</ErrorReport>
35-
<WarningLevel>4</WarningLevel>
3631
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
32+
<Prefer32Bit>false</Prefer32Bit>
3733
</PropertyGroup>
3834
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
3935
<DefineConstants>_WINDOWS</DefineConstants>
+13-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11

2-
Microsoft Visual Studio Solution File, Format Version 11.00
3-
# Visual C# Express 2010
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34009.444
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigiDocCSharp", "DigiDocCSharp.csproj", "{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}"
57
EndProject
68
Global
79
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8-
Debug|x86 = Debug|x86
9-
Release|x86 = Release|x86
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
1012
EndGlobalSection
1113
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12-
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|x86.ActiveCfg = Debug|x86
13-
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|x86.Build.0 = Debug|x86
14-
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|x86.ActiveCfg = Release|x86
15-
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|x86.Build.0 = Release|x86
14+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|Any CPU.Build.0 = Release|Any CPU
1618
EndGlobalSection
1719
GlobalSection(SolutionProperties) = preSolution
1820
HideSolutionNode = FALSE
1921
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7D43E58D-0FD9-4023-A18F-D69EE6A229E1}
24+
EndGlobalSection
2025
EndGlobal

examples/DigiDocCSharp/Program.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ private static void Sign(string[] args)
124124
b.addDataFile(args[i], "application/octet-stream");
125125
}
126126
#if _WINDOWS
127-
using (WinSigner signer = new WinSigner())
127+
using (var signer = new WinSigner())
128128
{
129129
#else
130-
using (PKCS11Signer signer = new PKCS11Signer())
130+
using (var signer = new PKCS11Signer())
131131
{
132132
signer.setPin(args[1]);
133133
#endif
@@ -184,7 +184,8 @@ private static void Verify(string file)
184184
try
185185
{
186186
Console.WriteLine("Opening file: " + file);
187-
Container b = Container.open(file);
187+
var cb = new ContainerOpen();
188+
Container b = Container.open(file, cb);
188189

189190
Console.WriteLine("Files:");
190191
foreach (DataFile d in b.dataFiles())
@@ -226,4 +227,9 @@ private static void Version()
226227
" libdigidocpp " + digidoc.digidoc.version());
227228
}
228229
}
230+
231+
class ContainerOpen : ContainerOpenCB
232+
{
233+
override public bool validateOnline() { return true; }
234+
}
229235
}

examples/java/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
## Run
88

9-
java -Djava.library.path=/Library/libdigidocpp/lib -jar build/libs/libdigidoc.jar
9+
java -Djava.library.path=/some/path/lib -jar build/libs/libdigidoc.jar
2.06 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

examples/java/gradlew

+10-5
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ done
8383
# This is normally unused
8484
# shellcheck disable=SC2034
8585
APP_BASE_NAME=${0##*/}
86-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87-
88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
9088

9189
# Use the maximum available, or set MAX_FD != -1 to use that value.
9290
MAX_FD=maximum
@@ -133,10 +131,13 @@ location of your Java installation."
133131
fi
134132
else
135133
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
134+
if ! command -v java >/dev/null 2>&1
135+
then
136+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137137
138138
Please set the JAVA_HOME variable in your environment to match the
139139
location of your Java installation."
140+
fi
140141
fi
141142

142143
# Increase the maximum file descriptors if we can.
@@ -197,6 +198,10 @@ if "$cygwin" || "$msys" ; then
197198
done
198199
fi
199200

201+
202+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204+
200205
# Collect all arguments for the java command;
201206
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202207
# shell script including quotes and variable substitutions, so put them in

examples/java/src/main/java/ee/ria/libdigidocpp/libdigidocpp.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ static void verify(String file) {
133133
try
134134
{
135135
System.out.println("Opening file: " + file);
136-
Container b = Container.open(file);
136+
ContainerOpen cb = new ContainerOpen();
137+
Container b = Container.open(file, cb);
137138
assert b != null;
138139

139140
System.out.println("Files:");
@@ -200,4 +201,10 @@ static byte[] fromHex(String s) {
200201
}
201202
return data;
202203
}
204+
205+
static private class ContainerOpen extends ContainerOpenCB
206+
{
207+
@Override
208+
public boolean validateOnline() { return true; }
209+
}
203210
}

examples/python/main.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import sys
33
import os
44

5+
class ContainerOpenCB(digidoc.ContainerOpenCB):
6+
7+
def __init__(self):
8+
digidoc.ContainerOpenCB.__init__(self)
9+
10+
def validateOnline(self):
11+
return True
512

613
class Program:
714
digidoc.initialize()
@@ -78,7 +85,8 @@ def sign(self, args):
7885

7986
def verify(self, file):
8087
print("Opening file: " + file)
81-
doc = digidoc.Container.open(file)
88+
cb = ContainerOpenCB()
89+
doc = digidoc.Container.open(file, cb)
8290

8391
print("Files:")
8492
for d in doc.dataFiles():

libdigidocpp.dox

+2
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,8 @@ Signature Validation Policy
13801380
Default POLv2
13811381

13821382
http://open-eid.github.io/SiVa/siva/appendix/validation_policy/</td></tr>
1383+
<tr><td>\-\-offline </td><td>Optional</td><td>
1384+
open container offline (eg. Don't send to SiVa)</td></tr>
13831385
<tr><td>\-\-warnings=
13841386

13851387
(ignore, warning, error) </td><td>Optional</td><td>

libdigidocpp.i

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// digidocpp.i - SWIG interface for libdigidocpp library
2121

22-
%module digidoc
22+
%module(directors="1") digidoc
2323

2424
%begin %{
2525
#ifdef _MSC_VER
@@ -231,6 +231,8 @@ extern "C"
231231
%newobject digidoc::Container::open;
232232
%newobject digidoc::Container::create;
233233

234+
%feature("director") digidoc::ContainerOpenCB;
235+
234236
%typemap(javacode) digidoc::Conf %{
235237
public Conf transfer() {
236238
swigCMemOwn = false;
@@ -318,16 +320,21 @@ namespace std {
318320
}
319321
}
320322
%extend digidoc::Container {
323+
static digidoc::Container* open(const std::string &path, digidoc::ContainerOpenCB *cb)
324+
{
325+
return digidoc::Container::openPtr(path, cb).release();
326+
}
327+
321328
digidoc::Signature* prepareWebSignature(const std::vector<unsigned char> &cert, const std::string &profile = {},
322329
const std::vector<std::string> &roles = {},
323330
const std::string &city = {}, const std::string &state = {},
324331
const std::string &postalCode = {}, const std::string &country = {})
325332
{
326-
class : public digidoc::Signer
333+
class final: public digidoc::Signer
327334
{
328335
public:
329-
digidoc::X509Cert cert() const override { return _cert; }
330-
std::vector<unsigned char> sign(const std::string &, const std::vector<unsigned char> &) const override
336+
digidoc::X509Cert cert() const final { return _cert; }
337+
std::vector<unsigned char> sign(const std::string &, const std::vector<unsigned char> &) const final
331338
{
332339
THROW("Not implemented");
333340
}

src/ASiC_S.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void ASiC_S::addAdESSignature(istream & /*signature*/)
102102
THROW("Not implemented.");
103103
}
104104

105-
unique_ptr<Container> ASiC_S::openInternal(const string &path)
105+
unique_ptr<Container> ASiC_S::openInternal(const string &path, ContainerOpenCB * /*cb*/)
106106
{
107107
if (!isContainerSimpleFormat(path))
108108
return {};

src/ASiC_S.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace digidoc
4141
Signature* sign(Signer* signer) override;
4242

4343
static std::unique_ptr<Container> createInternal(const std::string &path);
44-
static std::unique_ptr<Container> openInternal(const std::string &path);
44+
static std::unique_ptr<Container> openInternal(const std::string &path, ContainerOpenCB *cb);
4545

4646
private:
4747
ASiC_S();

src/CMakeLists.txt

+9-8
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,11 @@ if(SWIG_FOUND)
271271
target_include_directories(digidoc_java PRIVATE ${JAVA_INCLUDE_PATH} $<$<BOOL:${JAVA_INCLUDE_PATH2}>:${JAVA_INCLUDE_PATH2}>)
272272
target_compile_definitions(digidoc_java PRIVATE TARGET_NAME="$<TARGET_NAME:digidoc_java>")
273273
target_link_libraries(digidoc_java digidocpp digidocpp_util digidocpp_ver)
274-
set_property(TARGET digidoc_java PROPERTY SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>)
275-
if(APPLE)
276-
set_target_properties(digidoc_java PROPERTIES MACOSX_RPATH YES INSTALL_RPATH /Library/Frameworks)
277-
install(TARGETS digidoc_java DESTINATION /Library/Java/Extensions)
278-
else()
279-
install(TARGETS digidoc_java DESTINATION ${CMAKE_INSTALL_LIBDIR})
280-
endif()
274+
set_target_properties(digidoc_java PROPERTIES
275+
INSTALL_RPATH $<$<PLATFORM_ID:Darwin>:/Library/Frameworks>
276+
SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>
277+
)
278+
install(TARGETS digidoc_java DESTINATION $<IF:$<PLATFORM_ID:Darwin>,/Library/Java/Extensions,${CMAKE_INSTALL_LIBDIR}>)
281279
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/java/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ee/ria/libdigidocpp FILES_MATCHING PATTERN "*.java")
282280
if(WIN32)
283281
install(FILES $<TARGET_PDB_FILE:digidoc_java> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
@@ -289,7 +287,6 @@ if(SWIG_FOUND)
289287
swig_add_library(digidoc_python LANGUAGE python SOURCES ../libdigidocpp.i)
290288
target_compile_definitions(digidoc_python PRIVATE TARGET_NAME="$<TARGET_NAME:digidoc_python>")
291289
target_link_libraries(digidoc_python digidocpp digidocpp_util digidocpp_ver Python3::Module)
292-
set_property(TARGET digidoc_python PROPERTY SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>)
293290
#configure_file(setup.py.cmake setup.py)
294291
#install(CODE "execute_process(COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)")
295292
if(NOT Python3_SITELIB)
@@ -303,6 +300,10 @@ if(SWIG_FOUND)
303300
else()
304301
set_target_properties(digidoc_python PROPERTIES SUFFIX .so)
305302
endif()
303+
set_target_properties(digidoc_python PROPERTIES
304+
INSTALL_RPATH $<$<PLATFORM_ID:Darwin>:/Library/Frameworks>
305+
SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>
306+
)
306307
install(TARGETS digidoc_python DESTINATION ${Python3_SITELIB})
307308
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc.py DESTINATION ${Python3_SITELIB})
308309
endif()

src/Container.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ namespace digidoc
6868
static string m_appName = "libdigidocpp";
6969
static string m_userAgent = "libdigidocpp";
7070
static vector<decltype(&Container::createPtr)> m_createList {};
71-
static vector<decltype(&Container::openPtr)> m_openList {};
71+
using OpenCB = std::unique_ptr<Container> (*)(const std::string &path, ContainerOpenCB *cb);
72+
static vector<OpenCB> m_openList {};
7273
}
7374

7475
/**
@@ -96,14 +97,7 @@ string digidoc::userAgent() { return m_userAgent; }
9697
* Returns libdigidocpp library version
9798
*/
9899
string digidoc::version() {
99-
string ver = FILE_VER_STR;
100-
#if defined(DYNAMIC_LIBDIGIDOC) || defined(LINKED_LIBDIGIDOC)
101-
ver += "_ddoc";
102-
#endif
103-
#ifdef PDF_SUPPORT
104-
ver += "_siva";
105-
#endif
106-
return ver;
100+
return FILE_VER_STR;
107101
}
108102

109103
/**
@@ -348,10 +342,22 @@ Container* Container::open(const string &path)
348342
* @throws Exception
349343
*/
350344
unique_ptr<Container> Container::openPtr(const string &path)
345+
{
346+
return openPtr(path, {});
347+
}
348+
349+
/**
350+
* Opens container from a file
351+
*
352+
* @param path
353+
* @param cb Callback called when needed
354+
* @throws Exception
355+
*/
356+
unique_ptr<Container> Container::openPtr(const string &path, ContainerOpenCB *cb)
351357
{
352358
for(auto open: m_openList)
353359
{
354-
if(unique_ptr<Container> container = open(path))
360+
if(unique_ptr<Container> container = open(path, cb))
355361
return container;
356362
}
357363
return ASiC_E::openInternal(path);
@@ -417,7 +423,7 @@ unique_ptr<Container> Container::openPtr(const string &path)
417423
*
418424
* It must contain static members:
419425
* * static Container* createInternal(const std::string &path);
420-
* * static Container* openInternal(const std::string &path);
426+
* * static Container* openInternal(const std::string &path, digidoc::ContainerOpenCB *cb);
421427
*
422428
* @see Container::create, Container::open
423429
*/

0 commit comments

Comments
 (0)