domain list
This commit is contained in:
		
							parent
							
								
									c26ea0fe41
								
							
						
					
					
						commit
						ee6ef8dde3
					
				|  | @ -26,6 +26,8 @@ func Start() { | |||
| 	} | ||||
| 	command := args[1] | ||||
| 	switch command { | ||||
| 	case "block": | ||||
| 		doTask() | ||||
| 	case "start": | ||||
| 		daemonStart() | ||||
| 	case "stop": | ||||
|  |  | |||
							
								
								
									
										20
									
								
								src/http.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/http.go
									
									
									
									
									
								
							|  | @ -7,6 +7,8 @@ import ( | |||
| 	"crypto/rand" | ||||
| 	"crypto/rsa" | ||||
| 	"crypto/x509" | ||||
| 	"encoding/base64" | ||||
| 	"encoding/json" | ||||
| 	"encoding/pem" | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"io" | ||||
|  | @ -23,12 +25,28 @@ func InitHttpServer(host string, port int) { | |||
| 	h := gin.Default() | ||||
| 	h.GET("/api/v1/refresh", refreshCert) | ||||
| 	h.GET("/api/v1/cert", getCert) | ||||
| 	h.GET("/api/v1/domain/list", domainList) | ||||
| 	err := h.Run(host + ":" + strconv.Itoa(port)) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func domainList(c *gin.Context) { | ||||
| 	token := getToken(c) | ||||
| 	domains := GetAppConfig().Domains | ||||
| 	data, err := json.Marshal(domains) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c.JSON(200, gin.H{ | ||||
| 		"code": 200, | ||||
| 		"msg":  "Success", | ||||
| 		"data": encryptResult(string(data), token), | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func getCert(c *gin.Context) { | ||||
| 	name := c.Param("name") | ||||
| 	token := getToken(c) | ||||
|  | @ -137,7 +155,7 @@ func encryptResult(content string, token string) string { | |||
| 	ciphertext := make([]byte, len(plaintext)) | ||||
| 	mode.CryptBlocks(ciphertext, plaintext) | ||||
| 
 | ||||
| 	return string(ciphertext) | ||||
| 	return base64.StdEncoding.EncodeToString(ciphertext) | ||||
| } | ||||
| 
 | ||||
| func pad(src []byte, blockSize int) []byte { | ||||
|  |  | |||
|  | @ -13,10 +13,11 @@ func GenRsa() (priKey string, pubKey string, err error) { | |||
| 		return "", "", err | ||||
| 	} | ||||
| 	publicKey := &privateKey.PublicKey | ||||
| 	publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey) | ||||
| 	if err != nil { | ||||
| 		return "", "", err | ||||
| 	} | ||||
| 	publicKeyBytes := x509.MarshalPKCS1PublicKey(publicKey) | ||||
| 	//publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
 | ||||
| 	//if err != nil {
 | ||||
| 	//	return "", "", err
 | ||||
| 	//}
 | ||||
| 	pubKey = base64.StdEncoding.EncodeToString(publicKeyBytes) | ||||
| 	//pemBlock := &pem.Block{
 | ||||
| 	//	Type:  "",
 | ||||
|  |  | |||
							
								
								
									
										31
									
								
								test/encrypt_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								test/encrypt_test.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,31 @@ | |||
| package test | ||||
| 
 | ||||
| import ( | ||||
| 	"crypto/rand" | ||||
| 	"crypto/rsa" | ||||
| 	"crypto/x509" | ||||
| 	"encoding/base64" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"testing" | ||||
| ) | ||||
| 
 | ||||
| func TestGenRsa(t *testing.T) { | ||||
| 	privateKey, err := rsa.GenerateKey(rand.Reader, 2048) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 	publicKeyBytes, err := x509.MarshalPKIXPublicKey(&privateKey.PublicKey) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 	pubKey := base64.StdEncoding.EncodeToString(publicKeyBytes) | ||||
| 	//publicKey := &privateKey.PublicKey
 | ||||
| 	//publicKeyBytes := x509.MarshalPKCS1PublicKey(publicKey)
 | ||||
| 	//pubKey := base64.StdEncoding.EncodeToString(publicKeyBytes)
 | ||||
| 	key := x509.MarshalPKCS1PrivateKey(privateKey) | ||||
| 	priKey := base64.StdEncoding.EncodeToString(key) | ||||
| 	fmt.Println(pubKey) | ||||
| 	fmt.Println() | ||||
| 	fmt.Println(priKey) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user