mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-27 05:52:29 +08:00 
			
		
		
		
	* cicd: robot automated Change * feat: add api test Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: add api test make file Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: add openim e2e test Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: add openim e2e test Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * fix: Fixed some unused scripts and some names Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * docs: optimize openim docs Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: add prom address Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: add openim info test * feat: add openim images config path Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * fix: fix tim file rename * fix: fix tim file rename * fix: fix tim file rename * fix: fix tim file rename * fix: add openim test e2e * feat: add openim test .keep Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: add openim test .keep Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: openim test Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: openim test Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * feat: openim test Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> Co-authored-by: cubxxw <cubxxw@users.noreply.github.com>
		
			
				
	
	
		
			86 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
		
			Executable File
		
	
	
	
	
| // Copyright © 2023 OpenIM. All rights reserved.
 | |
| //
 | |
| // Licensed under the Apache License, Version 2.0 (the "License");
 | |
| // you may not use this file except in compliance with the License.
 | |
| // You may obtain a copy of the License at
 | |
| //
 | |
| //     http://www.apache.org/licenses/LICENSE-2.0
 | |
| //
 | |
| // Unless required by applicable law or agreed to in writing, software
 | |
| // distributed under the License is distributed on an "AS IS" BASIS,
 | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| // See the License for the specific language governing permissions and
 | |
| // limitations under the License.
 | |
| 
 | |
| package tls
 | |
| 
 | |
| import (
 | |
| 	"crypto/tls"
 | |
| 	"crypto/x509"
 | |
| 	"encoding/pem"
 | |
| 	"errors"
 | |
| 	"os"
 | |
| 
 | |
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/config"
 | |
| )
 | |
| 
 | |
| // decryptPEM decrypts a PEM block using a password.
 | |
| func decryptPEM(data []byte, passphrase []byte) ([]byte, error) {
 | |
| 	if len(passphrase) == 0 {
 | |
| 		return data, nil
 | |
| 	}
 | |
| 	b, _ := pem.Decode(data)
 | |
| 	d, err := x509.DecryptPEMBlock(b, passphrase)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return pem.EncodeToMemory(&pem.Block{
 | |
| 		Type:  b.Type,
 | |
| 		Bytes: d,
 | |
| 	}), nil
 | |
| }
 | |
| 
 | |
| func readEncryptablePEMBlock(path string, pwd []byte) ([]byte, error) {
 | |
| 	data, err := os.ReadFile(path)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return decryptPEM(data, pwd)
 | |
| }
 | |
| 
 | |
| // NewTLSConfig setup the TLS config from general config file.
 | |
| func NewTLSConfig(clientCertFile, clientKeyFile, caCertFile string, keyPwd []byte) *tls.Config {
 | |
| 	tlsConfig := tls.Config{}
 | |
| 
 | |
| 	if clientCertFile != "" && clientKeyFile != "" {
 | |
| 		certPEMBlock, err := os.ReadFile(clientCertFile)
 | |
| 		if err != nil {
 | |
| 			panic(err)
 | |
| 		}
 | |
| 		keyPEMBlock, err := readEncryptablePEMBlock(clientKeyFile, keyPwd)
 | |
| 		if err != nil {
 | |
| 			panic(err)
 | |
| 		}
 | |
| 		cert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock)
 | |
| 		if err != nil {
 | |
| 			panic(err)
 | |
| 		}
 | |
| 		tlsConfig.Certificates = []tls.Certificate{cert}
 | |
| 	}
 | |
| 
 | |
| 	caCert, err := os.ReadFile(caCertFile)
 | |
| 	if err != nil {
 | |
| 		panic(err)
 | |
| 	}
 | |
| 	caCertPool := x509.NewCertPool()
 | |
| 	ok := caCertPool.AppendCertsFromPEM(caCert)
 | |
| 	if !ok {
 | |
| 		panic(errors.New("not a valid CA cert"))
 | |
| 	}
 | |
| 	tlsConfig.RootCAs = caCertPool
 | |
| 
 | |
| 	tlsConfig.InsecureSkipVerify = config.Config.Kafka.TLS.InsecureSkipVerify
 | |
| 
 | |
| 	return &tlsConfig
 | |
| }
 |