mirror of
https://github.com/makeplane/plane.git
synced 2026-07-13 14:01:45 +02:00
* feat: migrated email service to plane-ee * feat: added build files * fix: goreleaser for naming the binary * fix: github CI * feat: added certification generation * fix: github CI * feat: changed name for email service * minor fixes to docker file and cert gen process. Added k8s manifest for testing * removed build-email action * added eks-cloudflare-setup instructions * added support to gke * modfied container ports from 25 465 587 to 10025 10465 10587 * cleanup yml files * email docs cleanup * added email service build action in plane cloud github action file * fix: typo fix of email service image name * fix: replaced base action for email service * fix: registry name * fix: uses in email service * feat:modified-k8s-proxy * updated k8s manifest * updated k8s template * fix: email build action * fix image name * fixed the spam detection mechanism * upated k8s manifest --------- Co-authored-by: Manish Gupta <manish@plane.so> Co-authored-by: akshat5302 <akshatjain9782@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> Co-authored-by: Manish Gupta <59428681+mguptahub@users.noreply.github.com>
120 lines
2.5 KiB
Go
120 lines
2.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/rsa"
|
|
"crypto/x509"
|
|
"crypto/x509/pkix"
|
|
"encoding/base64"
|
|
"encoding/pem"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func GenerateCerts() {
|
|
// Create keys directory
|
|
err := os.MkdirAll("keys", 0755)
|
|
if err != nil {
|
|
fmt.Println("Error creating directory:", err)
|
|
return
|
|
}
|
|
|
|
// Check if keys already exist
|
|
if keysExist() {
|
|
fmt.Println("Keys and certificate already exist. Skipping generation.")
|
|
return
|
|
}
|
|
|
|
// Generate self-signed certificate
|
|
err = generateSelfSignedCert()
|
|
if err != nil {
|
|
fmt.Println("Error generating self-signed certificate:", err)
|
|
return
|
|
}
|
|
|
|
fmt.Println("Keys and certificate generated successfully.")
|
|
}
|
|
|
|
func keysExist() bool {
|
|
files := []string{
|
|
"keys/key.pem",
|
|
"keys/cert.pem",
|
|
}
|
|
|
|
for _, file := range files {
|
|
if _, err := os.Stat(file); os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func generateSelfSignedCert() error {
|
|
// Generate private key
|
|
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Save private key
|
|
privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
privatePEM := pem.EncodeToMemory(&pem.Block{
|
|
Type: "PRIVATE KEY",
|
|
Bytes: privateKeyBytes,
|
|
})
|
|
err = os.WriteFile("keys/key.pem", privatePEM, 0600)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Save public key
|
|
publicKeyDER, err := x509.MarshalPKIXPublicKey(&privateKey.PublicKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
publicKeyBase64 := base64.StdEncoding.EncodeToString(publicKeyDER)
|
|
err = os.WriteFile("keys/key.pub", []byte(publicKeyBase64), 0644)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Create certificate template
|
|
template := x509.Certificate{
|
|
SerialNumber: big.NewInt(1),
|
|
Subject: pkix.Name{
|
|
Country: []string{"US"},
|
|
Province: []string{"Delaware"},
|
|
Organization: []string{"Plane Software Inc"},
|
|
CommonName: "plane.so",
|
|
},
|
|
NotBefore: time.Now(),
|
|
NotAfter: time.Now().AddDate(1, 0, 0),
|
|
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
|
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
|
BasicConstraintsValid: true,
|
|
}
|
|
|
|
// Create certificate
|
|
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &privateKey.PublicKey, privateKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Save certificate
|
|
certPEM := pem.EncodeToMemory(&pem.Block{
|
|
Type: "CERTIFICATE",
|
|
Bytes: derBytes,
|
|
})
|
|
err = os.WriteFile("keys/cert.pem", certPEM, 0644)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|