X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FGigi.java;h=2f4c27dd0f16fba0df323819e6a10d8f5bff7f07;hp=d080e290dbdc072c120d4e6a0651a0dcf47fafc9;hb=8eaf45ee6a71969eff3e04b40e4435e0dd380824;hpb=07f74d10bddc819f4524e2e0c1a2815eb4e7ec79 diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index d080e290..2f4c27dd 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -21,7 +21,9 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.cacert.gigi.database.DatabaseConnection; +import org.cacert.gigi.database.DatabaseConnection.Link; import org.cacert.gigi.dbObjects.CACertificate; +import org.cacert.gigi.dbObjects.CATS.CATSType; import org.cacert.gigi.dbObjects.CertificateProfile; import org.cacert.gigi.dbObjects.DomainPingConfiguration; import org.cacert.gigi.localisation.Language; @@ -29,31 +31,36 @@ import org.cacert.gigi.output.Menu; import org.cacert.gigi.output.MenuCollector; import org.cacert.gigi.output.PageMenuItem; import org.cacert.gigi.output.SimpleMenuItem; +import org.cacert.gigi.output.SimpleUntranslatedMenuItem; import org.cacert.gigi.output.template.Form.CSRFException; import org.cacert.gigi.output.template.Outputable; import org.cacert.gigi.output.template.Template; +import org.cacert.gigi.pages.AboutPage; import org.cacert.gigi.pages.HandlesMixedRequest; import org.cacert.gigi.pages.LoginPage; import org.cacert.gigi.pages.LogoutPage; import org.cacert.gigi.pages.MainPage; +import org.cacert.gigi.pages.OneFormPage; import org.cacert.gigi.pages.Page; import org.cacert.gigi.pages.PasswordResetPage; -import org.cacert.gigi.pages.PolicyIndex; import org.cacert.gigi.pages.RootCertPage; import org.cacert.gigi.pages.StaticPage; import org.cacert.gigi.pages.TestSecure; import org.cacert.gigi.pages.Verify; import org.cacert.gigi.pages.account.ChangePasswordPage; +import org.cacert.gigi.pages.account.FindAgentAccess; import org.cacert.gigi.pages.account.History; import org.cacert.gigi.pages.account.MyDetails; import org.cacert.gigi.pages.account.UserTrainings; import org.cacert.gigi.pages.account.certs.CertificateAdd; import org.cacert.gigi.pages.account.certs.Certificates; import org.cacert.gigi.pages.account.domain.DomainOverview; +import org.cacert.gigi.pages.account.domain.EditDomain; import org.cacert.gigi.pages.account.mail.MailOverview; import org.cacert.gigi.pages.admin.TTPAdminPage; -import org.cacert.gigi.pages.admin.support.FindDomainPage; -import org.cacert.gigi.pages.admin.support.FindUserPage; +import org.cacert.gigi.pages.admin.support.FindCertPage; +import org.cacert.gigi.pages.admin.support.FindUserByDomainPage; +import org.cacert.gigi.pages.admin.support.FindUserByEmailPage; import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage; import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage; import org.cacert.gigi.pages.error.AccessDenied; @@ -61,13 +68,16 @@ import org.cacert.gigi.pages.error.PageNotFound; import org.cacert.gigi.pages.main.RegisterPage; import org.cacert.gigi.pages.orga.CreateOrgPage; import org.cacert.gigi.pages.orga.ViewOrgPage; +import org.cacert.gigi.pages.statistics.StatisticsRoles; import org.cacert.gigi.pages.wot.AssurePage; -import org.cacert.gigi.pages.wot.MyListingPage; -import org.cacert.gigi.pages.wot.MyPoints; +import org.cacert.gigi.pages.wot.Points; import org.cacert.gigi.pages.wot.RequestTTPPage; import org.cacert.gigi.ping.PingerDaemon; import org.cacert.gigi.util.AuthorizationContext; +import org.cacert.gigi.util.DomainAssessment; +import org.cacert.gigi.util.PasswordHash; import org.cacert.gigi.util.ServerConstants; +import org.cacert.gigi.util.TimeConditions; public final class Gigi extends HttpServlet { @@ -109,35 +119,37 @@ public final class Gigi extends HttpServlet { public MenuCollector generateMenu() throws ServletException { putPage("/denied", new AccessDenied(), null); putPage("/error", new PageNotFound(), null); - putPage("/login", new LoginPage("Password Login"), null); - getMenu("CAcert.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getWwwHostNamePort() + "/login", "Password Login") { + putPage("/login", new LoginPage(), null); + getMenu("SomeCA.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getWwwHostNamePort() + "/login", "Password Login") { @Override public boolean isPermitted(AuthorizationContext ac) { return ac == null; } }); - getMenu("CAcert.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getSecureHostNamePort() + "/login", "Certificate Login") { + getMenu("SomeCA.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getSecureHostNamePort() + "/login", "Certificate Login") { @Override public boolean isPermitted(AuthorizationContext ac) { return ac == null; } }); - putPage("/", new MainPage("CAcert - Home"), null); - putPage("/roots", new RootCertPage(truststore), "CAcert.org"); + putPage("/", new MainPage(), null); + putPage("/roots", new RootCertPage(truststore), "SomeCA.org"); + putPage(StatisticsRoles.PATH, new StatisticsRoles(), "SomeCA.org"); + putPage("/about", new AboutPage(), "SomeCA.org"); putPage("/secure", new TestSecure(), null); putPage(Verify.PATH, new Verify(), null); - putPage(Certificates.PATH + "/*", new Certificates(), "Certificates"); - putPage(RegisterPage.PATH, new RegisterPage(), "CAcert.org"); + putPage(Certificates.PATH + "/*", new Certificates(false), "Certificates"); + putPage(RegisterPage.PATH, new RegisterPage(), "SomeCA.org"); putPage(CertificateAdd.PATH, new CertificateAdd(), "Certificates"); - putPage(MailOverview.DEFAULT_PATH, new MailOverview("Email addresses"), "Certificates"); - putPage(DomainOverview.PATH + "*", new DomainOverview("Domains"), "Certificates"); + putPage(MailOverview.DEFAULT_PATH, new MailOverview(), "Certificates"); + putPage(DomainOverview.PATH, new DomainOverview(), "Certificates"); + putPage(EditDomain.PATH + "*", new EditDomain(), null); putPage(AssurePage.PATH + "/*", new AssurePage(), "Web of Trust"); - putPage(MyPoints.PATH, new MyPoints("My Points"), "Web of Trust"); - putPage(MyListingPage.PATH, new MyListingPage(), "Web of Trust"); + putPage(Points.PATH, new Points(false), "Web of Trust"); putPage(RequestTTPPage.PATH, new RequestTTPPage(), "Web of Trust"); putPage(TTPAdminPage.PATH + "/*", new TTPAdminPage(), "Admin"); @@ -145,19 +157,23 @@ public final class Gigi extends HttpServlet { putPage(ViewOrgPage.DEFAULT_PATH + "/*", new ViewOrgPage(), "Organisation Admin"); putPage(SupportEnterTicketPage.PATH, new SupportEnterTicketPage(), "Support Console"); - putPage(FindUserPage.PATH, new FindUserPage("Find User"), "Support Console"); - putPage(FindDomainPage.PATH, new FindDomainPage("Find Domain"), "Support Console"); + putPage(FindUserByEmailPage.PATH, new FindUserByEmailPage(), "Support Console"); + putPage(FindUserByDomainPage.PATH, new FindUserByDomainPage(), "Support Console"); + putPage(FindCertPage.PATH, new FindCertPage(), "Support Console"); - putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage("Support: User Details"), null); + putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage(), null); putPage(ChangePasswordPage.PATH, new ChangePasswordPage(), "My Account"); - putPage(LogoutPage.PATH, new LogoutPage("Logout"), "My Account"); putPage(History.PATH, new History(false), "My Account"); + putPage(FindAgentAccess.PATH, new OneFormPage("Access to Find Agent", FindAgentAccess.class), "My Account"); putPage(History.SUPPORT_PATH, new History(true), null); putPage(UserTrainings.PATH, new UserTrainings(false), "My Account"); putPage(MyDetails.PATH, new MyDetails(), "My Account"); putPage(UserTrainings.SUPPORT_PATH, new UserTrainings(true), null); + putPage(Points.SUPPORT_PATH, new Points(true), null); + putPage(Certificates.SUPPORT_PATH + "/*", new Certificates(true), null); putPage(PasswordResetPage.PATH, new PasswordResetPage(), null); + putPage(LogoutPage.PATH, new LogoutPage(), null); if (testing) { try { @@ -175,25 +191,10 @@ public final class Gigi extends HttpServlet { } catch (UnsupportedEncodingException e) { throw new ServletException(e); } - baseTemplate = new Template(Gigi.class.getResource("Gigi.templ")); rootMenu = new MenuCollector(); - Menu about = new Menu("About CAcert.org"); - categories.add(about); - - about.addItem(new SimpleMenuItem("//blog.cacert.org/", "CAcert News")); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/", "Wiki Documentation")); - putPage(PolicyIndex.DEFAULT_PATH, new PolicyIndex(), "About CAcert.org"); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/FAQ/Privileges", "Point System")); - about.addItem(new SimpleMenuItem("//bugs.cacert.org/", "Bug Database")); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/Board", "CAcert Board")); - about.addItem(new SimpleMenuItem("//lists.cacert.org/wws", "Mailing Lists")); - about.addItem(new SimpleMenuItem("//blog.CAcert.org/feed", "RSS News Feed")); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/Impress", "Impress")); - - Menu languages = new Menu("Translations"); - for (Locale l : Language.getSupportedLocales()) { - languages.addItem(new SimpleMenuItem("?lang=" + l.toString(), l.getDisplayName(l))); - } + + Menu languages = new Menu("Language"); + addLanguages(languages); categories.add(languages); for (Menu menu : categories) { menu.prepare(); @@ -204,6 +205,12 @@ public final class Gigi extends HttpServlet { return rootMenu; } + private void addLanguages(Menu languages) { + for (Locale l : Language.getSupportedLocales()) { + languages.addItem(new SimpleUntranslatedMenuItem("?lang=" + l.toString(), l.getDisplayName(l))); + } + } + public Map getPages() { return Collections.unmodifiableMap(pages); } @@ -223,7 +230,7 @@ public final class Gigi extends HttpServlet { private static Gigi instance; - private Template baseTemplate; + private static final Template baseTemplate = new Template(Gigi.class.getResource("Gigi.templ"));; private PingerDaemon pinger; @@ -244,7 +251,10 @@ public final class Gigi extends HttpServlet { } testing = conf.getProperty("testing") != null; instance = this; + DomainAssessment.init(conf); DatabaseConnection.init(conf); + TimeConditions.init(conf); + PasswordHash.init(conf); this.truststore = truststore; pinger = new PingerDaemon(truststore); pinger.start(); @@ -258,8 +268,13 @@ public final class Gigi extends HttpServlet { return; } // ensure those static initializers are finished - CACertificate.getById(1); - CertificateProfile.getById(1); + try (Link l = DatabaseConnection.newLink(false)) { + CACertificate.getById(1); + CertificateProfile.getById(1); + CATSType.ASSURER_CHALLENGE.getDisplayName(); + } catch (InterruptedException e) { + throw new Error(e); + } MenuBuilder mb = new MenuBuilder(); rootMenu = mb.generateMenu(); @@ -300,30 +315,33 @@ public final class Gigi extends HttpServlet { } - private static String staticTemplateVarHttp = "http://" + ServerConstants.getStaticHostNamePort(); - - private static String staticTemplateVarHttps = "https://" + ServerConstants.getStaticHostNamePortSecure(); + private static String staticTemplateVar = "//" + ServerConstants.getStaticHostNamePort(); - private static String getStaticTemplateVar(boolean https) { - if (https) { - return staticTemplateVarHttps; - } else { - return staticTemplateVarHttp; + @Override + protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + if ("/error".equals(req.getPathInfo()) || "/denied".equals(req.getPathInfo())) { + if (DatabaseConnection.hasInstance()) { + serviceWithConnection(req, resp); + return; + } + } + try (DatabaseConnection.Link l = DatabaseConnection.newLink( !req.getMethod().equals("POST"))) { + serviceWithConnection(req, resp); + } catch (InterruptedException e) { + e.printStackTrace(); } } - @Override - protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + protected void serviceWithConnection(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { boolean isSecure = req.isSecure(); addXSSHeaders(resp, isSecure); // Firefox only sends this, if it's a cross domain access; safari sends // it always String originHeader = req.getHeader("Origin"); if (originHeader != null // - && - !(originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getWwwHostNamePortSecure()) + "(/.*|)") || // + && !(originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getWwwHostNamePortSecure()) + "(/.*|)") || // originHeader.matches("^" + Pattern.quote("http://" + ServerConstants.getWwwHostNamePort()) + "(/.*|)") || // - originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getSecureHostNamePort()) + "(/.*|)"))) { + originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getSecureHostNamePort()) + "(/.*|)"))) { resp.setContentType("text/html; charset=utf-8"); resp.getWriter().println("AlertNo cross domain access allowed.
If you don't know why you're seeing this you may have been fished! Please change your password immediately!"); return; @@ -333,7 +351,7 @@ public final class Gigi extends HttpServlet { if (clientSerial != null) { X509Certificate[] cert = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate"); if (cert == null || cert[0] == null// - || !cert[0].getSerialNumber().toString(16).toUpperCase().equals(clientSerial) // + || !cert[0].getSerialNumber().toString(16).toLowerCase().equals(clientSerial) // || !cert[0].getIssuerDN().equals(hs.getAttribute(CERT_ISSUER))) { hs.invalidate(); resp.sendError(403, "Certificate mismatch."); @@ -344,7 +362,7 @@ public final class Gigi extends HttpServlet { if (req.getParameter("lang") != null) { Locale l = Language.getLocaleFromString(req.getParameter("lang")); Language lu = Language.getInstance(l); - req.getSession().setAttribute(Language.SESSION_ATTRIB_NAME, lu.getLocale()); + req.getSession().setAttribute(Language.SESSION_ATTRIB_NAME, lu != null ? lu.getLocale() : Locale.ENGLISH); } final Page p = getPage(req.getPathInfo()); @@ -401,12 +419,12 @@ public final class Gigi extends HttpServlet { vars.put(Menu.AUTH_VALUE, currentAuthContext); vars.put("menu", rootMenu); vars.put("title", lang.getTranslation(p.getTitle())); - vars.put("static", getStaticTemplateVar(isSecure)); + vars.put("static", staticTemplateVar); vars.put("year", Calendar.getInstance().get(Calendar.YEAR)); vars.put("content", content); if (currentAuthContext != null) { // TODO maybe move this information into the AuthContext object - vars.put("loginMethod", lang.getTranslation((String) req.getSession().getAttribute(LOGIN_METHOD))); + vars.put("loginMethod", req.getSession().getAttribute(LOGIN_METHOD)); vars.put("authContext", currentAuthContext); } @@ -443,7 +461,7 @@ public final class Gigi extends HttpServlet { csp.append(";script-src https://" + ServerConstants.getStaticHostNamePortSecure()); csp.append(";style-src https://" + ServerConstants.getStaticHostNamePortSecure()); csp.append(";form-action https://" + ServerConstants.getSecureHostNamePort() + " https://" + ServerConstants.getWwwHostNamePortSecure()); - csp.append(";report-url https://api.cacert.org/security/csp/report"); + // csp.append(";report-url https://api.cacert.org/security/csp/report"); return csp.toString(); } @@ -456,7 +474,7 @@ public final class Gigi extends HttpServlet { csp.append(";script-src http://" + ServerConstants.getStaticHostNamePort()); csp.append(";style-src http://" + ServerConstants.getStaticHostNamePort()); csp.append(";form-action https://" + ServerConstants.getSecureHostNamePort() + " https://" + ServerConstants.getWwwHostNamePort()); - csp.append(";report-url http://api.cacert.org/security/csp/report"); + // csp.append(";report-url http://api.cacert.org/security/csp/report"); return csp.toString(); }