////////////////////////////////////////////////// // Bakalarska praca // // Meno studenta: Tomas Lukac // // Veduci BP: prof. Ing. Milos Drutarovsky CSc. // // Skola: KEMT FEI TUKE // // Datum poslednej upravy: 12.3.2020 // ////////////////////////////////////////////////// #include #include #include #include #include #include #ifdef _WIN32 #include #include #include #define O_NOCTTY 0 #else #include #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) { (void)ssl; (void)ctx; int uspech = 0; while(uspech <= 0) { uspech = (int)read(rs232_prijat, buf, (size_t)sz); } return uspech; } int rs232_zapis(WOLFSSL *ssl, char *buf, int sz, void *ctx) { (void)ssl; (void)ctx; int uspech = 0; uspech = (int) write(rs232_poslat, buf, (size_t)sz); return uspech; } int main(int argc, char const *argv[]) { char rezim[]={'8','N','1', 0}; int cislo_rozhrania = 4; int rychlost = 9600; WOLFSSL *ssl; WOLFSSL_CTX *ctx = NULL; rs232_poslat = open("server.txt", O_WRONLY | O_NOCTTY); rs232_prijat = open("klient.txt", O_RDONLY | O_NOCTTY); int uspech; /* uspech = rs232_otvorit_rozhranie(cislo_rozhrania, rychlost, rezim, 0); if(uspech == -1) { return -1; }*/ if((ctx = nastavit_ctx_klient()) == NULL) { return -1; } const char* subor_certifikat = "../certifikaty/klient/klient_rsa.pem"; const char* subor_kluc = "../certifikaty/klient/klient_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_connect(ssl); printf("bol sss\n"); if(uspech != SSL_SUCCESS) { printf("Nepodarilo sa pripojit%d\n", uspech); return -1; } else { printf("oukej\n"); } } printf("bol som aj tu tu\n"); wolfSSL_write(ssl, "nieco", 10); RS232_CloseComport(cislo_rozhrania); return 0; }