e76c51710e6c1c664d19c72c176d238f9f05c2ee
[gigi.git] / src / club / wpia / gigi / Gigi.java
1 package club.wpia.gigi;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.io.UnsupportedEncodingException;
6 import java.math.BigInteger;
7 import java.nio.channels.FileChannel;
8 import java.nio.file.FileSystems;
9 import java.nio.file.NoSuchFileException;
10 import java.security.KeyStore;
11 import java.security.MessageDigest;
12 import java.security.NoSuchAlgorithmException;
13 import java.security.cert.X509Certificate;
14 import java.util.Calendar;
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.LinkedList;
18 import java.util.Locale;
19 import java.util.Map;
20 import java.util.Properties;
21 import java.util.regex.Pattern;
22
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27 import javax.servlet.http.HttpSession;
28
29 import club.wpia.gigi.database.DatabaseConnection;
30 import club.wpia.gigi.database.DatabaseConnection.Link;
31 import club.wpia.gigi.dbObjects.CACertificate;
32 import club.wpia.gigi.dbObjects.CATS.CATSType;
33 import club.wpia.gigi.dbObjects.CertificateProfile;
34 import club.wpia.gigi.dbObjects.DomainPingConfiguration;
35 import club.wpia.gigi.localisation.Language;
36 import club.wpia.gigi.output.Menu;
37 import club.wpia.gigi.output.MenuCollector;
38 import club.wpia.gigi.output.PageMenuItem;
39 import club.wpia.gigi.output.SimpleMenuItem;
40 import club.wpia.gigi.output.SimpleUntranslatedMenuItem;
41 import club.wpia.gigi.output.template.Form.CSRFException;
42 import club.wpia.gigi.output.template.Outputable;
43 import club.wpia.gigi.output.template.PlainOutputable;
44 import club.wpia.gigi.output.template.Template;
45 import club.wpia.gigi.output.template.TranslateCommand;
46 import club.wpia.gigi.pages.AboutPage;
47 import club.wpia.gigi.pages.HandlesMixedRequest;
48 import club.wpia.gigi.pages.LoginPage;
49 import club.wpia.gigi.pages.LogoutPage;
50 import club.wpia.gigi.pages.MainPage;
51 import club.wpia.gigi.pages.OneFormPage;
52 import club.wpia.gigi.pages.Page;
53 import club.wpia.gigi.pages.PasswordResetPage;
54 import club.wpia.gigi.pages.RootCertPage;
55 import club.wpia.gigi.pages.StaticPage;
56 import club.wpia.gigi.pages.Verify;
57 import club.wpia.gigi.pages.account.ChangePasswordPage;
58 import club.wpia.gigi.pages.account.FindAgentAccess;
59 import club.wpia.gigi.pages.account.History;
60 import club.wpia.gigi.pages.account.MyDetails;
61 import club.wpia.gigi.pages.account.UserTrainings;
62 import club.wpia.gigi.pages.account.certs.CertificateAdd;
63 import club.wpia.gigi.pages.account.certs.Certificates;
64 import club.wpia.gigi.pages.account.domain.DomainOverview;
65 import club.wpia.gigi.pages.account.domain.EditDomain;
66 import club.wpia.gigi.pages.account.mail.MailOverview;
67 import club.wpia.gigi.pages.admin.TTPAdminPage;
68 import club.wpia.gigi.pages.admin.support.FindCertPage;
69 import club.wpia.gigi.pages.admin.support.FindUserByDomainPage;
70 import club.wpia.gigi.pages.admin.support.FindUserByEmailPage;
71 import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
72 import club.wpia.gigi.pages.admin.support.SupportOrgDomainPage;
73 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
74 import club.wpia.gigi.pages.error.AccessDenied;
75 import club.wpia.gigi.pages.error.PageNotFound;
76 import club.wpia.gigi.pages.main.CertStatusRequestPage;
77 import club.wpia.gigi.pages.main.KeyCompromisePage;
78 import club.wpia.gigi.pages.main.RegisterPage;
79 import club.wpia.gigi.pages.orga.CreateOrgPage;
80 import club.wpia.gigi.pages.orga.SwitchOrganisation;
81 import club.wpia.gigi.pages.orga.ViewOrgPage;
82 import club.wpia.gigi.pages.statistics.StatisticsRoles;
83 import club.wpia.gigi.pages.wot.Points;
84 import club.wpia.gigi.pages.wot.RequestTTPPage;
85 import club.wpia.gigi.pages.wot.VerifyPage;
86 import club.wpia.gigi.passwords.DelegatingPasswordChecker;
87 import club.wpia.gigi.passwords.PasswordChecker;
88 import club.wpia.gigi.passwords.PasswordHashChecker;
89 import club.wpia.gigi.passwords.PasswordStrengthChecker;
90 import club.wpia.gigi.ping.PingerDaemon;
91 import club.wpia.gigi.util.AuthorizationContext;
92 import club.wpia.gigi.util.DomainAssessment;
93 import club.wpia.gigi.util.PasswordHash;
94 import club.wpia.gigi.util.ServerConstants;
95 import club.wpia.gigi.util.ServerConstants.Host;
96 import club.wpia.gigi.util.TimeConditions;
97
98 public final class Gigi extends HttpServlet {
99
100     public static final String LINK_HOST = "linkHost";
101
102     private class MenuBuilder {
103
104         private LinkedList<Menu> categories = new LinkedList<Menu>();
105
106         private HashMap<String, Page> pages = new HashMap<String, Page>();
107
108         private MenuCollector rootMenu;
109
110         public MenuBuilder() {}
111
112         private void putPage(String path, Page p, Menu m) {
113             pages.put(path, p);
114             if (m == null) {
115                 return;
116             }
117             m.addItem(new PageMenuItem(p, path.replaceFirst("/?\\*$", "")));
118
119         }
120
121         private Menu createMenu(String name) {
122             Menu m = new Menu(new TranslateCommand(name));
123             categories.add(m);
124             return m;
125         }
126
127         private Menu createMenu(Outputable name) {
128             Menu m = new Menu(name);
129             categories.add(m);
130             return m;
131         }
132
133         public MenuCollector generateMenu() throws ServletException {
134             putPage("/denied", new AccessDenied(), null);
135             putPage("/error", new PageNotFound(), null);
136             putPage("/login", new LoginPage(), null);
137             Menu mainMenu = createMenu(new PlainOutputable(ServerConstants.getAppName()));
138             mainMenu.addItem(new SimpleMenuItem("https://" + ServerConstants.getHostNamePort(Host.WWW) + "/login", "Password Login") {
139
140                 @Override
141                 public boolean isPermitted(AuthorizationContext ac) {
142                     return ac == null;
143                 }
144             });
145             mainMenu.addItem(new SimpleMenuItem("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + "/login", "Certificate Login") {
146
147                 @Override
148                 public boolean isPermitted(AuthorizationContext ac) {
149                     return ac == null;
150                 }
151             });
152             putPage("/", new MainPage(), null);
153             putPage("/roots", new RootCertPage(truststore), mainMenu);
154             putPage(StatisticsRoles.PATH, new StatisticsRoles(), mainMenu);
155             putPage("/about", new AboutPage(), mainMenu);
156             putPage(RegisterPage.PATH, new RegisterPage(), mainMenu);
157             putPage(CertStatusRequestPage.PATH, new CertStatusRequestPage(), mainMenu);
158             putPage(KeyCompromisePage.PATH, new KeyCompromisePage(), mainMenu);
159
160             putPage(Verify.PATH, new Verify(), null);
161             Menu certificates = createMenu("Certificates");
162             putPage(Certificates.PATH + "/*", new Certificates(false), certificates);
163             putPage(CertificateAdd.PATH, new CertificateAdd(), certificates);
164
165             Menu wot = createMenu("Verification");
166             putPage(MailOverview.DEFAULT_PATH, new MailOverview(), wot);
167             putPage(DomainOverview.PATH, new DomainOverview(), wot);
168             putPage(EditDomain.PATH + "*", new EditDomain(), null);
169             putPage(VerifyPage.PATH + "/*", new VerifyPage(), wot);
170             putPage(Points.PATH, new Points(false), wot);
171             putPage(RequestTTPPage.PATH, new RequestTTPPage(), wot);
172
173             Menu admMenu = createMenu("Admin");
174             Menu orgAdm = createMenu("Organisation Admin");
175             putPage(TTPAdminPage.PATH + "/*", new TTPAdminPage(), admMenu);
176             putPage(CreateOrgPage.DEFAULT_PATH, new CreateOrgPage(), orgAdm);
177             putPage(ViewOrgPage.DEFAULT_PATH + "/*", new ViewOrgPage(), orgAdm);
178             putPage(SwitchOrganisation.PATH, new SwitchOrganisation(), orgAdm);
179
180             Menu support = createMenu("Support Console");
181             putPage(SupportEnterTicketPage.PATH, new SupportEnterTicketPage(), support);
182             putPage(FindUserByEmailPage.PATH, new FindUserByEmailPage(), support);
183             putPage(FindUserByDomainPage.PATH, new FindUserByDomainPage(), support);
184             putPage(FindCertPage.PATH, new FindCertPage(), support);
185
186             Menu account = createMenu("My Account");
187             putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage(), null);
188             putPage(SupportOrgDomainPage.PATH + "*", new SupportOrgDomainPage(), null);
189             putPage(ChangePasswordPage.PATH, new ChangePasswordPage(), account);
190             putPage(History.PATH, new History(false), account);
191             putPage(FindAgentAccess.PATH, new OneFormPage("Access to Find Agent", FindAgentAccess.class), account);
192             putPage(History.SUPPORT_PATH, new History(true), null);
193             putPage(UserTrainings.PATH, new UserTrainings(false), account);
194             putPage(MyDetails.PATH, new MyDetails(), account);
195             putPage(UserTrainings.SUPPORT_PATH, new UserTrainings(true), null);
196             putPage(Points.SUPPORT_PATH, new Points(true), null);
197             putPage(Certificates.SUPPORT_PATH + "/*", new Certificates(true), null);
198
199             putPage(PasswordResetPage.PATH, new PasswordResetPage(), null);
200             putPage(LogoutPage.PATH, new LogoutPage(), null);
201
202             if (testing) {
203                 try {
204                     Class<?> manager = Class.forName("club.wpia.gigi.pages.Manager");
205                     Page p = (Page) manager.getMethod("getInstance").invoke(null);
206                     String pa = (String) manager.getField("PATH").get(null);
207                     Menu testServer = createMenu("Gigi test server");
208                     putPage(pa + "/*", p, testServer);
209                 } catch (ReflectiveOperationException e) {
210                     e.printStackTrace();
211                 }
212             }
213
214             try {
215                 putPage("/wot/rules", new StaticPage("Verification Rules", VerifyPage.class.getResourceAsStream("Rules.templ")), wot);
216             } catch (UnsupportedEncodingException e) {
217                 throw new ServletException(e);
218             }
219             rootMenu = new MenuCollector();
220
221             Menu languages = createMenu("Language");
222             addLanguages(languages);
223             for (Menu menu : categories) {
224                 menu.prepare();
225                 rootMenu.put(menu);
226             }
227
228             // rootMenu.prepare();
229             return rootMenu;
230         }
231
232         private void addLanguages(Menu languages) {
233             for (Locale l : Language.getSupportedLocales()) {
234                 languages.addItem(new SimpleUntranslatedMenuItem("?lang=" + l.toString(), l.getDisplayName(l)));
235             }
236         }
237
238         public Map<String, Page> getPages() {
239             return Collections.unmodifiableMap(pages);
240         }
241     }
242
243     public static final String LOGGEDIN = "loggedin";
244
245     public static final String CERT_SERIAL = "club.wpia.gigi.serial";
246
247     public static final String CERT_ISSUER = "club.wpia.gigi.issuer";
248
249     public static final String AUTH_CONTEXT = "auth";
250
251     public static final String LOGIN_METHOD = "club.wpia.gigi.loginMethod";
252
253     private static final long serialVersionUID = -6386785421902852904L;
254
255     private static Gigi instance;
256
257     private static PasswordChecker passwordChecker;
258
259     private static final Template baseTemplate = new Template(Gigi.class.getResource("Gigi.templ"));
260
261     private PingerDaemon pinger;
262
263     private KeyStore truststore;
264
265     private boolean testing;
266
267     private MenuCollector rootMenu;
268
269     private Map<String, Page> pages;
270
271     private boolean firstInstanceInited = false;
272
273     public Gigi(Properties conf, KeyStore truststore) {
274         synchronized (Gigi.class) {
275             if (instance != null) {
276                 throw new IllegalStateException("Multiple Gigi instances!");
277             }
278             testing = conf.getProperty("testing") != null;
279             instance = this;
280             DomainAssessment.init(conf);
281             DatabaseConnection.init(conf);
282             TimeConditions.init(conf);
283             PasswordHash.init(conf);
284             this.truststore = truststore;
285             pinger = new PingerDaemon(truststore);
286             pinger.start();
287             Gigi.passwordChecker = getPasswordChecker(conf);
288         }
289     }
290
291     private PasswordChecker getPasswordChecker(Properties conf) {
292         final String knownPasswordHashesPath;
293         final boolean knownPasswordHashesRequired;
294         String knownPasswordHashesConfig = conf.getProperty("knownPasswordHashes");
295         if (knownPasswordHashesConfig != null) {
296             knownPasswordHashesPath = knownPasswordHashesConfig;
297             knownPasswordHashesRequired = true;
298         } else {
299             knownPasswordHashesPath = "/usr/share/pwned-passwords/pwned-passwords.bin";
300             knownPasswordHashesRequired = false;
301         }
302
303         final MessageDigest sha1;
304         try {
305             sha1 = MessageDigest.getInstance("SHA-1");
306         } catch (NoSuchAlgorithmException e) {
307             throw new RuntimeException(e);
308         }
309
310         try {
311             final FileChannel knownPasswordHashesFile = FileChannel.open(
312                 FileSystems.getDefault().getPath(knownPasswordHashesPath));
313             return new DelegatingPasswordChecker(new PasswordChecker[] {
314                     new PasswordStrengthChecker(),
315                     new PasswordHashChecker(knownPasswordHashesFile, sha1)
316                 });
317         } catch (IOException e) {
318             if (knownPasswordHashesRequired) {
319                 throw new RuntimeException("Error while opening password hash database, refusing startup", e);
320             } else {
321                 System.err.println("Warning: A problem was encountered while opening the password hash database, passwords will be checked only by strength.");
322                 if ( !(e instanceof NoSuchFileException)) {
323                     e.printStackTrace();
324                 }
325                 return new PasswordStrengthChecker();
326             }
327         }
328     }
329
330     @Override
331     public synchronized void init() throws ServletException {
332         if (firstInstanceInited) {
333             super.init();
334             return;
335         }
336         // ensure those static initializers are finished
337         try (Link l = DatabaseConnection.newLink(false)) {
338             CACertificate.getById(1);
339             CertificateProfile.getById(1);
340             CATSType.AGENT_CHALLENGE.getDisplayName();
341         } catch (InterruptedException e) {
342             throw new Error(e);
343         }
344
345         MenuBuilder mb = new MenuBuilder();
346         rootMenu = mb.generateMenu();
347         pages = mb.getPages();
348
349         firstInstanceInited = true;
350         super.init();
351     }
352
353     private Page getPage(String pathInfo) {
354         if (pathInfo.endsWith("/") && !pathInfo.equals("/")) {
355             pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
356         }
357         Page page = pages.get(pathInfo);
358         if (page != null) {
359             return page;
360         }
361         page = pages.get(pathInfo + "/*");
362         if (page != null) {
363             return page;
364         }
365         int idx = pathInfo.lastIndexOf('/');
366         if (idx == -1 || idx == 0) {
367             return null;
368         }
369
370         page = pages.get(pathInfo.substring(0, idx) + "/*");
371         if (page != null) {
372             return page;
373         }
374         int lIdx = pathInfo.lastIndexOf('/', idx - 1);
375         if (lIdx == -1) {
376             return null;
377         }
378         String lastResort = pathInfo.substring(0, lIdx) + "/*" + pathInfo.substring(idx);
379         page = pages.get(lastResort);
380         return page;
381
382     }
383
384     private static String staticTemplateVar = "//" + ServerConstants.getHostNamePort(Host.STATIC);
385
386     private static String staticTemplateVarSecure = "//" + ServerConstants.getHostNamePortSecure(Host.STATIC);
387
388     @Override
389     protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
390         if ("/error".equals(req.getPathInfo()) || "/denied".equals(req.getPathInfo())) {
391             if (DatabaseConnection.hasInstance()) {
392                 serviceWithConnection(req, resp);
393                 return;
394             }
395         }
396         try (DatabaseConnection.Link l = DatabaseConnection.newLink( !req.getMethod().equals("POST"))) {
397             serviceWithConnection(req, resp);
398         } catch (InterruptedException e) {
399             e.printStackTrace();
400         }
401     }
402
403     protected void serviceWithConnection(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
404         boolean isSecure = req.isSecure();
405         addXSSHeaders(resp, isSecure);
406         // Firefox only sends this, if it's a cross domain access; safari sends
407         // it always
408         String originHeader = req.getHeader("Origin");
409         if (originHeader != null //
410                 && !(originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getHostNamePortSecure(Host.WWW)) + "(/.*|)") || //
411                         originHeader.matches("^" + Pattern.quote("http://" + ServerConstants.getHostNamePort(Host.WWW)) + "(/.*|)") || //
412                         originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE)) + "(/.*|)"))) {
413             resp.setContentType("text/html; charset=utf-8");
414             resp.getWriter().println("<html><head><title>Alert</title></head><body>No cross domain access allowed.<br/><b>If you don't know why you're seeing this you may have been fished! Please change your password immediately!</b></body></html>");
415             return;
416         }
417         HttpSession hs = req.getSession();
418         BigInteger clientSerial = (BigInteger) hs.getAttribute(CERT_SERIAL);
419         if (clientSerial != null) {
420             X509Certificate[] cert = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate");
421             if (cert == null || cert[0] == null//
422                     || !cert[0].getSerialNumber().equals(clientSerial) //
423                     || !cert[0].getIssuerDN().equals(hs.getAttribute(CERT_ISSUER))) {
424                 hs.invalidate();
425                 resp.sendError(403, "Certificate mismatch.");
426                 return;
427             }
428
429         }
430         if (req.getParameter("lang") != null) {
431             Locale l = Language.getLocaleFromString(req.getParameter("lang"));
432             Language lu = Language.getInstance(l);
433             req.getSession().setAttribute(Language.SESSION_ATTRIB_NAME, lu != null ? lu.getLocale() : Locale.ENGLISH);
434         }
435         final Page p = getPage(req.getPathInfo());
436
437         if (p != null) {
438             if ( !isSecure && (p.needsLogin() || p instanceof LoginPage || p instanceof RegisterPage)) {
439                 resp.sendRedirect("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + req.getPathInfo());
440                 return;
441             }
442             AuthorizationContext currentAuthContext = LoginPage.getAuthorizationContext(req);
443             if ( !p.isPermitted(currentAuthContext)) {
444                 if (hs.getAttribute("loggedin") == null) {
445                     String request = req.getPathInfo();
446                     request = request.split("\\?")[0];
447                     hs.setAttribute(LoginPage.LOGIN_RETURNPATH, request);
448                     resp.sendRedirect("/login");
449                     return;
450                 }
451                 resp.sendError(403);
452                 return;
453             }
454             try {
455                 if (p.beforeTemplate(req, resp)) {
456                     return;
457                 }
458             } catch (CSRFException e) {
459                 resp.sendError(500, "CSRF invalid");
460                 return;
461             }
462             HashMap<String, Object> vars = new HashMap<String, Object>();
463             // System.out.println(req.getMethod() + ": " + req.getPathInfo() +
464             // " -> " + p);
465             Outputable content = new Outputable() {
466
467                 @Override
468                 public void output(PrintWriter out, Language l, Map<String, Object> vars) {
469                     try {
470                         if (req.getMethod().equals("POST")) {
471                             if (req.getQueryString() != null && !(p instanceof HandlesMixedRequest)) {
472                                 return;
473                             }
474                             p.doPost(req, resp);
475                         } else {
476                             p.doGet(req, resp);
477                         }
478                     } catch (CSRFException err) {
479                         try {
480                             resp.sendError(500, "CSRF invalid");
481                         } catch (IOException e) {
482                             e.printStackTrace();
483                         }
484                     } catch (IOException e) {
485                         e.printStackTrace();
486                     }
487
488                 }
489             };
490             Language lang = Page.getLanguage(req);
491
492             vars.put(Menu.AUTH_VALUE, currentAuthContext);
493             vars.put("menu", rootMenu);
494             vars.put("title", lang.getTranslation(p.getTitle()));
495             vars.put("static", isSecure ? staticTemplateVarSecure : staticTemplateVar);
496             vars.put("year", Calendar.getInstance().get(Calendar.YEAR));
497             vars.put("content", content);
498             if (isSecure) {
499                 req.setAttribute(LINK_HOST, ServerConstants.getHostNamePortSecure(Host.LINK));
500             } else {
501                 req.setAttribute(LINK_HOST, ServerConstants.getHostNamePort(Host.LINK));
502             }
503             vars.put(Gigi.LINK_HOST, req.getAttribute(Gigi.LINK_HOST));
504             if (currentAuthContext != null) {
505                 // TODO maybe move this information into the AuthContext object
506                 vars.put("loginMethod", req.getSession().getAttribute(LOGIN_METHOD));
507                 vars.put("authContext", currentAuthContext);
508
509             }
510             vars.put("appName", ServerConstants.getAppName());
511             resp.setContentType("text/html; charset=utf-8");
512             baseTemplate.output(resp.getWriter(), lang, vars);
513         } else {
514             resp.sendError(404, "Page not found.");
515         }
516
517     }
518
519     public static void addXSSHeaders(HttpServletResponse hsr, boolean doHttps) {
520         hsr.addHeader("Access-Control-Allow-Origin", "https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + " https://" + ServerConstants.getHostNamePortSecure(Host.SECURE));
521         hsr.addHeader("Access-Control-Max-Age", "60");
522         if (doHttps) {
523             hsr.addHeader("Content-Security-Policy", httpsCSP);
524         } else {
525             hsr.addHeader("Content-Security-Policy", httpCSP);
526         }
527         hsr.addHeader("Strict-Transport-Security", "max-age=31536000");
528
529     }
530
531     private static String httpsCSP = genHttpsCSP();
532
533     private static String httpCSP = genHttpCSP();
534
535     private static String genHttpsCSP() {
536         StringBuffer csp = new StringBuffer();
537         csp.append("default-src 'none'");
538         csp.append(";font-src https://" + ServerConstants.getHostNamePortSecure(Host.STATIC));
539         csp.append(";img-src https://" + ServerConstants.getHostNamePortSecure(Host.STATIC));
540         csp.append(";media-src 'none'; object-src 'none'");
541         csp.append(";script-src https://" + ServerConstants.getHostNamePortSecure(Host.STATIC));
542         csp.append(";style-src https://" + ServerConstants.getHostNamePortSecure(Host.STATIC));
543         csp.append(";form-action https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + " https://" + ServerConstants.getHostNamePortSecure(Host.WWW));
544         // csp.append(";report-url https://api.wpia.club/security/csp/report");
545         return csp.toString();
546     }
547
548     private static String genHttpCSP() {
549         StringBuffer csp = new StringBuffer();
550         csp.append("default-src 'none'");
551         csp.append(";font-src http://" + ServerConstants.getHostNamePort(Host.STATIC));
552         csp.append(";img-src http://" + ServerConstants.getHostNamePort(Host.STATIC));
553         csp.append(";media-src 'none'; object-src 'none'");
554         csp.append(";script-src http://" + ServerConstants.getHostNamePort(Host.STATIC));
555         csp.append(";style-src http://" + ServerConstants.getHostNamePort(Host.STATIC));
556         csp.append(";form-action http://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + " http://" + ServerConstants.getHostNamePort(Host.WWW));
557         // csp.append(";report-url http://api.wpia.club/security/csp/report");
558         return csp.toString();
559     }
560
561     /**
562      * Requests Pinging of domains.
563      * 
564      * @param toReping
565      *            if not null, the {@link DomainPingConfiguration} to test, if
566      *            null, just re-check if there is something to do.
567      */
568     public static void notifyPinger(DomainPingConfiguration toReping) {
569         if (toReping != null) {
570             instance.pinger.queue(toReping);
571         }
572         instance.pinger.interrupt();
573     }
574
575     public static PasswordChecker getPasswordChecker() {
576         if (passwordChecker == null) {
577             throw new IllegalStateException("Not yet initialized!");
578         }
579         return passwordChecker;
580     }
581
582     public static void setPasswordChecker(PasswordChecker passwordChecker) {
583         Gigi.passwordChecker = passwordChecker;
584     }
585
586 }