Beispiel #1
0
  private boolean prepareX509Infrastructure() {
    if (caKeystorePassword == null) {
      JPasswordField pass = new JPasswordField(10);
      pass.setText(caKeystorePassword);
      pass.addAncestorListener(new RequestFocusListener());
      JPanel panel = new JPanel(new BorderLayout());
      panel.add(new JLabel(Translation.get("gb.enterKeystorePassword")), BorderLayout.NORTH);
      panel.add(pass, BorderLayout.CENTER);
      int result =
          JOptionPane.showConfirmDialog(
              GitblitAuthority.this,
              panel,
              Translation.get("gb.password"),
              JOptionPane.OK_CANCEL_OPTION);
      if (result == JOptionPane.OK_OPTION) {
        caKeystorePassword = new String(pass.getPassword());
      } else {
        return false;
      }
    }

    X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);
    setMetadataDefaults(metadata);
    metadata.notAfter = new Date(System.currentTimeMillis() + 10 * TimeUtils.ONEYEAR);
    X509Utils.prepareX509Infrastructure(metadata, folder, this);
    return true;
  }
Beispiel #2
0
  private void setMetadataDefaults(X509Metadata metadata) {
    metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);
    if (StringUtils.isEmpty(metadata.serverHostname)) {
      metadata.serverHostname = Constants.NAME;
    }

    // set default values from config file
    File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
    FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
    if (certificatesConfigFile.exists()) {
      try {
        config.load();
      } catch (Exception e) {
        Utils.showException(GitblitAuthority.this, e);
      }
      NewCertificateConfig certificateConfig = NewCertificateConfig.KEY.parse(config);
      certificateConfig.update(metadata);
    }
  }