]> WPIA git - gigi.git/commitdiff
Merge remote-tracking branch 'origin/master' into janis_work
authorJanis Streib <janis@dogcraft.de>
Thu, 12 May 2016 22:47:37 +0000 (00:47 +0200)
committerJanis Streib <janis@dogcraft.de>
Thu, 12 May 2016 22:47:37 +0000 (00:47 +0200)
35 files changed:
build.xml
src/org/cacert/gigi/GigiConfig.java
src/org/cacert/gigi/Launcher.java
src/org/cacert/gigi/api/CATSImport.java
src/org/cacert/gigi/dbObjects/CertificateProfile.java
src/org/cacert/gigi/dbObjects/Organisation.java
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/email/EmailProvider.java
src/org/cacert/gigi/pages/account/MyDetailsForm.java
src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java
src/org/cacert/gigi/pages/account/certs/CertificateRequest.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
src/org/cacert/gigi/pages/main/RegisterPage.java
src/org/cacert/gigi/pages/main/Signup.java
src/org/cacert/gigi/util/Notary.java
src/org/cacert/gigi/util/RateLimit.java [new file with mode: 0644]
tests/org/cacert/gigi/LoginTest.java
tests/org/cacert/gigi/TestLanguage.java
tests/org/cacert/gigi/TestSecurityHeaders.java
tests/org/cacert/gigi/api/ImportCATSResult.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java
tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java
tests/org/cacert/gigi/pages/wot/TestTTP.java
tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java
tests/org/cacert/gigi/ping/TestDNS.java
tests/org/cacert/gigi/ping/TestHTTP.java
tests/org/cacert/gigi/ping/TestSSL.java
tests/org/cacert/gigi/testUtils/ManagedTest.java
tests/org/cacert/gigi/testUtils/PingTest.java
tests/org/cacert/gigi/util/TestNotary.java
util-testing/org/cacert/gigi/DevelLauncher.java
util-testing/org/cacert/gigi/util/SimpleSigner.java

index f5141b3f771075e48a43797b6cb35f651df87ada..20c6f496c25d2df87373d4c5c52104d733a49cfb 100644 (file)
--- a/build.xml
+++ b/build.xml
                </javac>
                <concat destfile="bintest/org/cacert/gigi/util/effective_tld_names.dat">
                        <path path="bin/org/cacert/gigi/util/effective_tld_names.dat"/>
-                       <footer>${test_nic}</footer>
+                       <path path="publicSuffixFooter.dat"/>
                </concat>
        </target>
        <target name="check-locale">
index 3a1b9eed6642aadbbf4d733e9b3440a118ff248e..8b7c220202f83e8b3b07724fb57824c9fb49f368 100644 (file)
@@ -83,6 +83,9 @@ public class GigiConfig {
     }
 
     public KeyStore getPrivateStore() throws GeneralSecurityException, IOException {
+        if (keystore == null || keystorpw == null) {
+            return null;
+        }
         KeyStore ks1 = KeyStore.getInstance("pkcs12");
         ks1.load(new ByteArrayInputStream(keystore), keystorpw);
         return ks1;
index f5b65d73c64d0527ca7526a1803ae12410e5cfdb..775823dc443a59991620f4529a57b40513efc135 100644 (file)
@@ -151,8 +151,12 @@ public class Launcher {
 
     private void initEmails(GigiConfig conf) throws GeneralSecurityException, IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
         KeyStore privateStore = conf.getPrivateStore();
-        Certificate mail = privateStore.getCertificate("mail");
-        Key k = privateStore.getKey("mail", conf.getPrivateStorePw().toCharArray());
+        Certificate mail = null;
+        Key k = null;
+        if (privateStore != null && privateStore.containsAlias("mail")) {
+            mail = privateStore.getCertificate("mail");
+            k = privateStore.getKey("mail", conf.getPrivateStorePw().toCharArray());
+        }
         EmailProvider.initSystem(conf.getMainProps(), mail, k);
     }
 
index 507a4a000f0e822134f38a400e16dc0576960385..b30658d6ecd484307d32b29c94347af068802e14 100644 (file)
@@ -21,7 +21,7 @@ public class CATSImport extends APIPoint {
             resp.sendError(500, "Error, invalid cert");
             return;
         }
-        if ( !"CAcert".equals(((Organisation) u).getName())) {
+        if ( !((Organisation) u).isSelfOrganisation()) {
             resp.sendError(500, "Error, invalid cert");
             return;
 
index c31f6cbfa3449dbaebb4ceb2e7f2564765da2640..5704497986388f70123d5bf7230839bed85fde0d 100644 (file)
@@ -263,6 +263,14 @@ public class CertificateProfile implements IdCachable {
                 if ( !actor.isInGroup(Group.CODESIGNING)) {
                     return false;
                 }
+            } else if (s.equals("ocsp")) {
+                if ( !(owner instanceof Organisation)) {
+                    return false;
+                }
+                Organisation o = (Organisation) owner;
+                if ( !o.isSelfOrganisation()) {
+                    return false;
+                }
             } else {
                 return false;
             }
index fa6ff1bee357d4ed52050e2226ad312f40b3bec3..5da2506855d0c16a764bd26eb6a37b87a43f366c 100644 (file)
@@ -217,4 +217,10 @@ public class Organisation extends CertificateOwner {
     public boolean isValidEmail(String email) {
         return isValidDomain(email.split("@", 2)[1]);
     }
+
+    public static final String SELF_ORG_NAME = "CAcert";
+
+    public boolean isSelfOrganisation() {
+        return SELF_ORG_NAME.equals(getName());
+    }
 }
index bf12dd772f993cb30b3b4c00134accfeadbf1810..70fd821442ccbce19454cd91f888b1a07dc15d80 100644 (file)
@@ -19,6 +19,10 @@ import org.cacert.gigi.util.Notary;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.PasswordStrengthChecker;
 
+/**
+ * Represents an acting, assurable, user. Synchronizing on user means: no
+ * name-change and no assurance.
+ */
 public class User extends CertificateOwner {
 
     private Name name = new Name(null, null, null, null);
index e2c4d5d63cb296b615fea0f9ee44093f4cfcca01..a32031187525f853b0306668b4b434ff739df4c9 100644 (file)
@@ -39,7 +39,13 @@ public abstract class EmailProvider {
     }
 
     protected final void sendSigned(String contents, PrintWriter output) throws IOException, GeneralSecurityException {
-        SMIME.smime(contents, k, c, output);
+        if (k == null || c == null) {
+            output.println("Content-Transfer-Encoding: base64");
+            output.println();
+            output.print(contents);
+        } else {
+            SMIME.smime(contents, k, c, output);
+        }
     }
 
     public static EmailProvider getInstance() {
index 0339326a024451de7475fa284e17e0acb51b2b0b..9ea66b359965f8ba0142b1ca4cbcced21f252335 100644 (file)
@@ -37,20 +37,23 @@ public class MyDetailsForm extends Form {
     @Override
     public boolean submit(PrintWriter out, HttpServletRequest req) {
         try {
-            if (target.getAssurancePoints() == 0) {
-                String newFname = req.getParameter("fname").trim();
-                String newLname = req.getParameter("lname").trim();
-                String newMname = req.getParameter("mname").trim();
-                String newSuffix = req.getParameter("suffix").trim();
-                if (newLname.isEmpty()) {
-                    throw new GigiApiException("Last name cannot be empty.");
+            synchronized (target) {
+                if (target.getAssurancePoints() == 0) {
+                    String newFname = req.getParameter("fname").trim();
+                    String newLname = req.getParameter("lname").trim();
+                    String newMname = req.getParameter("mname").trim();
+                    String newSuffix = req.getParameter("suffix").trim();
+                    if (newLname.isEmpty()) {
+                        throw new GigiApiException("Last name cannot be empty.");
+                    }
+
+                    target.setName(new Name(newFname, newLname, newMname, newSuffix));
+                    ds.update(req);
+                    target.setDoB(ds.getDate());
+                    target.updateUserData();
+                } else {
+                    throw new GigiApiException("No change after assurance allowed.");
                 }
-                target.setName(new Name(newFname, newLname, newMname, newSuffix));
-                ds.update(req);
-                target.setDoB(ds.getDate());
-                target.updateUserData();
-            } else {
-                throw new GigiApiException("No change after assurance allowed.");
             }
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
index 5712190bcd8f84e66329637fd9644e1e78806abe..7774fd814ea8007b619df1c67d9c75216aff0232 100644 (file)
@@ -152,16 +152,19 @@ public class CertificateIssueForm extends Form {
         vars2.put("hashs", new HashAlgorithms(cr.getSelectedDigest()));
         vars2.put("profiles", new IterableDataset() {
 
-            int i = 1;
+            CertificateProfile[] cps = CertificateProfile.getAll();
+
+            int i = 0;
 
             @Override
             public boolean next(Language l, Map<String, Object> vars) {
                 CertificateProfile cp;
                 do {
-                    cp = CertificateProfile.getById(i++);
-                    if (cp == null) {
+                    if (i >= cps.length) {
                         return false;
                     }
+                    cp = cps[i];
+                    i++;
                 } while ( !cp.canBeIssuedBy(c.getTarget(), c.getActor()));
 
                 if (cp.getId() == cr.getProfile().getId()) {
index 746529492146f30a0e44f23301edcbfdf24e2709..eba64f17a484a8dff96078cadd496e5f03a15057 100644 (file)
@@ -33,6 +33,7 @@ import org.cacert.gigi.output.template.Scope;
 import org.cacert.gigi.output.template.SprintfCommand;
 import org.cacert.gigi.util.AuthorizationContext;
 import org.cacert.gigi.util.PEM;
+import org.cacert.gigi.util.RateLimit;
 
 import sun.security.pkcs.PKCS9Attribute;
 import sun.security.pkcs10.PKCS10;
@@ -430,6 +431,9 @@ public class CertificateRequest {
             throw error;
         }
         try {
+            if (RATE_LIMIT.isLimitExceeded(Integer.toString(ctx.getActor().getId()))) {
+                throw new GigiApiException("Rate Limit Exceeded");
+            }
             return new Certificate(ctx.getTarget(), ctx.getActor(), subject, selectedDigest, //
                     this.csr, this.csrType, profile, SANs.toArray(new SubjectAlternateName[SANs.size()]));
         } catch (IOException e) {
@@ -438,6 +442,9 @@ public class CertificateRequest {
         return null;
     }
 
+    // 100 per 10 minutes
+    public static final RateLimit RATE_LIMIT = new RateLimit(100, 10 * 60 * 1000);
+
     private String verifyName(GigiApiException error, PropertyTemplate nameTemp, PropertyTemplate wotUserTemp, String verifiedCN) {
         // real names,
         // possible configurations: name {y,null,?}, name=WoTUser {y,null}
index e1c94c6b84577b92eaa9bad5edde0fb274a64a8c..74fb02bb706f76a5fded7b5bd89a0f3b11e638a6 100644 (file)
@@ -105,8 +105,10 @@ public class SupportUserDetailsForm extends Form {
             throw new GigiApiException("Invalid date of birth!");
         }
         Name newName = new Name(fname, lname, mname, suffix);
-        if (user.setDob(dobSelector.getDate()) | user.setName(newName)) {
-            user.submitSupportAction();
+        synchronized (user.getTargetUser()) {
+            if (user.setDob(dobSelector.getDate()) | user.setName(newName)) {
+                user.submitSupportAction();
+            }
         }
         return true;
     }
index 78b1cc19faa311089970778a59d854f5c3a3b8e4..4bc2cd957fa9b7d6e0e0c88cffbf0392cc5bba09 100644 (file)
@@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.util.AuthorizationContext;
+import org.cacert.gigi.util.RateLimit;
 
 public class RegisterPage extends Page {
 
@@ -18,6 +19,9 @@ public class RegisterPage extends Page {
 
     public static final String PATH = "/register";
 
+    // 5 per 5 min
+    public static final RateLimit RATE_LIMIT = new RateLimit(50, 5 * 60 * 1000);
+
     public RegisterPage() {
         super("Register");
     }
index bb72a9cd1a44fa516624823a36b7671c7d62ea58..52a6603f76615e364229d105e85845a01c4eafdb 100644 (file)
@@ -158,6 +158,10 @@ public class Signup extends Form {
         if (isFailed(out)) {
             return false;
         }
+        if (RegisterPage.RATE_LIMIT.isLimitExceeded(req.getRemoteAddr())) {
+            outputError(out, req, "Rate Limit Exceeded");
+            return false;
+        }
         try {
             run(req, pw1);
         } catch (SQLException e) {
index aa806fa929ce2b06ee4d4f31c5ce837213cddeae..7cb15aad203dc14619143dfd442b238221c28b62 100644 (file)
@@ -99,45 +99,47 @@ public class Notary {
         } else if (location.length() <= 2) {
             gae.mergeInto(new GigiApiException("You must enter a location with at least 3 characters eg town and country."));
         }
+        synchronized (assuree) {
 
-        try {
-            checkAssuranceIsPossible(assurer, assuree);
-        } catch (GigiApiException e) {
-            gae.mergeInto(e);
-        }
+            try {
+                checkAssuranceIsPossible(assurer, assuree);
+            } catch (GigiApiException e) {
+                gae.mergeInto(e);
+            }
 
-        if ( !assuree.getName().equals(assureeName) || !assuree.getDoB().equals(dob)) {
-            gae.mergeInto(new GigiApiException("The person you are assuring changed his personal details."));
-        }
-        if (awarded < 0) {
-            gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
-        } else {
-            if (type == AssuranceType.NUCLEUS) {
-                if (awarded > 50) {
-                    gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
-                }
+            if ( !assuree.getName().equals(assureeName) || !assuree.getDoB().equals(dob)) {
+                gae.mergeInto(new GigiApiException("The person you are assuring changed his personal details."));
+            }
+            if (awarded < 0) {
+                gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
             } else {
-                if (awarded > assurer.getMaxAssurePoints()) {
-                    gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
+                if (type == AssuranceType.NUCLEUS) {
+                    if (awarded > 50) {
+                        gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
+                    }
+                } else {
+                    if (awarded > assurer.getMaxAssurePoints()) {
+                        gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
+                    }
                 }
             }
-        }
 
-        if ( !gae.isEmpty()) {
-            throw gae;
-        }
+            if ( !gae.isEmpty()) {
+                throw gae;
+            }
 
-        if (type == AssuranceType.FACE_TO_FACE) {
-            assureF2F(assurer, assuree, awarded, location, date);
-        } else if (type == AssuranceType.NUCLEUS) {
-            assureNucleus(assurer, assuree, awarded, location, date);
-        } else if (type == AssuranceType.TTP_ASSISTED) {
-            assureTTP(assurer, assuree, awarded, location, date);
-        } else {
-            throw new GigiApiException("Unknown Assurance type: " + type);
+            if (type == AssuranceType.FACE_TO_FACE) {
+                assureF2F(assurer, assuree, awarded, location, date);
+            } else if (type == AssuranceType.NUCLEUS) {
+                assureNucleus(assurer, assuree, awarded, location, date);
+            } else if (type == AssuranceType.TTP_ASSISTED) {
+                assureTTP(assurer, assuree, awarded, location, date);
+            } else {
+                throw new GigiApiException("Unknown Assurance type: " + type);
+            }
+            assurer.invalidateMadeAssurances();
+            assuree.invalidateReceivedAssurances();
         }
-        assurer.invalidateMadeAssurances();
-        assuree.invalidateReceivedAssurances();
     }
 
     private static void assureF2F(User assurer, User assuree, int awarded, String location, String date) throws GigiApiException {
@@ -195,7 +197,7 @@ public class Notary {
     private static void assureNucleus(User assurer, User assuree, int awarded, String location, String date) throws GigiApiException {
         may(assurer, assuree, AssuranceType.NUCLEUS);
         // Do up to 35 points as f2f
-        int f2fPoints = Math.min(35, awarded);
+        int f2fPoints = Math.min(assurer.getMaxAssurePoints(), awarded);
         assureF2F(assurer, assuree, f2fPoints, location, date);
 
         awarded -= f2fPoints;
diff --git a/src/org/cacert/gigi/util/RateLimit.java b/src/org/cacert/gigi/util/RateLimit.java
new file mode 100644 (file)
index 0000000..65c1668
--- /dev/null
@@ -0,0 +1,78 @@
+package org.cacert.gigi.util;
+
+import java.util.HashMap;
+import java.util.TreeSet;
+
+public class RateLimit {
+
+    private class Entry implements Comparable<Entry> {
+
+        long firstAccess;
+
+        int count = 1;
+
+        String feature;
+
+        public Entry(long firstAccess, String feature) {
+            this.firstAccess = firstAccess;
+            this.feature = feature;
+        }
+
+        public void access() {
+            count++;
+        }
+
+        @Override
+        public int compareTo(Entry o) {
+            return feature.compareTo(o.feature);
+        }
+
+        public boolean isExpired() {
+            return firstAccess + time < System.currentTimeMillis();
+        }
+
+    }
+
+    private final int maxcount;
+
+    private final long time;
+
+    TreeSet<Entry> set = new TreeSet<Entry>();
+
+    HashMap<String, Entry> feat = new HashMap<>();
+
+    public RateLimit(int maxcount, long time) {
+        this.maxcount = maxcount;
+        this.time = time;
+    }
+
+    public synchronized boolean isLimitExceeded(String feature) {
+        clean();
+        Entry e = feat.get(feature);
+        if (e == null) {
+            e = new Entry(System.currentTimeMillis(), feature);
+            set.add(e);
+            feat.put(feature, e);
+        } else {
+            e.access();
+        }
+        return e.count > maxcount;
+    }
+
+    private void clean() {
+        while (set.size() > 0) {
+            Entry e = set.last();
+            if (e.isExpired()) {
+                set.remove(e);
+                feat.remove(e.feature);
+            } else {
+                return;
+            }
+        }
+    }
+
+    public synchronized void bypass() {
+        set.clear();
+        feat.clear();
+    }
+}
index f02f0ad04239a7fd66279c7a23b07f6396fe4ee0..29456c7b2a24a8d20b3580ea0801ec91ae330c79 100644 (file)
@@ -3,7 +3,6 @@ package org.cacert.gigi;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.URL;
 
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
@@ -43,7 +42,7 @@ public class LoginTest extends ManagedTest {
     }
 
     private void logout(String cookie) throws IOException {
-        cookie(new URL("https://" + getServerName() + "/logout").openConnection(), cookie).getHeaderField("Location");
+        get(cookie, "/logout").getHeaderField("Location");
     }
 
 }
index 1cac14527bc7d2f90a7e9d2e5786dbeff55b1db7..55a3d12684e893645ab57c0c65a4e97c8915a965 100644 (file)
@@ -4,7 +4,6 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.URL;
 import java.util.Locale;
 
 import org.cacert.gigi.dbObjects.User;
@@ -51,13 +50,13 @@ public class TestLanguage extends ManagedTest {
 
     @Test
     public void testSelectStandard() throws IOException {
-        String content = IOUtils.readURL(new URL("https://" + getServerName() + "/").openConnection());
+        String content = IOUtils.readURL(get("cook", "/"));
         assertThat(content, containsString("Translations"));
     }
 
     @Test
     public void testSelectGerman() throws IOException {
-        String content = IOUtils.readURL(new URL("https://" + getServerName() + "/?lang=de").openConnection());
+        String content = IOUtils.readURL(get("", "/?lang=de"));
         assertThat(content, containsString(Language.getInstance(Locale.GERMAN).getTranslation("Translations")));
     }
 
@@ -66,7 +65,7 @@ public class TestLanguage extends ManagedTest {
         setAcceptLanguage("de,en");
         User u = User.getById(createVerifiedUser("fname", "lname", createUniqueName() + "@example.org", TEST_PASSWORD));
         String cookie = login(u.getEmail(), TEST_PASSWORD);
-        String content = IOUtils.readURL(cookie(new URL("https://" + getServerName() + "/").openConnection(), cookie));
+        String content = IOUtils.readURL(get(cookie, "/"));
         assertThat(content, containsString(Language.getInstance(Locale.GERMAN).getTranslation("Translations")));
     }
 
@@ -75,7 +74,7 @@ public class TestLanguage extends ManagedTest {
         setAcceptLanguage("fr,de,en");
         User u = User.getById(createVerifiedUser("fname", "lname", createUniqueName() + "@example.org", TEST_PASSWORD));
         String cookie = login(u.getEmail(), TEST_PASSWORD);
-        String content = IOUtils.readURL(cookie(new URL("https://" + getServerName() + "/").openConnection(), cookie));
+        String content = IOUtils.readURL(get(cookie, "/"));
         assertThat(content, containsString(Language.getInstance(Locale.FRENCH).getTranslation("Translations")));
     }
 }
index 16f4f3a08580c4d7f5b50d00038b63b8b2cd0b72..8149d322a22f21d917aeb91749630e701cc072e8 100644 (file)
@@ -4,7 +4,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
-import java.net.URL;
 
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
@@ -13,17 +12,17 @@ public class TestSecurityHeaders extends ManagedTest {
 
     @Test
     public void testSTS() throws IOException {
-        HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName()).openConnection();
+        HttpURLConnection uc = get(null, "/");
         assertNotNull(uc.getHeaderField("Strict-Transport-Security"));
     }
 
     public void testCSP() throws IOException {
-        HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName()).openConnection();
+        HttpURLConnection uc = get(null, "/");
         assertNotNull(uc.getHeaderField("Content-Security-Policy"));
     }
 
     public void testAllowOrigin() throws IOException {
-        HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName()).openConnection();
+        HttpURLConnection uc = get(null, "/");
         assertNotNull(uc.getHeaderField("Access-Control-Allow-Origin"));
 
     }
index f8adbff83d2f313250bb5d5156de92b35a563958..be02a7b672d84f459164ab94e48ca117598470f9 100644 (file)
@@ -40,7 +40,8 @@ public class ImportCATSResult extends ClientTest {
         grant(u.getEmail(), Group.ORGASSURER);
         clearCaches();
         u = User.getById(u.getId());
-        Organisation o = new Organisation("CAcert", "NA", "NA", "NA", "contact@cacert.org", u);
+        Organisation o = new Organisation(Organisation.SELF_ORG_NAME, "NA", "NA", "NA", "contact@cacert.org", u);
+        assertTrue(o.isSelfOrganisation());
         KeyPair kp = generateKeypair();
         String key1 = generatePEMCSR(kp, "EMAIL=cats@cacert.org");
         Certificate c = new Certificate(o, u, Certificate.buildDN("EMAIL", "cats@cacert.org"), Digest.SHA256, key1, CSRType.CSR, CertificateProfile.getByName("client-orga"), new Certificate.SubjectAlternateName(SANType.EMAIL, "cats@cacert.org"));
index f27a26a4642af0557cf4be5a7d0f824e29a8277a..1563addadc5476a8157e0818c3c8c62d6bba5a0f 100644 (file)
@@ -5,7 +5,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.util.Locale;
 import java.util.regex.Matcher;
@@ -37,8 +36,7 @@ public class TestSEAdminPageDetails extends ClientTest {
         String fname = "Först";
         String lname = "Secönd";
         int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + SupportUserDetailsPage.PATH + id).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        URLConnection uc = get(SupportUserDetailsPage.PATH + id);
         uc.setDoOutput(true);
         String res = IOUtils.readURL(uc);
         assertThat(res, containsString("<input type=\"text\" value=\"" + fname + "\" name=\"fname\">"));
index 966adc1729bcd828edd79bc77d4a1fef251d6a83..4337e3324babc19f956991655398639cac941d9b 100644 (file)
@@ -4,10 +4,8 @@ import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 
@@ -37,17 +35,8 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
         User user = User.getById(id);
         String domainName = createUniqueName() + ".org";
         new Domain(user, user, domainName);
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
 
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=" + URLEncoder.encode(domainName, "UTF-8")).getBytes("UTF-8"));
-        os.flush();
         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
     }
 
@@ -58,33 +47,13 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
         User user = User.getById(id);
         String domainName = createUniqueName() + ".org";
         Domain d = new Domain(user, user, domainName);
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=#" + d.getId()).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=#" + d.getId());
         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
     }
 
     @Test
     public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 
@@ -102,16 +71,7 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
             found = true;
         }
         assumeTrue(found);
-        URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-        uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&domain=#" + id).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindDomainPage.PATH, "process&domain=#" + id);
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 }
index 95b9ec7468f616eb5c9ccabd7ca3bedc8da0b535..70e5bd4f098464819ed1a9ef8d239ccfce5d632e 100644 (file)
@@ -4,10 +4,8 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 
@@ -74,17 +72,7 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
 
     @Test
     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 
index 3ecc7a21dbb6705525db623b206c21390adba97e..6fe4f1828d57d79b771d3ac2d6b414e0feff00ab 100644 (file)
@@ -5,7 +5,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.sql.SQLException;
@@ -87,28 +86,25 @@ public class TestOrgaManagement extends ClientTest {
         o1.addAdmin(u2, u, false);
         String session2 = login(u2.getEmail(), TEST_PASSWORD);
 
-        URLConnection uc = new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH).openConnection();
-        uc.addRequestProperty("Cookie", session2);
+        URLConnection uc = get(session2, ViewOrgPage.DEFAULT_PATH);
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
 
-        uc = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
-        uc.addRequestProperty("Cookie", session2);
+        uc = get(session2, MyDetails.PATH);
         String content = IOUtils.readURL(uc);
         assertThat(content, containsString("name21"));
         assertThat(content, not(containsString("name12")));
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o1.getId()).openConnection(), session2);
+        uc = get(session2, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId());
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), session2);
+        uc = get(session2, ViewOrgPage.DEFAULT_PATH + "/" + o2.getId());
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
 
-        uc = new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        uc = get(ViewOrgPage.DEFAULT_PATH);
         content = IOUtils.readURL(uc);
         assertThat(content, containsString("name21"));
         assertThat(content, containsString("name12"));
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o1.getId()).openConnection(), cookie);
+        uc = get(ViewOrgPage.DEFAULT_PATH + "/" + o1.getId());
         assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
-        uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), cookie);
+        uc = get(ViewOrgPage.DEFAULT_PATH + "/" + o2.getId());
         assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
         o1.delete();
         o2.delete();
index 58a791f372fcc0066a83b00244ffd44e0b9e3884..ffc9ea5788fc1f83f04b229572fdf88aad79a6ba 100644 (file)
@@ -7,7 +7,6 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.sql.SQLException;
@@ -64,10 +63,8 @@ public class TestAssurance extends ManagedTest {
     }
 
     private String search(String query) throws MalformedURLException, IOException, UnsupportedEncodingException {
-        URL u = new URL("https://" + getServerName() + AssurePage.PATH);
-        URLConnection uc = u.openConnection();
+        URLConnection uc = get(cookie, AssurePage.PATH);
         uc.setDoOutput(true);
-        uc.addRequestProperty("Cookie", cookie);
         uc.getOutputStream().write(("search&" + query).getBytes("UTF-8"));
         uc.getOutputStream().flush();
 
@@ -186,8 +183,7 @@ public class TestAssurance extends ManagedTest {
         String error = getError("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
         assertNull(error);
         String cookie = login(assureeM, TEST_PASSWORD);
-        URLConnection url = new URL("https://" + getServerName() + MyPoints.PATH).openConnection();
-        url.setRequestProperty("Cookie", cookie);
+        URLConnection url = get(cookie, MyPoints.PATH);
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[0];
         assertThat(resp, containsString(uniqueLoc));
@@ -199,8 +195,7 @@ public class TestAssurance extends ManagedTest {
         String error = getError("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
         assertNull(error);
         String cookie = login(assurerM, TEST_PASSWORD);
-        URLConnection url = new URL("https://" + getServerName() + MyPoints.PATH).openConnection();
-        url.setRequestProperty("Cookie", cookie);
+        URLConnection url = get(cookie, MyPoints.PATH);
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[1];
         assertThat(resp, containsString(uniqueLoc));
@@ -219,15 +214,12 @@ public class TestAssurance extends ManagedTest {
     }
 
     public static URLConnection buildupAssureFormConnection(String cookie, String email, boolean doCSRF) throws MalformedURLException, IOException {
-        URL u = new URL("https://" + getServerName() + AssurePage.PATH);
-        URLConnection uc = u.openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        URLConnection uc = get(cookie, AssurePage.PATH);
         uc.setDoOutput(true);
         uc.getOutputStream().write(("email=" + URLEncoder.encode(email, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes("UTF-8"));
 
         String csrf = getCSRF(uc);
-        uc = u.openConnection();
-        uc.addRequestProperty("Cookie", cookie);
+        uc = get(cookie, AssurePage.PATH);
         uc.setDoOutput(true);
         if (doCSRF) {
             uc.getOutputStream().write(("csrf=" + csrf + "&").getBytes("UTF-8"));
index 7c8884ba8c22acb8a6952af95ac0fdabc5119301..34b0ca6dfc78c50d7ffad6d3c6a6a461ef72254d 100644 (file)
@@ -4,7 +4,6 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.URL;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Group;
@@ -16,17 +15,15 @@ import org.junit.Test;
 
 public class TestTTP extends ClientTest {
 
-    URL ttpPage = new URL("https://" + getServerName() + RequestTTPPage.PATH);
-
     public TestTTP() throws IOException {}
 
     @Test
     public void testTTPApply() throws IOException {
-        String ttp = IOUtils.readURL(cookie(ttpPage.openConnection(), cookie));
+        String ttp = IOUtils.readURL(get(RequestTTPPage.PATH));
         assertThat(ttp, containsString("<form"));
         executeBasicWebInteraction(cookie, RequestTTPPage.PATH, "country=0");
 
-        ttp = IOUtils.readURL(cookie(new URL("https://" + getServerName() + RequestTTPPage.PATH).openConnection(), cookie));
+        ttp = IOUtils.readURL(get(RequestTTPPage.PATH));
         assertThat(ttp, not(containsString("<form")));
         ObjectCache.clearAllCaches();
         u = User.getById(u.getId());
@@ -38,7 +35,7 @@ public class TestTTP extends ClientTest {
         User u = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@example.org", TEST_PASSWORD));
         cookie = login(u.getEmail(), TEST_PASSWORD);
 
-        String ttp = IOUtils.readURL(cookie(new URL("https://" + getServerName() + RequestTTPPage.PATH).openConnection(), cookie));
+        String ttp = IOUtils.readURL(get(RequestTTPPage.PATH));
         assertThat(ttp, not(containsString("<form")));
     }
 }
index 32c4268afc120846f613a5a72d07917b9953e824..31b0e51bd9d5bb3d77483fee2586cecc110a4ff7 100644 (file)
@@ -3,9 +3,7 @@ package org.cacert.gigi.pages.wot;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
-import java.net.URL;
 
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
@@ -38,15 +36,14 @@ public class TestTTPAdmin extends ClientTest {
         grant(u.getEmail(), TTPAdminPage.TTP_APPLICANT);
         cookie = login(u.getEmail(), TEST_PASSWORD);
 
-        assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH));
-        assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/"));
-        assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + u.getId()));
-        assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + us2.getId()));
-        assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + 100));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
+        assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
+        assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
     }
 
     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
-        URL u = new URL(path);
-        return ((HttpURLConnection) cookie(u.openConnection(), cookie)).getResponseCode();
+        return get(path).getResponseCode();
     }
 }
index 187bb382bd1b2a860ff63b77581c56866cb9260c..8bb61461ecc745dddc8219919f445fd8cd2297e6 100644 (file)
@@ -4,7 +4,6 @@ import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
 import java.io.IOException;
-import java.net.URL;
 import java.net.URLEncoder;
 import java.sql.SQLException;
 import java.util.regex.Matcher;
@@ -12,7 +11,6 @@ import java.util.regex.Pattern;
 
 import javax.naming.NamingException;
 
-import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -63,8 +61,7 @@ public class TestDNS extends PingTest {
         String test = getTestProps().getProperty("domain.dnstest");
         assumeNotNull(test);
 
-        URL u = new URL("https://" + getServerName() + DomainOverview.PATH);
-        Matcher m = initailizeDomainForm(u);
+        Matcher m = initailizeDomainForm();
         updateService(m.group(1) + (dnsVariant == 1 ? "a" : ""), m.group(2) + (dnsVariant == 2 ? "a" : ""), "dns");
 
         String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + //
@@ -74,7 +71,7 @@ public class TestDNS extends PingTest {
                 "&ssl-type-2=direct&ssl-port-2=" + //
                 "&ssl-type-3=direct&ssl-port-3=" + //
                 "&adddomain&csrf=" + csrf;
-        URL u2 = sendDomainForm(u, content);
+        String p2 = sendDomainForm(content);
 
         TestMail mail = getMailReciever().receive();
         if (emailVariant == 0) {
@@ -83,7 +80,7 @@ public class TestDNS extends PingTest {
 
         waitForPings(2);
 
-        String newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(p2));
         Pattern pat = Pattern.compile("<td>dns</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successDNS ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
index da9892b41e854cb1735bff4a8d87331ac287e53b..31fecd942bb53e2ba4055aad9a182d77b953cbff 100644 (file)
@@ -18,7 +18,6 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
 import org.cacert.gigi.dbObjects.DomainPingType;
-import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -58,8 +57,7 @@ public class TestHTTP extends PingTest {
         String test = getTestProps().getProperty("domain.http");
         assumeNotNull(test);
 
-        URL u = new URL("https://" + getServerName() + DomainOverview.PATH);
-        Matcher m = initailizeDomainForm(u);
+        Matcher m = initailizeDomainForm();
         updateService(m.group(1) + (httpVariant == 1 ? "a" : ""), m.group(2) + (httpVariant == 2 ? "a" : ""), "http");
 
         String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + //
@@ -69,7 +67,7 @@ public class TestHTTP extends PingTest {
                 "&ssl-type-2=direct&ssl-port-2=" + //
                 "&ssl-type-3=direct&ssl-port-3=" + //
                 "&adddomain&csrf=" + csrf;
-        URL u2 = sendDomainForm(u, content);
+        String p2 = sendDomainForm(content);
 
         TestMail mail = getMailReciever().receive();
         if (emailVariant == 0) {
@@ -77,14 +75,14 @@ public class TestHTTP extends PingTest {
         }
         waitForPings(2);
 
-        String newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(p2));
         Pattern pat = Pattern.compile("<td>http</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successHTTP ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find());
 
         if (successHTTP) { // give it a second try
-            int id = Integer.parseInt(u2.toString().replaceFirst("^.*/([0-9]+)$", "$1"));
+            int id = Integer.parseInt(p2.replaceFirst("^.*/([0-9]+)$", "$1"));
             Domain d = Domain.getById(id);
             DomainPingConfiguration dpc = null;
             for (DomainPingConfiguration conf : d.getConfiguredPings()) {
@@ -96,7 +94,7 @@ public class TestHTTP extends PingTest {
             if (dpc == null) {
                 fail("Http config not found");
             }
-            String res = executeBasicWebInteraction(cookie, u2.getPath(), "configId=" + dpc.getId());
+            String res = executeBasicWebInteraction(cookie, p2, "configId=" + dpc.getId());
             assertThat(res, containsString("only allowed after"));
         }
     }
index 82d1c820b11eb81cf58e79adcbfb604df4940300..62e652aa06aeb297fff9f51a2273e0da0ddbdca7 100644 (file)
@@ -6,7 +6,6 @@ import static org.junit.Assume.*;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.Socket;
-import java.net.URL;
 import java.net.URLEncoder;
 import java.security.GeneralSecurityException;
 import java.security.KeyManagementException;
@@ -42,7 +41,6 @@ import org.cacert.gigi.dbObjects.Certificate.CSRType;
 import org.cacert.gigi.dbObjects.CertificateProfile;
 import org.cacert.gigi.dbObjects.Digest;
 import org.cacert.gigi.dbObjects.User;
-import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -154,9 +152,7 @@ public class TestSSL extends PingTest {
     private void testEmailAndSSL(int sslVariant, int emailVariant, boolean successMail) throws IOException, InterruptedException, SQLException, GeneralSecurityException, GigiApiException {
         String test = getTestProps().getProperty("domain.local");
         assumeNotNull(test);
-        URL u = new URL("https://" + getServerName() + DomainOverview.PATH);
-
-        Matcher m = initailizeDomainForm(u);
+        Matcher m = initailizeDomainForm();
         String value = m.group(2);
 
         if (self) {
@@ -182,7 +178,7 @@ public class TestSSL extends PingTest {
                 "&ssl-type-2=direct&ssl-port-2=" + //
                 "&ssl-type-3=direct&ssl-port-3=" + //
                 "&adddomain&csrf=" + csrf;
-        URL u2 = sendDomainForm(u, content);
+        String p2 = sendDomainForm(content);
         boolean firstSucceeds = sslVariant != 0 && sslVariant != 2;
         AsyncTask<Boolean> ass = new AsyncTask<Boolean>() {
 
@@ -206,7 +202,7 @@ public class TestSSL extends PingTest {
         }
         waitForPings(3);
 
-        String newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(p2));
         Pattern pat = Pattern.compile("<td>ssl</td>\\s*<td>success</td>");
         Matcher matcher = pat.matcher(newcontent);
         assertTrue(newcontent, firstSucceeds ^ matcher.find());
index 96b4e61b06886d689ebf3d0b6d867f80005ae2b1..098c257f9adb7e6202bdfb72d1eed4a2f834a0b4 100644 (file)
@@ -474,7 +474,7 @@ public class ManagedTest extends ConfiguredTest {
         return (HttpURLConnection) uc;
     }
 
-    public HttpURLConnection get(String cookie, String path) throws IOException {
+    public static HttpURLConnection get(String cookie, String path) throws IOException {
         URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
         uc.addRequestProperty("Cookie", cookie);
         return (HttpURLConnection) uc;
index fd5de700daa9d0c87a0443cda2c3c097f54cabc4..0d15f2e86c3cf5807c3a969d647b83e061103c89 100644 (file)
@@ -46,27 +46,26 @@ public abstract class PingTest extends ClientTest {
         }
     }
 
-    protected URL sendDomainForm(URL u, String content) throws IOException, MalformedURLException {
-        URLConnection openConnection = u.openConnection();
-        openConnection.setRequestProperty("Cookie", cookie);
+    protected String sendDomainForm(String content) throws IOException, MalformedURLException {
+        URLConnection openConnection = get(DomainOverview.PATH);
         openConnection.setDoOutput(true);
         openConnection.getOutputStream().write(content.getBytes("UTF-8"));
         openConnection.getHeaderField("Location");
+        if (((HttpURLConnection) openConnection).getResponseCode() != 302) {
+            throw new Error(IOUtils.readURL(openConnection));
+        }
 
-        String newcontent = IOUtils.readURL(cookie(u.openConnection(), cookie));
+        String newcontent = IOUtils.readURL(get(DomainOverview.PATH));
         Pattern dlink = Pattern.compile(DomainOverview.PATH + "([0-9]+)'>");
         Matcher m1 = dlink.matcher(newcontent);
         if ( !m1.find()) {
             throw new Error(newcontent);
         }
-        URL u2 = new URL(u.toString() + m1.group(1));
-        return u2;
+        return DomainOverview.PATH + m1.group(1);
     }
 
-    protected Matcher initailizeDomainForm(URL u) throws IOException, Error {
-        URLConnection openConnection = u.openConnection();
-        openConnection.setRequestProperty("Cookie", cookie);
-        String content1 = IOUtils.readURL(openConnection);
+    protected Matcher initailizeDomainForm() throws IOException, Error {
+        String content1 = IOUtils.readURL(get(DomainOverview.PATH));
         csrf = getCSRF(1, content1);
 
         Pattern p = Pattern.compile("([A-Za-z0-9]+)._cacert._auth IN TXT ([A-Za-z0-9]+)");
index 6fd69d7cfcc7d7292eca1f00bd440e6497efb4b2..d9f190e096a5adca0ed539673b331b817bb14548 100644 (file)
@@ -2,6 +2,7 @@ package org.cacert.gigi.util;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Date;
 
@@ -15,8 +16,15 @@ import org.junit.Test;
 
 public class TestNotary extends ManagedTest {
 
+    // These tests create a lot of users and therefore require resetting of the
+    // registering-rate-limit.
     @Test
     public void testNormalAssurance() throws SQLException, GigiApiException {
+        try {
+            clearCaches();
+        } catch (IOException e) {
+            throw new Error(e);
+        }
         User[] users = new User[30];
         for (int i = 0; i < users.length; i++) {
             int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD);
@@ -58,6 +66,11 @@ public class TestNotary extends ManagedTest {
 
     @Test
     public void testPoJam() throws SQLException, GigiApiException {
+        try {
+            clearCaches();
+        } catch (IOException e) {
+            throw new Error(e);
+        }
         User[] users = new User[30];
         for (int i = 0; i < users.length; i++) {
             int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD);
index df5a790d24297fd728316c9e0978da3ae8924eb7..8c010bdc42bdf3105abd1b3dd9a5b794862e97db 100644 (file)
@@ -16,6 +16,7 @@ import java.lang.reflect.Field;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.HashMap;
@@ -31,6 +32,8 @@ import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.pages.account.certs.CertificateRequest;
+import org.cacert.gigi.pages.main.RegisterPage;
 import org.cacert.gigi.util.AuthorizationContext;
 import org.cacert.gigi.util.ServerConstants;
 import org.kamranzafar.jtar.TarEntry;
@@ -55,7 +58,13 @@ public class DevelLauncher {
         ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
         DataOutputStream dos = new DataOutputStream(chunkConfig);
         byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
-        byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
+        byte[] keystore = null;
+        Path p = Paths.get("config/keystore.pkcs12");
+        if (p.toFile().exists()) {
+            keystore = Files.readAllBytes(p);
+        } else {
+            mainProps.setProperty("proxy", "true");
+        }
 
         DevelLauncher.writeGigiConfig(dos, "changeit".getBytes("UTF-8"), "changeit".getBytes("UTF-8"), mainProps, cacerts, keystore);
         dos.flush();
@@ -119,6 +128,8 @@ public class DevelLauncher {
                 @Override
                 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
                     ObjectCache.clearAllCaches();
+                    RegisterPage.RATE_LIMIT.bypass();
+                    CertificateRequest.RATE_LIMIT.bypass();
                     resp.getWriter().println("All caches cleared.");
                     System.out.println("Caches cleared.");
 
@@ -229,6 +240,9 @@ public class DevelLauncher {
     }
 
     private static void putTarEntry(byte[] data, TarOutputStream tos, String name) throws IOException {
+        if (data == null) {
+            return;
+        }
         TarHeader th = new TarHeader();
         th.name = new StringBuffer(name);
         th.size = data.length;
index 970c719f468b222dfb9c7eec2b2fa39eb508d84d..d23b78bc6d83fd1f7a0c8a008183159b7403c882 100644 (file)
@@ -494,6 +494,9 @@ public class SimpleSigner {
             case "emailProtection":
                 oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.4");
                 break;
+            case "OCSPSigning":
+                oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.9");
+                break;
 
             default:
                 throw new Error(name);