env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
env.put(Context.AUTHORITATIVE, "true");
env.put(Context.PROVIDER_URL, "dns://" + server);
+
InitialDirContext context = new InitialDirContext(env);
try {
-
Attributes dnsLookup = context.getAttributes(name, new String[] {
"TXT"
});
+
return extractTextEntries(dnsLookup.get("TXT"));
} finally {
context.close();
}
-
}
private static String[] extractTextEntries(Attribute nsRecords) throws NamingException {
public static CAARecord[] getCAAEntries(String domain) throws NamingException {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
+
InitialDirContext context = new InitialDirContext(env);
- Attributes dnsLookup;
try {
- dnsLookup = context.getAttributes(domain, new String[] {
+ Attributes dnsLookup;
+ try {
+ dnsLookup = context.getAttributes(domain, new String[] {
"257"
- });
- } catch (NameNotFoundException e) {
- // We treat non-existing names as names without CAA-records
- return new CAARecord[0];
- }
- Attribute nsRecords = dnsLookup.get("257");
- if (nsRecords == null) {
- return new CAARecord[] {};
- }
- CAA.CAARecord[] result = new CAA.CAARecord[nsRecords.size()];
- for (int i = 0; i < result.length; i++) {
- byte[] rec = (byte[]) nsRecords.get(i);
+ });
+ } catch (NameNotFoundException e) {
+ // We treat non-existing names as names without CAA-records
+ return new CAARecord[0];
+ }
+
+ Attribute nsRecords = dnsLookup.get("257");
+ if (nsRecords == null) {
+ return new CAARecord[] {};
+ }
+
+ CAA.CAARecord[] result = new CAA.CAARecord[nsRecords.size()];
+ for (int i = 0; i < result.length; i++) {
+ byte[] rec = (byte[]) nsRecords.get(i);
- result[i] = new CAA.CAARecord(rec);
+ result[i] = new CAA.CAARecord(rec);
+ }
+
+ return result;
+ } finally {
+ context.close();
}
- return result;
}
public static void main(String[] args) throws NamingException {
public static void init(Properties conf) {
String financialName = conf.getProperty("highFinancialValue");
+
if (financialName == null) {
throw new Error("No property highFinancialValue was configured");
}
- try {
- financial = new DomainSet(new InputStreamReader(new FileInputStream(new File(financialName)), "UTF-8"));
+
+ try (FileInputStream fis = new FileInputStream(new File(financialName)); //
+ InputStreamReader isr = new InputStreamReader(fis, "UTF-8")) {
+ financial = new DomainSet(isr);
} catch (IOException e) {
throw new Error(e);
}
package club.wpia.gigi.util;
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.Properties;
import com.lambdaworks.crypto.SCryptUtil;
if (password == null || password.isEmpty()) {
return null;
}
+
if (hash.contains("$")) {
if (SCryptUtil.check(password, hash)) {
return hash;
return null;
}
}
- String newhash = sha1(password);
- boolean match = true;
- if (newhash.length() != hash.length()) {
- match = false;
- }
- for (int i = 0; i < newhash.length(); i++) {
- match &= newhash.charAt(i) == hash.charAt(i);
- }
- if (match) {
- return hash(password);
- } else {
- return null;
- }
- }
- public static String sha1(String password) {
- try {
- MessageDigest md = MessageDigest.getInstance("SHA1");
- byte[] digest = md.digest(password.getBytes("UTF-8"));
- StringBuffer res = new StringBuffer(digest.length * 2);
- for (int i = 0; i < digest.length; i++) {
- res.append(Integer.toHexString((digest[i] & 0xF0) >> 4));
- res.append(Integer.toHexString(digest[i] & 0xF));
- }
- return res.toString();
- } catch (NoSuchAlgorithmException e) {
- throw new Error(e);
- } catch (UnsupportedEncodingException e) {
- throw new Error(e);
- }
+ return null;
}
public static String hash(String password) {
import club.wpia.gigi.database.GigiResultSet;
import club.wpia.gigi.testUtils.ManagedTest;
import club.wpia.gigi.testUtils.RegisteredUser;
-import club.wpia.gigi.util.PasswordHash;
public class TestPasswordMigration extends ManagedTest {
@Rule
public RegisteredUser ru = new RegisteredUser();
+ /**
+ * Gigi used to support plain SHA-1 password hashes, for compatibility with
+ * legacy software. Since there currently is only one accepted hash format,
+ * this test now verifies that plain SHA-1 hashes are no longer accepted nor
+ * migrated to more recent hash formats.
+ *
+ * @see PasswordHash.verifyHash
+ * @see PasswordHash.hash
+ * @throws IOException
+ */
@Test
- public void testPasswordMigration() throws IOException {
+ public void testNoSHA1PasswordMigration() throws IOException {
try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE users SET `password`=? WHERE id=?")) {
- stmt.setString(1, PasswordHash.sha1("a"));
+ stmt.setString(1, "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"); // sha1("a")
stmt.setInt(2, ru.getUser().getId());
stmt.execute();
}
+
String cookie = login(ru.getUser().getEmail(), "a");
- assertTrue(isLoggedin(cookie));
+ assertFalse(isLoggedin(cookie));
try (GigiPreparedStatement stmt = new GigiPreparedStatement("SELECT `password` FROM users WHERE id=?")) {
stmt.setInt(1, ru.getUser().getId());
GigiResultSet res = stmt.executeQuery();
assertTrue(res.next());
String newHash = res.getString(1);
- assertThat(newHash, containsString("$"));
+ assertThat(newHash, not(containsString("$")));
}
}
}
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import sun.security.x509.X509Key;
import club.wpia.gigi.Gigi;
import club.wpia.gigi.GigiApiException;
import club.wpia.gigi.crypto.SPKAC;
import club.wpia.gigi.dbObjects.User;
import club.wpia.gigi.dbObjects.Verification.VerificationType;
import club.wpia.gigi.email.DelegateMailProvider;
+import club.wpia.gigi.email.EmailProvider;
import club.wpia.gigi.localisation.Language;
import club.wpia.gigi.output.template.IterableDataset;
import club.wpia.gigi.output.template.Template;
import club.wpia.gigi.ping.PingerDaemon;
import club.wpia.gigi.util.AuthorizationContext;
import club.wpia.gigi.util.DayDate;
+import club.wpia.gigi.util.DomainAssessment;
import club.wpia.gigi.util.HTMLEncoder;
import club.wpia.gigi.util.Notary;
import club.wpia.gigi.util.TimeConditions;
-import sun.security.x509.X509Key;
public class Manager extends Page {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (req.getParameter("create") != null) {
- batchCreateUsers(req.getParameter("prefix"), req.getParameter("suffix"), Integer.parseInt(req.getParameter("amount")), resp.getWriter());
- resp.getWriter().println("User batch created.");
+ String prefix = req.getParameter("prefix");
+ String domain = req.getParameter("suffix");
+ try {
+ if (null == prefix) {
+ throw new GigiApiException("No prefix given.");
+ }
+ if (null == domain) {
+ throw new GigiApiException("No domain given.");
+ }
+
+ DomainAssessment.checkCertifiableDomain(domain, false, true);
+
+ if ( !EmailProvider.isValidMailAddress(prefix + "@" + domain)) {
+ throw new GigiApiException("Invalid email address template.");
+ }
+
+ batchCreateUsers(prefix, domain, Integer.parseInt(req.getParameter("amount")), resp.getWriter());
+ resp.getWriter().println("User batch created.");
+ } catch (GigiApiException e) {
+ throw new Error(e);
+ }
} else if (req.getParameter("addpriv") != null || req.getParameter("delpriv") != null) {
User u = User.getByEmail(req.getParameter("email"));
if (u == null) {