107 lines
2.4 KiB
C
107 lines
2.4 KiB
C
//////////////////////////////////////////////////
|
|
// Bakalarska praca //
|
|
// Meno studenta: Tomas Lukac //
|
|
// Veduci BP: prof. Ing. Milos Drutarovsky CSc. //
|
|
// Skola: KEMT FEI TUKE //
|
|
// Datum poslednej upravy: 12.3.2020 //
|
|
//////////////////////////////////////////////////
|
|
|
|
#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>
|
|
#include <io.h>
|
|
#include <fcntl.h>
|
|
#define O_NOCTTY 0
|
|
#else
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include "../kniznica/kryptografia.h"
|
|
#include "../kniznica/komunikacia.h"
|
|
#include "../kniznica/rs232.h"
|
|
|
|
int rs232_poslat;
|
|
int rs232_prijat;
|
|
|
|
int rs232_citanie(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
|
{
|
|
int uspech = 0;
|
|
while(uspech <= 0)
|
|
{
|
|
uspech = read(rs232_prijat, buf, sz);
|
|
}
|
|
return uspech;
|
|
}
|
|
|
|
int rs232_zapis(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
|
{
|
|
int uspech = 0;
|
|
uspech = write(rs232_poslat, buf, sz);
|
|
return uspech;
|
|
}
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
WOLFSSL *ssl;
|
|
WOLFSSL_CTX *ctx = NULL;
|
|
int cislo_rozhrania = 5;
|
|
int rychlost = 9600;
|
|
char rezim[]={'8','N','1', 0};
|
|
|
|
rs232_poslat = open("klient.txt", O_WRONLY | O_NOCTTY);
|
|
printf("%d\n", rs232_poslat);
|
|
rs232_prijat = open("server.txt", O_RDONLY | O_NOCTTY);
|
|
printf("%d\n", rs232_prijat);
|
|
|
|
|
|
int uspech;
|
|
/* uspech = rs232_otvorit_rozhranie(cislo_rozhrania, rychlost, rezim, 0);
|
|
if(uspech == -1)
|
|
{
|
|
return -1;
|
|
}
|
|
*/
|
|
if((ctx = nastavit_ctx_server()) == NULL)
|
|
{
|
|
return -1;
|
|
}
|
|
const char* subor_certifikat = "../certifikaty/server/server_rsa.pem";
|
|
const char* subor_kluc = "../certifikaty/server/server_rsa.key";
|
|
if(nacitat_certifikaty(ctx, subor_certifikat, subor_kluc) == -1) 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, rs232_prijat);
|
|
wolfSSL_set_using_nonblock(ssl, rs232_prijat);
|
|
|
|
printf("bol som tu\n");
|
|
while(uspech != SSL_SUCCESS)
|
|
{
|
|
uspech = wolfSSL_accept(ssl);
|
|
printf("%d\n", uspech);
|
|
}
|
|
printf("bol som aj tu tu\n");
|
|
|
|
|
|
char sprava[100];
|
|
wolfSSL_read(ssl, sprava, 10);
|
|
printf("%s\n", sprava);
|
|
|
|
RS232_CloseComport(cislo_rozhrania);
|
|
|
|
return 0;
|
|
}
|