Skip to content

Commit b7a4247

Browse files
committed
add test cases back in benchmark package. Check in scorecard generator files too.
1 parent 792a995 commit b7a4247

File tree

42,141 files changed

+1733833
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42,141 files changed

+1733833
-0
lines changed

results/Benchmark_1.1-findsecbugs-334.xml

Lines changed: 384 additions & 0 deletions
Large diffs are not rendered by default.

results/Benchmark_1.1-pmd-61.xml

Lines changed: 69130 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* OWASP Benchmark Project
3+
*
4+
* This file is part of the Open Web Application Security Project (OWASP)
5+
* Benchmark Project For details, please see
6+
* <a href="https://www.owasp.org/index.php/Benchmark">https://www.owasp.org/index.php/Benchmark</a>.
7+
*
8+
* The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9+
* of the GNU General Public License as published by the Free Software Foundation, version 2.
10+
*
11+
* The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details
14+
*
15+
* @author Juan Gama <a href="https://www.aspectsecurity.com">Aspect Security</a>
16+
* @created 2015
17+
*/
18+
19+
package org.owasp.benchmark.helpers;
20+
21+
import java.sql.Connection;
22+
import java.sql.DriverManager;
23+
import java.sql.SQLException;
24+
import java.sql.Statement;
25+
26+
public class DatabaseHelper {
27+
private static Statement stmt;
28+
private static Connection conn;
29+
30+
static {
31+
initData();
32+
}
33+
34+
public static java.sql.Statement getSqlStatement() {
35+
if (conn == null) {
36+
getSqlConnection();
37+
}
38+
39+
if (stmt == null) {
40+
try {
41+
stmt = conn.createStatement();
42+
} catch (SQLException e) {
43+
System.out.println("Problem with database init.");
44+
}
45+
}
46+
47+
return stmt;
48+
}
49+
public static void reset(){
50+
initData();
51+
}
52+
public static java.sql.Connection getSqlConnection() {
53+
if (conn == null) {
54+
try {
55+
Class.forName("org.hsqldb.jdbcDriver");
56+
String url = "jdbc:hsqldb:benchmarkDataBase;sql.enforce_size=false";
57+
conn = DriverManager.getConnection(url, "sa", "");
58+
} catch (SQLException | ClassNotFoundException e) {
59+
System.out.println("Problem with database init.");
60+
}
61+
}
62+
return conn;
63+
// return org.mockito.Mockito.mock(java.sql.Connection.class);
64+
}
65+
66+
private static void initData() {
67+
try {
68+
executeSQLCommand("DROP PROCEDURE IF EXISTS verifyUserPassword");
69+
executeSQLCommand("DROP TABLE IF EXISTS USERS");
70+
executeSQLCommand("DROP TABLE IF EXISTS EMPLOYEE");
71+
executeSQLCommand("DROP TABLE IF EXISTS CERTIFICATE");
72+
executeSQLCommand("DROP TABLE IF EXISTS SCORE");
73+
74+
executeSQLCommand("CREATE TABLE USERS (userid int NOT NULL GENERATED BY DEFAULT AS IDENTITY, username varchar(50), password varchar(50),PRIMARY KEY (userid));");
75+
executeSQLCommand("CREATE TABLE SCORE (userid int NOT NULL GENERATED BY DEFAULT AS IDENTITY, nick varchar(50), score INTEGER,PRIMARY KEY (userid));");
76+
executeSQLCommand("CREATE PROCEDURE verifyUserPassword(IN username_ varchar(50), IN password_ varchar(50))"
77+
+ " READS SQL DATA"
78+
+ " DYNAMIC RESULT SETS 1"
79+
+ " BEGIN ATOMIC"
80+
+ " DECLARE resultSet SCROLL CURSOR WITH HOLD WITH RETURN FOR SELECT * FROM USERS;" //WHERE USERNAME = user AND PASSWORD = pass;"
81+
+ " OPEN resultSet;"
82+
+"END;");
83+
84+
executeSQLCommand("create table EMPLOYEE ("
85+
+ " id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY,"
86+
+ " first_name VARCHAR(20) default NULL,"
87+
+ " last_name VARCHAR(20) default NULL,"
88+
+ " salary INT default NULL," + " PRIMARY KEY (id)"
89+
+ " );");
90+
91+
executeSQLCommand("create table CERTIFICATE ("
92+
+ " id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY,"
93+
+ " certificate_name VARCHAR(30) default NULL,"
94+
+ " employee_id INT default NULL," + " PRIMARY KEY (id)"
95+
+ ");");
96+
97+
executeSQLCommand("INSERT INTO USERS (username, password) VALUES('User01', 'P455w0rd')");
98+
executeSQLCommand("INSERT INTO USERS (username, password) VALUES('User02', 'B3nchM3rk')");
99+
executeSQLCommand("INSERT INTO USERS (username, password) VALUES('User03', 'a$c11')");
100+
executeSQLCommand("INSERT INTO USERS (username, password) VALUES('foo', 'bar')");
101+
102+
executeSQLCommand("INSERT INTO SCORE (nick, score) VALUES('User03', 155)");
103+
executeSQLCommand("INSERT INTO SCORE (nick, score) VALUES('foo', 40)");
104+
105+
} catch (Exception e1) {
106+
System.out.println("Problem with database init.");
107+
}
108+
}
109+
110+
public static void executeSQLCommand(String sql) throws Exception {
111+
if (stmt == null) {
112+
getSqlStatement();
113+
}
114+
stmt.executeUpdate(sql);
115+
}
116+
117+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* OWASP Benchmark Project
3+
*
4+
* This file is part of the Open Web Application Security Project (OWASP)
5+
* Benchmark Project For details, please see
6+
* <a href="https://www.owasp.org/index.php/Benchmark">https://www.owasp.org/index.php/Benchmark</a>.
7+
*
8+
* The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9+
* of the GNU General Public License as published by the Free Software Foundation, version 2.
10+
*
11+
* The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details
14+
*
15+
* @author Juan Gama <a href="https://www.aspectsecurity.com">Aspect Security</a>
16+
* @created 2015
17+
*/
18+
19+
package org.owasp.benchmark.helpers;
20+
21+
import java.util.Map;
22+
23+
import javax.servlet.jsp.el.ELException;
24+
import javax.servlet.jsp.el.Expression;
25+
import javax.servlet.jsp.el.FunctionMapper;
26+
import javax.servlet.jsp.el.VariableResolver;
27+
28+
@SuppressWarnings("deprecation")
29+
public class ExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEvaluator
30+
{
31+
public static String evaluateEL(String expression, Map<String, Object> properties)
32+
{
33+
return null;
34+
}
35+
36+
@Override
37+
public Object evaluate(String arg0, Class arg1, VariableResolver arg2, FunctionMapper arg3) throws ELException {
38+
return null;
39+
}
40+
41+
@Override
42+
public Expression parseExpression(String arg0, Class arg1, FunctionMapper arg2) throws ELException {
43+
return null;
44+
}
45+
46+
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/**
2+
* OWASP Benchmark Project
3+
*
4+
* This file is part of the Open Web Application Security Project (OWASP)
5+
* Benchmark Project For details, please see
6+
* <a href="https://www.owasp.org/index.php/Benchmark">https://www.owasp.org/index.php/Benchmark</a>.
7+
*
8+
* The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
9+
* of the GNU General Public License as published by the Free Software Foundation, version 2.
10+
*
11+
* The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details
14+
*
15+
* @author Juan Gama <a href="https://www.aspectsecurity.com">Aspect Security</a>
16+
* @created 2015
17+
*/
18+
19+
package org.owasp.benchmark.helpers;
20+
21+
import java.util.Hashtable;
22+
23+
import javax.naming.Context;
24+
import javax.naming.NamingEnumeration;
25+
import javax.naming.NamingException;
26+
import javax.naming.directory.Attribute;
27+
import javax.naming.directory.Attributes;
28+
import javax.naming.directory.BasicAttribute;
29+
import javax.naming.directory.BasicAttributes;
30+
import javax.naming.directory.DirContext;
31+
import javax.naming.directory.InitialDirContext;
32+
import javax.naming.directory.ModificationItem;
33+
import javax.naming.directory.SearchControls;
34+
import javax.naming.directory.SearchResult;
35+
36+
import org.apache.log4j.Logger;
37+
38+
//import sun.misc.BASE64Encoder;
39+
40+
public class LDAPHelper {
41+
private static Logger logger = Logger.getLogger(LDAPHelper.class);
42+
private static Hashtable<String, String> env = new Hashtable<String, String>();
43+
private static DirContext dctx = null;
44+
45+
public LDAPHelper() {
46+
try {
47+
/* This needs to be replaced with a real LDAP */
48+
env.put(Context.INITIAL_CONTEXT_FACTORY,
49+
"com.sun.jndi.ldap.LdapCtxFactory");
50+
env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
51+
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
52+
env.put(Context.SECURITY_CREDENTIALS, "xxx");
53+
} catch (Exception e) {
54+
logger.error(e, e);
55+
}
56+
57+
}
58+
59+
public static InitialDirContext getInitialDirContext(){
60+
return (InitialDirContext)getInitialDirContext();
61+
}
62+
63+
public static DirContext getDirContext(){
64+
if(dctx == null){
65+
try {
66+
dctx = new InitialDirContext(env);
67+
} catch (NamingException e) {
68+
System.out.println("Problem with LDAP init.");
69+
}
70+
}
71+
return dctx;
72+
}
73+
74+
public static boolean insert(LDAPPerson person) {
75+
try {
76+
77+
DirContext ctx = getDirContext();
78+
Attributes matchAttrs = new BasicAttributes(true);
79+
matchAttrs.put(new BasicAttribute("uid", person.getName()));
80+
matchAttrs.put(new BasicAttribute("cn", person.getName()));
81+
matchAttrs.put(new BasicAttribute("street", person.getAddress()));
82+
matchAttrs.put(new BasicAttribute("sn", person.getName()));
83+
matchAttrs.put(new BasicAttribute("userpassword",
84+
encryptLdapPassword("SHA", person.getPassword())));
85+
matchAttrs.put(new BasicAttribute("objectclass", "top"));
86+
matchAttrs.put(new BasicAttribute("objectclass", "person"));
87+
matchAttrs.put(new BasicAttribute("objectclass",
88+
"organizationalPerson"));
89+
matchAttrs.put(new BasicAttribute("objectclass", "inetorgperson"));
90+
String name = "uid=" + person.getName() + ",ou=users,ou=system";
91+
InitialDirContext iniDirContext = (InitialDirContext) ctx;
92+
iniDirContext.bind(name, ctx, matchAttrs);
93+
94+
logger.debug("success inserting " + person.getName());
95+
return true;
96+
} catch (Exception e) {
97+
logger.error(e, e);
98+
return false;
99+
}
100+
}
101+
102+
private static boolean edit(LDAPPerson person) {
103+
try {
104+
105+
DirContext ctx = getDirContext();
106+
ModificationItem[] mods = new ModificationItem[2];
107+
Attribute mod0 = new BasicAttribute("street", person.getAddress());
108+
Attribute mod1 = new BasicAttribute("userpassword",
109+
encryptLdapPassword("SHA", person.getPassword()));
110+
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
111+
mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod1);
112+
113+
ctx.modifyAttributes("uid=" + person.getName()
114+
+ ",ou=users,ou=system", mods);
115+
116+
logger.debug("success editing " + person.getName());
117+
return true;
118+
} catch (Exception e) {
119+
logger.error(e, e);
120+
return false;
121+
}
122+
}
123+
124+
private static boolean delete(LDAPPerson person) {
125+
try {
126+
127+
DirContext ctx = getDirContext();
128+
ctx.destroySubcontext("uid=" + person.getName()
129+
+ ",ou=users,ou=system");
130+
131+
logger.debug("success deleting " + person.getName());
132+
return true;
133+
} catch (Exception e) {
134+
logger.error(e, e);
135+
return false;
136+
}
137+
}
138+
139+
private static boolean search(LDAPPerson person) {
140+
try {
141+
142+
DirContext ctx = getDirContext();
143+
String base = "ou=users,ou=system";
144+
145+
SearchControls sc = new SearchControls();
146+
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
147+
148+
String filter = "(&(objectclass=person)(uid=" + person.getName()
149+
+ "))";
150+
151+
NamingEnumeration<SearchResult> results = ctx.search(base, filter, sc);
152+
153+
while (results.hasMore()) {
154+
SearchResult sr = (SearchResult) results.next();
155+
Attributes attrs = sr.getAttributes();
156+
157+
Attribute attr = attrs.get("uid");
158+
if (attr != null)
159+
logger.debug("record found " + attr.get());
160+
}
161+
ctx.close();
162+
163+
return true;
164+
} catch (Exception e) {
165+
logger.error(e, e);
166+
return false;
167+
}
168+
}
169+
170+
private static String encryptLdapPassword(String algorithm, String _password) {
171+
/*
172+
* Removed until adding BouncyCastle
173+
String sEncrypted = _password;
174+
if ((_password != null) && (_password.length() > 0)) {
175+
boolean bMD5 = algorithm.equalsIgnoreCase("MD5");
176+
boolean bSHA = algorithm.equalsIgnoreCase("SHA")
177+
|| algorithm.equalsIgnoreCase("SHA1")
178+
|| algorithm.equalsIgnoreCase("SHA-1");
179+
if (bSHA || bMD5) {
180+
String sAlgorithm = "MD5";
181+
if (bSHA) {
182+
sAlgorithm = "SHA";
183+
}
184+
try {
185+
MessageDigest md = MessageDigest.getInstance(sAlgorithm);
186+
md.update(_password.getBytes("UTF-8"));
187+
sEncrypted = "{" + sAlgorithm + "}"
188+
+ (new BASE64Encoder()).encode(md.digest());
189+
} catch (Exception e) {
190+
sEncrypted = null;
191+
logger.error(e, e);
192+
}
193+
}
194+
}
195+
return sEncrypted;
196+
*/
197+
return _password;
198+
}
199+
}

0 commit comments

Comments
 (0)