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