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 |
|
package issrg.ac; |
77 |
|
|
78 |
|
import iaik.asn1.structures.GeneralNames; |
79 |
|
|
80 |
|
import issrg.utils.EnvironmentalVariables; |
81 |
|
|
82 |
|
import java.security.MessageDigest; |
83 |
|
import java.util.Calendar; |
84 |
|
import java.util.GregorianCalendar; |
85 |
|
import java.util.Map; |
86 |
|
import java.math.BigInteger; |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@author |
93 |
|
@version |
94 |
|
|
95 |
|
|
|
|
| 51.1% |
Uncovered Elements: 65 (133) |
Complexity: 28 |
Complexity Density: 0.46 |
|
96 |
|
public class Util { |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
final public static String SN_ATTRIBUTE_TYPE = "SN"; |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
|
108 |
|
@return |
109 |
|
|
110 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
111 |
3651
|
public static String generalNamesToString(iaik.asn1.structures.GeneralNames gns){... |
112 |
3651
|
try{ |
113 |
3651
|
iaik.asn1.structures.Name name=new iaik.asn1.structures.Name(); |
114 |
3651
|
if (gns!=null){ |
115 |
|
|
116 |
7302
|
for (java.util.Enumeration e = gns.getNames(); e.hasMoreElements(); ){ |
117 |
3651
|
iaik.asn1.structures.GeneralName gn = (iaik.asn1.structures.GeneralName)e.nextElement(); |
118 |
3651
|
if (gn.getType()==iaik.asn1.structures.GeneralName.directoryName){ |
119 |
3651
|
iaik.asn1.structures.Name n=(iaik.asn1.structures.Name)gn.getName(); |
120 |
18514
|
for (java.util.Enumeration e_rdns=n.elements(); e_rdns.hasMoreElements();){ |
121 |
14863
|
name.addRDN((iaik.asn1.structures.RDN)e_rdns.nextElement()); |
122 |
|
} |
123 |
|
} |
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
3651
|
return name.getRFC2253String(); |
128 |
|
}catch (iaik.utils.RFC2253NameParserException re){ |
129 |
0
|
return null; |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@param |
138 |
|
@param |
139 |
|
|
140 |
|
@return |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
142 |
0
|
public static String issuerSerialToDN(String issuerDN, java.math.BigInteger serialNumber){... |
143 |
0
|
if (issuerDN==null || serialNumber==null){ |
144 |
|
|
145 |
0
|
return null; |
146 |
|
} |
147 |
0
|
return SN_ATTRIBUTE_TYPE+"="+serialNumber.toString()+((issuerDN.intern()=="")?"":(","+issuerDN)); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@param |
155 |
|
|
156 |
|
@return |
157 |
|
|
158 |
|
|
159 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
160 |
0
|
public static String issuerToString(AttCertIssuer aci){... |
161 |
0
|
String issuer = null; |
162 |
0
|
if (aci.getV1Form() != null) issuer=generalNamesToString(aci.getV1Form()); |
163 |
0
|
else if (aci.getV2Form() != null){ |
164 |
0
|
if (aci.getV2Form().getIssuerName() != null) issuer=generalNamesToString(aci.getV2Form().getIssuerName()); |
165 |
|
} |
166 |
|
|
167 |
0
|
return issuer; |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@param |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
@return |
182 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
183 |
22
|
public static iaik.asn1.structures.GeneralNames buildGeneralNames(String DN){... |
184 |
|
|
185 |
22
|
try{ |
186 |
22
|
DN = issrg.utils.RFC2253NameParser.toCanonicalDN(issrg.utils.RFC2253NameParser.distinguishedName(DN)); |
187 |
|
|
188 |
22
|
iaik.asn1.structures.GeneralNames result=new iaik.asn1.structures.GeneralNames( |
189 |
|
new iaik.asn1.structures.GeneralName( |
190 |
|
iaik.asn1.structures.GeneralName.directoryName, |
191 |
|
new iaik.utils.RFC2253NameParser(DN).parse() |
192 |
|
)); |
193 |
|
|
194 |
22
|
if (result==null){ |
195 |
0
|
throw new iaik.utils.RFC2253NameParserException(); |
196 |
|
} |
197 |
|
|
198 |
22
|
return result; |
199 |
|
}catch (issrg.utils.RFC2253ParsingException npe){ |
200 |
0
|
return new iaik.asn1.structures.GeneralNames( |
201 |
|
new iaik.asn1.structures.GeneralName( |
202 |
|
iaik.asn1.structures.GeneralName.directoryName, |
203 |
|
new iaik.asn1.structures.Name() |
204 |
|
) |
205 |
|
); |
206 |
|
}catch (iaik.utils.RFC2253NameParserException re){ |
207 |
0
|
return new iaik.asn1.structures.GeneralNames( |
208 |
|
new iaik.asn1.structures.GeneralName( |
209 |
|
iaik.asn1.structures.GeneralName.directoryName, |
210 |
|
new iaik.asn1.structures.Name() |
211 |
|
) |
212 |
|
); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@param |
222 |
|
|
223 |
|
@return |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
225 |
48
|
public static String hashToString(byte [] hash){... |
226 |
48
|
BigInteger bi = new BigInteger(hash); |
227 |
48
|
if (bi.signum()<0) bi = bi.xor(BigInteger.ONE. |
228 |
|
negate(). |
229 |
|
shiftLeft(hash.length<<3) |
230 |
|
); |
231 |
|
|
232 |
48
|
return bi.toString(16); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
@param |
239 |
|
|
240 |
|
@return |
241 |
|
|
242 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
243 |
48
|
public static byte[] hashString(String s){... |
244 |
0
|
if (s==null) return null; |
245 |
|
|
246 |
48
|
try{ |
247 |
48
|
MessageDigest md5 = MessageDigest.getInstance("MD5"); |
248 |
48
|
return md5.digest(s.getBytes()); |
249 |
|
}catch(java.security.NoSuchAlgorithmException nse){ |
250 |
0
|
return null; |
251 |
|
} |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
@param |
260 |
|
|
261 |
|
@return |
262 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
263 |
48
|
public static byte[] hashDN(String name){... |
264 |
48
|
try{ |
265 |
48
|
name = issrg.utils.RFC2253NameParser.toCanonicalDN(issrg.utils.RFC2253NameParser.distinguishedName(name)).toUpperCase(); |
266 |
|
}catch (issrg.utils.RFC2253ParsingException rpe){ |
267 |
0
|
name = null; |
268 |
|
} |
269 |
|
|
270 |
48
|
return hashString(name); |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
@param |
278 |
|
|
279 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
280 |
0
|
public static byte[] hashName(GeneralNames gn){... |
281 |
0
|
String name = Util.generalNamesToString(gn); |
282 |
0
|
return hashDN(name); |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
@param |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
@return |
297 |
|
@throws |
298 |
|
|
299 |
|
|
|
|
| 65% |
Uncovered Elements: 14 (40) |
Complexity: 8 |
Complexity Density: 0.29 |
|
300 |
60
|
public static issrg.ac.Generalized_Time buildGeneralizedTime(String date) throws ACCreationException{... |
301 |
60
|
int yr=0, mon=1, day=1; |
302 |
60
|
int hour=0, min=0, sec=0; |
303 |
|
|
304 |
60
|
int i; |
305 |
60
|
String d = date+Util.DATE_SEPARATOR; |
306 |
|
|
307 |
60
|
try{ |
308 |
60
|
i=d.indexOf(Util.DATE_SEPARATOR); |
309 |
60
|
yr = Integer.parseInt(d.substring(0, i)); |
310 |
0
|
if ((d = d.substring(i+Util.DATE_SEPARATOR.length())).intern()!=""){ |
311 |
60
|
i=d.indexOf(Util.DATE_SEPARATOR); |
312 |
60
|
mon = Integer.parseInt(d.substring(0, i)); |
313 |
0
|
if ((d = d.substring(i+Util.DATE_SEPARATOR.length())).intern()!=""){ |
314 |
60
|
d=d.substring(0, d.length()-Util.DATE_SEPARATOR.length())+" "; |
315 |
60
|
i=d.indexOf(" "); |
316 |
60
|
day = Integer.parseInt(d.substring(0, i)); |
317 |
0
|
if ((d = d.substring(i+1)).intern()!=""){ |
318 |
60
|
d=d.substring(0, d.length()-1)+Util.TIME_SEPARATOR; |
319 |
60
|
i=d.indexOf(Util.TIME_SEPARATOR); |
320 |
60
|
hour = Integer.parseInt(d.substring(0, i)); |
321 |
0
|
if ((d = d.substring(i+Util.TIME_SEPARATOR.length())).intern()!=""){ |
322 |
60
|
i=d.indexOf(Util.TIME_SEPARATOR); |
323 |
60
|
min = Integer.parseInt(d.substring(0, i)); |
324 |
0
|
if ((d = d.substring(i+Util.TIME_SEPARATOR.length())).intern()!=""){ |
325 |
60
|
i=d.indexOf(Util.TIME_SEPARATOR); |
326 |
60
|
sec = Integer.parseInt(d.substring(0, i)); |
327 |
0
|
if ((d = d.substring(i+Util.TIME_SEPARATOR.length())).intern()!=""){ |
328 |
0
|
throw new NumberFormatException(); |
329 |
|
} |
330 |
|
} |
331 |
|
} |
332 |
|
} |
333 |
|
} |
334 |
|
} |
335 |
|
|
336 |
60
|
return new issrg.ac.Generalized_Time(new java.util.GregorianCalendar(yr, mon-1, day, hour, min, sec)); |
337 |
|
|
338 |
|
|
339 |
|
}catch (NumberFormatException nfe){ |
340 |
0
|
throw new ACCreationException("Invalid date format in ["+date+"].\n[yyyy"+Util.DATE_SEPARATOR+"mm"+Util.DATE_SEPARATOR+"dd hh"+Util.TIME_SEPARATOR+"mm"+Util.TIME_SEPARATOR+"ss] was expected."); |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
public static String TIME_SEPARATOR = ":"; |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
public static String SN_NAME_SEPARATOR = ";"; |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
public static String DATE_SEPARATOR = "."; |
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
@param |
363 |
|
@return |
364 |
|
|
365 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
366 |
0
|
public static String timeToString(java.util.Calendar date){... |
367 |
0
|
return date.get(date.YEAR)+Util.DATE_SEPARATOR+ |
368 |
|
(date.get(date.MONTH)+1)+Util.DATE_SEPARATOR+ |
369 |
|
|
370 |
|
date.get(date.DAY_OF_MONTH)+" "+ |
371 |
|
date.get(date.HOUR_OF_DAY)+Util.TIME_SEPARATOR+ |
372 |
|
date.get(date.MINUTE)+Util.TIME_SEPARATOR+ |
373 |
|
date.get(date.SECOND); |
374 |
|
} |
375 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
376 |
0
|
public static issrg.ac.IssuerSerial buildIssuerSerial(String what) throws ACCreationException{... |
377 |
|
|
378 |
|
|
379 |
0
|
if (what.equals("")) return null; |
380 |
|
|
381 |
0
|
int i = what.indexOf(Util.SN_NAME_SEPARATOR); |
382 |
0
|
if (i<1){ |
383 |
0
|
throw new ACCreationException("Illegal separator between Serial Number and Issuer Name: \""+Util.SN_NAME_SEPARATOR+"\" was expected"); |
384 |
|
} |
385 |
0
|
try{ |
386 |
0
|
return new issrg.ac.IssuerSerial(buildGeneralNames(what.substring(i+1)), |
387 |
|
new java.math.BigInteger(what.substring(0,i)), |
388 |
|
null); |
389 |
|
|
390 |
|
}catch (NumberFormatException nfe){ |
391 |
0
|
throw new ACCreationException("Issuer's Certificate Serial Number must be a valid Integer value"); |
392 |
|
} |
393 |
|
} |
394 |
|
} |