Skip to content

Commit e0a9340

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

19 files changed

+120
-58
lines changed

examples/DigiDocCSharp/DigiDocCSharp.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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>
5+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
66
<ProductVersion>8.0.30703</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
88
<ProjectGuid>{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}</ProjectGuid>
@@ -14,8 +14,8 @@
1414
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
1515
<FileAlignment>512</FileAlignment>
1616
</PropertyGroup>
17-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18-
<PlatformTarget>x86</PlatformTarget>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
18+
<PlatformTarget>x64</PlatformTarget>
1919
<DebugSymbols>true</DebugSymbols>
2020
<DebugType>full</DebugType>
2121
<Optimize>false</Optimize>
@@ -25,8 +25,8 @@
2525
<WarningLevel>4</WarningLevel>
2626
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2727
</PropertyGroup>
28-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
29-
<PlatformTarget>x86</PlatformTarget>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
29+
<PlatformTarget>x64</PlatformTarget>
3030
<DebugType>pdbonly</DebugType>
3131
<Optimize>true</Optimize>
3232
<OutputPath>bin\Release\</OutputPath>

examples/DigiDocCSharp/DigiDocCSharp.sln

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigiDocCSharp", "DigiDocCSh
55
EndProject
66
Global
77
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8-
Debug|x86 = Debug|x86
9-
Release|x86 = Release|x86
8+
Debug|x64 = Debug|x64
9+
Release|x64 = Release|x64
1010
EndGlobalSection
1111
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
12+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|x64.ActiveCfg = Debug|x64
13+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|x64.Build.0 = Debug|x64
14+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|x64.ActiveCfg = Release|x64
15+
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|x64.Build.0 = Release|x64
1616
EndGlobalSection
1717
GlobalSection(SolutionProperties) = preSolution
1818
HideSolutionNode = FALSE

examples/DigiDocCSharp/Program.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -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
}
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
*/

src/Container.h

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ DIGIDOCPP_EXPORT void terminate();
4040
DIGIDOCPP_EXPORT std::string userAgent();
4141
DIGIDOCPP_EXPORT std::string version();
4242

43+
struct ContainerOpenCB {
44+
virtual ~ContainerOpenCB() = default;
45+
virtual bool validateOnline() const { return true; }
46+
};
47+
4348
class DIGIDOCPP_EXPORT Container
4449
{
4550
public:
@@ -66,6 +71,7 @@ class DIGIDOCPP_EXPORT Container
6671
static std::unique_ptr<Container> createPtr(const std::string &path);
6772
DIGIDOCPP_DEPRECATED static Container* open(const std::string &path);
6873
static std::unique_ptr<Container> openPtr(const std::string &path);
74+
static std::unique_ptr<Container> openPtr(const std::string &path, digidoc::ContainerOpenCB *cb);
6975
template<class T>
7076
static void addContainerImplementation();
7177

0 commit comments

Comments
 (0)