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-03-12 16:22:08 +00:00
|
|
|
// Datum poslednej upravy: 12.3.2020 //
|
2020-03-11 21:01:54 +00:00
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wolfssl/wolfcrypt/settings.h>
|
|
|
|
#include <wolfssl/ssl.h>
|
|
|
|
#include <wolfssl/certs_test.h>
|
|
|
|
#include <wolfssl/wolfcrypt/types.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../kniznica/kryptografia.h"
|
|
|
|
#include "../kniznica/rs232.h"
|
|
|
|
|
|
|
|
int cislo_portu = 2;
|
|
|
|
int baud_frekvencia = 9600;
|
|
|
|
char rezim[]={'8','N','1', 0};
|
|
|
|
|
|
|
|
int main(int argc, char const *argv[])
|
|
|
|
{
|
|
|
|
WOLFSSL *ssl;
|
|
|
|
WOLFSSL_CTX *ctx = NULL;
|
|
|
|
|
|
|
|
if(RS232_OpenComport(cislo_portu, baud_frekvencia, rezim, 1))
|
|
|
|
{
|
|
|
|
printf("Nebolo mozne otvorit serialovy port\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ctx = nastavit_ctx_klient()) == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
const char* subor_certifikat = "../certifikaty/klient.pem";
|
|
|
|
const char* subor_kluc = "../certifikaty/klient.key";
|
|
|
|
if(!nacitat_certifikaty(ctx, subor_certifikat, subor_kluc)) return -1;
|
|
|
|
|
|
|
|
wolfSSL_SetIOSend(ctx, rs232_zapis);
|
|
|
|
wolfSSL_SetIORecv(ctx, rs232_citanie);
|
|
|
|
|
|
|
|
|
|
|
|
if ((ssl = wolfSSL_new(ctx)) == NULL)
|
|
|
|
{
|
|
|
|
printf("Nepodarilo sa vytvorit ssl relaciu\n");
|
|
|
|
wolfSSL_CTX_free(ctx);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wolfSSL_set_fd(ssl, *(int*)ctx);
|
|
|
|
wolfSSL_set_using_nonblock(ssl, *(int*)ctx);
|
|
|
|
|
|
|
|
int uspech = 0;
|
|
|
|
if(wolfSSL_connect(ssl) != SSL_SUCCESS)
|
|
|
|
{
|
2020-03-13 09:25:19 +00:00
|
|
|
printf("Nepodarilo sa pripojit%d\n", uspech);
|
2020-03-11 21:01:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
RS232_CloseComport(cislo_portu);
|
|
|
|
return 0;
|
|
|
|
}
|