X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=inline;f=util-testing%2Fclub%2Fwpia%2Fgigi%2Fpages%2FManager.java;h=0ca611994798cedbadfd8868aad45791ff0e2b24;hb=a7dd0d91bd94ec5eb3ff4e066c8e3492659c7174;hp=81dfeaebacbe6f33a1eca5dc0f3c7fc7150cbd21;hpb=a1ee192e00a8c1c1bb970d82e06c82ca25d9ab35;p=gigi.git
diff --git a/util-testing/club/wpia/gigi/pages/Manager.java b/util-testing/club/wpia/gigi/pages/Manager.java
index 81dfeaeb..0ca61199 100644
--- a/util-testing/club/wpia/gigi/pages/Manager.java
+++ b/util-testing/club/wpia/gigi/pages/Manager.java
@@ -7,6 +7,7 @@ import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.Signature;
+import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Calendar;
@@ -31,17 +32,23 @@ import club.wpia.gigi.Gigi;
import club.wpia.gigi.GigiApiException;
import club.wpia.gigi.crypto.SPKAC;
import club.wpia.gigi.database.GigiPreparedStatement;
+import club.wpia.gigi.database.GigiResultSet;
import club.wpia.gigi.dbObjects.CATS;
import club.wpia.gigi.dbObjects.CATS.CATSType;
import club.wpia.gigi.dbObjects.Certificate;
import club.wpia.gigi.dbObjects.Certificate.CertificateStatus;
import club.wpia.gigi.dbObjects.CertificateOwner;
+import club.wpia.gigi.dbObjects.Contract;
+import club.wpia.gigi.dbObjects.Contract.ContractType;
import club.wpia.gigi.dbObjects.Country;
import club.wpia.gigi.dbObjects.Digest;
import club.wpia.gigi.dbObjects.Domain;
+import club.wpia.gigi.dbObjects.DomainPingConfiguration;
+import club.wpia.gigi.dbObjects.DomainPingExecution;
import club.wpia.gigi.dbObjects.DomainPingType;
import club.wpia.gigi.dbObjects.EmailAddress;
import club.wpia.gigi.dbObjects.Group;
+import club.wpia.gigi.dbObjects.Name;
import club.wpia.gigi.dbObjects.NamePart;
import club.wpia.gigi.dbObjects.NamePart.NamePartType;
import club.wpia.gigi.dbObjects.User;
@@ -160,6 +167,7 @@ public class Manager extends Page {
ps.setString(6, getRandomCountry().getCode());
ps.execute();
}
+ new Contract(u, ContractType.RA_AGENT_CONTRACT);
return u;
}
}
@@ -168,6 +176,24 @@ public class Manager extends Page {
CATS.enterResult(u, t, new Date(System.currentTimeMillis()), "en_EN", "1");
}
+ private void expireCATS(User u, CATSType t) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `cats_passed` WHERE `user_id`=? AND `variant_id`=? AND `pass_date`>?")) {
+ ps.setInt(1, u.getId());
+ ps.setInt(2, t.getId());
+ ps.setTimestamp(3, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 366));
+ ps.execute();
+ GigiResultSet rs = ps.executeQuery();
+ while (rs.next()) {
+ GigiPreparedStatement ps1 = new GigiPreparedStatement("UPDATE `cats_passed` SET `pass_date`=? WHERE `id`=?");
+ ps1.setTimestamp(1, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 367));
+ ps1.setInt(2, rs.getInt(1));
+ ps1.execute();
+ ps1.close();
+ }
+ }
+
+ }
+
private static Manager instance;
private static final Template t = new Template(Manager.class.getResource("ManagerMails.templ"));
@@ -233,12 +259,14 @@ public class Manager extends Page {
}
@Override
- public void ping(Domain domain, String configuration, CertificateOwner target, int confId) {
- System.out.println("Test: " + domain);
+ public DomainPingExecution ping(Domain domain, String configuration, CertificateOwner target, DomainPingConfiguration conf) {
+ System.err.println("TestManager: " + domain.getSuffix());
if (pingExempt.contains(domain.getSuffix())) {
- enterPingResult(confId, DomainPinger.PING_SUCCEDED, "Succeeded by TestManager pass-by", null);
+ return enterPingResult(conf, DomainPinger.PING_SUCCEDED, "Succeeded by TestManager pass-by", null);
} else {
- dps.get(dpt).ping(domain, configuration, target, confId);
+ DomainPinger pinger = dps.get(dpt);
+ System.err.println("Forward to old pinger: " + pinger);
+ return pinger.ping(domain, configuration, target, conf);
}
}
@@ -298,6 +326,7 @@ public class Manager extends Page {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ AuthorizationContext sessionAc = (AuthorizationContext) req.getSession().getAttribute(Gigi.AUTH_CONTEXT);
if (req.getParameter("create") != null) {
String prefix = req.getParameter("prefix");
String domain = req.getParameter("suffix");
@@ -355,6 +384,21 @@ public class Manager extends Page {
CATSType test = CATSType.values()[Integer.parseInt(testId)];
passCATS(byEmail, test);
resp.getWriter().println("Test '" + test.getDisplayName() + "' was added to user account.");
+ } else if (req.getParameter("catsexpire") != null) {
+ String mail = req.getParameter("catsEmail");
+ String testId = req.getParameter("catsType");
+ User byEmail = User.getByEmail(mail);
+ if (byEmail == null) {
+ resp.getWriter().println("User not found.");
+ return;
+ }
+ if (testId == null) {
+ resp.getWriter().println("No test given.");
+ return;
+ }
+ CATSType test = CATSType.values()[Integer.parseInt(testId)];
+ expireCATS(byEmail, test);
+ resp.getWriter().println("Test '" + test.getDisplayName() + "' is set expired for user account.");
} else if (req.getParameter("verify") != null) {
String mail = req.getParameter("verifyEmail");
String verificationPoints = req.getParameter("verificationPoints");
@@ -366,35 +410,55 @@ public class Manager extends Page {
}
int vp = 0;
- int agentNumber = 0;
+ int verifications = 0;
+ String info = "";
try {
try {
vp = Integer.parseInt(verificationPoints);
} catch (NumberFormatException e) {
- throw new GigiApiException("No valid Verification Points entered.");
+ resp.getWriter().println("The value for Verification Points must be an integer.");
+ vp = 0;
}
- if (vp > 100) { // only allow max 100 Verification points
- vp = 100;
- }
+ int agentNumber = addVerificationPoints(vp, byEmail);
while (vp > 0) {
int currentVP = 10;
if (vp < 10) {
currentVP = vp;
}
- Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
+ if (Notary.checkVerificationIsPossible(getAgent(agentNumber), byEmail.getPreferredName())) {
+
+ Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
+ vp -= currentVP;
+ verifications += 1;
+
+ }
agentNumber += 1;
- vp -= currentVP;
+ if (agentNumber >= agents.length) {
+ info = "
The limit of agents is reached. You cannot add any more Verification Points to the preferred name of this user using this method.";
+ break;
+ }
}
} catch (GigiApiException e) {
throw new Error(e);
}
- resp.getWriter().println("User has been verified " + agentNumber + " times.");
+ resp.getWriter().println("User has been verified " + verifications + " times." + info);
+
+ } else if (req.getParameter("verifyexpire") != null) {
+ String mail = req.getParameter("verifyEmail");
+ User byEmail = User.getByEmail(mail);
+ if (byEmail == null) {
+ resp.getWriter().println("User not found.");
+ return;
+ } else {
+ setVerificationDateToPast(byEmail.getPreferredName());
+ }
+ resp.getWriter().println("Verification set to time past the limit.");
} else if (req.getParameter("letverify") != null) {
String mail = req.getParameter("letverifyEmail");
User byEmail = User.getByEmail(mail);
@@ -434,7 +498,7 @@ public class Manager extends Page {
byte[] res = s.getEncoded(sign);
- CertificateRequest cr = new CertificateRequest(new AuthorizationContext(u, u), Base64.getEncoder().encodeToString(res), "challenge");
+ CertificateRequest cr = new CertificateRequest(new AuthorizationContext(u, u, sessionAc.isStronglyAuthenticated()), Base64.getEncoder().encodeToString(res), "challenge");
cr.update(CertificateRequest.DEFAULT_CN, Digest.SHA512.toString(), "client", null, "", "email:" + u.getEmail());
Certificate draft = cr.draft();
draft.issue(null, "2y", u).waitFor(10000);
@@ -460,10 +524,54 @@ public class Manager extends Page {
pingExempt.remove(dom);
resp.getWriter().println("Updated domains exempt from pings. Current set:
");
resp.getWriter().println(HTMLEncoder.encodeHTML(pingExempt.toString()));
+ } else if (req.getParameter("makeAgent") != null) {
+ User u = User.getByEmail(req.getParameter("agentEmail"));
+ if (u == null) {
+ resp.getWriter().println("User not found, or found user is not allowed to verify.");
+ } else {
+ if (u.getVerificationPoints() < 100) {
+ addVerificationPoints(100, u);
+ }
+ if ( !u.hasPassedCATS()) {
+ passCATS(u, CATSType.AGENT_CHALLENGE);
+ }
+ if ( !Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT)) {
+ try {
+ new Contract(u, Contract.ContractType.RA_AGENT_CONTRACT);
+ } catch (GigiApiException e) {
+ throw new Error(e);
+ }
+ }
+ resp.getWriter().println("User has all requirements to be an RA Agent");
+ }
}
resp.getWriter().println("
Go back");
}
+ private int addVerificationPoints(int vp, User byEmail) throws Error {
+ int agentNumber = 0;
+
+ try {
+ if (vp > 100) { // only allow max 100 Verification points
+ vp = 100;
+ }
+
+ while (vp > 0) {
+ int currentVP = 10;
+ if (vp < 10) {
+ currentVP = vp;
+ }
+ Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
+ agentNumber += 1;
+ vp -= currentVP;
+ }
+
+ } catch (GigiApiException e) {
+ throw new Error(e);
+ }
+ return agentNumber;
+ }
+
private void fetchMails(HttpServletRequest req, HttpServletResponse resp, String mail) throws IOException {
final LinkedList mails = emails.get(mail);
HashMap vars = new HashMap<>();
@@ -532,4 +640,18 @@ public class Manager extends Page {
form.output(resp.getWriter(), getLanguage(req), vars);
}
+
+ private static void setVerificationDateToPast(Name name) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(System.currentTimeMillis());
+ c.add(Calendar.MONTH, -TimeConditions.getInstance().getVerificationMonths());
+ String date = sdf.format(new Date(c.getTimeInMillis()));
+ GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `notary` SET `date`=? WHERE `to`=? AND `date`>?");
+ ps.setString(1, date);
+ ps.setInt(2, name.getId());
+ ps.setString(3, date);
+ ps.execute();
+ ps.close();
+ }
}