Skip to content

Commit 3704870

Browse files
committed
Sending email (certificate zip file) based on locale that user selected
1 parent 651b998 commit 3704870

File tree

8 files changed

+164
-12
lines changed

8 files changed

+164
-12
lines changed

.classpath

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<classpathentry kind="lib" path="ext/httpcore-4.3.3.jar" sourcepath="ext/src/httpcore-4.3.3.jar" />
5050
<classpathentry kind="lib" path="ext/commons-logging-1.1.3.jar" sourcepath="ext/src/commons-logging-1.1.3.jar" />
5151
<classpathentry kind="lib" path="ext/commons-codec-1.7.jar" sourcepath="ext/src/commons-codec-1.7.jar" />
52-
<classpathentry kind="lib" path="ext/org.eclipse.jdt.annotation-1.1.0.jar" />
52+
<classpathentry kind="lib" path="ext/org.eclipse.jdt.annotation-1.1.0.jar" sourcepath="ext/src/org.eclipse.jdt.annotation-1.1.0.jar" />
5353
<classpathentry kind="lib" path="ext/org.eclipse.jgit.http.server-4.1.1.201511131810-r.jar" sourcepath="ext/src/org.eclipse.jgit.http.server-4.1.1.201511131810-r.jar" />
5454
<classpathentry kind="lib" path="ext/bcprov-jdk15on-1.52.jar" sourcepath="ext/src/bcprov-jdk15on-1.52.jar" />
5555
<classpathentry kind="lib" path="ext/bcmail-jdk15on-1.52.jar" sourcepath="ext/src/bcmail-jdk15on-1.52.jar" />
@@ -94,10 +94,5 @@
9494
<classpathentry kind="lib" path="ext/mockito-core-1.10.19.jar" sourcepath="ext/src/mockito-core-1.10.19.jar" />
9595
<classpathentry kind="lib" path="ext/objenesis-2.1.jar" sourcepath="ext/src/objenesis-2.1.jar" />
9696
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
97-
<classpathentry kind="src" path="src/main/dagger">
98-
<attributes>
99-
<attribute name="optional" value="true"/>
100-
</attributes>
101-
</classpathentry>
10297
<classpathentry kind="output" path="bin/classes" />
10398
</classpath>

gitblit.iml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@
491491
<root url="jar://$MODULE_DIR$/ext/org.eclipse.jdt.annotation-1.1.0.jar!/" />
492492
</CLASSES>
493493
<JAVADOC />
494-
<SOURCES />
494+
<SOURCES>
495+
<root url="jar://$MODULE_DIR$/ext/src/org.eclipse.jdt.annotation-1.1.0.jar!/" />
496+
</SOURCES>
495497
</library>
496498
</orderEntry>
497499
<orderEntry type="module-library">
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
********************************************************************************
2+
Gitblit 伺服器 $serverHostname 所需之 SSL 用戶端憑證
3+
********************************************************************************
4+
5+
$userDisplayname 您好,
6+
7+
伺服器 $serverHostname 所需要的私鑰,公鑰以及Gitblit簽證檔案(CA)存放於 $username.p12, PKCS#12 certificate store[1] 以及 $username.pem.
8+
9+
兩種證書皆受密碼保護.
10+
密碼提示: $storePasswordHint
11+
12+
13+
Git 憑證匯入步驟
14+
=============================================
15+
16+
附件之 PEM 檔案可以直接匯入至您的git程式裡.
17+
18+
git config [--global] http.sslCert path/to/$username.pem
19+
20+
PEM檔案受密碼保護,因此匯入過程會提示多次. 如果您偏好不使用密碼,您需要另外匯出無密碼之私鑰後,再匯入git程式裡.
21+
22+
openssl rsa -in path/to/$username.pem -out path/to/$username.key
23+
git config [--global] http.sslKey path/to/$username.key
24+
25+
此外,您應該妥善保管已經解除密碼保護之私鑰.
26+
27+
註:
28+
如果沒有匯出私鑰, 有些早期git版本將會發生匯入失敗問題,例如:Ubuntu 12.04 with git 1.7.9.5.
29+
30+
31+
Firefox 憑證匯入步驟
32+
=============================================
33+
34+
Firefox 有自己的證書管理介面.
35+
36+
1. 點選 "選項->進階->憑證"
37+
2. 點選 "檢視憑證清單"
38+
3. 切換至 "您的憑證"
39+
4. 點選 "匯入(M)"
40+
5. 選擇電腦中的憑證檔案 $username.p12
41+
6. 輸入憑證檔案所需的密碼
42+
7. 切換至"憑證機構"
43+
8. 找到 "Gitblit Certificate Authority" 憑證
44+
9. 點選"編輯信任(E)"
45+
10.選擇信任網站.
46+
47+
48+
Chrome/IE (Windows) 憑證匯入步驟
49+
=============================================
50+
51+
在Windows作業系統下, Chrome 與 IE 共用相同的憑證設定.
52+
53+
IE
54+
------------------------------------
55+
1. 選擇 "網際網路選項->內容"
56+
2. 點選"憑證"
57+
58+
Chrome
59+
------------------------------------
60+
1. 選擇 "設定->顯示進階設定->HTTP/SSL"
61+
2. 點選"管理憑證"
62+
63+
共同步驟 (Windows)
64+
------------------------------------
65+
3. 切換至 "個人"
66+
4. 點選"匯入(I)"
67+
5. 依照指示匯入.
68+
請切換匯入檔案類型為p12並且找到 $username.p12 這個憑證檔案
69+
6. 輸入憑證檔案保護密碼
70+
7. 由於主要發放憑證單位(CA)與個人憑證檔案皆儲存於 $username.p12, 因此匯入時候,必須選擇 "自動根據憑證類型來選擇憑證存放區".
71+
如果選擇預設值匯入, 將不會安裝主要發放憑證單位(CA)
72+
73+
74+
Chrome (Linux) Installation Instructions
75+
=============================================
76+
77+
On Linux, Chrome maintains it's own certificate store.
78+
79+
1. Navigate to Settings->Show Advanced Settings->HTTP/SSL
80+
2. Click the "Manage Certificates..." button
81+
3. Navigate your filesystem and select $username.p12
82+
4. At the password prompt enter the certificate store password
83+
You have now imported your private key, public certificate, and the CA certificate
84+
but now we must manually set the trust settings of the CA certificate.
85+
5. Switch to the "Authorities" tab
86+
6. Scroll down and find "Gitblit-> Gitblit Certificate Authority"
87+
7. Select it and click "Edit Trust..."
88+
8. Check "This certificate can identify websites" and click OK.
89+
90+
91+
Chrome/Safari (Mac OS X) Installation Instructions
92+
=============================================
93+
94+
On Mac OS X, Chrome and Safari both use Keychain Access to store certificates
95+
so configuring one will automatically apply for both.
96+
97+
1. Double-click $username.pem
98+
2. At the password prompt enter the certificate store password
99+
You have now imported your private key, public certificate, and the CA certificate
100+
but now we must manually set the trust settings of the CA certificate.
101+
3. Find the Gitblit Certificate Authority certificate, it should have a red
102+
indicator meaning untrusted, and double-click it.
103+
4. Open the "Trust" disclosure triangle and change "When using this certificate"
104+
to "Always Trust".
105+
5. Close the certificate view and enter your system password to save the changes
106+
to your keychain.
107+
108+
109+
[1] PKCS#12 is one of the standard container formats for sharing private keys and
110+
public certificates.
111+
[2] http://www.openssl.org
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$userDisplayname 您好
2+
3+
伺服器 $serverHostname 所需要的私鑰,公鑰以及Gitblit簽證檔案(CA)已經全部打包並且以zip壓縮檔方式寄給您.
4+
5+
此外,檔案還附上各瀏覽器設定步驟供您參考.

src/main/java/com/gitblit/authority/GitblitAuthority.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.HashMap;
5050
import java.util.List;
5151
import java.util.Map;
52+
import java.util.ResourceBundle;
5253

5354
import javax.mail.Message;
5455
import javax.swing.ImageIcon;
@@ -98,6 +99,7 @@
9899
import com.gitblit.utils.X509Utils.RevocationReason;
99100
import com.gitblit.utils.X509Utils.X509Log;
100101
import com.gitblit.utils.X509Utils.X509Metadata;
102+
import com.gitblit.wicket.GitBlitWebSession;
101103

102104
/**
103105
* Simple GUI tool for administering Gitblit client certificates.
@@ -447,7 +449,7 @@ public boolean newCertificate(UserCertificateModel ucm, X509Metadata metadata, b
447449
}
448450

449451
File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
450-
File zip = X509Utils.newClientBundle(metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);
452+
File zip = X509Utils.newClientBundle(user,metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);
451453

452454
// save latest expiration date
453455
if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {
@@ -850,9 +852,16 @@ private boolean sendEmail(UserModel user, X509Metadata metadata, File zip) {
850852
try {
851853
if (mail.isReady()) {
852854
Mailing mailing = Mailing.newPlain();
853-
mailing.subject = "Your Gitblit client certificate for " + metadata.serverHostname;
855+
mailing.subject = MessageFormat.format(ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp",user.getPreferences().getLocale()).getString("gb.emailClientCertificateSubject"), metadata.serverHostname);
854856
mailing.setRecipients(user.emailAddress);
855-
String body = X509Utils.processTemplate(new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl"), metadata);
857+
File fileMailTmp = null;
858+
String body = null;
859+
if( (fileMailTmp = new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl"+"_"+user.getPreferences().getLocale())).exists())
860+
body = X509Utils.processTemplate(fileMailTmp, metadata);
861+
else{
862+
fileMailTmp = new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl");
863+
body = X509Utils.processTemplate(fileMailTmp, metadata);
864+
}
856865
if (StringUtils.isEmpty(body)) {
857866
body = MessageFormat.format("Hi {0}\n\nHere is your client certificate bundle.\nInside the zip file are installation instructions.", user.getDisplayName());
858867
}

src/main/java/com/gitblit/utils/X509Utils.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,25 @@ public static void addTrustedCertificate(String alias, X509Certificate cert, Fil
743743
*/
744744
public static File newClientBundle(X509Metadata clientMetadata, File caKeystoreFile,
745745
String caKeystorePassword, X509Log x509log) {
746+
return newClientBundle(null,clientMetadata,caKeystoreFile,caKeystorePassword,x509log);
747+
}
748+
749+
/**
750+
* Creates a new client certificate PKCS#12 and PEM store. Any existing
751+
* stores are destroyed. After generation, the certificates are bundled
752+
* into a zip file with a personalized README file.
753+
*
754+
* The zip file reference is returned.
755+
*
756+
* @param user
757+
* @param clientMetadata a container for dynamic parameters needed for generation
758+
* @param caKeystoreFile
759+
* @param caKeystorePassword
760+
* @param x509log
761+
* @return a zip file containing the P12, PEM, and personalized README
762+
*/
763+
public static File newClientBundle(com.gitblit.models.UserModel user,X509Metadata clientMetadata, File caKeystoreFile,
764+
String caKeystorePassword, X509Log x509log) {
746765
try {
747766
// read the Gitblit CA key and certificate
748767
KeyStore store = openKeyStore(caKeystoreFile, caKeystorePassword);
@@ -755,8 +774,17 @@ public static File newClientBundle(X509Metadata clientMetadata, File caKeystoreF
755774
x509log.log(MessageFormat.format("New client certificate {0,number,0} [{1}]", cert.getSerialNumber(), cert.getSubjectDN().getName()));
756775

757776
// process template message
758-
String readme = processTemplate(new File(caKeystoreFile.getParentFile(), "instructions.tmpl"), clientMetadata);
759-
777+
String readme = null;
778+
String sInstructionsFileName = "instructions.tmpl";
779+
if( user == null )
780+
readme = processTemplate(new File(caKeystoreFile.getParentFile(),sInstructionsFileName), clientMetadata);
781+
else{
782+
File fileInstructionsTmp = null;
783+
if( (fileInstructionsTmp = new File(caKeystoreFile.getParentFile(),sInstructionsFileName+"_"+user.getPreferences().getLocale())).exists() )
784+
readme = processTemplate(fileInstructionsTmp,clientMetadata);
785+
else
786+
readme = processTemplate(new File(caKeystoreFile.getParentFile(),sInstructionsFileName),clientMetadata);
787+
}
760788
// Create a zip bundle with the p12, pem, and a personalized readme
761789
File zipFile = new File(targetFolder, clientMetadata.commonName + ".zip");
762790
if (zipFile.exists()) {

src/main/java/com/gitblit/wicket/GitBlitWebApp.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,4 @@ gb.deletePatchsetSuccess = Deleted Patchset {0}.
783783
gb.deletePatchsetFailure = Error deleting Patchset {0}.
784784
gb.referencedByCommit = Referenced by commit.
785785
gb.referencedByTicket = Referenced by ticket.
786+
gb.emailClientCertificateSubject = Your Gitblit client certificate for {0}

src/main/java/com/gitblit/wicket/GitBlitWebApp_zh_TW.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,4 @@ gb.deletePatchsetSuccess = \u5df2\u522a\u9664 Patchset {0}.
781781
gb.deletePatchsetFailure = \u522a\u9664 Patchset {0} \u932f\u8aa4.
782782
gb.referencedByCommit = Referenced by commit.
783783
gb.referencedByTicket = Referenced by ticket.
784+
gb.emailClientCertificateSubject = \u4F3A\u670D\u5668 {0} \u9023\u7DDA\u6191\u8B49

0 commit comments

Comments
 (0)