Skip to content

Commit

Permalink
fix:修复项目部署时使用自定义证书不生效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyan075500 committed Dec 19, 2024
1 parent bed2ad8 commit 0904a00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion deploy/sso_example/zabbix.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Zabbix 支持的单点登录方式:SAML2
1. **创建密钥和证书**:可以使用 [在线生成工具](https://www.qvdv.net/tools/qvdv-csrpfx.html "在线生成工具")。建议证书有效期设置为10年,不设置密码,生成完成后需要下载 CRT 证书和私钥并按以下名称命名:<br><br>
* sp.key:私钥。
* sp.crt:证书。<br><br>
2. **获取 IDP 证书**:IDP 的证书的存放路径为项目的 `config/certs/certificate.crt`,需要将此证书下载并保存为 `idp.crt`。<br><br>
2. **获取 IDP 证书**:IDP 的证书默认为为项目的 `config/certs/certificate.crt`,需要将此证书下载并保存为 `idp.crt`,如果你使用了自定义证书请使用自己的证书。<br><br>
3. **上传密钥和证书**:将 `sp.key``sp.crt``idp.crt` 上传到 Zabbix 站点部署的 `ui/conf/certs/` 目录下,除非 `zabbix.conf.php` 中提供了自定义路径,否则 Zabbix 默认在 `ui/conf/certs/` 路径中查找文件。<br><br>
4. **Zabbix 单点登录配置**:登录到 Zabbix,进入【认证】配置界面,如下图所示:<br><br>
![img.png](img/zabbix-config.jpg)<br><br>
Expand Down
16 changes: 8 additions & 8 deletions utils/decryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
"encoding/pem"
)

var privateKey []byte

func readPrivateKeyFile(file string) {
privateKey, _ = ReadFile(file)
}

// Decrypt 字符串解密
func Decrypt(cipherText string) (string, error) {
// 对Base64编码的字符串解码
str, err := base64.RawURLEncoding.DecodeString(cipherText)

readPrivateKeyFile("config/certs/private.key")
block, _ := pem.Decode(privateKey)
file, err := ReadFile("/data/certs/private.key")
if err != nil {
file, err = ReadFile("config/certs/private.key")
if err != nil {
return "", err
}
}
block, _ := pem.Decode(file)

// 解析私钥
privateKeyInterface, err := x509.ParsePKCS8PrivateKey(block.Bytes)
Expand Down
16 changes: 8 additions & 8 deletions utils/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
"encoding/pem"
)

var publicKey []byte

func readPublicKeyFile(file string) {
publicKey, _ = ReadFile(file)
}

// Encrypt 字符串加密
func Encrypt(str string) (string, error) {
readPublicKeyFile("config/certs/public.key")
file, err := ReadFile("/data/certs/public.key")
if err != nil {
file, err = ReadFile("config/certs/public.pem")
if err != nil {
return "", err
}
}

// 解析公钥数据
block, _ := pem.Decode(publicKey)
block, _ := pem.Decode(file)

// 解析PEM格式的公钥
publicKey, err := x509.ParsePKIXPublicKey(block.Bytes)
Expand Down

0 comments on commit 0904a00

Please sign in to comment.