2020-03-11 21:01:54 +00:00
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// Bakalarska praca //
|
|
|
|
// Meno studenta: Tomas Lukac //
|
|
|
|
// Veduci BP: prof. Ing. Milos Drutarovsky CSc. //
|
|
|
|
// Skola: KEMT FEI TUKE //
|
2020-04-16 09:25:05 +00:00
|
|
|
// Datum poslednej upravy: 15.4.2020 //
|
2020-03-11 21:01:54 +00:00
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wolfssl/ssl.h>
|
|
|
|
#include <wolfssl/certs_test.h>
|
|
|
|
#include <wolfssl/wolfcrypt/types.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
2020-03-30 01:32:44 +00:00
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
2020-04-07 20:11:21 +00:00
|
|
|
#define O_NOCTTY 0x8000
|
|
|
|
#define O_NDELAY 0x4000
|
2020-03-11 21:01:54 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2020-04-16 09:25:05 +00:00
|
|
|
#include "../../kniznica/kryptografia.h"
|
|
|
|
#include "../../kniznica/komunikacia.h"
|
|
|
|
#include "../../kniznica/rs232.h"
|
2020-03-11 21:01:54 +00:00
|
|
|
|
2020-04-07 20:11:21 +00:00
|
|
|
#define RSA_VELKOST 2048
|
|
|
|
#define ECC_VELKOST 32
|
|
|
|
#define RSA_EXPONENT 65537
|
|
|
|
|
|
|
|
//cesty ku suborom
|
2020-04-16 09:25:05 +00:00
|
|
|
#define RSA_KLUC "../../certifikaty/server/server_rsa.key"
|
|
|
|
#define RSA_CERTIFIKAT "../../certifikaty/server/server_rsa.pem"
|
|
|
|
#define ECC_KLUC "../../certifikaty/server/server_ecc.key"
|
|
|
|
#define ECC_CERTIFIKAT "../../certifikaty/server/server_ecc.pem"
|
|
|
|
#define VYGENEROVANY_KLUC "../../certifikaty/server/vygenerovany_kluc.key"
|
|
|
|
#define VYGENEROVANY_CERTIFIKAT "../../certifikaty/server/vygenerovany_certifikat.pem"
|
|
|
|
#define KOMUNIKACNY_SUBOR "server.txt"
|
2020-04-07 20:11:21 +00:00
|
|
|
|
2020-03-30 01:32:44 +00:00
|
|
|
int rs232_prijat;
|
2020-04-10 17:04:14 +00:00
|
|
|
int cislo_rozhrania = 0;
|
2020-04-07 20:11:21 +00:00
|
|
|
int aktualne_data = 0;
|
2020-03-30 01:32:44 +00:00
|
|
|
|
|
|
|
int rs232_citanie(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
|
|
|
{
|
|
|
|
int uspech = 0;
|
2020-04-16 09:25:05 +00:00
|
|
|
int prebieha_nacitanie = 0;
|
|
|
|
int prebieha_nacitanie_velkosti_spravy = 0;
|
|
|
|
unsigned char znak;
|
|
|
|
|
2020-04-07 20:11:21 +00:00
|
|
|
|
|
|
|
//ziskanie dat zo serioveho rozhrania
|
|
|
|
if(aktualne_data == 0)
|
2020-03-30 01:32:44 +00:00
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
//otvorenie suboru do ktoreho sa zapisuju prijate binarne data
|
|
|
|
//ktore sa nasledne nacitaju do buffera (buf) pre desifrovanie
|
|
|
|
FILE* f = fopen(KOMUNIKACNY_SUBOR, "ab+");
|
|
|
|
|
|
|
|
//mnozstvo nacitanych dat
|
2020-04-07 20:11:21 +00:00
|
|
|
int nacitane_data = 0;
|
2020-04-16 09:25:05 +00:00
|
|
|
//velkost spravy, ktora sa bude prijmat
|
|
|
|
int velkost_spravy = 0;
|
|
|
|
//urcuje kolko bajtov z informacie o velkosti spravy
|
|
|
|
//uz bolo prijatych z celkoveho poctu (4)
|
|
|
|
int velkost_spravy_bajt = 0;
|
|
|
|
int velkost_spravy_pocet_bajtov = 4;
|
2020-04-07 20:11:21 +00:00
|
|
|
|
|
|
|
//kontrolne vzory, ktore jednoznacne identifikuju zaciatok a koniec spravy
|
|
|
|
unsigned char zaciatok_spravy[] = {0xAA, 0xAA, 0xAA, 0xAA};
|
|
|
|
int zaciatok_spravy_pozicia = 0; //aktualna pozicia v kontrolnom vzore
|
|
|
|
unsigned char koniec_spravy[] = {0xBB, 0xBB, 0xBB, 0xBB};
|
2020-04-16 09:25:05 +00:00
|
|
|
int koniec_spravy_pozicia = 0; //aktualna pozicia v kontrolnom vzore
|
|
|
|
int velkost_kontrolneho_vzoru = sizeof(zaciatok_spravy)/sizeof(zaciatok_spravy[0]);
|
2020-04-07 20:11:21 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
uspech = RS232_PollComport(cislo_rozhrania, &znak, 1);
|
|
|
|
if(uspech > 0)
|
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
//ak nacitanie spravy este nezacalo, ale bol najdeny bajt, ktory je sucastou kontrolneho vzoru,
|
|
|
|
//ktory urcuje zaciatok spravy, posun sa v kontrolnom vzore o jednu poziciu a cakaj ci nebudu
|
|
|
|
//prichadzat dalsie bajty z tohto kontrolneho vzoru
|
|
|
|
if(!prebieha_nacitanie && (znak == zaciatok_spravy[zaciatok_spravy_pozicia]) &&
|
|
|
|
(zaciatok_spravy_pozicia < velkost_kontrolneho_vzoru - 1))
|
2020-04-07 20:11:21 +00:00
|
|
|
{
|
|
|
|
zaciatok_spravy_pozicia++;
|
|
|
|
}
|
2020-04-16 09:25:05 +00:00
|
|
|
//ak prebehlo nacitanie vsetkych bajtov, ktore su sucastou kontrolneho vzoru urcujuceho zaciatok spravy
|
|
|
|
//ocakavaj prichod bajtov, ktore budu niest informaciu o velkosti spravy
|
|
|
|
else if(!prebieha_nacitanie && (znak == zaciatok_spravy[zaciatok_spravy_pozicia]) &&
|
|
|
|
(zaciatok_spravy_pozicia == velkost_kontrolneho_vzoru - 1))
|
2020-04-07 20:11:21 +00:00
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
prebieha_nacitanie_velkosti_spravy = 1;
|
2020-04-10 17:04:14 +00:00
|
|
|
zaciatok_spravy_pozicia = 0;
|
2020-04-07 20:11:21 +00:00
|
|
|
}
|
2020-04-16 09:25:05 +00:00
|
|
|
//pokracuj v nacitavani bajtov urcujucich velkost spravy, dokym nie su vsetky nacitane
|
|
|
|
//a po nacitani vsetkych bajtov moze zacat nacitanie spravy
|
|
|
|
else if(!prebieha_nacitanie && prebieha_nacitanie_velkosti_spravy)
|
|
|
|
{
|
|
|
|
velkost_spravy_bajt++;
|
|
|
|
if(velkost_spravy_bajt == velkost_spravy_pocet_bajtov)
|
|
|
|
{
|
|
|
|
prebieha_nacitanie = 1;
|
|
|
|
prebieha_nacitanie_velkosti_spravy = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//ak prebieha nacitanie a bol najdeny bajt, ktory je sucastou kontrolneho vzoru, ktory urcuje koniec spravy,
|
|
|
|
//posun sa v kontrolnom vzore o jednu poziciu a cakaj ci nebudu prichadzat dalsie bajty z tohto kontrolneho vzoru
|
|
|
|
else if((prebieha_nacitanie && (znak == koniec_spravy[koniec_spravy_pozicia]) &&
|
|
|
|
(koniec_spravy_pozicia == 0)) || (!prebieha_nacitanie && (znak == koniec_spravy[koniec_spravy_pozicia]) &&
|
|
|
|
(koniec_spravy_pozicia < velkost_kontrolneho_vzoru - 1)))
|
2020-04-07 20:11:21 +00:00
|
|
|
{
|
|
|
|
koniec_spravy_pozicia++;
|
2020-04-10 17:04:14 +00:00
|
|
|
prebieha_nacitanie = 0;
|
2020-04-07 20:11:21 +00:00
|
|
|
}
|
2020-04-16 09:25:05 +00:00
|
|
|
//v pripade ak zacalo nacitanie kontrolneho vzoru, ktory urcuje koniec spravy, ale nebol najdeny posledny znak z tohto vzoru
|
|
|
|
//nacitaj do suboru docasne nezapisane znaky, ktore su sucastou kontrolneho vzoru a zaroven nacitaj aktualny znak
|
|
|
|
else if(!prebieha_nacitanie_velkosti_spravy && !prebieha_nacitanie && znak != koniec_spravy[koniec_spravy_pozicia])
|
2020-04-10 17:04:14 +00:00
|
|
|
{
|
|
|
|
for(int i = 0; i < koniec_spravy_pozicia; i++)
|
|
|
|
{
|
|
|
|
fwrite((char*)&koniec_spravy[i], 1, uspech, f);
|
|
|
|
nacitane_data += uspech;
|
|
|
|
}
|
|
|
|
fwrite((char*)&znak, 1, uspech, f);
|
|
|
|
nacitane_data += uspech;
|
|
|
|
|
|
|
|
koniec_spravy_pozicia = 0;
|
|
|
|
prebieha_nacitanie = 1;
|
|
|
|
}
|
2020-04-16 09:25:05 +00:00
|
|
|
//ak prebehlo nacitanie vsetkych bajtov, ktore su sucastou kontrolneho vzoru urcujuceho koniec spravy
|
|
|
|
//ukonci nacitanie spravy
|
|
|
|
else if(!prebieha_nacitanie_velkosti_spravy && !prebieha_nacitanie && (znak == koniec_spravy[0]) &&
|
|
|
|
(koniec_spravy_pozicia == 3))
|
2020-04-07 20:11:21 +00:00
|
|
|
{
|
|
|
|
prebieha_nacitanie = 0;
|
2020-04-10 17:04:14 +00:00
|
|
|
koniec_spravy_pozicia = 0;
|
2020-04-07 20:11:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-04-16 09:25:05 +00:00
|
|
|
//inak prebieha nacitanie, cize zapis aktualny znak (bajt) do suboru
|
2020-04-07 20:11:21 +00:00
|
|
|
else
|
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
if(prebieha_nacitanie && !prebieha_nacitanie_velkosti_spravy)
|
2020-04-07 20:11:21 +00:00
|
|
|
{
|
|
|
|
fwrite((char*)&znak, 1, uspech, f);
|
|
|
|
nacitane_data += uspech;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 17:04:14 +00:00
|
|
|
aktualne_data = nacitane_data;
|
|
|
|
nacitane_data = 0;
|
2020-04-07 20:11:21 +00:00
|
|
|
fclose(f);
|
2020-03-30 01:32:44 +00:00
|
|
|
}
|
2020-04-16 09:25:05 +00:00
|
|
|
//nacitanie dat zo suboru do buffera pre desifrovanie
|
2020-04-07 20:11:21 +00:00
|
|
|
uspech = 0;
|
|
|
|
while(uspech <= 0)
|
|
|
|
uspech = read(rs232_prijat, buf, sz);
|
|
|
|
aktualne_data -= uspech;
|
2020-04-16 09:25:05 +00:00
|
|
|
|
2020-03-30 01:32:44 +00:00
|
|
|
return uspech;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rs232_zapis(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
|
|
|
{
|
|
|
|
int uspech = 0;
|
2020-04-16 09:25:05 +00:00
|
|
|
|
2020-04-07 20:11:21 +00:00
|
|
|
//kontrolne vzory, ktore jednoznacne identifikuju zaciatok a koniec spravy
|
|
|
|
unsigned char zaciatok_spravy[] = {0xAA, 0xAA, 0xAA, 0xAA};
|
|
|
|
unsigned char koniec_spravy[] = {0xBB, 0xBB, 0xBB, 0xBB};
|
2020-04-16 09:25:05 +00:00
|
|
|
|
|
|
|
//vytvorenie bajtov ktore budu niest informaciu o velkosti posielanej spravy
|
|
|
|
unsigned char* velkost_spravy = calloc(4, sizeof(unsigned char));
|
|
|
|
velkost_spravy[0] = (sz >> 24) & 0xFF;
|
|
|
|
velkost_spravy[1] = (sz >> 16) & 0xFF;
|
|
|
|
velkost_spravy[2] = (sz >> 8) & 0xFF;
|
|
|
|
velkost_spravy[3] = sz & 0xFF;
|
|
|
|
|
|
|
|
//odoslanie kontrolnych vzorov, bajtov s velkostou spravy a samotnych dat na seriove rozhranie
|
2020-04-07 20:11:21 +00:00
|
|
|
RS232_SendBuf(cislo_rozhrania, (unsigned char*)zaciatok_spravy, sizeof(zaciatok_spravy));
|
2020-04-16 09:25:05 +00:00
|
|
|
RS232_SendBuf(cislo_rozhrania, (unsigned char*)velkost_spravy, 4);
|
2020-04-10 17:04:14 +00:00
|
|
|
uspech = (int)RS232_SendBuf(cislo_rozhrania, (unsigned char*)buf, sz);
|
2020-04-07 20:11:21 +00:00
|
|
|
RS232_SendBuf(cislo_rozhrania, (unsigned char*)koniec_spravy, sizeof(koniec_spravy));
|
2020-04-16 09:25:05 +00:00
|
|
|
free(velkost_spravy);
|
2020-04-07 20:11:21 +00:00
|
|
|
|
2020-03-30 01:32:44 +00:00
|
|
|
return uspech;
|
|
|
|
}
|
2020-03-11 21:01:54 +00:00
|
|
|
|
|
|
|
int main(int argc, char const *argv[])
|
|
|
|
{
|
|
|
|
WOLFSSL *ssl;
|
|
|
|
WOLFSSL_CTX *ctx = NULL;
|
2020-04-16 09:25:05 +00:00
|
|
|
int rychlost = 9600;
|
|
|
|
char rezim[]={'8','N','1', 0};
|
2020-04-07 20:11:21 +00:00
|
|
|
int zadane_rozhranie = 0;
|
|
|
|
int generovanie_certifikatu = 0;
|
2020-04-16 09:25:05 +00:00
|
|
|
int nacitanie_zo_suboru = 0;
|
2020-04-07 20:11:21 +00:00
|
|
|
nastavenia_aplikacie nastavenia;
|
2020-04-16 09:25:05 +00:00
|
|
|
RS232_flushRXTX(cislo_rozhrania);
|
2020-03-30 01:32:44 +00:00
|
|
|
|
2020-04-16 09:25:05 +00:00
|
|
|
rs232_prijat = open(KOMUNIKACNY_SUBOR, O_RDWR | O_NOCTTY | O_NDELAY);
|
|
|
|
|
2020-03-30 01:32:44 +00:00
|
|
|
int uspech;
|
2020-04-16 09:25:05 +00:00
|
|
|
if((ctx = nastavit_ctx_server()) == NULL)
|
2020-03-11 21:01:54 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-04-07 20:11:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if( (!strcmp(argv[i], "-port")) )
|
|
|
|
{
|
|
|
|
zadane_rozhranie = 1;
|
|
|
|
if((argv[i+1] == NULL))
|
|
|
|
{
|
|
|
|
printf("Nezadali ste cislo serioveho rozhrania\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cislo_rozhrania = atoi(argv[i+1]);
|
|
|
|
if(RS232_OpenComport(cislo_rozhrania, rychlost, rezim, 1))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Nebolo mozne otvorit seriove rozhranie\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( (!strcmp(argv[i], "-n")) )
|
|
|
|
{
|
|
|
|
nacitanie_zo_suboru = 1;
|
|
|
|
if(generovanie_certifikatu)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Nie je mozne zvolit obidve metody nacitania certifikatov naraz\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if((argv[i+1] == NULL) || (i == argc-1))
|
|
|
|
{
|
|
|
|
printf("Nezadali ste typ certifikatu ktory chcete nacitat zo suboru\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(!strcmp(argv[i+1], "rsa"))
|
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
wolfSSL_CTX_load_verify_locations(ctx, "../../certifikaty/autorita/autorita_rsa.pem", NULL);
|
2020-04-07 20:11:21 +00:00
|
|
|
if(nacitat_certifikaty(ctx, RSA_CERTIFIKAT, RSA_KLUC) == -1) return -1;
|
|
|
|
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(!strcmp(argv[i+1], "ecc"))
|
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
wolfSSL_CTX_load_verify_locations(ctx, "../../certifikaty/autorita/autorita_ecc.pem", NULL);
|
2020-04-07 20:11:21 +00:00
|
|
|
if(nacitat_certifikaty(ctx, ECC_CERTIFIKAT, ECC_KLUC) == -1) return -1;
|
|
|
|
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Zadali ste nespravny typ certifikatu\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( (!strcmp(argv[i], "-g")) )
|
|
|
|
{
|
|
|
|
generovanie_certifikatu = 1;
|
|
|
|
if(nacitanie_zo_suboru)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Nie je mozne zvolit obidve metody nacitania certifikatov naraz\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if((argv[i+1] == NULL) || (i == argc-1))
|
|
|
|
{
|
|
|
|
printf("Nezadali ste typ certifikatu ktory chcete vygenerovat\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(!strcmp(argv[i+1], "rsa"))
|
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
wolfSSL_CTX_load_verify_locations(ctx, "../../certifikaty/autorita/autorita_rsa.pem", NULL);
|
2020-04-07 20:11:21 +00:00
|
|
|
if(generovat_rsa_certifikat(RSA_VELKOST, RSA_EXPONENT, CTC_SHA256wRSA, "SR", "Kosice", "local.dev", "server@server.sk") == -1) return -1;
|
|
|
|
if(nacitat_certifikaty(ctx, VYGENEROVANY_CERTIFIKAT, VYGENEROVANY_KLUC) == -1) return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(!strcmp(argv[i+1], "ecc"))
|
|
|
|
{
|
2020-04-16 09:25:05 +00:00
|
|
|
wolfSSL_CTX_load_verify_locations(ctx, "../../certifikaty/autorita/autorita_ecc.pem", NULL);
|
2020-04-07 20:11:21 +00:00
|
|
|
if(generovat_ecc_certifikat(ECC_VELKOST, ECC_SECP256R1, CTC_SHAwECDSA, "SR", "Kosice", "local.dev", "server@server.sk") == -1) return -1;
|
|
|
|
if(nacitat_certifikaty(ctx, VYGENEROVANY_CERTIFIKAT, VYGENEROVANY_KLUC) == -1) return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Zadali ste nespravny typ certifikatu\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!zadane_rozhranie)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Nebol urcene seriove rozhranie\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(!generovanie_certifikatu && !nacitanie_zo_suboru)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Nebola zvolena metoda nacitania certifikatov\n");
|
|
|
|
printf("Zadajde prepinac -g (generovanie), alebo -n (nacitanie_zo_suboru) s parametrom rsa alebo ecc\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//nastav_sifry(ctx, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
|
2020-04-16 09:25:05 +00:00
|
|
|
|
|
|
|
//nastavenie vlastnych I/O funkcii
|
2020-03-11 21:01:54 +00:00
|
|
|
wolfSSL_SetIOSend(ctx, rs232_zapis);
|
|
|
|
wolfSSL_SetIORecv(ctx, rs232_citanie);
|
|
|
|
|
2020-04-16 09:25:05 +00:00
|
|
|
//pokus o vytvorenie novej wolfSSL relacie
|
2020-03-11 21:01:54 +00:00
|
|
|
if ((ssl = wolfSSL_new(ctx)) == NULL)
|
|
|
|
{
|
|
|
|
printf("Nepodarilo sa vytvorit ssl relaciu\n");
|
|
|
|
wolfSSL_CTX_free(ctx);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-16 09:25:05 +00:00
|
|
|
//priradenie file descriptora suboru ako I/O pre TLS spojenie
|
2020-03-30 01:32:44 +00:00
|
|
|
wolfSSL_set_fd(ssl, rs232_prijat);
|
|
|
|
wolfSSL_set_using_nonblock(ssl, rs232_prijat);
|
2020-04-16 09:25:05 +00:00
|
|
|
|
|
|
|
//cakanie na inicializaciu TLS handshaku klientom
|
|
|
|
uspech = wolfSSL_accept(ssl);
|
2020-04-07 20:11:21 +00:00
|
|
|
if(uspech != SSL_SUCCESS)
|
2020-03-11 21:01:54 +00:00
|
|
|
{
|
2020-04-07 20:11:21 +00:00
|
|
|
char* popis_chyby = calloc(100, sizeof(char));
|
|
|
|
int chyba = wolfSSL_get_error(ssl, 0);
|
|
|
|
wolfSSL_ERR_error_string(chyba, popis_chyby);
|
|
|
|
fprintf(stderr, "Nastala chyba v spojeni.\nCislo chyby: %d\nDovod chyby: %s\n", chyba, popis_chyby);
|
|
|
|
printf("Skontrolujte certifikaty.\n");
|
2020-04-16 09:25:05 +00:00
|
|
|
free(popis_chyby);
|
2020-04-07 20:11:21 +00:00
|
|
|
return -1;
|
2020-03-11 21:01:54 +00:00
|
|
|
}
|
2020-04-07 20:11:21 +00:00
|
|
|
zobraz_sifru(ssl);
|
|
|
|
zobraz_certifikat(ssl);
|
2020-04-16 09:25:05 +00:00
|
|
|
nastav_funkciu(&nastavenia, "crc", ziadna);
|
|
|
|
prijat_subor(ssl, ctx, &nastavenia);
|
|
|
|
|
|
|
|
//ukoncenie spojenia, vymazanie komunikacneho suboru
|
|
|
|
//a vycistenie serioveho buffera
|
2020-04-07 20:11:21 +00:00
|
|
|
ukoncit_spojenie(ssl, ctx);
|
2020-04-16 09:25:05 +00:00
|
|
|
RS232_flushRXTX(cislo_rozhrania);
|
2020-03-30 01:32:44 +00:00
|
|
|
RS232_CloseComport(cislo_rozhrania);
|
2020-04-07 20:11:21 +00:00
|
|
|
close(rs232_prijat);
|
2020-04-16 09:25:05 +00:00
|
|
|
fclose(fopen(KOMUNIKACNY_SUBOR, "wb"));
|
2020-03-11 21:01:54 +00:00
|
|
|
return 0;
|
2020-04-16 09:25:05 +00:00
|
|
|
}
|