]> source.dussan.org Git - gitblit.git/commitdiff
Password prompt for GCA
authorJames Moger <james.moger@gitblit.com>
Tue, 27 Nov 2012 02:55:37 +0000 (21:55 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 27 Nov 2012 02:55:37 +0000 (21:55 -0500)
src/com/gitblit/authority/GitblitAuthority.java
src/com/gitblit/authority/UserCertificatePanel.java
src/com/gitblit/wicket/GitBlitWebApp.properties

index 846e9424ae8758bfddd8aa5fc5ddbdd8d2cf3bad..446c0292fc87069f0c5633b045a6b9cb1a9b68d4 100644 (file)
@@ -61,6 +61,7 @@ import javax.swing.JFrame;
 import javax.swing.JLabel;\r
 import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
+import javax.swing.JPasswordField;\r
 import javax.swing.JScrollPane;\r
 import javax.swing.JSplitPane;\r
 import javax.swing.JTable;\r
@@ -116,7 +117,7 @@ public class GitblitAuthority extends JFrame implements X509Log {
        \r
        private IUserService userService;\r
        \r
-       private String caKeystorePassword = null;\r
+       private String caKeystorePassword;\r
 \r
        private JTable table;\r
        \r
@@ -234,7 +235,6 @@ public class GitblitAuthority extends JFrame implements X509Log {
                }\r
                gitblitSettings = new FileSettings(file.getAbsolutePath());\r
                mail = new MailExecutor(gitblitSettings);\r
-               caKeystorePassword = gitblitSettings.getString(Keys.server.storePassword, null);\r
                String us = gitblitSettings.getString(Keys.realm.userService, "users.conf");\r
                String ext = us.substring(us.lastIndexOf(".") + 1).toLowerCase();\r
                IUserService service = null;\r
@@ -300,9 +300,34 @@ public class GitblitAuthority extends JFrame implements X509Log {
                }\r
        }\r
        \r
-       private void prepareX509Infrastructure() {\r
+       private boolean prepareX509Infrastructure() {\r
+               if (caKeystorePassword == null) {\r
+                       caKeystorePassword = gitblitSettings.getString(Keys.server.storePassword, null);\r
+                       JPasswordField pass = new JPasswordField(10){\r
+                               private static final long serialVersionUID = 1L;\r
+\r
+                               public void addNotify()             \r
+                           {                 \r
+                               super.addNotify();\r
+                               requestFocusInWindow();             \r
+                           }         \r
+                       }; \r
+                       pass.setText(caKeystorePassword);\r
+                       JPanel panel = new JPanel(new BorderLayout());\r
+                       panel.add(new JLabel(Translation.get("gb.enterKeystorePassword")), BorderLayout.NORTH);\r
+                       panel.add(pass, BorderLayout.CENTER);\r
+                       int result = JOptionPane.showConfirmDialog(GitblitAuthority.this, panel, Translation.get("gb.password"), JOptionPane.OK_CANCEL_OPTION);\r
+                       if (result == JOptionPane.OK_OPTION) {\r
+                               caKeystorePassword = new String(pass.getPassword());\r
+                       } else {\r
+                               caKeystorePassword = null;\r
+                               return false;\r
+                       }\r
+               }\r
+\r
                X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);\r
                X509Utils.prepareX509Infrastructure(metadata, folder, this);\r
+               return true;\r
        }\r
        \r
        private List<X509Certificate> findCerts(File folder, String username) {\r
@@ -357,13 +382,16 @@ public class GitblitAuthority extends JFrame implements X509Log {
                        }\r
                        \r
                        @Override\r
-                       public void saveUser(String username, UserCertificateModel ucm) {\r
-                               userService.updateUserModel(username, ucm.user);\r
+                       public boolean saveUser(String username, UserCertificateModel ucm) {\r
+                               return userService.updateUserModel(username, ucm.user);\r
                        }\r
                        \r
                        @Override\r
-                       public void newCertificate(UserCertificateModel ucm, X509Metadata metadata, boolean sendEmail) {\r
-                               prepareX509Infrastructure();\r
+                       public boolean newCertificate(UserCertificateModel ucm, X509Metadata metadata, boolean sendEmail) {\r
+                               if (!prepareX509Infrastructure()) {\r
+                                       return false;\r
+                               }\r
+\r
                                Date notAfter = metadata.notAfter;\r
                                metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);\r
                                if (StringUtils.isEmpty(metadata.serverHostname)) {\r
@@ -408,7 +436,7 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                File zip = X509Utils.newClientBundle(metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);\r
 \r
                                // save latest expiration date\r
-                               if (ucm.expires == null || metadata.notAfter.after(ucm.expires)) {\r
+                               if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {\r
                                        ucm.expires = metadata.notAfter;\r
                                }\r
                                ucm.update(config);\r
@@ -427,10 +455,15 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                if (sendEmail) {\r
                                        sendEmail(user, metadata, zip);\r
                                }\r
+                               return true;\r
                        }\r
                        \r
                        @Override\r
-                       public void revoke(UserCertificateModel ucm, X509Certificate cert, RevocationReason reason) {\r
+                       public boolean revoke(UserCertificateModel ucm, X509Certificate cert, RevocationReason reason) {\r
+                               if (!prepareX509Infrastructure()) {\r
+                                       return false;\r
+                               }\r
+\r
                                File caRevocationList = new File(folder, X509Utils.CA_REVOCATION_LIST);\r
                                File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);\r
                                if (X509Utils.revoke(cert, reason, caRevocationList, caKeystoreFile, caKeystorePassword, GitblitAuthority.this)) {\r
@@ -458,7 +491,10 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                        tableModel.fireTableDataChanged();\r
                                        table.getSelectionModel().setSelectionInterval(modelIndex, modelIndex);\r
                                        \r
+                                       return true;\r
                                }\r
+                               \r
+                               return false;\r
                        }\r
                };\r
                \r
@@ -551,8 +587,6 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                                certificateConfig.duration = Integer.parseInt(durationTF.getText());\r
                                                certificateConfig.store(config, metadata);\r
                                                config.save();\r
-                                               \r
-                                               prepareX509Infrastructure();\r
                                        } catch (Exception e1) {\r
                                                Utils.showException(GitblitAuthority.this, e1);\r
                                        }\r
@@ -580,7 +614,9 @@ public class GitblitAuthority extends JFrame implements X509Log {
 \r
                                        @Override\r
                                        protected Boolean doRequest() throws IOException {\r
-                                               prepareX509Infrastructure();\r
+                                               if (!prepareX509Infrastructure()) {\r
+                                                       return false;\r
+                                               }\r
                                                \r
                                                // read CA private key and certificate\r
                                                File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);\r
index 8a60f47eca2a2b9d35f0cfc77213a54ea38fb320..0c49252cc7ba15c2e0aa05a717580b3bb5a02ba8 100644 (file)
@@ -169,8 +169,7 @@ public abstract class UserCertificatePanel extends JPanel {
                                        AuthorityWorker worker = new AuthorityWorker(UserCertificatePanel.this.owner) {\r
                                                @Override\r
                                                protected Boolean doRequest() throws IOException {\r
-                                                       newCertificate(ucm, metadata, sendEmail);\r
-                                                       return true;\r
+                                                       return newCertificate(ucm, metadata, sendEmail);\r
                                                }\r
 \r
                                                @Override\r
@@ -241,8 +240,7 @@ public abstract class UserCertificatePanel extends JPanel {
 \r
                                                        @Override\r
                                                        protected Boolean doRequest() throws IOException {\r
-                                                               revoke(ucm, cert, reason);\r
-                                                               return true;\r
+                                                               return revoke(ucm, cert, reason);\r
                                                        }\r
 \r
                                                        @Override\r
@@ -294,7 +292,7 @@ public abstract class UserCertificatePanel extends JPanel {
        public abstract Date getDefaultExpiration();\r
        public abstract boolean isAllowEmail();\r
        \r
-       public abstract void saveUser(String username, UserCertificateModel ucm);\r
-       public abstract void newCertificate(UserCertificateModel ucm, X509Metadata metadata, boolean sendEmail);\r
-       public abstract void revoke(UserCertificateModel ucm, X509Certificate cert, RevocationReason reason);\r
+       public abstract boolean saveUser(String username, UserCertificateModel ucm);\r
+       public abstract boolean newCertificate(UserCertificateModel ucm, X509Metadata metadata, boolean sendEmail);\r
+       public abstract boolean revoke(UserCertificateModel ucm, X509Certificate cert, RevocationReason reason);\r
 }\r
index 2de266e977d32132c0a93afee64ba73c99a22c27..46dcbee84e8fa4bfa8eaa20f6e8054c1f015da7e 100644 (file)
@@ -427,4 +427,5 @@ gb.newClientCertificateMessage = NOTE:\nThe 'password' is not the user's passwor
 gb.certificate = certificate\r
 gb.emailCertificateBundle = email client certificate bundle\r
 gb.pleaseGenerateClientCertificate = Please generate a client certificate for {0}\r
-gb.clientCertificateBundleSent = Client certificate bundle for {0} sent
\ No newline at end of file
+gb.clientCertificateBundleSent = Client certificate bundle for {0} sent\r
+gb.enterKeystorePassword = Please enter the Gitblit keystore password\r