aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2023-01-10 13:38:16 +0100
committerFranciszek Malinka <franciszek.malinka@gmail.com>2023-01-10 13:38:16 +0100
commit7aa692ac8dc64b6c86d3f172909183d31a67c83b (patch)
tree0084e1dd6b76998a7f63c38a43a067028cba73f4
parenta31e673136786de2e3efc1b51c1ba911f306982a (diff)
update
-rw-r--r--semestr1/frontend/lista3/index.html2
-rw-r--r--semestr1/frontend/lista3/styles.css130
-rw-r--r--semestr1/od/lista6/serwer/Makefile2
-rw-r--r--semestr1/od/lista6/serwer/client.c109
-rw-r--r--semestr1/od/lista6/serwer/server.c13
5 files changed, 226 insertions, 30 deletions
diff --git a/semestr1/frontend/lista3/index.html b/semestr1/frontend/lista3/index.html
index 315d4f8..ea482ef 100644
--- a/semestr1/frontend/lista3/index.html
+++ b/semestr1/frontend/lista3/index.html
@@ -194,7 +194,7 @@
<img
src="./img/dog8.jpeg"
alt="forth gallery item"
- class="gallery__image gallery__forth_item"
+ class="gallery__image gallery__fourth_item"
/>
</div>
</section>
diff --git a/semestr1/frontend/lista3/styles.css b/semestr1/frontend/lista3/styles.css
index 0188404..f41dcf3 100644
--- a/semestr1/frontend/lista3/styles.css
+++ b/semestr1/frontend/lista3/styles.css
@@ -1,11 +1,10 @@
-/* * { */
-/* box-sizing: border-box; */
-/* } */
+html {
+ font-family: Roboto, Arial;
+}
body {
display: flex;
flex-flow: column;
- overflow: scroll;
background-color: #FBF5F5
}
@@ -16,34 +15,143 @@ body {
.main_header {
background-color: white;
- box-shadow: 0px 3px 4px rgba(0, 0, 0, 0.1)
+ box-shadow: 0px 3px 4px rgba(0, 0, 0, 0.1);
}
-.navigation__wrapper {
-
- position: fixed;
+.main_header__header {
+ font-size: 2.5rem;
+ text-align: center;
}
-/* czemu jak to zmienie na .navigation__wrapper to nie dziala? */
.navigation {
will-change: transform;
+ /* czemu jak to zmienie na .navigation__wrapper to nie dziala? */
list-style-type: none;
padding-left: 0;
display: flex;
flex-flow: column;
+ top: 0px;
+ position: sticky;
+}
+
+.content__main h2 {
+ font-size: 1.8rem;
+ text-align: center;
+}
+
+.content__main h3 {
+ font-size: 1.5rem;
}
.navigation__link {
height: 4rem;
padding-left: 2rem;
padding-right: 2rem;
- align-items:center;
- justify-content: center;
+ align-items: center;
display: flex;
color: black;
text-decoration: none;
+ font-size: 1.5rem;
}
.navigation__link:hover {
background-color: rgba(0,0,0,0.1);
}
+
+.content__main {
+ background-color: #ECECF7;
+ padding: 2rem;
+}
+
+.article {
+ clear: both;
+}
+
+.figure__caption {
+ font-size: 0.8rem;
+ text-align: center;
+}
+
+.figure {
+ /* margin: 0px; */
+ margin: 8px 20px 8px 20px;
+}
+
+.figure--right {
+ float: right;
+}
+
+.figure--left {
+ float: left;
+}
+
+.warning__wrapper {
+ display: flex;
+ align-items:center;
+ justify-content: center;
+}
+
+.warning__header {
+ text-align: center;
+}
+
+.warning__paragraph {
+ margin: 0px;
+}
+
+.warning__figure {
+ margin-top: 0px;
+ margin-right: 2rem;
+}
+
+.warning {
+ width: 70%;
+ min-width: 500px;
+ background-color: #F4C5B7;
+ border: 3px solid #FAF9F8;
+ border-radius: 20px;
+ overflow: auto;
+}
+
+.gallery__wrapper {
+ display: grid;
+ gap: 1rem;
+ grid-template-columns: repeat(3, 1fr);
+}
+
+.gallery__image {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+
+}
+
+.gallery__first_item {
+ grid-column: 1;
+ grid-row: 1 / 3;
+}
+
+.gallery__second_item {
+ grid-column: 2;
+ grid-row: 1;
+}
+
+.gallery__third_item {
+ grid-column: -3 / -1;
+ grid-row: 2;
+}
+
+.gallery__fourth_item {
+ grid-column: -2;
+ grid-row: 1;
+}
+
+.footer {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-flow: column;
+ height: 7rem;
+ border-top: 1px solid black;
+ font-size: 0.7rem;
+}
diff --git a/semestr1/od/lista6/serwer/Makefile b/semestr1/od/lista6/serwer/Makefile
index 8dc752a..d796ee2 100644
--- a/semestr1/od/lista6/serwer/Makefile
+++ b/semestr1/od/lista6/serwer/Makefile
@@ -1,5 +1,5 @@
CC = gcc
-CFLAGS = -O2
+CFLAGS = -Og
LDFLAGS = -lpthread -lreadline
LIBS = libs2n.a libssl.a libtls.a libcrypto.a
diff --git a/semestr1/od/lista6/serwer/client.c b/semestr1/od/lista6/serwer/client.c
index 5d137d7..b471510 100644
--- a/semestr1/od/lista6/serwer/client.c
+++ b/semestr1/od/lista6/serwer/client.c
@@ -72,55 +72,143 @@ int open_clientfd(const char *hostname, const char *port) {
return clientfd;
}
-void start_client(const char *host, const char* port, int use_tls) {
+void initialize_tls(
+ int sock,
+ struct s2n_config *config,
+ struct s2n_connection *conn,
+ const char *cert_file,
+ const char* host) {
+ s2n_blocked_status blocked;
+
+ S2N_GUARD(s2n_init(), "s2n_init error");
+ config = s2n_config_new();
+ S2N_GUARD(s2n_config_wipe_trust_store(config),
+ "s2n_config_wipe_trust_store error");
+ if (cert_file) {
+ fprintf(stderr, "%s\n", cert_file);
+ S2N_GUARD(s2n_config_set_verification_ca_location(config, cert_file, NULL),
+ "s2n_config_add_pem_to_trust_store error");
+ }
+ else {
+ fprintf(stderr, "WARNING, running in insecure mode\n");
+ S2N_GUARD(s2n_config_disable_x509_verification(config),
+ "s2n_config_disable_x509_verification");
+ }
+ // S2N_GUARD(s2n_config_set_send_buffer_size(config, MAX_BUF),
+ // "s2n_config_set_send_buffer_size error");
+
+ conn = s2n_connection_new(S2N_CLIENT);
+ if (conn == NULL) {
+ s2n_errx(EXIT_FAILURE, "s2n_connection_new error");
+ }
+
+ S2N_GUARD(s2n_connection_set_config(conn, config),
+ "s2n_connection_set_config error");
+ S2N_GUARD(s2n_set_server_name(conn, host), "s2n_set_server_name error");
+ S2N_GUARD(s2n_connection_set_fd(conn, sock), "s2n_connection_set_fd error");
+ S2N_GUARD(s2n_connection_set_client_auth_type(conn, S2N_CERT_AUTH_OPTIONAL),
+ "s2n_connection_set_client_auth_type error");
+ S2N_GUARD(s2n_negotiate(conn, &blocked), "s2n_negotiate error");
+ S2N_GUARD(s2n_connection_free_handshake(conn),
+ "s2n_connection_free_handshake error");
+}
+
+void print_hex(const char *buf, size_t len) {
+ printf("%lu: ", len);
+ for (int i = 0; i < len; i++) {
+ printf("%02X ", buf[i]);
+ }
+ printf("\n");
+}
+
+void start_client(
+ const char *host,
+ const char* port,
+ const char *cert_file,
+ int use_tls) {
struct sockaddr_in sa;
+ struct s2n_config *config;
+ struct s2n_connection *conn;
+ s2n_blocked_status blocked;
char *input;
char buf[MAX_BUF];
int sock;
ssize_t len;
GUARD(inet_pton(AF_INET, host, &(sa.sin_addr)), "inet_pton error");
+
sock = open_clientfd(host, port);
+ if (use_tls) {
+ initialize_tls(sock, config, conn, cert_file, host);
+ }
+
+ fprintf(stderr, "Connected to %s:%s\n", host, port);
+
while((input = readline(">>> ")) != NULL) {
if (!strlen(input)) {
- GUARD(send(sock, "\r\n", 2, 0), "send error");
+ if (use_tls) {
+ S2N_GUARD(s2n_send(conn, "\r\n", 2, &blocked), "s2n_send error");
+ }
+ else {
+ GUARD(send(sock, "\r\n", 2, 0), "send error");
+ }
}
add_history(input);
input = realloc(input, strlen(input) + 5);
strcat(input, "\r\n");
- GUARD(send(sock, input, strlen(input), 0), "send error");
- GUARD(len = recv(sock, buf, MAX_BUF, 0), "recv error");
+ // printf("Trying to send: ");
+ // print_hex(input, strlen(input));
+
+ if (use_tls) {
+ S2N_GUARD(s2n_send(conn, input, strlen(input), &blocked),
+ "s2n_send error");
+ S2N_GUARD(len = s2n_recv(conn, buf, MAX_BUF, &blocked),
+ "s2n_recv error");
+ }
+ else {
+ GUARD(send(sock, input, strlen(input), 0), "send error");
+ GUARD(len = recv(sock, buf, MAX_BUF, 0), "recv error");
+ }
+
buf[len] = '\0';
- printf("%s", buf);
+ // print_hex(buf, len);
+ printf("%s\n", buf);
free(input);
}
+ if (use_tls) {
+ s2n_shutdown(conn, &blocked);
+ s2n_connection_free(conn);
+ }
+
close(sock);
}
int main(int argc, char* argv[]) {
char *port = NULL;
char *host = "0.0.0.0";
+ char *cert = NULL;
int use_tls = 0;
char c;
- while ((c = getopt(argc, argv, "sh:p:")) != -1) {
+ while ((c = getopt(argc, argv, "sh:p:c:")) != -1) {
switch (c) {
case 'p':
port = optarg;
break;
case 's':
- fprintf(stderr, "TLS not implemented yet\n");
- exit(EXIT_FAILURE);
use_tls = 1;
break;
case 'h':
host = optarg;
break;
+ case 'c':
+ cert = optarg;
+ break;
case '?':
- if (optopt == 'p' || optopt == 'h') {
+ if (optopt == 'c' || optopt == 'p' || optopt == 'h') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else if (isprint(optopt)) {
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
@@ -135,9 +223,10 @@ int main(int argc, char* argv[]) {
}
}
+
if (port == NULL) {
port = use_tls ? DEFAULT_TLS_PORT : DEFAULT_PORT;
}
- start_client(host, port, use_tls);
+ start_client(host, port, cert, use_tls);
}
diff --git a/semestr1/od/lista6/serwer/server.c b/semestr1/od/lista6/serwer/server.c
index 5303518..bf54758 100644
--- a/semestr1/od/lista6/serwer/server.c
+++ b/semestr1/od/lista6/serwer/server.c
@@ -1,4 +1,4 @@
-/* Copywright Franciszek Malinka 2022 */
+/* Copyright Franciszek Malinka 2022 */
#include <stdio.h>
#include <ctype.h>
@@ -22,7 +22,7 @@
#define MAX_BUF 65535
#define errx(err, msg) { \
- fprintf(stderr, msg ": %s", strerror(errno)); \
+ fprintf(stderr, msg ": %s\n", strerror(errno)); \
exit(err); \
}
@@ -32,7 +32,7 @@
}
#define s2n_errx(err, msg) { \
- fprintf(stderr, msg ": %s", s2n_strerror(s2n_errno, "EN")); \
+ fprintf(stderr, msg ": %s\n", s2n_strerror(s2n_errno, "EN")); \
exit(err); \
}
@@ -155,7 +155,7 @@ static _Noreturn void worker(int sock) {
break;
}
- reverse(line_start, line_end - 2);
+ reverse(line_start, line_end - 3);
if (send(sock, line_start, line_end-line_start, 0) < 0) {
errx(EXIT_FAILURE, "Send error");
}
@@ -193,6 +193,7 @@ static _Noreturn void tls_worker(int sock, struct s2n_config *config) {
S2N_GUARD(s2n_connection_free_handshake(conn),
"s2n_connection_free_handshake error");
+ fprintf(stderr, "%u: negotiated connection\n", getpid());
while (connection_up) {
S2N_GUARD(cur_len = s2n_recv(conn, buf + read_len, max_len - cur_len, &blocked),
"s2n_recv error");
@@ -212,15 +213,13 @@ static _Noreturn void tls_worker(int sock, struct s2n_config *config) {
reverse(line_start, line_end - 2);
S2N_GUARD(s2n_send(conn, line_start, line_end-line_start, &blocked), "s2n_send error");
- if (s2n_send(conn, line_start, line_end-line_start, &blocked) < 0) {
- s2n_errx(EXIT_FAILURE, "Send error");
- }
read_len -= (line_end - line_start);
line_start = line_end;
}
memmove(buf, line_start, read_len);
}
+ fprintf(stderr, "%u: shutting down.\n", getpid());
s2n_shutdown(conn, &blocked);
s2n_connection_free(conn);