Skip to content

Commit

Permalink
Update changelog and signing support with swig C# wrapper
Browse files Browse the repository at this point in the history
IB-3896
  • Loading branch information
metsma committed Apr 10, 2015
1 parent 15c032c commit c0b179e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 50 deletions.
13 changes: 12 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
Libdigidocpp library 3.10 release notes
Libdigidocpp library 3.10.3 release notes
--------------------------------------
Changes compared to ver 3.10.0
- Updated experimental .NET C# wrapper swig configuration file to recent API
- Included C# wrapper files in Windows installer package
- Filter out CA certificates in PKCS11Signer implementation to support Finland id-card signing in digidoc-tool
- On signature validation at least one DataFile should be signed
- Disable OCSP time slot check – local computer time against OCSP server time



Libdigidocpp library 3.10.0 release notes
--------------------------------------
Changes compared to ver 3.9

Expand Down
2 changes: 1 addition & 1 deletion cmake
6 changes: 0 additions & 6 deletions examples/DigiDocCSharp/DigiDocCSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
83 changes: 45 additions & 38 deletions examples/DigiDocCSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// This software is released under the BSD License (see LICENSE.BSD)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using digidoc;

namespace DigiDocCSharp
Expand All @@ -21,21 +19,13 @@ static void Main(string[] args)
return;
}

int pos = args[0].IndexOf("=");
switch (pos == -1 ? args[0] : args[0].Substring(0, pos))
switch (args[0])
{
case "-extract":
if (pos < 0)
{
Console.WriteLine("Index must be 0 or greater");
help();
}
else
extract(Convert.ToInt32(args[0].Substring(pos + 1)), args[1]);
return;
case "-verify": verify(args[1]); return;
case "-version": version(); return;
case "-help":
case "extract": extract(Convert.ToInt32(args[1]), args[2]); return;
case "sign": sign(args); return;
case "verify": verify(args[1]); return;
case "version": version(); return;
case "help":
default: help(); return;
}
}
Expand Down Expand Up @@ -69,15 +59,38 @@ static void extract(int index, string file)

static void help()
{
Console.WriteLine("DigiDocCSharpt [[command] file]");
Console.WriteLine("DigiDocCSharpt command");
Console.WriteLine("Command:");
Console.WriteLine(" -extract=[num]\tExtracts files from document");
Console.WriteLine(" -help\t\tPrints utility commands");
Console.WriteLine(" -verify\tVerifies document signature and shows info");
Console.WriteLine(" -version\tPrints utility version");
Console.WriteLine(" extract\tExtracts files from document");
Console.WriteLine(" num");
Console.WriteLine(" file");
Console.WriteLine(" help\t\tPrints utility commands");
Console.WriteLine(" sign\t\tSigns file");
Console.WriteLine(" verify\t\tVerifies document signature and shows info");
Console.WriteLine(" file");
Console.WriteLine(" version\tPrints utility version");
version();
}

static void sign(string[] args)
{
digidoc.digidoc.initialize();
try
{
Console.WriteLine("Creating file: " + args[args.Length-1]);
Container b = new Container(Container.DocumentType.BDocType);
for (int i = 1; i < args.Length - 1; ++i)
b.addDataFile(args[i], "");
b.sign("", "", "", "", new StringVector { }, "");
b.save(args[args.Length - 1]);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
digidoc.digidoc.terminate();
}

static void verify(string file)
{
digidoc.digidoc.initialize();
Expand All @@ -88,9 +101,7 @@ static void verify(string file)

Console.WriteLine("Files:");
foreach (DataFile d in b.dataFiles())
{
Console.WriteLine(" {0} - {1}", d.fileName(), d.mediaType());
}
Console.WriteLine();

Console.WriteLine("Signatures:");
Expand All @@ -104,32 +115,28 @@ static void verify(string file)
Console.WriteLine();

Console.WriteLine("Time: " + s.signingTime());

System.Security.Cryptography.X509Certificates.X509Certificate2 c =
new System.Security.Cryptography.X509Certificates.X509Certificate2(s.signingCert());
X509Certificate2 c = new X509Certificate2(s.signingCert());
Console.WriteLine("Cert: " + c.Subject);
try
{
s.validate();
Console.WriteLine("Signature is valid");
}
catch (Exception e)
{
Console.WriteLine("Signature is invalid");
Console.WriteLine(e.Message);
}

Console.WriteLine("ProducedAt: " + s.producedAt());
c = new X509Certificate2(s.OCSPCert());
Console.WriteLine("OCSP Cert: " + c.Subject);

s.validate();
Console.WriteLine("Signature is valid");
}
}
catch (Exception e)
{
Console.WriteLine("Signature is invalid");
Console.WriteLine(e.Message);
}
digidoc.digidoc.terminate();
}

static void version()
{
Console.WriteLine("DigiDocCSharp 0.1");
Console.WriteLine("DigiDocCSharp 0.1 libdigidocpp " + digidoc.digidoc.version());
}
}
}
2 changes: 1 addition & 1 deletion examples/DigiDocCSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DigiDocCSharp")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
5 changes: 2 additions & 3 deletions src/digidoc.i
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@
%feature("notabstract") digidoc::Signature; // Breaks PHP if abstract
#endif

// TODO: useful, but broken
%ignore *::sign;

// ignore X509Cert and implement later cert as ByteVector
%ignore digidoc::Signature::signingCertificate;
%ignore digidoc::Signature::OCSPCertificate;
%ignore digidoc::Signature::TSCertificate;
%ignore digidoc::Container::addRawSignature(std::istream &signature);
%ignore digidoc::Container::addDataFile(std::istream *is, const std::string &fileName, const std::string &mediaType);
%ignore digidoc::Container::sign(Signer* signer);
%ignore digidoc::Container::sign(Signer* signer, const std::string &profile);
%ignore digidoc::DataFile::saveAs(std::ostream &os) const;

// Handle standard C++ types
Expand Down

0 comments on commit c0b179e

Please sign in to comment.