Skip to content

Commit c79951b

Browse files
committed
Added crypto, fixing isues with handshakes
1 parent b02da2a commit c79951b

95 files changed

Lines changed: 7024 additions & 37 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ add_subdirectory(Server)
77
add_subdirectory(Client)
88
add_subdirectory(test/flatServer)
99
add_subdirectory(test/simpleClient)
10+
add_subdirectory(test/cryptSockServer)
11+
add_subdirectory(test/cryptSockClient)
12+
1013

1114

Server/Server.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ static const char * my_addr = "127.0.0.1";
99
static const uint16_t my_port = 44301;
1010

1111

12+
void isRoot(){
13+
if (getuid() !=0){
14+
cerr << "You should have root preveledges" << endl;
15+
exit(0);
16+
}
17+
}
18+
1219
void listen_cycle(AsyncServer * server){
1320
mutex mtx;
1421
while(1){
@@ -23,6 +30,7 @@ void listen_cycle(AsyncServer * server){
2330

2431

2532
int main(){
33+
isRoot();
2634
auto Server = new AsyncServer(my_addr, my_port);
2735
thread handle_conns_async(listen_cycle, Server);
2836
handle_conns_async.detach();

Service/config.sh

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
#!/usr/bin/env bash
22

3-
global_path="`cd ..`"
4-
exec_path="/usr/bin/telemetry_service/"
5-
6-
create_conf(option){
7-
cat > "telemetry_${option}.service" <<EOF
8-
[Unit]
9-
Description="Telemetry service"
10-
After=multi-user.target
11-
Conflicts=getty@tty1.service
12-
13-
[Service]
14-
Type=simple
15-
ExecStart=/usr/bin/telemetry_service/telemetry_${option}
16-
StandardInput=tty-force
17-
Restart=always
3+
if [["`whoami`" -ne "root"]] then
4+
echo "You are not root. Please retry."
5+
exit 0
6+
fi
187

19-
[Install]
20-
WantedBy=multi-user.target
21-
exec_path="`cd ..`"
22-
conf_path="/usr/bin/telemtry_service/telemetry.srvice"
23-
EOF
248

25-
cp "telemetry_${option}.service" "${exec_path}/${option}.service"
26-
}
9+
global_path="`cd ..`"
10+
exec_path="/usr/bin/telemetry_service/"
2711

2812

2913
check_dependencies(){
@@ -48,7 +32,6 @@ setup_service(){
4832
if [$choice=="y" or $choice=="Y"] then
4933
while true; do
5034
read -p "Which config may I setup: Server or Client? (S/C for appropriate option)" choice
51-
5235
case $choice in
5336
"S"|"s") load_binary("Server") && create_conf("Server");;
5437
"C"|"c") load_binary("Client") && create_conf("Client");;
@@ -57,28 +40,85 @@ setup_service(){
5740
continue;;
5841
esac
5942
done
43+
fi
44+
}
45+
6046

61-
systemctl daemon-reload
47+
create_conf(option){
48+
cat > "telemetry_${option}.service" <<EOF
49+
[Unit]
50+
Description="Telemetry service"
51+
After=multi-user.target
52+
Conflicts=getty@tty1.service
53+
54+
[Service]
55+
Type=simple
56+
ExecStart=/usr/bin/telemetry_service/telemetry_${option}
57+
StandardInput=tty-force
58+
Restart=always
6259
63-
read -p "Would want you to autorun telemtry service? (y/n or another key)" choice
60+
[Install]
61+
WantedBy=multi-user.target
62+
exec_path="`cd ..`"
63+
conf_path="/usr/bin/telemtry_service/telemetry_${option}.srvice"
64+
EOF
6465

65-
if [$choice=="y" or $choice=="Y"] then
66-
systemctl enable telemetry.service
67-
else break
68-
fi
66+
cp "telemetry_${option}.service" "${exec_path}/telemetry_${option}.service"
6967

70-
systemctl start telemetry.service
71-
systemctl status telemetry.service
68+
read -p "Would want you to autorun telemtry service? (y/n or another key)" choice
7269

73-
else break
70+
if [$choice=="y" or $choice=="Y"] then
71+
systemctl enable telemetry.service
72+
else break
73+
fi
74+
75+
read -p "Should service start now? (y/n or another key)" choice
76+
77+
if [$choice=="y" or $choice=="Y"] then
78+
79+
systemctl start telemetry_${option}.service
80+
systemctl status telemetry_${option}.service
81+
else
82+
echo "You always can do that using next command:\"systemctl start telemetry_${option}.service\""
7483
fi
84+
systemctl daemon-reload
7585
}
7686

7787

7888
gen_ciphers(){
7989
cd "$(pwd)/cryptkeys"
80-
openssl genpkey -algorithm ed25519 -out ed25519-priv-key.pem
81-
openssl pkey -in ed25519key.pem -pubout
90+
openssl ecparam -name c2tnb191v3 -out X9_62.pem
91+
openssl ecparam -in X9_62.pem -genkey -noout -out X9_62-key.pem
92+
openssl ecparam -in X9_62.pem -text -param_enc explicit -noout
93+
94+
openssl req -x509 -new -SHA384 -nodes -key X9_62-key.pem 3650 -out X9_62-cert.pem
95+
openssl x509 -req -SHA384 -extfile v3.ext -days 365 -in X9_62-cert.pem -CA ca.crt -CAkey X9_62-key.pem -CAcreateserial -out X9_62-cert.pem
96+
openssl req -in X9_62-cert.pem -noout -text
97+
98+
openssl ec -in X9_62-key.pem -pubout -out X9_62-pub.pem
99+
100+
#openssl genpkey -algorithm ed25519 -out ed25519-priv-key.pem
101+
#openssl pkey -in ed25519key.pem -pubout
102+
# read -p "Few details are necessary for certificate creating. Please enter CN: " CN
103+
# read -p "Also I need cert owner email: " email
104+
# read -p "And last enter your email (example@service.com): " email
105+
# cat >> "${exec_path}/cryptkeys/openssl.cnf"<< EOF
106+
#[ req ]
107+
#prompt = no
108+
#encrypt_key = no
109+
#default_md = sha512
110+
#distinguished_name = dname
111+
#req_extensions = reqext
112+
113+
#[ dname ]
114+
#CN = ${CN}
115+
#emailAddress = ${email}
116+
#
117+
#[ reqext ]
118+
#subjectAltName = ${altname}
119+
#EOF
120+
# openssl req -new -config openssl.cnf -key privkey.pem -out csr.pem
121+
# openssl req -in csr.pem -noout -text -verify
82122
}
83123

84124

Service/cryptkeys/X9_62-cert.pem

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIIBCjCBwgIBADA4MRQwEgYDVQQDDAtleGFtcGxlLmNvbTEgMB4GCSqGSIb3DQEJ
3+
ARYRYWRtaW5AZXhhbXBsZS5jb20wSTATBgcqhkjOPQIBBggqhkjOPQMABwMyAAQV
4+
gA4WQAUTwA/38SLvowdLf+kQNLVCtUN5j42DSuwXBbJOVfrO9LW4Z6RD6Wr8jLGg
5+
ODA2BgkqhkiG9w0BCQ4xKTAnMCUGA1UdEQQeMByCC2V4YW1wbGUuY29tgg0qLmV4
6+
YW1wbGUuY29tMAoGCCqGSM49BAMEAzcAMDQCGALdLDEnRYkTFg6SK5fh9EyoypDr
7+
WjkkzwIYDvI65GqhNfUOS8DvQucNF7aJsq8YSzxL
8+
-----END CERTIFICATE REQUEST-----

Service/cryptkeys/X9_62-cert1.pem

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICLjCCAeWgAwIBAgIUBFVAQV/xoAMtC15yE0WV4k926D0wCgYIKoZIzj0EAwMw
3+
fTELMAkGA1UEBhMCdWExDTALBgNVBAgMBG5pa28xEzARBgNVBAcMCm5pa28tZGlz
4+
dHIxCzAJBgNVBAoMAmRmMRIwEAYDVQQLDAlkZi1vZmZpY2UxDDAKBgNVBAMMA01h
5+
eDEbMBkGCSqGSIb3DQEJARYMeWFAZW1haWwuY29tMB4XDTE5MDkxMTE5MjczN1oX
6+
DTI5MDkwODE5MjczN1owfTELMAkGA1UEBhMCdWExDTALBgNVBAgMBG5pa28xEzAR
7+
BgNVBAcMCm5pa28tZGlzdHIxCzAJBgNVBAoMAmRmMRIwEAYDVQQLDAlkZi1vZmZp
8+
Y2UxDDAKBgNVBAMMA01heDEbMBkGCSqGSIb3DQEJARYMeWFAZW1haWwuY29tMEkw
9+
EwYHKoZIzj0CAQYIKoZIzj0DAAcDMgAEFYAOFkAFE8AP9/Ei76MHS3/pEDS1QrVD
10+
eY+Ng0rsFwWyTlX6zvS1uGekQ+lq/Iyxo1MwUTAdBgNVHQ4EFgQUqp+Wba9NcSoS
11+
39/jjMi8RBOA34YwHwYDVR0jBBgwFoAUqp+Wba9NcSoS39/jjMi8RBOA34YwDwYD
12+
VR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAwM3ADA0AhgOXpTcEHKFCif9AGmTISiF
13+
XI3T0KKa7B8CGARx2a4o6IW+ijNMW+DZhWQSnDuP3mGCag==
14+
-----END CERTIFICATE-----

Service/cryptkeys/X9_62-key.pem

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN EC PRIVATE KEY-----
2+
MF8CAQEEGACQNhm6kWR+8R1ONOieY6L8K684mZxWRKAKBggqhkjOPQMAB6E0AzIA
3+
BBWADhZABRPAD/fxIu+jB0t/6RA0tUK1Q3mPjYNK7BcFsk5V+s70tbhnpEPpavyM
4+
sQ==
5+
-----END EC PRIVATE KEY-----

Service/cryptkeys/X9_62-pub.pem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAAcDMgAEFYAOFkAFE8AP9/Ei76MHS3/pEDS1
3+
QrVDeY+Ng0rsFwWyTlX6zvS1uGekQ+lq/Iyx
4+
-----END PUBLIC KEY-----

Service/cryptkeys/X9_62.pem

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-----BEGIN EC PARAMETERS-----
2+
BggqhkjOPQMABw==
3+
-----END EC PARAMETERS-----

Service/cryptkeys/openssl.cnf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[ req ]
2+
prompt = no
3+
encrypt_key = no
4+
default_md = sha512
5+
distinguished_name = dname
6+
req_extensions = reqext
7+
8+
[ dname ]
9+
CN = example.com
10+
emailAddress = admin@example.com
11+
12+
[ reqext ]
13+
subjectAltName = DNS:example.com, DNS:*.example.com

cryptkeys/ed25519-priv-key.pem

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)