PDFSignatureReference.java
7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.cos.CosString
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.digsig;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosString;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFSignature;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFTransformParameters;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFTransformParametersDocMDP;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFTransformParametersFieldMDP;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFTransformParametersUR;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
public class PDFSignatureReference
extends PDFCosDictionary {
public static final ASName k_SigRef = ASName.create((String)"SigRef");
public static final ASName k_TransformParams = ASName.create((String)"TransformParams");
public static final ASName k_TransformMethod = ASName.create((String)"TransformMethod");
public static final ASName k_DigestMethod = ASName.create((String)"DigestMethod");
public static final ASName k_DigestValue = ASName.create((String)"DigestValue");
public static final ASName k_DigestLocation = ASName.create((String)"DigestLocation");
protected PDFSignatureReference(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFSignatureReference getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFSignatureReference pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFSignatureReference.class);
if (pdfObject == null) {
pdfObject = new PDFSignatureReference(cosObject);
}
return pdfObject;
}
public static PDFSignatureReference newInstance(PDFDocument pdfDocument, ASName transformMethod) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
CosDictionary cosObject = PDFCosObject.newCosDirectDictionary(pdfDocument);
PDFSignatureReference pdfObject = new PDFSignatureReference((CosObject)cosObject);
pdfObject.setDictionaryNameValue(ASName.k_Type, k_SigRef);
pdfObject.setDictionaryNameValue(k_TransformMethod, transformMethod);
return pdfObject;
}
public ASName getType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Type);
}
public ASName getTransformMethodName() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
return this.getDictionaryNameValue(k_TransformMethod);
}
public void setTransformMethodName(String transformMethod) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
this.setDictionaryNameValue(k_TransformMethod, transformMethod);
}
public PDFTransformParameters getPDFTransformParameters() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
ASName transformMethod = this.getTransformMethodName();
if (transformMethod == PDFSignature.k_DocMDP) {
return PDFTransformParametersDocMDP.getInstance(this.getDictionaryCosObjectValue(k_TransformParams));
}
if (transformMethod == PDFSignature.k_UR || transformMethod == PDFSignature.k_UR3) {
return PDFTransformParametersUR.getInstance(this.getDictionaryCosObjectValue(k_TransformParams));
}
if (transformMethod == PDFSignature.k_FieldMDP) {
return PDFTransformParametersFieldMDP.getInstance(this.getDictionaryCosObjectValue(k_TransformParams));
}
return null;
}
public void setPDFTransformParameters(PDFTransformParameters params) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
this.setDictionaryValue(k_TransformParams, params);
}
public CosObject getData() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
return this.getDictionaryCosObjectValue(ASName.k_Data);
}
public void setData(CosObject data) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
if (data == null && (this.getTransformMethodName() == PDFSignature.k_FieldMDP || this.getTransformMethodName() == PDFSignature.k_Identity)) {
throw new PDFInvalidDocumentException("Invalid Parameter: data can not be null");
}
this.setDictionaryValue(ASName.k_Data, data);
}
public String getDigestMethod() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
return this.getDictionaryNameValueAsString(k_DigestMethod);
}
public ASName getDigestMethodName() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
return this.getDictionaryNameValue(k_DigestMethod);
}
public void setDigestMethod(String method) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
this.setDictionaryNameValue(k_DigestMethod, method);
}
public byte[] getDigest() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
CosString digestStr = this.getCosDictionary().getCosString(k_DigestValue);
if (digestStr != null) {
if (digestStr.getIsEncrypted()) {
digestStr.setIsEncrypted(false);
}
return digestStr.byteArrayValue();
}
return null;
}
public void setDigest(byte[] value) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
this.setDictionaryByteArrayValue(k_DigestValue, value);
CosString digestStr = this.getCosDictionary().getCosString(k_DigestValue);
digestStr.setWriteHex(true);
if (digestStr.getToEncrypt()) {
digestStr.setToEncrypt(false);
}
this.setDigestLocation(1234567890, 1234567890);
}
public long[] getDigestLocation() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(k_DigestLocation);
if (cosArray != null) {
return cosArray.getArrayLong();
}
return null;
}
public void setDigestLocation(long offset, long length) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
CosArray cosArray = null;
if (this.getCosDictionary().containsKey((Object)k_DigestLocation)) {
cosArray = this.getDictionaryArrayValue(k_DigestLocation);
cosArray.clear();
} else {
cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
this.setDictionaryArrayValue(k_DigestLocation, cosArray);
}
cosArray.addLong(0, offset);
cosArray.addLong(1, length);
}
}