|
|
@@ -2,24 +2,23 @@ package modules
|
|
2
|
2
|
|
|
3
|
3
|
import (
|
|
4
|
4
|
"fmt"
|
|
5
|
|
- "testing"
|
|
6
|
5
|
)
|
|
7
|
6
|
|
|
8
|
|
-func TestCompare(t *testing.T) {
|
|
9
|
|
- var security = NewSecurity()
|
|
10
|
|
- var sm SecurityManager
|
|
11
|
|
- sm = security
|
|
12
|
|
-
|
|
13
|
|
- ksm := KeyShareMsg{Message: Message{From: "1.1.1.1", Version: "1", Time: "2", Kind: 1}, key: "1234"}
|
|
14
|
|
- sm.RegKey(ksm)
|
|
15
|
|
- sm.GetNodeKey(ksm.Message.From)
|
|
16
|
|
- fmt.Println(sm.GetNodeKey(ksm.Message.From))
|
|
17
|
|
- var targetKey []int64
|
|
18
|
|
- targetKey = []int64{1234, 1235, 1236}
|
|
19
|
|
- fmt.Println(sm.ReEncrypt(sm.GetNodeKey(ksm.Message.From), 0, targetKey))
|
|
20
|
|
- //fmt.Println(sm.CompareDigit(1236, 1234))
|
|
21
|
|
-
|
|
22
|
|
-}
|
|
|
7
|
+//func TestCompare(t *testing.T) {
|
|
|
8
|
+// var security = NewSecurity()
|
|
|
9
|
+// var sm SecurityManager
|
|
|
10
|
+// sm = security
|
|
|
11
|
+//
|
|
|
12
|
+// ksm := KeyShareMsg{Message: Message{From: "1.1.1.1", Version: "1", Time: "2", Kind: 1}, key: "1234"}
|
|
|
13
|
+// sm.RegKey(ksm)
|
|
|
14
|
+// sm.GetNodeKey(ksm.Message.From)
|
|
|
15
|
+// fmt.Println(sm.GetNodeKey(ksm.Message.From))
|
|
|
16
|
+// var targetKey []int64
|
|
|
17
|
+// targetKey = []int64{1234, 1235, 1236}
|
|
|
18
|
+// fmt.Println(sm.ReEncrypt(sm.GetNodeKey(ksm.Message.From), 0, targetKey))
|
|
|
19
|
+// //fmt.Println(sm.CompareDigit(1236, 1234))
|
|
|
20
|
+//
|
|
|
21
|
+//}
|
|
23
|
22
|
|
|
24
|
23
|
func CreatePubMsg(msg Message, topic string, value string, content string) *PublishMsg {
|
|
25
|
24
|
toPubMsg := new(PublishMsg)
|
|
|
@@ -113,28 +112,28 @@ func printMsg(msg *PublishMsg) {
|
|
113
|
112
|
}
|
|
114
|
113
|
|
|
115
|
114
|
// From "1.1.1.1" to "3.3.3.3" node
|
|
116
|
|
-func TestReEnc(t *testing.T) {
|
|
117
|
|
- var security = NewSecurity()
|
|
118
|
|
- var sm SecurityManager
|
|
119
|
|
- sm = security
|
|
120
|
|
- security.KeyMap["1.1.1.1"] = "56789"
|
|
121
|
|
- security.KeyMap["3.3.3.3"] = "99999"
|
|
122
|
|
-
|
|
123
|
|
- //fmt.Println(sm.GetNodeKey("3.3.3.3"))
|
|
124
|
|
- msg := Message{From: "1.1.1.1", Version: "1", Time: "123", Kind: 3}
|
|
125
|
|
- //fmt.Println(msg)
|
|
126
|
|
- publishMsg := CreatePubMsg(msg, "soccer123한글", "playerList", "Son and 10 players")
|
|
127
|
|
- fmt.Println(publishMsg)
|
|
128
|
|
- fmt.Println("original publish message is...")
|
|
129
|
|
- printMsg(publishMsg)
|
|
130
|
|
- encPublishMsg := EncryptionMsg(publishMsg, 1234, 56789)
|
|
131
|
|
- fmt.Println("encrypt publish message by publisher's private key")
|
|
132
|
|
- printMsg(encPublishMsg)
|
|
133
|
|
- fmt.Println(encPublishMsg)
|
|
134
|
|
- reEncPublishMsg := sm.ReEncPubMsg(*encPublishMsg, "3.3.3.3")
|
|
135
|
|
- fmt.Println("re-encrypt publish message by subscriber's private key")
|
|
136
|
|
- printMsg(reEncPublishMsg)
|
|
137
|
|
- //fmt.Println(reEncPublishMsg)
|
|
138
|
|
- fmt.Println("decrypted publish message is...")
|
|
139
|
|
- DecryptionMsg(reEncPublishMsg, 1234, 99999)
|
|
140
|
|
-}
|
|
|
115
|
+//func TestReEnc(t *testing.T) {
|
|
|
116
|
+// var security = NewSecurity()
|
|
|
117
|
+// var sm SecurityManager
|
|
|
118
|
+// sm = security
|
|
|
119
|
+// security.KeyMap["1.1.1.1"] = "56789"
|
|
|
120
|
+// security.KeyMap["3.3.3.3"] = "99999"
|
|
|
121
|
+//
|
|
|
122
|
+// //fmt.Println(sm.GetNodeKey("3.3.3.3"))
|
|
|
123
|
+// msg := Message{From: "1.1.1.1", Version: "1", Time: "123", Kind: 3}
|
|
|
124
|
+// //fmt.Println(msg)
|
|
|
125
|
+// publishMsg := CreatePubMsg(msg, "soccer123한글", "playerList", "Son and 10 players")
|
|
|
126
|
+// fmt.Println(publishMsg)
|
|
|
127
|
+// fmt.Println("original publish message is...")
|
|
|
128
|
+// printMsg(publishMsg)
|
|
|
129
|
+// encPublishMsg := EncryptionMsg(publishMsg, 1234, 56789)
|
|
|
130
|
+// fmt.Println("encrypt publish message by publisher's private key")
|
|
|
131
|
+// printMsg(encPublishMsg)
|
|
|
132
|
+// fmt.Println(encPublishMsg)
|
|
|
133
|
+// reEncPublishMsg := sm.ReEncPubMsg(*encPublishMsg, "3.3.3.3")
|
|
|
134
|
+// fmt.Println("re-encrypt publish message by subscriber's private key")
|
|
|
135
|
+// printMsg(reEncPublishMsg)
|
|
|
136
|
+// //fmt.Println(reEncPublishMsg)
|
|
|
137
|
+// fmt.Println("decrypted publish message is...")
|
|
|
138
|
+// DecryptionMsg(reEncPublishMsg, 1234, 99999)
|
|
|
139
|
+//}
|