summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Kellner <tobias.kellner@iaik.tugraz.at>2016-10-25 17:13:56 +0200
committerTobias Kellner <tobias.kellner@iaik.tugraz.at>2016-10-25 17:13:56 +0200
commitf2628d686bc18f84fc740741634b03908aa28d4f (patch)
tree87133913aed5bb6ad0e257800a36e414992a49ed
parentb2aa9ee20c719530cebebd6778ccedde292e6df2 (diff)
downloadpdf-over-f2628d686bc18f84fc740741634b03908aa28d4f.tar.gz
pdf-over-f2628d686bc18f84fc740741634b03908aa28d4f.tar.bz2
pdf-over-f2628d686bc18f84fc740741634b03908aa28d4f.zip
Check emblem hash for placeholder cache
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java6
-rw-r--r--pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java17
2 files changed, 22 insertions, 1 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java
index 306f74b7..6dc93ae9 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java
@@ -69,15 +69,18 @@ public class SignaturePlaceholderCache {
final String sigLangProp = "LANG"; //$NON-NLS-1$
final String sigEmblProp = "EMBL"; //$NON-NLS-1$
+ final String sigEHshProp = "EHSH"; //$NON-NLS-1$
final String sigPdfAProp = "PDFA"; //$NON-NLS-1$
final String sigNoteProp = "NOTE"; //$NON-NLS-1$
String sigLang = param.getSignatureLanguage();
String sigEmbl = ""; //$NON-NLS-1$
+ String sigEHsh = ""; //$NON-NLS-1$
if (param.getEmblem() != null) {
Emblem embl = param.getEmblem();
if (embl instanceof CachedFileNameEmblem) {
sigEmbl = ((CachedFileNameEmblem) embl).getOriginalFileName();
+ sigEHsh = ((CachedFileNameEmblem) embl).getOriginalFileHash();
} else {
sigEmbl = embl.getFileName();
}
@@ -94,6 +97,7 @@ public class SignaturePlaceholderCache {
sigProps.load(in);
if (sigLang.equals(sigProps.getProperty(sigLangProp)) &&
sigEmbl.equals(sigProps.getProperty(sigEmblProp)) &&
+ sigEHsh.equals(sigProps.getProperty(sigEHshProp)) &&
sigNote.equals(sigProps.getProperty(sigNoteProp)) &&
sigPdfA.equals(sigProps.getProperty(sigPdfAProp))) {
log.debug("Placeholder cache hit"); //$NON-NLS-1$
@@ -102,6 +106,7 @@ public class SignaturePlaceholderCache {
log.debug("Placeholder cache miss (" + //$NON-NLS-1$
sigLang + "|" + sigProps.getProperty(sigLangProp) + " - " +//$NON-NLS-1$ //$NON-NLS-2$
sigEmbl + "|" + sigProps.getProperty(sigEmblProp) + " - " + //$NON-NLS-1$ //$NON-NLS-2$
+ sigEHsh + "|" + sigProps.getProperty(sigEHshProp) + " - " + //$NON-NLS-1$ //$NON-NLS-2$
sigNote + "|" + sigProps.getProperty(sigNoteProp) + " - " + //$NON-NLS-1$ //$NON-NLS-2$
sigPdfA + "|" + sigProps.getProperty(sigPdfAProp) + ")"); //$NON-NLS-1$ //$NON-NLS-2$
} catch (Exception e) {
@@ -112,6 +117,7 @@ public class SignaturePlaceholderCache {
try {
sigProps.setProperty(sigLangProp, sigLang);
sigProps.setProperty(sigEmblProp, sigEmbl);
+ sigProps.setProperty(sigEHshProp, sigEHsh);
sigProps.setProperty(sigNoteProp, sigNote);
sigProps.setProperty(sigPdfAProp, sigPdfA);
OutputStream out = new FileOutputStream(new File(fileDir, propFileName));
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java
index dc54d84a..fe08abb6 100644
--- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java
+++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java
@@ -93,7 +93,7 @@ public class CachedFileNameEmblem implements Emblem {
return cachedEmblemFileName; //$NON-NLS-1$
}
}
- log.debug("Emblem cache miss");
+ log.debug("Emblem cache miss"); //$NON-NLS-1$
} catch (Exception e) {
log.warn("Can't load emblem cache", e); //$NON-NLS-1$
}
@@ -147,4 +147,19 @@ public class CachedFileNameEmblem implements Emblem {
public String getOriginalFileName() {
return this.fileName;
}
+
+ /**
+ * Return the original filename
+ * @return the original filename
+ */
+ public String getOriginalFileHash() {
+ if (this.fileName == null || !(new File(this.fileName).exists()))
+ return ""; //$NON-NLS-1$
+ try {
+ return getFileHash(this.fileName);
+ } catch (IOException e) {
+ log.debug("Error getting file hash", e);
+ return ""; //$NON-NLS-1$
+ }
+ }
}