PDFSubjectDN.java
7.25 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
161
162
163
164
165
166
167
168
169
170
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator
* com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator$Entry
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.digsig;
import com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public final class PDFSubjectDN
extends PDFCosDictionary {
private static HashSet<String> allowedAttribs = PDFSubjectDN.initializeSubjectDNAttributes();
private PDFSubjectDN(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
static PDFSubjectDN getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFSubjectDN pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFSubjectDN.class);
if (pdfObject == null) {
pdfObject = new PDFSubjectDN(cosObject);
}
return pdfObject;
}
public static PDFSubjectDN newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary cosObject = PDFCosObject.newCosDictionary(pdfDocument);
PDFSubjectDN pdfObject = new PDFSubjectDN((CosObject)cosObject);
return pdfObject;
}
protected static HashSet<String> initializeSubjectDNAttributes() {
HashSet<String> allowedAttribs = new HashSet<String>();
allowedAttribs.add("2.5.4.3");
allowedAttribs.add("cn");
allowedAttribs.add("2.5.4.4");
allowedAttribs.add("sn");
allowedAttribs.add("2.5.4.5");
allowedAttribs.add("serialNumber");
allowedAttribs.add("2.5.4.6");
allowedAttribs.add("c");
allowedAttribs.add("2.5.4.7");
allowedAttribs.add("l");
allowedAttribs.add("2.5.4.8");
allowedAttribs.add("st");
allowedAttribs.add("2.5.4.9");
allowedAttribs.add("street");
allowedAttribs.add("2.5.4.10");
allowedAttribs.add("o");
allowedAttribs.add("2.5.4.11");
allowedAttribs.add("ou");
allowedAttribs.add("2.5.4.12");
allowedAttribs.add("title");
allowedAttribs.add("2.5.4.14");
allowedAttribs.add("TEL");
allowedAttribs.add("2.5.4.15");
allowedAttribs.add("BC");
allowedAttribs.add("2.5.4.16");
allowedAttribs.add("postalAddress");
allowedAttribs.add("2.5.4.17");
allowedAttribs.add("postalCode");
allowedAttribs.add("2.5.4.41");
allowedAttribs.add("name");
allowedAttribs.add("2.5.4.42");
allowedAttribs.add("givenName");
allowedAttribs.add("2.5.4.43");
allowedAttribs.add("initials");
allowedAttribs.add("2.5.4.44");
allowedAttribs.add("generationQualifier");
allowedAttribs.add("2.5.4.46");
allowedAttribs.add("dnQualifier");
allowedAttribs.add("2.5.4.65");
allowedAttribs.add("pseudonym");
allowedAttribs.add("0.9.2342.19200300.100.1.25");
allowedAttribs.add("dc");
allowedAttribs.add("1.2.840.113549.1.9.1");
allowedAttribs.add("e");
allowedAttribs.add("email");
allowedAttribs.add("emailaddress");
allowedAttribs.add("ea");
allowedAttribs.add("1.3.36.8.3.14");
allowedAttribs.add("nameAtBirth");
allowedAttribs.add("1.3.6.1.5.5.7.9.3");
allowedAttribs.add("gender");
allowedAttribs.add("1.3.6.1.5.5.7.9.1");
allowedAttribs.add("dateOfBirth");
allowedAttribs.add("1.3.6.1.5.5.7.9.5");
allowedAttribs.add("countryOfResidence");
allowedAttribs.add("1.3.6.1.5.5.7.9.4");
allowedAttribs.add("countryOfCitizenship");
allowedAttribs.add("1.3.6.1.5.5.7.9.2");
allowedAttribs.add("placeOfBirth");
allowedAttribs.add("2.16.840.1.113730.3.2.2");
allowedAttribs.add("businessCategory");
return allowedAttribs;
}
public static HashSet<String> getAllowedAttribsSet() {
return allowedAttribs;
}
public void setAttributeValue(String attribute, String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (!this.checkValidity(attribute)) {
throw new PDFInvalidParameterException("The attribute " + attribute + " provided as part of the SubjectDN is not present in the legal attribute list.");
}
this.setDictionaryStringValue(ASName.create((String)attribute), value);
}
public Map getAttributes() throws PDFSecurityException, PDFIOException, PDFInvalidParameterException {
HashMap<String, String> subDNAttrValueMap = null;
CosDictionary cosDict = this.getCosDictionary();
if (cosDict == null) {
return subDNAttrValueMap;
}
CosContainerValuesIterator entriesIterator = cosDict.getValuesIterator();
subDNAttrValueMap = new HashMap<String, String>();
while (entriesIterator.hasNext()) {
try {
CosContainerValuesIterator.Entry entry = entriesIterator.next();
subDNAttrValueMap.put(entry.getKey().asString(true), entry.getValue().stringValue().asString());
continue;
}
catch (PDFCosParseException e) {
throw new PDFInvalidParameterException("SubjectDN attributes cannot be retrieved from the seed value dictionary", (Throwable)e);
}
}
return subDNAttrValueMap;
}
private boolean checkValidity(String attribute) {
if (allowedAttribs.contains(attribute.toLowerCase(Locale.getDefault()))) {
return true;
}
return false;
}
}