|
|
@@ -22,8 +22,8 @@ const (
|
|
|
tlsName = "syncthing"
|
|
|
)
|
|
|
|
|
|
-func loadCert(dir string) (tls.Certificate, error) {
|
|
|
- return tls.LoadX509KeyPair(filepath.Join(dir, "cert.pem"), filepath.Join(dir, "key.pem"))
|
|
|
+func loadCert(dir string, prefix string) (tls.Certificate, error) {
|
|
|
+ return tls.LoadX509KeyPair(filepath.Join(dir, prefix+"cert.pem"), filepath.Join(dir, prefix+"key.pem"))
|
|
|
}
|
|
|
|
|
|
func certID(bs []byte) string {
|
|
|
@@ -40,7 +40,7 @@ func certSeed(bs []byte) int64 {
|
|
|
return int64(binary.BigEndian.Uint64(id))
|
|
|
}
|
|
|
|
|
|
-func newCertificate(dir string) {
|
|
|
+func newCertificate(dir string, prefix string) {
|
|
|
l.Infoln("Generating RSA certificate and key...")
|
|
|
|
|
|
priv, err := rsa.GenerateKey(rand.Reader, tlsRSABits)
|
|
|
@@ -65,13 +65,13 @@ func newCertificate(dir string) {
|
|
|
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
|
|
|
l.FatalErr(err)
|
|
|
|
|
|
- certOut, err := os.Create(filepath.Join(dir, "cert.pem"))
|
|
|
+ certOut, err := os.Create(filepath.Join(dir, prefix+"cert.pem"))
|
|
|
l.FatalErr(err)
|
|
|
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
|
|
|
certOut.Close()
|
|
|
l.Okln("Created RSA certificate file")
|
|
|
|
|
|
- keyOut, err := os.OpenFile(filepath.Join(dir, "key.pem"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
|
+ keyOut, err := os.OpenFile(filepath.Join(dir, prefix+"key.pem"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
|
l.FatalErr(err)
|
|
|
pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
|
|
|
keyOut.Close()
|