Skip to content

Commit

Permalink
Merge pull request #3 from MrMabulous/ltv_fix
Browse files Browse the repository at this point in the history
Fixed an error if pdf is signed without tsa defined
  • Loading branch information
MrMabulous authored Feb 21, 2021
2 parents e5c8b5f + 44f7eb1 commit 3127b6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ token, which will actually timestamp the document. This way Adobe Reader will re

## usage
```
pdfsign v1.6.0, (c) 2021 Mabulous GmbH
pdfsign v1.6.1, (c) 2021 Mabulous GmbH
powered by:
pdfsign v1.3.0, (c) 2019 icomedias GmbH
iTextSharp 5.5 Copyright (C) 1999-2018 by iText Group NV
Expand Down
4 changes: 2 additions & 2 deletions pdfsign/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
19 changes: 17 additions & 2 deletions pdfsign/pdfsign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Program
{
static void ShowHelp(OptionSet p)
{
Console.WriteLine("pdfsign v1.6.0, (c) 2021 Mabulous GmbH");
Console.WriteLine("pdfsign v1.6.1, (c) 2021 Mabulous GmbH");
Console.WriteLine("powered by:");
Console.WriteLine("pdfsign v1.3.0, (c) 2019 icomedias GmbH");
Console.WriteLine("iTextSharp 5.5 Copyright (C) 1999-2018 by iText Group NV");
Expand Down Expand Up @@ -133,7 +133,7 @@ static int Main(string[] args)
{ "tsa=", "URL of rfc3161 TSA (Time Stamping Authority)", v => tsa_url = v },
{ "tsauser=", "If selected TSA server requires credentials, enter username (optional)", v => tsa_user = v },
{ "tsapass=", "If selected TSA server requires credentials, enter password (optional)", v => tsa_user = v },
{ "ltv", "Enables Long Term Validation, on: -ltv+, off: -ltv-, default on", v => use_ltv = v != null },
{ "ltv", "Enables Long Term Validation, on: -ltv+, off: -ltv-, only takes effect if tsa is defined, default on", v => use_ltv = v != null },
{ "certlevel=", "Certification Level. 0: Not certified, 1: No changes allowed, 2: Only Allow Form-Filling, 3: Only Allow Form-Filling & Annotations, default 0", (int v) => certification_level = v},
{ "width=", "Signature width, default 180", (int v) => width = v},
{ "height=", "Signature height, default 80", (int v) => height = v},
Expand Down Expand Up @@ -229,6 +229,9 @@ static int Main(string[] args)
if(certification_level > 3 || certification_level < 0)
throw new OptionException("invalid value for parameter {0}, must be 0-3", "certlevel");

if(string.IsNullOrEmpty(tsa_url))
use_ltv = false;

if((tsa_user != null && tsa_pass == null) || (tsa_user == null && tsa_pass != null))
throw new OptionException("To use TSA authentication both {0} must be specified", "tsauser and tsapass");

Expand Down Expand Up @@ -535,6 +538,18 @@ static int Main(string[] args)
sap.Certificate = tsaCert;
}
adobeLtvEnabling.outputDss();
} else if(tsaClient != null)
{
// Request a dummy token in any case so that size estimate for actual token will be correct.
IDigest messageDigest = tsaClient.GetMessageDigest();
byte[] tsImprint = new byte[messageDigest.GetDigestSize()];
messageDigest.DoFinal(tsImprint, 0);
byte[] tsToken;
try {
tsToken = tsaClient.GetTimeStampToken(tsImprint);
} catch(Exception e) {
throw new InvalidOperationException("Failed to request dummy TSA token: "+ e.Message);
}
}

if(timestamp_only) {
Expand Down

0 comments on commit 3127b6c

Please sign in to comment.