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 |
|
package issrg.pba.rbac.x509; |
33 |
|
|
34 |
|
import issrg.ac.AttributeCertificate; |
35 |
|
import issrg.ac.Extension; |
36 |
|
import issrg.ac.attributes.BasicAttConstraint; |
37 |
|
import issrg.ac.extensions.AttributeAuthorityInformationAccess; |
38 |
|
import issrg.ac.extensions.AuthorityInformationAccess; |
39 |
|
import issrg.ac.extensions.NoRevocation; |
40 |
|
import issrg.ac.extensions.WebdavCertificate; |
41 |
|
import issrg.ac.extensions.WebdavRevocation; |
42 |
|
import issrg.ac.attributes.NoAssertion; |
43 |
|
import issrg.pba.ParsedToken; |
44 |
|
import issrg.pba.DefaultParsedToken; |
45 |
|
import issrg.pba.DefaultDelegatableToken; |
46 |
|
import issrg.pba.rbac.LDAPDNPrincipal; |
47 |
|
import issrg.pba.rbac.SignatureVerifier; |
48 |
|
import issrg.pba.PbaException; |
49 |
|
import issrg.pba.WebDAVRevocableDelegatableParsedToken; |
50 |
|
import issrg.pba.WebDAVRevocableParsedToken; |
51 |
|
import issrg.pba.rbac.*; |
52 |
|
import issrg.pba.rbac.policies.Subtree; |
53 |
|
import issrg.pba.rbac.policies.DITSubtree; |
54 |
|
import issrg.pba.rbac.x509.ACUserEntry; |
55 |
|
import issrg.utils.repository.TokenLocator; |
56 |
|
import issrg.utils.repository.Entry; |
57 |
|
import issrg.pba.repository.EntryLocator; |
58 |
|
import issrg.pba.rbac.policies.SimpleEntry; |
59 |
|
import issrg.pba.rbac.PermisRBAC; |
60 |
|
import java.util.ArrayList; |
61 |
|
import issrg.utils.repository.AttributeRepository; |
62 |
|
import java.security.Principal; |
63 |
|
import java.util.*; |
64 |
|
import java.util.Vector; |
65 |
|
import org.apache.log4j.*; |
66 |
|
import org.apache.commons.logging.Log; |
67 |
|
import org.apache.commons.logging.LogFactory; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@author |
79 |
|
@version |
80 |
|
|
81 |
|
|
|
|
| 63.5% |
Uncovered Elements: 76 (208) |
Complexity: 42 |
Complexity Density: 0.4 |
|
82 |
|
public class RoleBasedACParser implements issrg.pba.rbac.RoleBasedAuthzTokenParser { |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
91 |
27
|
public RoleBasedACParser(){}... |
92 |
|
|
93 |
|
issrg.pba.rbac.RoleHierarchyPolicy roleHierarchy = null; |
94 |
|
private static final issrg.pba.Credentials NullCreds=new issrg.pba.rbac.SetOfSubsetsCredentials(); |
95 |
|
private SignatureVerifier SV = null; |
96 |
|
Logger logger = Logger.getLogger("issrg.pba.rbac.x509.RoleBasedACParser"); |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@param |
105 |
|
|
106 |
|
@param |
107 |
|
|
108 |
|
|
109 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
110 |
0
|
public RoleBasedACParser(issrg.pba.rbac.RoleHierarchyPolicy rhpn, SignatureVerifier signatureVerifier ) {... |
111 |
0
|
setRoleHierarchy(rhpn); |
112 |
0
|
setSignatureVerifier(signatureVerifier); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
@param |
123 |
|
@param |
124 |
|
|
125 |
|
|
126 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
127 |
0
|
public RoleBasedACParser(java.util.Map m, SignatureVerifier signatureVerifier){... |
128 |
0
|
setAuthTokenParsingRules(m); |
129 |
0
|
setSignatureVerifier(signatureVerifier); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@return |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
142 |
0
|
public java.util.Map getAuthTokenParsingRules(){... |
143 |
0
|
java.util.Map m = new java.util.Hashtable(); |
144 |
0
|
if (roleHierarchy!=null) m.put(issrg.pba.rbac.RoleHierarchyPolicy.class, roleHierarchy); |
145 |
0
|
return m; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@param |
153 |
|
|
154 |
|
|
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
13
|
public void setSignatureVerifier(SignatureVerifier signatureVerifier){... |
157 |
13
|
this.SV = signatureVerifier; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@return |
164 |
|
|
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0
|
public SignatureVerifier getSignatureVerifier(){... |
167 |
0
|
return SV; |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@param |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
15
|
public void setAuthTokenParsingRules(java.util.Map m){... |
178 |
15
|
setRoleHierarchy((issrg.pba.rbac.RoleHierarchyPolicy) m.get(issrg.pba.rbac.RoleHierarchyPolicy.class)); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
@param |
186 |
|
|
187 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
188 |
15
|
public void setRoleHierarchy(issrg.pba.rbac.RoleHierarchyPolicy rhpn){... |
189 |
0
|
if (logger.isDebugEnabled())logger.debug("got parsing rules: "+rhpn); |
190 |
|
|
191 |
15
|
roleHierarchy = rhpn; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
@param |
239 |
|
|
240 |
|
@return |
241 |
|
|
242 |
|
@throws |
243 |
|
|
244 |
|
|
245 |
|
|
|
|
| 67% |
Uncovered Elements: 59 (179) |
Complexity: 40 |
Complexity Density: 0.35 |
|
246 |
1788
|
protected ParsedToken decodeX509AC(Object acB) throws issrg.pba.PbaException {... |
247 |
1788
|
logger.debug("to parse an X509 AC in DER"); |
248 |
0
|
if (roleHierarchy==null) throw new issrg.pba.PbaException("Failed to decode an AC: no Role Hierarchy was specified"); |
249 |
|
|
250 |
|
|
251 |
1788
|
boolean bSignatureVerification=false; |
252 |
1788
|
boolean checkRevocation=true; |
253 |
1788
|
if (acB instanceof ParsedToken) return (ParsedToken)acB; |
254 |
1779
|
issrg.ac.AttributeCertificate ac; |
255 |
|
|
256 |
1779
|
Principal signer; |
257 |
1779
|
try{ |
258 |
|
|
259 |
1779
|
ac = issrg.ac.AttributeCertificate.guessEncoding(acB); |
260 |
0
|
if (logger.isDebugEnabled())logger.debug("Recieved certificate : " + ac.toString()); |
261 |
1779
|
signer = new LDAPDNPrincipal(issrg.ac.Util.generalNamesToString(ac.getACInfo().getIssuer().getV1Form()==null?ac.getACInfo().getIssuer().getV2Form().getIssuerName():ac.getACInfo().getIssuer().getV1Form())); |
262 |
|
}catch (Throwable th){ |
263 |
0
|
if (logger.isDebugEnabled())logger.debug("Couldn't decode the Attribute Certificate"); |
264 |
0
|
throw new issrg.pba.PbaException("Couldn't decode the Attribute Certificate", th); |
265 |
|
} |
266 |
|
|
267 |
1779
|
byte[] value; |
268 |
1779
|
byte[] signature; |
269 |
1779
|
String algorithmid; |
270 |
1779
|
Exception signatureVerificationFailed=null; |
271 |
1779
|
issrg.pba.rbac.ValidityPeriod vp = new issrg.pba.rbac.AbsoluteValidityPeriod( |
272 |
|
ac.getACInfo().getValidityPeriod().getNotBefore().getTime().getTime(), |
273 |
|
ac.getACInfo().getValidityPeriod().getNotAfter().getTime().getTime() |
274 |
|
); |
275 |
1779
|
java.util.Vector attributes = ac.getACInfo().getAttributes(); |
276 |
1779
|
java.util.Vector roles = new java.util.Vector(); |
277 |
|
|
278 |
3562
|
for (int i=attributes.size(); i-->0;){ |
279 |
1783
|
issrg.ac.Attribute att = (issrg.ac.Attribute)attributes.get(i); |
280 |
1783
|
String type = roleHierarchy.getTypeByOID(att.getType()); |
281 |
1783
|
if (type!=null){ |
282 |
1779
|
java.util.Vector av = att.getValues(); |
283 |
1779
|
try{ |
284 |
3667
|
for (int j=av.size(); j-->0;){ |
285 |
1888
|
issrg.pba.rbac.RoleHierarchyNode rhn = roleHierarchy.getRole(type, new issrg.ac.attributes.PermisRole( |
286 |
|
(issrg.ac.AttributeValue)av.get(j) |
287 |
|
).getRoleValue() |
288 |
|
); |
289 |
|
|
290 |
|
|
291 |
1888
|
if (rhn!=null){ |
292 |
1888
|
if (logger.isDebugEnabled()){ |
293 |
0
|
logger.debug((issrg.ac.AttributeValue)av.get(j) + " has been found in the role hierarchy policy as has been added to the valid roles"); |
294 |
|
} |
295 |
1888
|
roles.add(new issrg.pba.rbac.ExpirableCredentials( |
296 |
|
new issrg.pba.rbac.PermisCredentials(rhn), |
297 |
|
vp |
298 |
|
) |
299 |
|
); |
300 |
|
}else{ |
301 |
0
|
if (logger.isDebugEnabled()){ |
302 |
0
|
logger.debug((issrg.ac.AttributeValue)av.get(j) + " has not been found in the role hierarchy policy as has been ignored"); |
303 |
|
} |
304 |
|
} |
305 |
|
} |
306 |
|
}catch(iaik.asn1.CodingException ce){ |
307 |
|
|
308 |
|
} |
309 |
|
} |
310 |
|
} |
311 |
|
|
312 |
1779
|
Vector extensions = ac.getACInfo().getExtensions().getValues(); |
313 |
1779
|
int numberOfExtension = extensions.size(); |
314 |
1779
|
int depth=0; |
315 |
|
|
316 |
1779
|
issrg.pba.Credentials creds=new issrg.pba.rbac.SetOfSubsetsCredentials(roles); |
317 |
1779
|
issrg.pba.Credentials assertableCredentials=creds; |
318 |
1779
|
issrg.pba.Credentials delegateableCredentials=null; |
319 |
1779
|
ACUserEntry h = new ACUserEntry(ac); |
320 |
1779
|
TokenLocator issuerTokenLocator=null; |
321 |
1779
|
TokenLocator signerTokenLocator=null; |
322 |
|
|
323 |
|
|
324 |
1779
|
Subtree subjectDomain=new DITSubtree(LDAPDNPrincipal.WHOLE_WORLD_DN, 0, -1, null, |
325 |
|
new Subtree[]{new DITSubtree(h.getDN(), 0, 0, null, null)}); |
326 |
|
|
327 |
1779
|
Entry signerEntry = new SimpleEntry(signer); |
328 |
1779
|
String revLoc=null, valLoc=null; |
329 |
|
|
330 |
4765
|
for (int ii = 0; ii < numberOfExtension; ii++) { |
331 |
2986
|
Extension e = (Extension) extensions.get(ii); |
332 |
2986
|
if (e instanceof NoAssertion) { |
333 |
622
|
assertableCredentials=NullCreds; |
334 |
|
} |
335 |
2986
|
if (e instanceof BasicAttConstraint) { |
336 |
870
|
delegateableCredentials=creds; |
337 |
870
|
depth = ((BasicAttConstraint) e).getDepth(); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
2986
|
if(e instanceof NoRevocation){ |
350 |
0
|
checkRevocation=false; |
351 |
|
} |
352 |
|
|
353 |
2986
|
if(checkRevocation){ |
354 |
12124
|
for(int i =0;i<extensions.size();i++){ |
355 |
9138
|
if(e instanceof AuthorityInformationAccess){ |
356 |
0
|
AuthorityInformationAccess aia =(AuthorityInformationAccess)e; |
357 |
0
|
ArrayList exts =aia.getValues(); |
358 |
0
|
for(int j=0;j<exts.size();j++){ |
359 |
0
|
if(exts.get(j)instanceof WebdavRevocation){ |
360 |
0
|
revLoc =((WebdavRevocation)exts.get(j)).getLocation(); |
361 |
|
} |
362 |
0
|
if(exts.get(j)instanceof WebdavCertificate){ |
363 |
0
|
valLoc =((WebdavCertificate)exts.get(j)).getLocation(); |
364 |
|
} |
365 |
|
|
366 |
|
} |
367 |
|
} |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
2986
|
if (e.getClass().equals(Extension.class) && e.isCritical()){ |
373 |
|
|
374 |
|
|
375 |
0
|
assertableCredentials=NullCreds; |
376 |
0
|
delegateableCredentials=null; |
377 |
0
|
break; |
378 |
|
} |
379 |
|
} |
380 |
1779
|
if (signerTokenLocator==null) signerTokenLocator=issuerTokenLocator; |
381 |
|
|
382 |
1779
|
issuerTokenLocator=new EntryLocator(signerEntry, signer, null, issuerTokenLocator); |
383 |
1779
|
signerTokenLocator=new EntryLocator(signerEntry, signer, null, signerTokenLocator); |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
1779
|
ParsedToken p; |
389 |
|
|
390 |
1779
|
if(delegateableCredentials!=null && revLoc!=null && valLoc!=null){ |
391 |
0
|
p= new WebDAVRevocableDelegatableParsedToken(h, issuerTokenLocator, assertableCredentials, delegateableCredentials, subjectDomain, depth,revLoc,valLoc,(byte[])acB, checkRevocation); |
392 |
|
|
393 |
1779
|
}else if (delegateableCredentials!=null){ |
394 |
870
|
p=new DefaultDelegatableToken(h, issuerTokenLocator, assertableCredentials, delegateableCredentials, subjectDomain, depth, checkRevocation); |
395 |
|
|
396 |
909
|
}else if(revLoc!=null && valLoc!=null){ |
397 |
0
|
p=new WebDAVRevocableParsedToken(h,issuerTokenLocator,assertableCredentials,revLoc,valLoc,(byte[])acB,checkRevocation); |
398 |
|
|
399 |
|
}else{ |
400 |
909
|
p=new DefaultParsedToken(h, issuerTokenLocator, assertableCredentials,checkRevocation); |
401 |
|
} |
402 |
|
|
403 |
1779
|
try{ |
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
1779
|
value=issrg.ac.AttributeCertificate.getToBeSignedByteArray((byte[])acB); |
409 |
|
|
410 |
1779
|
signature=(byte[]) ac.getSignatureValue().getValue(); |
411 |
|
|
412 |
1779
|
algorithmid=ac.getSignatureAlgorithm().getAlgorithm().getID(); |
413 |
|
|
414 |
1779
|
if (SV == null) { |
415 |
0
|
if (logger.isDebugEnabled())logger.debug("Signature verification is turned off"); |
416 |
740
|
bSignatureVerification = true; |
417 |
|
} |
418 |
|
else { |
419 |
0
|
if (logger.isDebugEnabled())logger.debug("Signature verification is enabled"); |
420 |
1039
|
Date date = new Date(); |
421 |
1039
|
long start=date.getTime(); |
422 |
1039
|
bSignatureVerification=SV.checkSignature(value,signature,algorithmid,signerTokenLocator); |
423 |
1039
|
date = new Date(); |
424 |
1039
|
long end=date.getTime(); |
425 |
1039
|
end = end - start; |
426 |
|
} |
427 |
|
|
428 |
1779
|
if(bSignatureVerification==false){ |
429 |
|
|
430 |
0
|
if (logger.isDebugEnabled()){ |
431 |
0
|
String but = ""; |
432 |
0
|
int i = 0; |
433 |
|
|
434 |
0
|
logger.debug("Signature verification failed for token"); |
435 |
|
} |
436 |
0
|
throw new issrg.pba.PbaException("Signature verification failed"); |
437 |
|
|
438 |
|
} |
439 |
|
|
440 |
|
}catch(Exception e){ |
441 |
0
|
signatureVerificationFailed=e; |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
|
446 |
0
|
if (signatureVerificationFailed!=null) throw new SignatureVerificationFailedException(signatureVerificationFailed, p, acB); |
447 |
0
|
if (logger.isDebugEnabled())logger.debug("certificate parsed succesfully : " + p.getHolder().getEntryName().getName() + " has : " + p.getCredentials()); |
448 |
1779
|
return p; |
449 |
|
} |
450 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
451 |
1788
|
public ParsedToken decode(Object acB) throws issrg.pba.PbaException {... |
452 |
1788
|
return this.decodeX509AC(acB); |
453 |
|
} |
454 |
|
} |
455 |
|
|