Skip to content

Commit

Permalink
Add callback to ask online validation confirmation (#566)
Browse files Browse the repository at this point in the history
IB-7865

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored Nov 20, 2023
1 parent 14e2f1f commit 8a28362
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
container: ${{ matrix.container }}
strategy:
matrix:
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:23.04', 'ubuntu:23.10']
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:23.10']
env:
DEBIAN_FRONTEND: noninteractive
DEBFULLNAME: github-actions
Expand Down
20 changes: 8 additions & 12 deletions examples/DigiDocCSharp/DigiDocCSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,34 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<ProjectGuid>{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DigiDocCSharp</RootNamespace>
<AssemblyName>DigiDocCSharp</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<DefineConstants>_WINDOWS</DefineConstants>
Expand Down
21 changes: 13 additions & 8 deletions examples/DigiDocCSharp/DigiDocCSharp.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C# Express 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34009.444
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigiDocCSharp", "DigiDocCSharp.csproj", "{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|x86.ActiveCfg = Debug|x86
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|x86.Build.0 = Debug|x86
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|x86.ActiveCfg = Release|x86
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|x86.Build.0 = Release|x86
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDEE2029-EA2A-49D2-80CB-F0E2E396B005}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D43E58D-0FD9-4023-A18F-D69EE6A229E1}
EndGlobalSection
EndGlobal
12 changes: 9 additions & 3 deletions examples/DigiDocCSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ private static void Sign(string[] args)
b.addDataFile(args[i], "application/octet-stream");
}
#if _WINDOWS
using (WinSigner signer = new WinSigner())
using (var signer = new WinSigner())
{
#else
using (PKCS11Signer signer = new PKCS11Signer())
using (var signer = new PKCS11Signer())
{
signer.setPin(args[1]);
#endif
Expand Down Expand Up @@ -184,7 +184,8 @@ private static void Verify(string file)
try
{
Console.WriteLine("Opening file: " + file);
Container b = Container.open(file);
var cb = new ContainerOpen();
Container b = Container.open(file, cb);

Console.WriteLine("Files:");
foreach (DataFile d in b.dataFiles())
Expand Down Expand Up @@ -226,4 +227,9 @@ private static void Version()
" libdigidocpp " + digidoc.digidoc.version());
}
}

class ContainerOpen : ContainerOpenCB
{
override public bool validateOnline() { return true; }
}
}
2 changes: 1 addition & 1 deletion examples/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

## Run

java -Djava.library.path=/Library/libdigidocpp/lib -jar build/libs/libdigidoc.jar
java -Djava.library.path=/some/path/lib -jar build/libs/libdigidoc.jar
Binary file modified examples/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 10 additions & 5 deletions examples/java/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,10 +131,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down Expand Up @@ -197,6 +198,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ static void verify(String file) {
try
{
System.out.println("Opening file: " + file);
Container b = Container.open(file);
ContainerOpen cb = new ContainerOpen();
Container b = Container.open(file, cb);
assert b != null;

System.out.println("Files:");
Expand Down Expand Up @@ -200,4 +201,10 @@ static byte[] fromHex(String s) {
}
return data;
}

static private class ContainerOpen extends ContainerOpenCB
{
@Override
public boolean validateOnline() { return true; }
}
}
10 changes: 9 additions & 1 deletion examples/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
import sys
import os

class ContainerOpenCB(digidoc.ContainerOpenCB):

def __init__(self):
digidoc.ContainerOpenCB.__init__(self)

def validateOnline(self):
return True

class Program:
digidoc.initialize()
Expand Down Expand Up @@ -78,7 +85,8 @@ def sign(self, args):

def verify(self, file):
print("Opening file: " + file)
doc = digidoc.Container.open(file)
cb = ContainerOpenCB()
doc = digidoc.Container.open(file, cb)

print("Files:")
for d in doc.dataFiles():
Expand Down
2 changes: 2 additions & 0 deletions libdigidocpp.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,8 @@ Signature Validation Policy
Default POLv2

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

(ignore, warning, error) </td><td>Optional</td><td>
Expand Down
15 changes: 11 additions & 4 deletions libdigidocpp.i
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// digidocpp.i - SWIG interface for libdigidocpp library

%module digidoc
%module(directors="1") digidoc

%begin %{
#ifdef _MSC_VER
Expand Down Expand Up @@ -231,6 +231,8 @@ extern "C"
%newobject digidoc::Container::open;
%newobject digidoc::Container::create;

%feature("director") digidoc::ContainerOpenCB;

%typemap(javacode) digidoc::Conf %{
public Conf transfer() {
swigCMemOwn = false;
Expand Down Expand Up @@ -318,16 +320,21 @@ namespace std {
}
}
%extend digidoc::Container {
static digidoc::Container* open(const std::string &path, digidoc::ContainerOpenCB *cb)
{
return digidoc::Container::openPtr(path, cb).release();
}

digidoc::Signature* prepareWebSignature(const std::vector<unsigned char> &cert, const std::string &profile = {},
const std::vector<std::string> &roles = {},
const std::string &city = {}, const std::string &state = {},
const std::string &postalCode = {}, const std::string &country = {})
{
class : public digidoc::Signer
class final: public digidoc::Signer
{
public:
digidoc::X509Cert cert() const override { return _cert; }
std::vector<unsigned char> sign(const std::string &, const std::vector<unsigned char> &) const override
digidoc::X509Cert cert() const final { return _cert; }
std::vector<unsigned char> sign(const std::string &, const std::vector<unsigned char> &) const final
{
THROW("Not implemented");
}
Expand Down
8 changes: 3 additions & 5 deletions src/ASiC_S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void ASiC_S::addAdESSignature(istream & /*signature*/)
THROW("Not implemented.");
}

unique_ptr<Container> ASiC_S::openInternal(const string &path)
unique_ptr<Container> ASiC_S::openInternal(const string &path, ContainerOpenCB * /*cb*/)
{
if (!isContainerSimpleFormat(path))
return {};
Expand Down Expand Up @@ -130,11 +130,9 @@ Signature *ASiC_S::sign(Signer * /*signer*/)
bool ASiC_S::isContainerSimpleFormat(const string &path)
{
DEBUG("isContainerSimpleFormat(path = '%s')", path.c_str());
const auto extension = util::File::fileExtension(path);
if(extension == ASICE_EXTENSION || extension == ASICE_EXTENSION_ABBR ||
extension == BDOC_EXTENSION)
if(util::File::fileExtension(path, {"asice", "sce", "bdoc"}))
return false;
if(extension == ASICS_EXTENSION || extension == ASICS_EXTENSION_ABBR)
if(util::File::fileExtension(path, {"asics", "scs"}))
return true;
DEBUG("Check if ASiC/zip containter");
try
Expand Down
2 changes: 1 addition & 1 deletion src/ASiC_S.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace digidoc
Signature* sign(Signer* signer) override;

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

private:
ASiC_S();
Expand Down
6 changes: 0 additions & 6 deletions src/ASiContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ class ASiContainer::Private
map<string, ZipSerialize::Properties> properties;
};

const string_view ASiContainer::ASICE_EXTENSION = "asice";
const string_view ASiContainer::ASICE_EXTENSION_ABBR = "sce";
const string_view ASiContainer::ASICS_EXTENSION = "asics";
const string_view ASiContainer::ASICS_EXTENSION_ABBR = "scs";
const string_view ASiContainer::BDOC_EXTENSION = "bdoc";

const string ASiContainer::MIMETYPE_ASIC_E = "application/vnd.etsi.asic-e+zip";
const string ASiContainer::MIMETYPE_ASIC_S = "application/vnd.etsi.asic-s+zip";
//https://signa.mitsoft.lt/static/signa-web/webResources/docs/ADOC_specification_approved20090907_EN.pdf
Expand Down
6 changes: 0 additions & 6 deletions src/ASiContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ namespace digidoc
class ASiContainer: public Container
{
public:
static const std::string_view ASICE_EXTENSION;
static const std::string_view ASICE_EXTENSION_ABBR;
static const std::string_view ASICS_EXTENSION;
static const std::string_view ASICS_EXTENSION_ABBR;
static const std::string_view BDOC_EXTENSION;

static const std::string MIMETYPE_ASIC_E;
static const std::string MIMETYPE_ASIC_S;
static const std::string MIMETYPE_ADOC;
Expand Down
17 changes: 9 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,11 @@ if(SWIG_FOUND)
target_include_directories(digidoc_java PRIVATE ${JAVA_INCLUDE_PATH} $<$<BOOL:${JAVA_INCLUDE_PATH2}>:${JAVA_INCLUDE_PATH2}>)
target_compile_definitions(digidoc_java PRIVATE TARGET_NAME="$<TARGET_NAME:digidoc_java>")
target_link_libraries(digidoc_java digidocpp digidocpp_util digidocpp_ver)
set_property(TARGET digidoc_java PROPERTY SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>)
if(APPLE)
set_target_properties(digidoc_java PROPERTIES MACOSX_RPATH YES INSTALL_RPATH /Library/Frameworks)
install(TARGETS digidoc_java DESTINATION /Library/Java/Extensions)
else()
install(TARGETS digidoc_java DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
set_target_properties(digidoc_java PROPERTIES
INSTALL_RPATH $<$<PLATFORM_ID:Darwin>:/Library/Frameworks>
SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>
)
install(TARGETS digidoc_java DESTINATION $<IF:$<PLATFORM_ID:Darwin>,/Library/Java/Extensions,${CMAKE_INSTALL_LIBDIR}>)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/java/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ee/ria/libdigidocpp FILES_MATCHING PATTERN "*.java")
if(WIN32)
install(FILES $<TARGET_PDB_FILE:digidoc_java> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
Expand All @@ -289,7 +287,6 @@ if(SWIG_FOUND)
swig_add_library(digidoc_python LANGUAGE python SOURCES ../libdigidocpp.i)
target_compile_definitions(digidoc_python PRIVATE TARGET_NAME="$<TARGET_NAME:digidoc_python>")
target_link_libraries(digidoc_python digidocpp digidocpp_util digidocpp_ver Python3::Module)
set_property(TARGET digidoc_python PROPERTY SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>)
#configure_file(setup.py.cmake setup.py)
#install(CODE "execute_process(COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)")
if(NOT Python3_SITELIB)
Expand All @@ -303,6 +300,10 @@ if(SWIG_FOUND)
else()
set_target_properties(digidoc_python PROPERTIES SUFFIX .so)
endif()
set_target_properties(digidoc_python PROPERTIES
INSTALL_RPATH $<$<PLATFORM_ID:Darwin>:/Library/Frameworks>
SWIG_COMPILE_DEFINITIONS $<$<PLATFORM_ID:Windows>:SWIGWIN>
)
install(TARGETS digidoc_python DESTINATION ${Python3_SITELIB})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc.py DESTINATION ${Python3_SITELIB})
endif()
Expand Down
Loading

0 comments on commit 8a28362

Please sign in to comment.