-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.go
More file actions
169 lines (135 loc) · 4.02 KB
/
demo.go
File metadata and controls
169 lines (135 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"strings"
"time"
"quantum-safe-mesh/pkg/pqc"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
if len(os.Args) > 1 && os.Args[1] == "benchmark" {
runBenchmark()
return
}
fmt.Println("🌟 Quantum-Safe Service Mesh Demo")
fmt.Println(strings.Repeat("=", 50))
time.Sleep(2 * time.Second)
fmt.Println("\n🔍 Step 1: Checking service health...")
checkHealth()
time.Sleep(1 * time.Second)
fmt.Println("\n📡 Step 2: Testing Echo Endpoint...")
testEcho()
time.Sleep(1 * time.Second)
fmt.Println("\n🧠 Step 3: Testing Data Processing...")
testProcess()
time.Sleep(1 * time.Second)
fmt.Println("\n📊 Step 4: Checking Service Status...")
testStatus()
time.Sleep(1 * time.Second)
fmt.Println("\n🔐 Step 5: Performance Summary...")
showPerformanceSummary()
fmt.Println("\n🎉 Demo completed successfully!")
fmt.Println("All requests were authenticated using Post-Quantum Cryptography!")
}
func checkHealth() {
services := map[string]string{
"Auth Service": "http://localhost:8080/health",
"Gateway Service": "http://localhost:8081/health",
"Backend Service": "http://localhost:8082/health",
}
for name, url := range services {
resp, err := http.Get(url)
if err != nil || resp.StatusCode != 200 {
fmt.Printf("❌ %s: Not responding\n", name)
} else {
fmt.Printf("✅ %s: Healthy\n", name)
resp.Body.Close()
}
}
}
func testEcho() {
data := map[string]interface{}{
"message": "Hello Quantum-Safe World!",
"demo": true,
"timestamp": time.Now(),
"test_data": []string{"quantum", "cryptography", "demo"},
}
jsonData, _ := json.Marshal(data)
start := time.Now()
resp, err := http.Post(
"http://localhost:8081/echo",
"application/json",
bytes.NewBuffer(jsonData),
)
duration := time.Since(start)
if err != nil {
fmt.Printf("❌ Echo test failed: %v\n", err)
return
}
defer resp.Body.Close()
fmt.Printf("✅ Echo test successful (latency: %v)\n", duration)
fmt.Printf(" Status: %s\n", resp.Status)
}
func testProcess() {
data := map[string]interface{}{
"operation": "quantum_safe_processing",
"data": map[string]interface{}{
"input": "Sensitive data for quantum-safe processing",
"algorithm": "advanced",
"priority": "high",
},
"metadata": map[string]interface{}{
"client_id": "demo-client",
"request_id": fmt.Sprintf("req-%d", time.Now().Unix()),
"quantum_safe": true,
},
}
jsonData, _ := json.Marshal(data)
start := time.Now()
resp, err := http.Post(
"http://localhost:8081/process",
"application/json",
bytes.NewBuffer(jsonData),
)
duration := time.Since(start)
if err != nil {
fmt.Printf("❌ Process test failed: %v\n", err)
return
}
defer resp.Body.Close()
fmt.Printf("✅ Process test successful (latency: %v)\n", duration)
fmt.Printf(" Status: %s\n", resp.Status)
}
func testStatus() {
start := time.Now()
resp, err := http.Get("http://localhost:8081/status")
duration := time.Since(start)
if err != nil {
fmt.Printf("❌ Status test failed: %v\n", err)
return
}
defer resp.Body.Close()
fmt.Printf("✅ Status test successful (latency: %v)\n", duration)
fmt.Printf(" Status: %s\n", resp.Status)
}
func showPerformanceSummary() {
fmt.Println("\n📈 PQC Performance Characteristics:")
fmt.Println(" • Dilithium3 Signatures: Quantum-resistant digital signatures")
fmt.Println(" • Kyber768 KEM: Quantum-resistant key encapsulation")
fmt.Println(" • All inter-service communication is cryptographically verified")
fmt.Println(" • Zero-trust architecture with PQC mutual authentication")
fmt.Println("\n🛡️ Security Benefits:")
fmt.Println(" • Protection against quantum computer attacks")
fmt.Println(" • Forward secrecy with Kyber key exchange")
fmt.Println(" • Mutual authentication between all services")
fmt.Println(" • Tamper-evident message signatures")
}
func runBenchmark() {
fmt.Println("🚀 Running PQC Performance Benchmark...")
pqc.BenchmarkRSAvsDialithium()
}