]> source.dussan.org Git - gitblit.git/commitdiff
Gitblit CA generation needs to use the default OIDs
authorJames Moger <james.moger@gitblit.com>
Wed, 28 Nov 2012 22:31:12 +0000 (17:31 -0500)
committerJames Moger <james.moger@gitblit.com>
Wed, 28 Nov 2012 22:31:12 +0000 (17:31 -0500)
src/com/gitblit/authority/GitblitAuthority.java

index 6d219b731fa6610a15547f10679f84d3052341a7..441fa13f50c2e0d9b94cdff0fe798436763245dd 100644 (file)
@@ -329,6 +329,7 @@ public class GitblitAuthority extends JFrame implements X509Log {
                }\r
 \r
                X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);\r
+               setMetadataDefaults(metadata);\r
                X509Utils.prepareX509Infrastructure(metadata, folder, this);\r
                return true;\r
        }\r
@@ -396,29 +397,11 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                }\r
 \r
                                Date notAfter = metadata.notAfter;\r
-                               metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);\r
-                               if (StringUtils.isEmpty(metadata.serverHostname)) {\r
-                                       metadata.serverHostname = Constants.NAME;\r
-                               }\r
-                               UserModel user = ucm.user;                              \r
-                               \r
-                               // set default values from config file\r
-                               File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);\r
-                               FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());\r
-                               if (certificatesConfigFile.exists()) {\r
-                                       try {\r
-                                               config.load();\r
-                                       } catch (Exception e) {\r
-                                               Utils.showException(GitblitAuthority.this, e);\r
-                                       }\r
-                                       NewCertificateConfig certificateConfig = NewCertificateConfig.KEY.parse(config);\r
-                                       certificateConfig.update(metadata);\r
-                               }\r
-                               \r
-                               // restore expiration date\r
+                               setMetadataDefaults(metadata);\r
                                metadata.notAfter = notAfter;\r
                                \r
                                // set user's specified OID values\r
+                               UserModel user = ucm.user;                              \r
                                if (!StringUtils.isEmpty(user.organizationalUnit)) {\r
                                        metadata.oids.put("OU", user.organizationalUnit);\r
                                }\r
@@ -442,12 +425,8 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {\r
                                        ucm.expires = metadata.notAfter;\r
                                }\r
-                               ucm.update(config);\r
-                               try {\r
-                                       config.save();\r
-                               } catch (Exception e) {\r
-                                       Utils.showException(GitblitAuthority.this, e);\r
-                               }\r
+                               \r
+                               updateAuthorityConfig(ucm);\r
                                \r
                                // refresh user\r
                                ucm.certs = null;\r
@@ -818,4 +797,42 @@ public class GitblitAuthority extends JFrame implements X509Log {
                }\r
                return false;\r
        }\r
+       \r
+       private void setMetadataDefaults(X509Metadata metadata) {\r
+               metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);\r
+               if (StringUtils.isEmpty(metadata.serverHostname)) {\r
+                       metadata.serverHostname = Constants.NAME;\r
+               }\r
+               \r
+               // set default values from config file\r
+               File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);\r
+               FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());\r
+               if (certificatesConfigFile.exists()) {\r
+                       try {\r
+                               config.load();\r
+                       } catch (Exception e) {\r
+                               Utils.showException(GitblitAuthority.this, e);\r
+                       }\r
+                       NewCertificateConfig certificateConfig = NewCertificateConfig.KEY.parse(config);\r
+                       certificateConfig.update(metadata);\r
+               }\r
+       }\r
+       \r
+       private void updateAuthorityConfig(UserCertificateModel ucm) {\r
+               File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);\r
+               FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());\r
+               if (certificatesConfigFile.exists()) {\r
+                       try {\r
+                               config.load();\r
+                       } catch (Exception e) {\r
+                               Utils.showException(GitblitAuthority.this, e);\r
+                       }\r
+               }\r
+               ucm.update(config);\r
+               try {\r
+                       config.save();\r
+               } catch (Exception e) {\r
+                       Utils.showException(GitblitAuthority.this, e);\r
+               }\r
+       }\r
 }\r