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.test; |
77 |
|
|
78 |
|
import issrg.pba.*; |
79 |
|
import issrg.pba.rbac.*; |
80 |
|
import issrg.utils.RFC2253NameParser; |
81 |
|
import issrg.pba.rbac.x509.RepositoryACPolicyFinder; |
82 |
|
import java.io.File; |
83 |
|
import java.io.FileNotFoundException; |
84 |
|
import java.io.FileOutputStream; |
85 |
|
import java.io.PrintStream; |
86 |
|
import javax.naming.Context; |
87 |
|
import javax.naming.directory.InitialDirContext; |
88 |
|
|
89 |
|
import java.security.cert.CertificateFactory; |
90 |
|
import java.security.cert.X509Certificate; |
91 |
|
import java.io.ByteArrayInputStream; |
92 |
|
import java.util.*; |
93 |
|
|
94 |
|
|
95 |
|
import javax.swing.text.*; |
96 |
|
import javax.swing.undo.*; |
97 |
|
import javax.swing.event.*; |
98 |
|
import javax.swing.*; |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@author |
103 |
|
|
104 |
|
|
|
|
| 75.8% |
Uncovered Elements: 55 (227) |
Complexity: 48 |
Complexity Density: 0.35 |
|
105 |
|
public class MSoDTest { |
106 |
|
|
107 |
|
private final static java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); |
108 |
|
private static final String PKC="rootca.cer"; |
109 |
|
private static final String PERMIS_EPF="permis.epf"; |
110 |
|
private static final String PERMIS_PSW="l3tM3InNow"; |
111 |
|
private static final String SALFORD_LDAP="ldap://sec.cs.kent.ac.uk/"; |
112 |
|
private static final String AC_ATTRIBUTE="attributeCertificateAttribute"; |
113 |
|
private static final String PKC_ATTRIBUTE="userCertificate"; |
114 |
|
|
115 |
|
private static String SOA = ""; |
116 |
|
private static String oID = ""; |
117 |
|
private static String LDAP = ""; |
118 |
|
private static String uRL = ""; |
119 |
|
private static String AC_attribute = ""; |
120 |
|
private static String PKC_attribute = ""; |
121 |
|
private final static issrg.utils.repository.VirtualRepository vr = new issrg.utils.repository.VirtualRepository(); |
122 |
|
|
123 |
|
private static CertificateFactory cf; |
124 |
|
|
125 |
|
|
|
|
| 78.4% |
Uncovered Elements: 38 (176) |
Complexity: 41 |
Complexity Density: 0.35 |
|
126 |
4
|
public static void main(String [] args){... |
127 |
|
|
128 |
|
|
129 |
4
|
System.setProperty("line.separator", "\r\n"); |
130 |
|
|
131 |
4
|
if ( (args.length>2) && (args[2] != null) ) |
132 |
4
|
try { |
133 |
4
|
PrintStream pt=new PrintStream(new FileOutputStream(args[2])); |
134 |
4
|
System.setOut(pt); |
135 |
4
|
System.setErr(pt); |
136 |
|
} catch (FileNotFoundException fnf) { |
137 |
0
|
System.out.println(" File Not found : " + fnf.getMessage()); |
138 |
|
} |
139 |
|
|
140 |
4
|
try{ |
141 |
|
|
142 |
4
|
if (args.length<1){ |
143 |
0
|
System.out.println("Sorry, but I need two arguments in the command line as the configuration file name and test input file name."); |
144 |
0
|
System.exit(0); |
145 |
|
} else{ |
146 |
4
|
java.io.BufferedReader in=null; |
147 |
4
|
try{ |
148 |
4
|
in = new java.io.BufferedReader(new java.io.FileReader(args[0])); |
149 |
|
}catch(java.io.IOException io){ |
150 |
0
|
System.err.println("Could not open file "+args[0]); |
151 |
0
|
throw io; |
152 |
|
} |
153 |
|
|
154 |
4
|
java.io.BufferedReader testIn=null; |
155 |
4
|
try{ |
156 |
4
|
testIn = new java.io.BufferedReader(new java.io.FileReader(args[1])); |
157 |
|
}catch(java.io.IOException io){ |
158 |
0
|
System.err.println("Could not open file "+args[1]); |
159 |
0
|
throw io; |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
4
|
int loglevel=4; |
165 |
|
|
166 |
|
|
167 |
4
|
if ( (args.length==2) ){ |
168 |
0
|
SATJDialog ff=new SATJDialog(null,true); |
169 |
0
|
if(ff!=null){ |
170 |
0
|
loglevel=ff.satlevel; |
171 |
0
|
ff=null; |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
4
|
String s; |
177 |
|
|
178 |
0
|
while ((s=in.readLine())!=null){ |
179 |
28
|
int i = s.indexOf('='); |
180 |
28
|
String varName = null; |
181 |
|
|
182 |
28
|
if (i>=0){ |
183 |
28
|
varName = s.substring(0, i).intern(); |
184 |
28
|
s = s.substring(i+1); |
185 |
|
} |
186 |
|
|
187 |
28
|
if (varName == "SOA"){ |
188 |
4
|
SOA = s; |
189 |
|
}else |
190 |
24
|
if (varName == "OID"){ |
191 |
4
|
oID = s; |
192 |
|
}else |
193 |
20
|
if (varName == "LDAP_AC_attribute"){ |
194 |
4
|
AC_attribute = s; |
195 |
|
}else |
196 |
16
|
if (varName == "LDAP_PKC_attribute"){ |
197 |
0
|
PKC_attribute = s; |
198 |
|
}else |
199 |
16
|
if (varName == "LDAP"){ |
200 |
4
|
LDAP = s; |
201 |
|
}else |
202 |
12
|
if (varName == "URL"){ |
203 |
4
|
uRL = s; |
204 |
|
}else |
205 |
8
|
if (varName == "PKC"){ |
206 |
4
|
loadPKC(vr, s); |
207 |
|
}else |
208 |
4
|
if (varName == "AC"){ |
209 |
4
|
loadAC(vr, s); |
210 |
|
}else |
211 |
0
|
println("Unrecognised line; ignored: "+varName+"="+s); |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
4
|
if (LDAP.intern()==""){ |
216 |
0
|
LDAP=SALFORD_LDAP; |
217 |
|
} |
218 |
4
|
if (AC_attribute.intern()==""){ |
219 |
0
|
AC_attribute=AC_ATTRIBUTE; |
220 |
|
} |
221 |
4
|
if (PKC_attribute.intern()==""){ |
222 |
4
|
PKC_attribute=PKC_ATTRIBUTE; |
223 |
|
} |
224 |
|
|
225 |
4
|
issrg.utils.repository.AttributeRepository r=vr; |
226 |
|
|
227 |
|
|
228 |
4
|
issrg.pba.rbac.SignatureVerifier sv = new SamplePKI(); |
229 |
|
|
230 |
4
|
String epf = null; |
231 |
4
|
CustomisePERMIS.configureX509Flavour(); |
232 |
|
|
233 |
4
|
RepositoryACPolicyFinder pf= new RepositoryACPolicyFinder(r, oID, new LDAPDNPrincipal(SOA), sv,loglevel); |
234 |
|
|
235 |
4
|
PBAAPI pbaApi = new PermisRBAC(pf, r, null); |
236 |
|
|
237 |
4
|
MSoDTest aef = new MSoDTest(pbaApi); |
238 |
|
|
239 |
4
|
String userDN = ""; |
240 |
4
|
String targetDN = ""; |
241 |
4
|
String action = ""; |
242 |
4
|
String contextInstance = null; |
243 |
4
|
String expectedResult = null; |
244 |
4
|
String testNo = null; |
245 |
4
|
String acFilename = null; |
246 |
4
|
int seq = 0; |
247 |
|
|
248 |
0
|
while ((s=testIn.readLine())!=null){ |
249 |
284
|
int i = s.indexOf('='); |
250 |
284
|
String varName = null; |
251 |
|
|
252 |
284
|
if (i>=0){ |
253 |
245
|
varName = s.substring(0, i).intern(); |
254 |
245
|
s = s.substring(i+1); |
255 |
|
} |
256 |
|
|
257 |
284
|
if (varName == "userDN"){ |
258 |
35
|
userDN = s; |
259 |
|
}else |
260 |
249
|
if (varName == "targetDN"){ |
261 |
35
|
targetDN = s; |
262 |
|
}else |
263 |
214
|
if (varName == "action"){ |
264 |
35
|
action = s; |
265 |
|
}else |
266 |
179
|
if (varName == "contextInstance"){ |
267 |
35
|
contextInstance = s; |
268 |
|
}else |
269 |
144
|
if (varName == "expectedResult"){ |
270 |
35
|
expectedResult = s; |
271 |
|
}else |
272 |
109
|
if (varName == "acFilename"){ |
273 |
35
|
acFilename = s; |
274 |
|
}else |
275 |
74
|
if (varName == "testNo"){ |
276 |
35
|
testNo = s; |
277 |
|
|
278 |
35
|
PermisTarget pt = null; |
279 |
35
|
try{ |
280 |
35
|
pt=new PermisTarget(targetDN); |
281 |
|
}catch (issrg.pba.rbac.BadURLException bue){ |
282 |
0
|
pt=new PermisTarget(targetDN, null); |
283 |
|
} |
284 |
35
|
Map env = new Hashtable(); |
285 |
35
|
if ( ( contextInstance != null) && (contextInstance.compareTo("null")!= 0) ) { |
286 |
35
|
env.put("ContextInstance", contextInstance); |
287 |
|
} |
288 |
35
|
println(" "); |
289 |
35
|
println("MSoD test " + testNo); |
290 |
35
|
println("UserDN: " + userDN); |
291 |
35
|
println("Action: " + action); |
292 |
35
|
println("Target: " + targetDN); |
293 |
35
|
println("ContextInstance: " + "context " + contextInstance ); |
294 |
35
|
println("Expected result: " + expectedResult); |
295 |
35
|
String result1 = aef.execute2(new LDAPDNPrincipal(userDN), new PermisAction(action), pt, env, acFilename); |
296 |
35
|
println("Final result: " + result1 ); |
297 |
35
|
if ((result1.startsWith("0") && expectedResult.startsWith("succ") ) || |
298 |
|
(result1.startsWith("1") && expectedResult.startsWith("not") )) { |
299 |
35
|
println("result correct!!!!!"); |
300 |
|
} else { |
301 |
0
|
println("result wrong????????????????????????????????????"); |
302 |
|
} |
303 |
|
|
304 |
|
}else{ |
305 |
|
|
306 |
|
} |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
4
|
((PermisRBAC)pbaApi).SAWSCloseLog(); |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
} |
315 |
|
|
316 |
|
}catch (Throwable th){ |
317 |
0
|
println("Failed to initialise: "+th.getMessage()); |
318 |
0
|
th.printStackTrace(); |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
4
|
if ( (args != null) && (args.length>2) ){ |
336 |
4
|
System.out.close(); |
337 |
4
|
System.err.close(); |
338 |
|
} |
339 |
|
else |
340 |
0
|
System.exit(0); |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
345 |
4
|
public static void loadAC(issrg.utils.repository.VirtualRepository vr, String filename){... |
346 |
4
|
try{ |
347 |
4
|
java.io.InputStream io = new java.io.FileInputStream(filename); |
348 |
4
|
byte [] ac = new byte [io.available()]; |
349 |
|
|
350 |
4
|
io.read(ac); |
351 |
|
|
352 |
4
|
issrg.ac.AttributeCertificate acd = issrg.ac.AttributeCertificate.guessEncoding(ac); |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
4
|
vr.populate(issrg.ac.Util.generalNamesToString(acd.getACInfo().getHolder().getEntityName()).toUpperCase(), |
358 |
|
CustomisePERMIS.getAttributeCertificateAttribute(), |
359 |
|
|
360 |
|
ac); |
361 |
|
}catch (Throwable th){ |
362 |
0
|
println("Failed to load AC from ["+filename+"]"); |
363 |
0
|
th.printStackTrace(); |
364 |
|
} |
365 |
|
} |
366 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
367 |
4
|
public static void loadPKC(issrg.utils.repository.VirtualRepository vr, String filename){... |
368 |
4
|
try{ |
369 |
4
|
if (cf==null) cf=CertificateFactory.getInstance("X.509"); |
370 |
|
|
371 |
4
|
java.io.InputStream io = new java.io.FileInputStream(filename); |
372 |
4
|
byte [] pkc = new byte [io.available()]; |
373 |
|
|
374 |
4
|
io.read(pkc); |
375 |
|
|
376 |
4
|
X509Certificate x509 = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(pkc)); |
377 |
|
|
378 |
|
|
379 |
4
|
String s=RFC2253NameParser.toCanonicalDN(RFC2253NameParser.distinguishedName(x509.getSubjectDN().getName())); |
380 |
|
|
381 |
4
|
vr.populate(s, CustomisePERMIS.getUserCertificateAttribute(), pkc); |
382 |
|
|
383 |
|
}catch (Throwable th){ |
384 |
0
|
println("Failed to load PKC from ["+filename+"]"); |
385 |
0
|
th.printStackTrace(); |
386 |
|
} |
387 |
|
} |
388 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
389 |
0
|
public static String readLine(String prompt){... |
390 |
0
|
System.out.print(prompt); |
391 |
0
|
String s = null; |
392 |
|
|
393 |
0
|
try{ |
394 |
0
|
s=in.readLine(); |
395 |
|
}catch(java.io.IOException ioe){ |
396 |
|
} |
397 |
|
|
398 |
0
|
return s==null?"":s; |
399 |
|
} |
400 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
401 |
315
|
public static void println(String s){... |
402 |
|
|
403 |
315
|
System.out.println(s); |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
PBAAPI pbaApi = null; |
409 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
410 |
4
|
public MSoDTest(PBAAPI pbaApi){... |
411 |
4
|
this.pbaApi = pbaApi; |
412 |
|
} |
413 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
414 |
35
|
public String execute2(java.security.Principal user, issrg.pba.Action action, Target target, Map env, String acFilename){... |
415 |
35
|
try{ |
416 |
|
|
417 |
35
|
java.io.InputStream io = new java.io.FileInputStream(acFilename); |
418 |
|
|
419 |
35
|
Object [] ac = new byte[1][io.available()]; |
420 |
|
|
421 |
|
|
422 |
|
|
423 |
35
|
io.read( (byte [])ac[0]); |
424 |
|
|
425 |
35
|
Subject s = pbaApi.getCreds(user, (Object [])ac, null); |
426 |
|
|
427 |
35
|
if (!(pbaApi.authzDecision(s, action, target, env).isAuthorised())){ |
428 |
17
|
return "1: the action is not allowed"; |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
}catch (PbaException pe){ |
433 |
0
|
pe.printStackTrace(); |
434 |
0
|
return "2: invalid input: "+pe.getMessage(); |
435 |
|
}catch (Throwable th){ |
436 |
0
|
th.printStackTrace(); |
437 |
0
|
return "3: run-time error: "+th.getMessage(); |
438 |
|
} |
439 |
|
|
440 |
18
|
return "0: action succeeded"; |
441 |
|
} |
442 |
|
|
443 |
|
} |