| | |
| | |
|
| | | private JButton certificateDefaultsButton;
|
| | |
|
| | | private JButton newSSLCertificate;
|
| | |
|
| | | public static void main(String... args) {
|
| | | EventQueue.invokeLater(new Runnable() {
|
| | | public void run() {
|
| | |
| | | if (!caKeystore.exists()) {
|
| | | // show certificate defaults dialog
|
| | | certificateDefaultsButton.doClick();
|
| | | |
| | | // create "localhost" ssl certificate
|
| | | prepareX509Infrastructure();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private boolean prepareX509Infrastructure() {
|
| | | if (caKeystorePassword == null) {
|
| | | caKeystorePassword = gitblitSettings.getString(Keys.server.storePassword, null);
|
| | | JPasswordField pass = new JPasswordField(10){
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public void addNotify() |
| | | { |
| | | super.addNotify();
|
| | | requestFocusInWindow(); |
| | | } |
| | | }; |
| | | 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);
|
| | |
| | | if (result == JOptionPane.OK_OPTION) {
|
| | | caKeystorePassword = new String(pass.getPassword());
|
| | | } else {
|
| | | caKeystorePassword = null;
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);
|
| | | setMetadataDefaults(metadata);
|
| | | X509Utils.prepareX509Infrastructure(metadata, folder, this);
|
| | | return true;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | Date notAfter = metadata.notAfter;
|
| | | metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);
|
| | | if (StringUtils.isEmpty(metadata.serverHostname)) {
|
| | | metadata.serverHostname = Constants.NAME;
|
| | | }
|
| | | UserModel user = ucm.user; |
| | | |
| | | // 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);
|
| | | }
|
| | | |
| | | // restore expiration date
|
| | | setMetadataDefaults(metadata);
|
| | | metadata.notAfter = notAfter;
|
| | |
|
| | | // set user's specified OID values
|
| | | UserModel user = ucm.user; |
| | | if (!StringUtils.isEmpty(user.organizationalUnit)) {
|
| | | metadata.oids.put("OU", user.organizationalUnit);
|
| | | }
|
| | |
| | | if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {
|
| | | ucm.expires = metadata.notAfter;
|
| | | }
|
| | | ucm.update(config);
|
| | | try {
|
| | | config.save();
|
| | | } catch (Exception e) {
|
| | | Utils.showException(GitblitAuthority.this, e);
|
| | | }
|
| | | |
| | | updateAuthorityConfig(ucm);
|
| | |
|
| | | // refresh user
|
| | | ucm.certs = null;
|
| | |
| | | }
|
| | | });
|
| | |
|
| | | JButton newSSLCertificate = new JButton(new ImageIcon(getClass().getResource("/rosette_16x16.png")));
|
| | | newSSLCertificate = new JButton(new ImageIcon(getClass().getResource("/rosette_16x16.png")));
|
| | | newSSLCertificate.setFocusable(false);
|
| | | newSSLCertificate.setToolTipText(Translation.get("gb.newSSLCertificate"));
|
| | | newSSLCertificate.addActionListener(new ActionListener() {
|
| | |
| | | metadata.serverHostname = Constants.NAME;
|
| | | }
|
| | | metadata.userDisplayname = ucm.user.getDisplayName();
|
| | | sendEmail(ucm.user, metadata, zip);
|
| | | return true;
|
| | | return sendEmail(ucm.user, metadata, zip);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private void sendEmail(UserModel user, X509Metadata metadata, File zip) {
|
| | | private boolean sendEmail(UserModel user, X509Metadata metadata, File zip) {
|
| | | // send email
|
| | | try {
|
| | | if (mail.isReady()) {
|
| | |
| | | message.setContent(mp);
|
| | |
|
| | | mail.sendNow(message);
|
| | | return true;
|
| | | } else {
|
| | | JOptionPane.showMessageDialog(GitblitAuthority.this, "Sorry, the mail server settings are not configured properly.\nCan not send email.", Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | Utils.showException(GitblitAuthority.this, e);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | |
| | | 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);
|
| | | }
|
| | | }
|
| | | |
| | | private void updateAuthorityConfig(UserCertificateModel ucm) {
|
| | | 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);
|
| | | }
|
| | | }
|
| | | ucm.update(config);
|
| | | try {
|
| | | config.save();
|
| | | } catch (Exception e) {
|
| | | Utils.showException(GitblitAuthority.this, e);
|
| | | }
|
| | | }
|
| | | }
|