Package com.gitblit.utils.X509Utils

Examples of com.gitblit.utils.X509Utils.X509Metadata


    String [] oids = settings.getStrings(Keys.git.certificateUsernameOIDs).toArray(new String[0]);
    UserModel model = HttpUtils.getUserModelFromCertificate(httpRequest, checkValidity, oids);
    if (model != null) {
      // grab real user model and preserve certificate serial number
      UserModel user = userManager.getUserModel(model.username);
      X509Metadata metadata = HttpUtils.getCertificateMetadata(httpRequest);
      if (user != null) {
        flagWicketSession(AuthenticationType.CERTIFICATE);
        logger.debug(MessageFormat.format("{0} authenticated by client certificate {1} from {2}",
            user.username, metadata.serialNumber, httpRequest.getRemoteAddr()));
        return validateAuthentication(user, AuthenticationType.CERTIFICATE);
View Full Code Here


      File serverKeyStore = new File(baseFolder, X509Utils.SERVER_KEY_STORE);
      File serverTrustStore = new File(baseFolder, X509Utils.SERVER_TRUST_STORE);
      File caRevocationList = new File(baseFolder, X509Utils.CA_REVOCATION_LIST);

      // generate CA & web certificates, create certificate stores
      X509Metadata metadata = new X509Metadata("localhost", params.storePassword);
      // set default certificate values from config file
      if (certificatesConf.exists()) {
        FileBasedConfig config = new FileBasedConfig(certificatesConf, FS.detect());
        try {
          config.load();
View Full Code Here

      } 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;
  }
View Full Code Here

    certificateDefaultsButton.setFocusable(false);
    certificateDefaultsButton.setToolTipText(Translation.get("gb.newCertificateDefaults"));
    certificateDefaultsButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        X509Metadata metadata = new X509Metadata("whocares", "whocares");
        File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
        FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
        NewCertificateConfig certificateConfig = null;
        if (certificatesConfigFile.exists()) {
          try {
            config.load();
          } catch (Exception x) {
            Utils.showException(GitblitAuthority.this, x);
          }
          certificateConfig = NewCertificateConfig.KEY.parse(config);
          certificateConfig.update(metadata);
        }
        InputVerifier verifier = new InputVerifier() {
          @Override
          public boolean verify(JComponent comp) {
            boolean returnValue;
            JTextField textField = (JTextField) comp;
            try {
              Integer.parseInt(textField.getText());
              returnValue = true;
            } catch (NumberFormatException e) {
              returnValue = false;
            }
            return returnValue;
          }
        };

        JTextField siteNameTF = new JTextField(20);
        siteNameTF.setText(gitblitSettings.getString(Keys.web.siteName, "Gitblit"));
        JPanel siteNamePanel = Utils.newFieldPanel(Translation.get("gb.siteName"),
            siteNameTF, Translation.get("gb.siteNameDescription"));

        JTextField validityTF = new JTextField(4);
        validityTF.setInputVerifier(verifier);
        validityTF.setVerifyInputWhenFocusTarget(true);
        validityTF.setText("" + certificateConfig.duration);
        JPanel validityPanel = Utils.newFieldPanel(Translation.get("gb.validity"),
            validityTF, Translation.get("gb.duration.days").replace("{0}""").trim());

        JPanel p1 = new JPanel(new GridLayout(0, 1, 5, 2));
        p1.add(siteNamePanel);
        p1.add(validityPanel);

        DefaultOidsPanel oids = new DefaultOidsPanel(metadata);

        JPanel panel = new JPanel(new BorderLayout());
        panel.add(p1, BorderLayout.NORTH);
        panel.add(oids, BorderLayout.CENTER);

        int result = JOptionPane.showConfirmDialog(GitblitAuthority.this,
            panel, Translation.get("gb.newCertificateDefaults"), JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, new ImageIcon(getClass().getResource("/settings_32x32.png")));
        if (result == JOptionPane.OK_OPTION) {
          try {
            oids.update(metadata);
            certificateConfig.duration = Integer.parseInt(validityTF.getText());
            certificateConfig.store(config, metadata);
            config.save();

            Map<String, String> updates = new HashMap<String, String>();
            updates.put(Keys.web.siteName, siteNameTF.getText());
            gitblitSettings.saveSettings(updates);
          } catch (Exception e1) {
            Utils.showException(GitblitAuthority.this, e1);
          }
        }
      }
    });

    newSSLCertificate = new JButton(new ImageIcon(getClass().getResource("/rosette_16x16.png")));
    newSSLCertificate.setFocusable(false);
    newSSLCertificate.setToolTipText(Translation.get("gb.newSSLCertificate"));
    newSSLCertificate.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        Date defaultExpiration = new Date(System.currentTimeMillis() + 10*TimeUtils.ONEYEAR);
        NewSSLCertificateDialog dialog = new NewSSLCertificateDialog(GitblitAuthority.this, defaultExpiration);
        dialog.setModal(true);
        dialog.setVisible(true);
        if (dialog.isCanceled()) {
          return;
        }
        final Date expires = dialog.getExpiration();
        final String hostname = dialog.getHostname();
        final boolean serveCertificate = dialog.isServeCertificate();

        AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {

          @Override
          protected Boolean doRequest() throws IOException {
            if (!prepareX509Infrastructure()) {
              return false;
            }

            // read CA private key and certificate
            File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
            PrivateKey caPrivateKey = X509Utils.getPrivateKey(X509Utils.CA_ALIAS, caKeystoreFile, caKeystorePassword);
            X509Certificate caCert = X509Utils.getCertificate(X509Utils.CA_ALIAS, caKeystoreFile, caKeystorePassword);

            // generate new SSL certificate
            X509Metadata metadata = new X509Metadata(hostname, caKeystorePassword);
            setMetadataDefaults(metadata);
            metadata.notAfter = expires;
            File serverKeystoreFile = new File(folder, X509Utils.SERVER_KEY_STORE);
            X509Certificate cert = X509Utils.newSSLCertificate(metadata, caPrivateKey, caCert, serverKeystoreFile, GitblitAuthority.this);
            boolean hasCert = cert != null;
            if (hasCert && serveCertificate) {
              // update Gitblit https connector alias
              Map<String, String> updates = new HashMap<String, String>();
              updates.put(Keys.server.certificateAlias, metadata.commonName);
              gitblitSettings.saveSettings(updates);
            }
            return hasCert;
          }

          @Override
          protected void onSuccess() {
            if (serveCertificate) {
              JOptionPane.showMessageDialog(GitblitAuthority.this,
                  MessageFormat.format(Translation.get("gb.sslCertificateGeneratedRestart"), hostname),
                  Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
            } else {
              JOptionPane.showMessageDialog(GitblitAuthority.this,
                MessageFormat.format(Translation.get("gb.sslCertificateGenerated"), hostname),
                Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
            }
          }
        };

        worker.execute();
      }
    });

    JButton emailBundle = new JButton(new ImageIcon(getClass().getResource("/mail_16x16.png")));
    emailBundle.setFocusable(false);
    emailBundle.setToolTipText(Translation.get("gb.emailCertificateBundle"));
    emailBundle.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        int row = table.getSelectedRow();
        if (row < 0) {
          return;
        }
        int modelIndex = table.convertRowIndexToModel(row);
        final UserCertificateModel ucm = tableModel.get(modelIndex);
        if (ArrayUtils.isEmpty(ucm.certs)) {
          JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.pleaseGenerateClientCertificate"), ucm.user.getDisplayName()));
        }
        final File zip = new File(folder, X509Utils.CERTS + File.separator + ucm.user.username + File.separator + ucm.user.username + ".zip");
        if (!zip.exists()) {
          return;
        }

        AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {
          @Override
          protected Boolean doRequest() throws IOException {
            X509Metadata metadata = new X509Metadata(ucm.user.username, "whocares");
            metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);
            if (StringUtils.isEmpty(metadata.serverHostname)) {
              metadata.serverHostname = Constants.NAME;
            }
            metadata.userDisplayname = ucm.user.getDisplayName();
View Full Code Here

            return;
          }

          final boolean sendEmail = dialog.sendEmail();
          final UserModel user = ucm.user;
          final X509Metadata metadata = new X509Metadata(user.username, dialog.getPassword());
          metadata.userDisplayname = user.getDisplayName();
          metadata.emailAddress = user.emailAddress;
          metadata.passwordHint = dialog.getPasswordHint();
          metadata.notAfter = dialog.getExpiration();
View Full Code Here

   * @param cert
   * @param usernameOids if unspecified CN is used as the username
   * @return
   */
  public static UserModel getUserModelFromCertificate(X509Certificate cert, String... usernameOIDs) {
    X509Metadata metadata = X509Utils.getMetadata(cert);

    UserModel user = new UserModel(metadata.commonName);
    user.emailAddress = metadata.emailAddress;
    user.isAuthenticated = false;

    if (usernameOIDs == null || usernameOIDs.length == 0) {
      // use default usename<->CN mapping
      usernameOIDs = new String [] { "CN" };
    }

    // determine username from OID fingerprint
    StringBuilder an = new StringBuilder();
    for (String oid : usernameOIDs) {
      String val = metadata.getOID(oid.toUpperCase(), null);
      if (val != null) {
        an.append(val).append(' ');
      }
    }
    user.username = an.toString().trim();
View Full Code Here

      File serverKeyStore = new File(baseFolder, X509Utils.SERVER_KEY_STORE);
      File serverTrustStore = new File(baseFolder, X509Utils.SERVER_TRUST_STORE);
      File caRevocationList = new File(baseFolder, X509Utils.CA_REVOCATION_LIST);

      // generate CA & web certificates, create certificate stores
      X509Metadata metadata = new X509Metadata("localhost", params.storePassword);
      // set default certificate values from config file
      if (certificatesConf.exists()) {
        FileBasedConfig config = new FileBasedConfig(certificatesConf, FS.detect());
        try {
          config.load();
View Full Code Here

  };

  @Before
  public void prepare() throws Exception {
    cleanUp();
    X509Metadata goMetadata = new X509Metadata("localhost", caPassword);
    X509Utils.prepareX509Infrastructure(goMetadata, folder, log);
  }
View Full Code Here

  public void testCertificateUserMapping() throws Exception {
    File storeFile = new File(folder, X509Utils.CA_KEY_STORE);
    PrivateKey caPrivateKey = X509Utils.getPrivateKey(X509Utils.CA_ALIAS, storeFile, caPassword);
    X509Certificate caCert = X509Utils.getCertificate(X509Utils.CA_ALIAS, storeFile, caPassword);

    X509Metadata userMetadata = new X509Metadata("james", "james");
    userMetadata.serverHostname = "www.myserver.com";
    userMetadata.userDisplayname = "James Moger";
    userMetadata.passwordHint = "your name";
    userMetadata.oids.put("C""US");
View Full Code Here

  @Test
  public void testUserBundle() throws Exception {
    File storeFile = new File(folder, X509Utils.CA_KEY_STORE);

    X509Metadata userMetadata = new X509Metadata("james", "james");
    userMetadata.serverHostname = "www.myserver.com";
    userMetadata.userDisplayname = "James Moger";
    userMetadata.passwordHint = "your name";

    File zip = X509Utils.newClientBundle(userMetadata, storeFile, caPassword, log);
View Full Code Here

TOP

Related Classes of com.gitblit.utils.X509Utils.X509Metadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.