Compare commits

..

144 Commits

Author SHA1 Message Date
e34f92b0d8
renamed WHY2_CHAT_COMMAND_PM to WHY2_CHAT_COMMAND_DM
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 14s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m49s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m6s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m12s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m24s
these will be direct messages - unencrypted communication between two users
2025-01-30 21:20:59 +01:00
6f773bcecf
replaced RSA comment with ECC 2025-01-30 20:23:21 +01:00
c1e7aba879
defined why2_chat_ecc_verify_signature
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 10s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m45s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 1m42s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m18s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m28s
one commit, 8 hours of going crazy together with AI
2025-01-30 20:07:19 +01:00
ac88620d99
added key parameter to why2_chat_ecc_verify_signature declaration 2025-01-30 20:06:20 +01:00
c8d197f6b9
returning length in base64_decode 2025-01-30 19:58:44 +01:00
210d23369b
implemented base64 delimiter 2025-01-30 19:38:47 +01:00
b859c88dcc
declared why2_chat_ecc_verify_signature 2025-01-30 19:38:02 +01:00
7c2c8b9138
created WHY2_CHAT_BASE64_LENGTH_DELIMITER macro 2025-01-30 19:37:49 +01:00
d764002546
added base64_decode fn
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 22s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m56s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m17s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m16s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m29s
and tweaked the encode fn a bit
2025-01-29 22:44:46 +01:00
685b8e446e
defined why2_chat_ecc_sign
and its not working as expected lol

i will fix it in next commits, i just need this for change comparison
2025-01-29 21:15:24 +01:00
0b3cb2f957
added local base64_encode fn 2025-01-29 21:14:39 +01:00
5cc8c43b62
declared why2_chat_ecc_sign
used for signing message with ECC
2025-01-29 21:13:59 +01:00
8d17915a05
generating only one keyfile
lol ima stoopid - it seems you need only private key file and you can generate the pub from it
2025-01-29 20:52:16 +01:00
b977d0dd40
removed unused key macro
and renamed the key file
2025-01-29 20:50:54 +01:00
8b7aa98b70
removed GMP dependency
All checks were successful
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m26s
Codacy Scan / Codacy Security Scan (push) Successful in 3m50s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m58s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m8s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 4m56s
2025-01-29 16:35:45 +01:00
eff50818ea
added code for ecc keypair generation
also removed unused rsa shit
2025-01-29 16:35:02 +01:00
b833b56aef
changed up crypto header for ECC update
ill replace rsa with ecc i guess. Why? i fucking hate myself
2025-01-29 16:33:57 +01:00
94969b5588
removed the stupid goto another way
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 11s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m48s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 1m50s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m33s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m43s
simply deleted it lol - i have no clue why i used the MSG_PEEK in the first place tho
2025-01-25 12:19:13 +01:00
99695875b1
revert "got rid of the dumbass goto in read_socket_raw"
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 6s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m53s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m3s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m13s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m25s
this reverts commit 37a615cb03f1f891c4e31fc54ead028db5a0ebf9

"and possibly created 10 new problems :))" ....... fuck me
2025-01-25 11:27:39 +01:00
56672a3cfd
fixed distro ifs case
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 5s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m43s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 1m50s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m24s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m35s
moo
2025-01-25 10:50:52 +01:00
6eeddbd14e
replaced lsb_release with os-release file
Some checks failed
Codacy Scan / Codacy Security Scan (push) Successful in 7s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 37s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 50s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 53s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Failing after 50s
also supporting X-based distributions
2025-01-25 10:45:35 +01:00
17a73d9157
implemented anon flags in logger
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 1m45s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 3m42s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m41s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m11s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m24s
2025-01-13 19:55:54 +01:00
520f8bce34
created anon fns for core-flags changed vars
calling sets flag without changing flag_changed variable
2025-01-13 19:54:44 +01:00
9e5016feb7
defined why2_get_padding_changed
and guess what it returns
2025-01-13 19:46:00 +01:00
59d6252fe3
declared why2_get_padding_changed fn 2025-01-13 19:45:19 +01:00
64f54fadce
added padding_changed to core-flags 2025-01-13 19:44:39 +01:00
4451b848f7
changed weird variable names in core-flags 2025-01-13 19:42:05 +01:00
917b466b11
replacing \n with space in logger
instead of null-term and breaking the string
2025-01-13 19:22:53 +01:00
0fe3f47752
added why2_set_padding fn
sets padding without messing with flags
2025-01-12 13:12:50 +01:00
d3aa932bdc
defined seeded-rand fns using hmac
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 33s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m36s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m31s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m2s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m14s
2025-01-12 11:07:58 +01:00
e34b8b962f
changed why2_seed_random's seed to UL 2025-01-12 11:07:11 +01:00
25782d1263
changed why2_random to boolean 2025-01-10 18:09:55 +01:00
fc2d3e1360
using openssl random in why2_random 2025-01-10 18:09:36 +01:00
023e201ac7
implemented seeded-rand fns in padding code 2025-01-10 17:56:34 +01:00
e363eccc59
defined seeded-rand fns 2025-01-10 17:55:45 +01:00
25113dc0b3
declared seeded-rand fns in crypto 2025-01-10 17:54:27 +01:00
3afe9f0d4c
moved codacy workflow check to every step
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 11s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m37s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m39s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m7s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m20s
crazy
2025-01-09 20:00:47 +01:00
24e5d1b8c2
checking bramborak secret on codacy start instead
All checks were successful
Codacy Scan / Codacy Security Scan (push) Has been skipped
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m19s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m20s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m52s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m4s
2025-01-09 19:56:20 +01:00
fba541d354
checking GITHUB_ACTIONS envvar on codacy start
All checks were successful
Codacy Scan / Codacy Security Scan (push) Has been skipped
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m28s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m25s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m54s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m7s
2025-01-09 19:51:31 +01:00
c5bcf99ffc
revert "created workflow symlinks for gitea actions"
this reverts commit 1edf24eefec59de8c58c35ce569532ed4ed1c48d
2025-01-09 19:45:05 +01:00
1edf24eefe
created workflow symlinks for gitea actions 2025-01-09 19:41:43 +01:00
a2c20439db
actually running codacy workflow only under github
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m28s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m46s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m54s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m15s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m27s
NOT GITEA FOR FUCK SAKE
2025-01-09 19:36:58 +01:00
90ac513be1
replaced GDB variable with duplicate code in gitlab-ci
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m48s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m3s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 3m11s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m38s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m52s
fuck gitlab
2025-01-09 19:32:26 +01:00
b2b2d95624
codacy workflow syntax fix 2025-01-09 19:27:51 +01:00
c5cd5a2d13
trying to fix gitlab-ci variables bug
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 1s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m31s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m28s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m4s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m16s
2025-01-09 19:26:52 +01:00
9b9ac32a70
only running codacy workflow on github 2025-01-09 19:20:37 +01:00
e4bb7eb1f2
invalid gitlab-ci syntax fix #2
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 3m14s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 4m3s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 4m9s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m41s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 4m56s
2025-01-09 19:09:33 +01:00
25561ca800
invalid gitlab-ci syntax fix
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m20s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m59s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m9s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m43s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m55s
2025-01-09 19:04:04 +01:00
44ce767709
applied workflow changes to gitlab-ci
Some checks failed
Codacy Scan / Codacy Security Scan (push) Has been cancelled
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Has been cancelled
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Has been cancelled
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Has been cancelled
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Has been cancelled
2025-01-09 19:01:58 +01:00
f903d265d9
using upload-artifact v3 instead of v4
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m25s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m56s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m54s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m31s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m43s
trying to make gitea artifacts work is pain in ass
2025-01-09 18:49:20 +01:00
7fc146f745
improved performance of tkch-gen a bit
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m57s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m55s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 3m2s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m26s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Has been cancelled
2025-01-09 18:45:44 +01:00
806cdc62c6
using padding in logger app 2025-01-09 18:42:31 +01:00
d6658a8e4f
removed padding error todo 2025-01-09 18:39:57 +01:00
854ec1259d
pimped out the WHY2_v4 tkch-gen a bit
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 3m12s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m16s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 3m24s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m39s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 3m56s
good luck
2025-01-09 18:23:57 +01:00
119899f714
added gitea to MIRRORS
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 1m58s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 2m29s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m25s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m54s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 3m7s
2025-01-09 16:26:26 +01:00
67d6dfd0e7
raised curl timeout to 10 2025-01-09 16:25:05 +01:00
e537f385e4
creating .config dir if needed
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 1m57s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 3m26s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 3m23s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 3m50s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 4m34s
stupid gitea
2025-01-09 16:19:03 +01:00
0a7e9ecee7
created WHY2_USER_CONFIG_DIR macro
stupid gitea runner making me do shit
2025-01-09 16:15:55 +01:00
d60401a181
added curl error printing to check_version
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m17s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 2m57s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m55s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 3m22s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 3m24s
2025-01-09 16:01:44 +01:00
4f2741b2ad
installing gdb in project workflow 2025-01-09 15:48:21 +01:00
d58374232a
running workflow file tests in gdb
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m31s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Failing after 2m23s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 3m24s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 3m30s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 4m12s
2025-01-09 15:42:14 +01:00
4244d2687e
using absolute paths in workflow 2025-01-09 15:41:47 +01:00
2758a32bb8
replaced debian-based nss-curl with openssl-curl
Some checks failed
Codacy Scan / Codacy Security Scan (push) Has been cancelled
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m33s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m42s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m45s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 1m26s
2025-01-09 15:21:07 +01:00
360d581084
replaced apt usage with apt-get
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 5m2s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m41s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m36s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m33s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 1m0s
No money, no girls, denied

Can you fuckin’ believe it?

Oh, oh, oh, oh, oh
2025-01-09 15:08:34 +01:00
ee6840ecfb
using non-interactive apt frontend
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 4m10s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 2m17s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m28s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m24s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 1m31s
2025-01-08 18:56:07 +01:00
9feca42ec5
fixed bs in workflows
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 1m22s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m13s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m0s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 4m48s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m9s
2025-01-08 18:01:54 +01:00
f8892b03bf
moved rust-toolchain to WHY2 install step
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m8s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 0s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 0s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 0s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 0s
2025-01-08 17:55:06 +01:00
be94830e84
added rust-toolchain to github workflows
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 1m43s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 0s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 0s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 0s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 0s
2025-01-08 17:52:25 +01:00
f1ebb2b6f7
revert "sourcing cargo env before running rules"
this reverts commit ad75a52e962d5e50d961090c1a0d5d70eb43672a.
2025-01-08 17:42:07 +01:00
ad75a52e96
sourcing cargo env before running rules
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m8s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 53s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 56s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 54s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 49s
2025-01-08 17:19:28 +01:00
a52031ad52
removed exit from anti-root check in makefile
Some checks failed
Codacy Scan / Codacy Security Scan (push) Failing after 2m5s
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m33s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m8s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m4s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 1m6s
2025-01-08 17:11:43 +01:00
c72eb44ab0 corrected output path in make
Some checks failed
Build WHY2-chat / test-why2 (./out/why2-chat-client, configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m19s
Test WHY2-core / test-why2 (why2, configure.sh, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 59s
Test WHY2-logger / test-why2 (why2-logger, configure.sh, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 59s
Test Project / test-project (configure.sh, ubuntu-latest, test) (push) Failing after 1m2s
Codacy Scan / Codacy Security Scan (push) Failing after 2m31s
2024-12-26 11:49:24 +00:00
0aed96415c
added todo to encrypter padding 2024-11-21 21:13:43 +01:00
3a62ed36e7
ignoring .gdbinit file 2024-11-21 21:08:47 +01:00
222f55587f
implemented WHY2_RECOMMENDED_PADDING_RATE in core-test input_flags 2024-11-21 21:05:28 +01:00
cf277b249f
created WHY2_RECOMMENDED_PADDING_RATE macro
basically padding every 3 chars
2024-11-21 21:04:52 +01:00
1027042edf
added core-crypto to why2 header 2024-11-21 21:03:52 +01:00
812e31f429
preventing modulating by 0 in tkch 2024-11-21 21:00:52 +01:00
6a3f005321
implemented padding in decrypter
FUCKKKKK remember how I mentioned that creating padding in encrypter was pain? This, compared to the encrypter is like getting stuck up your ass and getting it shaked by a fucking gorilla compared to stepping on a lego brick. FUCK.
2024-11-21 20:56:18 +01:00
126565cf97
preventing padding char from being 0 2024-11-21 20:53:06 +01:00
326f8f0768
created WHY2_PADDING_NONZERO_TRIES macro
when I try to generate random number, I need to prevent it from being zero, so I try this many times to be non-zero before I forcefully set it to 1

this should run few times but yk, theoretically the generated number can be the same for infinite time (or at least slow the performance :) )
2024-11-21 20:50:20 +01:00
7dcbd4fc80
created why2_list_reverse fn in llist
it reverses list you dipstick
2024-11-21 17:59:15 +01:00
90643d8247
created why2_list_remove_at in llist
removes element by index
2024-11-21 17:20:47 +01:00
38f814ac9c
implemented why2_list_push_at in encrypter paddding 2024-11-21 17:13:16 +01:00
98cc5b83b8
using why2-memory in why2-llist 2024-11-21 17:11:55 +01:00
994a2a8c4f
fixed memory leak in encrypter padding 2024-11-21 17:11:17 +01:00
c5394e63e5
created why2_recalloc fn in memory
deallocates and callocs
2024-11-21 16:52:06 +01:00
0e246be627
created why2_list_push_at fn in llist
pushes to specific position
2024-11-21 16:49:27 +01:00
08181e5f19
renamed decrypter's key_new to key
haha same shit
2024-11-20 21:45:45 +01:00
1aab7bf996
created padding in encrypter
lot of pain
2024-11-20 21:41:21 +01:00
5cc04d94b7
renamed encrypter's key_new to key
haha stupid old me was lazy af
2024-11-20 21:40:48 +01:00
f95608f52a
moved key's random number generation to why2_random fn 2024-11-20 17:56:04 +01:00
5b06ea5dc1
changed padding flag to UL 2024-11-20 17:12:54 +01:00
f754e43e19
made sum_segment comments more explanatory 2024-11-20 17:10:39 +01:00
6e7cdde99d
changed why2_sum_segment datatype to ULL
just in case
2024-11-20 16:33:22 +01:00
10fe26cca1
using rolling-hash-like way to count why2_sum_segment 2024-11-20 16:32:13 +01:00
b50305f080
created mod & base primes macros 2024-11-20 16:27:48 +01:00
e0274ec6c1
incread segment_size to 32 2024-11-20 16:24:21 +01:00
c0e9381642
renamed why2_checksum_segment to why2_sum_segment
it isn't that safe to be considered a checksum and the name checksum can be misleading. i am going to use it for getting padding size
2024-11-20 16:19:59 +01:00
c71b5275b5
changed checksum prime/segment ratio 2024-11-19 22:54:38 +01:00
5833502c7a
added checksum warning 2024-11-19 22:30:18 +01:00
7638881217
created why2_checksum_segment fn
it isn't meant to be unique checksum. it just really messses with the range of values
2024-11-19 22:29:07 +01:00
2f6ab00f93
defined WHY2_CHECKSUM_PRIME macro 2024-11-19 22:28:10 +01:00
fb2ac1a7bb
moved checksum stuff to core-crypto
also created the core-crypto
2024-11-19 21:57:29 +01:00
f3bd52b674
declared why2_checksum_segment 2024-11-19 21:39:34 +01:00
ceefd7ed98
removed constant modificator from padding rate 2024-11-19 21:17:39 +01:00
d0e6d794e0
implemented padding rate in all why2_input_flags usages 2024-11-19 21:12:02 +01:00
10edcdeccf
added padding parameter to why2_input_flags 2024-11-19 21:05:33 +01:00
d14f9adaf4
simplified stupid code in tkch_gen
damn old me was really dumb
2024-11-19 20:51:33 +01:00
035928456e
fixed possible WHY2_v4 security problem 2024-11-19 20:48:08 +01:00
5f1b5e2f92
added err todo about client password input 2024-11-17 22:35:56 +01:00
8569003872
not echoing password on prompt 2024-11-17 22:35:04 +01:00
d23c166fc6
preventing segfault when user doesn't have homedir in /home 2024-11-17 22:19:42 +01:00
a7523a64a2
removed 'unused' code from decrypter
dear god, I hate you from the bottom of my heart, but, please do not break my code by removing this code. i have no fucking idea what it does and how it got there. if you'll protect my code stability, I will do absolutely nothing. hail satan
2024-11-17 21:18:28 +01:00
ca81c49fdc
added comments to new tkch 2024-11-17 20:58:44 +01:00
1f0c302e17
Merge remote-tracking branch 'refs/remotes/origin/development' into development 2024-11-17 20:55:26 +01:00
f917140ae5
created more secure tkch WHY_v4
good luck with brute forcing now haha
2024-11-17 20:55:13 +01:00
5915f238cd
using master branch of codacy
lol ive been using commit
2024-10-14 08:48:33 +02:00
7790d194cb
added code for logging in 2024-09-02 15:34:46 +02:00
05bd4255e5
simplified toml_read in rust 2024-09-02 15:20:58 +02:00
4ff03864d0
included the rust fn in config header 2024-09-02 15:14:53 +02:00
9e17c9d06d
created rust fn why2_toml_equals
check if key is equal to x
2024-09-02 15:11:24 +02:00
42562013b5
proccessing password hash in client send loop 2024-09-02 15:02:58 +02:00
d6e540d9e7
implemented asking_password in client receive loop 2024-09-02 15:02:42 +02:00
e06a237491
replaced asking_password with boolean 2024-09-01 20:57:29 +02:00
e94a401308
replaced set_asking with increment_asking 2024-09-01 20:51:52 +02:00
357f73ae69
defined asking_password functions 2024-09-01 20:50:46 +02:00
5daf4f2375
declared asking_password functions 2024-09-01 20:49:40 +02:00
70e84980e7
removed unused fns from chat-flags header file 2024-09-01 20:45:39 +02:00
c4fc11063a
created source file for chat-flags 2024-09-01 20:44:57 +02:00
810a34d7c9
removed unused 'unused'
haha you dumb idiot
2024-09-01 20:43:31 +02:00
642ef37016
created sha256 function returning string 2024-09-01 20:40:21 +02:00
b836bf47d7
declared why2_sha256 2024-09-01 20:39:36 +02:00
5b213476d4
using libcrypto in chat build 2024-09-01 20:21:02 +02:00
477ab7342c
added openssl dependency 2024-09-01 20:20:44 +02:00
c51bb609ba
proccesing registration at client-side
it isnt hashed rn, do not use this pls
2024-09-01 20:18:13 +02:00
d6221da442
created server code for registering user 2024-09-01 20:11:23 +02:00
e8d60bc008
actually defined password codes
whoopsie
2024-09-01 20:05:17 +02:00
077ecc50c8
printing command info at connection 2024-09-01 19:59:12 +02:00
1d970b94f8
created max_password_tries entry in config 2024-09-01 19:45:36 +02:00
b54490514a
added password server codes 2024-09-01 19:44:33 +02:00
1011faa67f
allowing spaces in messages 💀 2024-08-31 16:50:41 +02:00
11ddd9c9b9
defined and implemented why2_get_server_users_path 2024-08-31 16:50:16 +02:00
48412cae73
declared why2_get_server_users_path 2024-08-31 16:31:37 +02:00
39 changed files with 945 additions and 337 deletions

View File

@ -25,6 +25,10 @@ on:
permissions: permissions:
contents: read contents: read
env:
bramborak: ${{ secrets.BRAMBORAK }}
jobs: jobs:
codacy-security-scan: codacy-security-scan:
permissions: permissions:
@ -34,11 +38,13 @@ jobs:
name: Codacy Security Scan name: Codacy Security Scan
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - if: env.bramborak == 'ted jsem tam mel jednu slapku' # Ensure this runs only on GitHub
name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Run Codacy Analysis - if: env.bramborak == 'ted jsem tam mel jednu slapku' # Ensure this runs only on GitHub
uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b name: Run Codacy Analysis
uses: codacy/codacy-analysis-cli-action@master
with: with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true verbose: true
@ -47,7 +53,8 @@ jobs:
gh-code-scanning-compat: true gh-code-scanning-compat: true
max-allowed-issues: 2147483647 max-allowed-issues: 2147483647
- name: Upload results file - if: env.bramborak == 'ted jsem tam mel jednu slapku' # Ensure this runs only on GitHub
name: Upload results file
uses: github/codeql-action/upload-sarif@v2 uses: github/codeql-action/upload-sarif@v2
with: with:
sarif_file: results.sarif sarif_file: results.sarif

View File

@ -34,7 +34,7 @@ jobs:
- os: ubuntu-latest - os: ubuntu-latest
client: ./out/why2-chat-client client: ./out/why2-chat-client
server: ./out/why2-chat-server server: ./out/why2-chat-server
configure: configure.sh configure: ./configure.sh
steps: steps:
- name: Checkout repository - name: Checkout repository
@ -45,8 +45,8 @@ jobs:
- if: matrix.os == 'ubuntu-latest' - if: matrix.os == 'ubuntu-latest'
name: Update packages name: Update packages
run: | run: |
sudo apt update sudo apt-get update
# sudo apt upgrade # sudo apt-get upgrade
- name: Permissions - name: Permissions
run: chmod +x ${{ matrix.configure }} run: chmod +x ${{ matrix.configure }}
@ -54,6 +54,9 @@ jobs:
- name: Preparation - name: Preparation
run: sudo ./${{ matrix.configure }} run: sudo ./${{ matrix.configure }}
- name: Set up Rust # Normally works with configure.sh, but gitea has some beef with cargo idk
uses: dtolnay/rust-toolchain@stable
- name: Install WHY2 - name: Install WHY2
run: make install run: make install
@ -61,13 +64,13 @@ jobs:
run: make build_chat run: make build_chat
- name: Upload Client - name: Upload Client
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v3
with: with:
name: WHY2 Chat Client name: WHY2 Chat Client
path: ${{ matrix.client }} path: ${{ matrix.client }}
- name: Upload Server - name: Upload Server
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v3
with: with:
name: WHY2 Chat Server name: WHY2 Chat Server
path: ${{ matrix.server }} path: ${{ matrix.server }}

View File

@ -33,8 +33,9 @@ jobs:
include: include:
- os: ubuntu-latest - os: ubuntu-latest
output: ./out/why2-core-test output: ./out/why2-core-test
gdb: gdb -ex "run" -ex "quit" --batch
valgrind: valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s valgrind: valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s
configure: configure.sh configure: ./configure.sh
app: why2 app: why2
steps: steps:
@ -46,8 +47,8 @@ jobs:
- if: matrix.os == 'ubuntu-latest' - if: matrix.os == 'ubuntu-latest'
name: Update packages name: Update packages
run: | run: |
sudo apt update sudo apt-get update
# sudo apt upgrade # sudo apt-get upgrade
- name: Permissions - name: Permissions
run: chmod +x ${{ matrix.configure }} run: chmod +x ${{ matrix.configure }}
@ -56,7 +57,10 @@ jobs:
run: sudo ./${{ matrix.configure }} run: sudo ./${{ matrix.configure }}
- name: Install Valgrind - name: Install Valgrind
run: sudo apt install valgrind run: sudo apt-get install valgrind -y
- name: Set up Rust # Normally works with configure.sh, but gitea has some beef with cargo idk
uses: dtolnay/rust-toolchain@stable
- name: Install WHY2 - name: Install WHY2
run: make install run: make install
@ -65,10 +69,10 @@ jobs:
run: make test_core run: make test_core
- name: Test Lib - name: Test Lib
run: ./${{ matrix.output }} run: ${{ matrix.gdb }} ${{ matrix.output }}
- name: Test App - name: Test App
run: ${{ matrix.app }} run: ${{ matrix.gdb }} ${{ matrix.app }}
- name: Test Lib by Valgrind - name: Test Lib by Valgrind
run: ${{ matrix.valgrind }} ${{ matrix.output }} run: ${{ matrix.valgrind }} ${{ matrix.output }}

View File

@ -33,7 +33,8 @@ jobs:
include: include:
- os: ubuntu-latest - os: ubuntu-latest
output: ./out/why2-logger-test output: ./out/why2-logger-test
configure: configure.sh gdb: gdb -ex "run" -ex "quit" --batch
configure: ./configure.sh
valgrind: valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s valgrind: valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s
app: why2-logger app: why2-logger
@ -46,8 +47,8 @@ jobs:
- if: matrix.os == 'ubuntu-latest' - if: matrix.os == 'ubuntu-latest'
name: Update packages name: Update packages
run: | run: |
sudo apt update sudo apt-get update
# sudo apt upgrade # sudo apt-get upgrade
- name: Permissions - name: Permissions
run: chmod +x ${{ matrix.configure }} run: chmod +x ${{ matrix.configure }}
@ -56,7 +57,10 @@ jobs:
run: sudo ./${{ matrix.configure }} run: sudo ./${{ matrix.configure }}
- name: Install Valgrind - name: Install Valgrind
run: sudo apt install valgrind run: sudo apt-get install valgrind -y
- name: Set up Rust # Normally works with configure.sh, but gitea has some beef with cargo idk
uses: dtolnay/rust-toolchain@stable
- name: Install WHY2 - name: Install WHY2
run: make install run: make install
@ -65,10 +69,10 @@ jobs:
run: make test_logger run: make test_logger
- name: Test Lib - name: Test Lib
run: ./${{ matrix.output }} run: ${{ matrix.gdb }} ${{ matrix.output }}
- name: Test App - name: Test App
run: ${{ matrix.app }} run: ${{ matrix.gdb }} ${{ matrix.app }}
- name: Test Lib by Valgrind - name: Test Lib by Valgrind
run: ${{ matrix.valgrind }} ${{ matrix.output }} run: ${{ matrix.valgrind }} ${{ matrix.output }}

View File

@ -30,8 +30,9 @@ jobs:
os: [ ubuntu-latest ] os: [ ubuntu-latest ]
include: include:
- os: ubuntu-latest - os: ubuntu-latest
configure: configure.sh gdb: gdb -ex "run" -ex "quit" --batch
test: test configure: ./configure.sh
test: ./test
steps: steps:
- name: Checkout repository - name: Checkout repository
@ -42,16 +43,22 @@ jobs:
- if: matrix.os == 'ubuntu-latest' - if: matrix.os == 'ubuntu-latest'
name: Update packages name: Update packages
run: | run: |
sudo apt update sudo apt-get update
# sudo apt upgrade # sudo apt-get upgrade
- name: Permissions - name: Permissions
run: | run: |
chmod +x ${{ matrix.configure }} chmod +x ${{ matrix.configure }}
- name: Install GDB
run: sudo apt-get install gdb -y
- name: Preparation - name: Preparation
run: sudo ./${{ matrix.configure }} run: sudo ./${{ matrix.configure }}
- name: Set up Rust # Normally works with configure.sh, but gitea has some beef with cargo idk
uses: dtolnay/rust-toolchain@stable
- name: Install WHY2 - name: Install WHY2
run: make install run: make install
@ -62,4 +69,4 @@ jobs:
run: cc ${{ matrix.test }}.c -lwhy2 -Wall -o ${{ matrix.test }} run: cc ${{ matrix.test }}.c -lwhy2 -Wall -o ${{ matrix.test }}
- name: Run test - name: Run test
run: ./${{ matrix.test }} run: ${{ matrix.gdb }} ./${{ matrix.test }}

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ logs/
vgcore.* vgcore.*
target/ target/
Cargo.lock Cargo.lock
.gdbinit

View File

@ -22,15 +22,17 @@ variables:
LOGGER_OUTPUT: "./out/why2-logger-test" LOGGER_OUTPUT: "./out/why2-logger-test"
LOGGER_APP: "why2-logger" LOGGER_APP: "why2-logger"
VALGRIND: "valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s" VALGRIND: "valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s"
CONFIGURE: "./configure.sh"
NEEDED_STUFF: "sudo lsb-release gdb"
why2-chat-build: why2-chat-build:
stage: build stage: build
image: rust:latest # Fixes cargo installation problems in ./configure.sh image: rust:latest # Fixes cargo installation problems in ./configure.sh
script: script:
- apt update # Update repos - apt-get update # Update repos
- apt install sudo lsb-release -y # Install needed stuff - apt-get install $NEEDED_STUFF -y # Install needed stuff
- chmod +x configure.sh # Permissions - chmod +x $CONFIGURE # Permissions
- sudo ./configure.sh # Preparation - sudo $CONFIGURE # Preparation
- make install BYPASS_CHECK=true # Install WHY2 - make install BYPASS_CHECK=true # Install WHY2
- make build_chat # Build Chat - make build_chat # Build Chat
artifacts: artifacts:
@ -42,39 +44,39 @@ why2-core-test:
stage: build stage: build
image: rust:latest image: rust:latest
script: script:
- apt update # Update repos - apt-get update # Update repos
- apt install sudo lsb-release valgrind -y # Install needed stuff - apt-get install $NEEDED_STUFF valgrind -y # Install needed stuff
- chmod +x configure.sh # Permissions - chmod +x $CONFIGURE # Permissions
- sudo ./configure.sh # Preparation - sudo $CONFIGURE # Preparation
- make install BYPASS_CHECK=true # Install WHY2 - make install BYPASS_CHECK=true # Install WHY2
- make test_core # Build WHY2 Test - make test_core # Build WHY2 Test
- ./$CORE_OUTPUT # Test Lib - gdb -ex "run" -ex "quit" --batch $CORE_OUTPUT # Test Lib
- $CORE_APP # Test App - gdb -ex "run" -ex "quit" --batch $CORE_APP # Test App
- $VALGRIND $CORE_OUTPUT # Test Lib by Valgrind - $VALGRIND $CORE_OUTPUT # Test Lib by Valgrind
why2-logger-test: why2-logger-test:
stage: build stage: build
image: rust:latest image: rust:latest
script: script:
- apt update # Update repos - apt-get update # Update repos
- apt install sudo lsb-release valgrind -y # Install needed stuff - apt-get install $NEEDED_STUFF valgrind -y # Install needed stuff
- chmod +x configure.sh # Permissions - chmod +x $CONFIGURE # Permissions
- sudo ./configure.sh # Preparation - sudo $CONFIGURE # Preparation
- make install BYPASS_CHECK=true # Install WHY2 - make install BYPASS_CHECK=true # Install WHY2
- make test_logger # Build WHY2 Test - make test_logger # Build WHY2 Test
- ./$LOGGER_OUTPUT # Test Lib - gdb -ex "run" -ex "quit" --batch $LOGGER_OUTPUT # Test Lib
- $LOGGER_APP # Test App - gdb -ex "run" -ex "quit" --batch $LOGGER_APP # Test App
- $VALGRIND $LOGGER_OUTPUT # Test Lib by Valgrind - $VALGRIND $LOGGER_OUTPUT # Test Lib by Valgrind
why2-project: why2-project:
stage: build stage: build
image: rust:latest image: rust:latest
script: script:
- apt update # Update repos - apt-get update # Update repos
- apt install sudo lsb-release -y # Install needed stuff - apt-get install $NEEDED_STUFF -y # Install needed stuff
- chmod +x configure.sh # Permissions - chmod +x $CONFIGURE # Permissions
- sudo ./configure.sh # Preparation - sudo $CONFIGURE # Preparation
- make install BYPASS_CHECK=true # Install WHY2 - make install BYPASS_CHECK=true # Install WHY2
- curl -Lo test.c https://gist.github.com/ENGO150/d8419b6c31ffb68ebb930a5b41af8c73/raw # Download WHY2 test project - curl -Lo ./test.c https://gist.github.com/ENGO150/d8419b6c31ffb68ebb930a5b41af8c73/raw # Download WHY2 test project
- cc test.c -lwhy2 -Wall -o test # Build WHY2 project - cc test.c -lwhy2 -Wall -o ./test # Build WHY2 project
- ./test # Run Test - $GDB ./test # Run Test

View File

@ -1,5 +1,6 @@
- https://github.com/ENGO150/WHY2 - https://github.com/ENGO150/WHY2
- https://gitlab.com/ENGO150/why2 - https://gitlab.com/ENGO150/why2
- https://gitlab.spseplzen.cz/smejkalv/why2 - https://gitlab.spseplzen.cz/smejkalv/why2
- https://gitea.coquette.baby/ENGO150/WHY2 # Private mirror
Contact me for access to private mirror. Contact me for access to private mirror.

View File

@ -23,8 +23,8 @@ CFLAGS=-Wall -Wextra -Werror -Wcomment -Wformat -Wformat-security -Wmain -Wnonnu
# Output Files # Output Files
PROJECT_NAME=why2 PROJECT_NAME=why2
OUTPUT=out OUTPUT=./out
LOGS=logs LOGS=./logs
OUTPUT_TEST_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-test OUTPUT_TEST_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-test
OUTPUT_APP_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-app OUTPUT_APP_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-app
@ -59,7 +59,7 @@ TEST_LOGGER=./src/logger/lib/test/main.c
LIBS_LOGGER=$(LIB_CORE) LIBS_LOGGER=$(LIB_CORE)
LIB_LOGGER=-l$(PROJECT_NAME)-logger LIB_LOGGER=-l$(PROJECT_NAME)-logger
LIBS_LIB_CHAT=$(LIB_CORE) -lpthread -lgmp LIBS_LIB_CHAT=$(LIB_CORE) -lpthread -lcrypto
LIB_CHAT=-l$(PROJECT_NAME)-chat LIB_CHAT=-l$(PROJECT_NAME)-chat
LIB_CHAT_CONFIG=$(LIB_CHAT)-config LIB_CHAT_CONFIG=$(LIB_CHAT)-config
LIBS_CHAT=$(LIB_CHAT) $(LIBS_LIB_CHAT) $(LIB_CHAT_CONFIG) LIBS_CHAT=$(LIB_CHAT) $(LIBS_LIB_CHAT) $(LIB_CHAT_CONFIG)
@ -81,7 +81,6 @@ check_root:
ifneq ($(BYPASS_CHECK),true) ifneq ($(BYPASS_CHECK),true)
@if [ "$(shell id -u)" = 0 ]; then\ @if [ "$(shell id -u)" = 0 ]; then\
echo "Do not run install rules as root.";\ echo "Do not run install rules as root.";\
exit 1;\
fi fi
endif endif

View File

@ -17,22 +17,30 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Get linux distro # Get linux distro
DISTRO=$(lsb_release -is) DISTRO=$(grep ^ID_LIKE= /etc/os-release | cut -d= -f2 | tr -d '"')
if [ -e $DISTRO ]
then
DISTRO=$(grep ^ID= /etc/os-release | cut -d= -f2 | tr -d '"')
fi
if [[ $(id -u) != "0" ]] && [[ $1 != "force" ]]; then if [[ $(id -u) != "0" ]] && [[ $1 != "force" ]]
then
echo "You must run this script as root! (To skip this, run with 'force' arg: \"./configure.sh force\")" echo "You must run this script as root! (To skip this, run with 'force' arg: \"./configure.sh force\")"
exit 1 exit 1
fi fi
COMMON="gcc make tmux curl" COMMON="gcc make tmux curl"
ARCH_GENTOO_COMMON="$COMMON json-c libgit2 gmp" ARCH_GENTOO_COMMON="$COMMON json-c libgit2 openssl"
# Get COMMAND # Get COMMAND
if [[ $DISTRO == "Arch" ]]; then if [[ $DISTRO == "arch" ]]
then
COMMAND="pacman -S --needed --noconfirm $ARCH_GENTOO_COMMON" COMMAND="pacman -S --needed --noconfirm $ARCH_GENTOO_COMMON"
elif [[ $DISTRO == "Ubuntu" ]] || [[ $DISTRO == "Debian" ]]; then elif [[ $DISTRO == "debian" ]]
COMMAND="apt install -y $COMMON libjson-c-dev libcurl4-nss-dev libgit2-dev libgmp-dev" then
elif [[ $DISTRO == "Gentoo" ]]; then COMMAND="apt-get install -y $COMMON libjson-c-dev libcurl4-openssl-dev libgit2-dev libssl-dev"
elif [[ $DISTRO == "gentoo" ]]
then
COMMAND="emerge -vn $ARCH_GENTOO_COMMON" COMMAND="emerge -vn $ARCH_GENTOO_COMMON"
# Add # Add
@ -60,7 +68,8 @@ fi
$COMMAND $COMMAND
# Install Rust # Install Rust
if ! [ -x "$(command -v cargo)" ]; then if ! [ -x "$(command -v cargo)" ]
then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y # Install Rust and components curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y # Install Rust and components
source "$HOME/.cargo/env" source "$HOME/.cargo/env"
fi fi

View File

@ -37,11 +37,14 @@ void why2_chat_init_client_config(void); //Dementia is a term used to describe a
char *why2_toml_read(const char* path, const char* key); //READ key FROM path TOML FILE char *why2_toml_read(const char* path, const char* key); //READ key FROM path TOML FILE
void why2_toml_write(const char *path, const char *key, const char *value); //WRITE value AS key INTO path TOML FILE void why2_toml_write(const char *path, const char *key, const char *value); //WRITE value AS key INTO path TOML FILE
why2_bool why2_toml_contains(const char *path, const char *key); //CHECK IF path CONTAINS key why2_bool why2_toml_contains(const char *path, const char *key); //CHECK IF path CONTAINS key
why2_bool why2_toml_equals(const char *path, const char *key, const char *value); //CHECK IF key IN path IS EQUAL TO value
void why2_toml_read_free(char* s); //DEALLOCATE THE READ VALUE void why2_toml_read_free(char* s); //DEALLOCATE THE READ VALUE
char *why2_chat_server_config(char *key); //why2_toml_read BUT YOU DO NOT HAVE TO INCLUDE path char *why2_chat_server_config(char *key); //why2_toml_read BUT YOU DO NOT HAVE TO INCLUDE path
char *why2_chat_client_config(char *key); //hihi, *grabs shotgun quietly* char *why2_chat_client_config(char *key); //hihi, *grabs shotgun quietly*
char *why2_get_server_users_path(void); //RETURNS WHY2_CHAT_CONFIG_SERVER_USERS LOCATION
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -23,26 +23,27 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
#include <openssl/types.h>
#include <why2/flags.h>
#include <why2/chat/config.h> #include <why2/chat/config.h>
//MACROS //MACROS
#define WHY2_CHAT_KEY_BITS 4096 //BITS.. #define WHY2_CHAT_ECC NID_secp521r1 //CURVE NAME
#define WHY2_CHAT_PRIME_ITERS 100 //NUMBER OF ITERATIONS WHEN CHECKING PRIME NUMBER
#define WHY2_CHAT_RSA_EXPONENT "H33" //DEFAULT e IN BASE WHY2_CHAT_KEY_BASE
#define WHY2_CHAT_KEY_LOCATION WHY2_CONFIG_DIR "/keys" //KEYS LOCATION #define WHY2_CHAT_KEY_LOCATION WHY2_CONFIG_DIR "/keys" //KEYS LOCATION
#define WHY2_CHAT_PUB_KEY "pub" #define WHY2_CHAT_KEY "secp521r1.pem"
#define WHY2_CHAT_PRI_KEY "pri"
#define WHY2_CHAT_KEY_BASE 62 //BASE IN THE GENERATED KEYS ARE STORED IN WHY2_CHAT_KEY_LOCATION
void why2_chat_init_keys(void); //INIT (POSSIBLY GENERATE) RSA KEYS #define WHY2_CHAT_BASE64_LENGTH_DELIMITER ':' //SEPARATES BASE64 FROM LENGTH (YnJhbWJvcmFrCg==:9)
void why2_chat_init_keys(void); //INIT (POSSIBLY GENERATE) ECC KEYS
void why2_chat_deallocate_keys(void); //DEALLOCATE :) (NO SLUR HERE) void why2_chat_deallocate_keys(void); //DEALLOCATE :) (NO SLUR HERE)
char *why2_get_chat_modulus(void); //GET THE RSA MODULUS char *why2_chat_ecc_sign(char *message); //SIGN message WITH ECC KEY
char *why2_get_chat_d(void); //GET THE RSA d why2_bool why2_chat_ecc_verify_signature(char *message, char *signature, EVP_PKEY *key);
char *why2_chat_rsa_pub_encrypt(char *to_encrypt); //RSA ENCRYPT USING PUBLIC KEY char *why2_sha256(char *input); //HASH input USING SHA256 AND RETURN IN STRING
char *why2_chat_rsa_pri_decrypt(char *to_decrypt); //RSA DECRYPT USING PRIVATE KEY
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -23,6 +23,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
#include <why2/flags.h>
//MACROS //MACROS
#define WHY2_SA struct sockaddr #define WHY2_SA struct sockaddr
#define WHY2_CHAT_SERVER_PORT 1204 //PORT #define WHY2_CHAT_SERVER_PORT 1204 //PORT
@ -40,6 +42,8 @@ extern "C" {
#define WHY2_CHAT_CODE_LIST_SERVER "code_004" //SAME AS WHY2_CHAT_CODE_LIST BUT BACK TO THE CLIENT #define WHY2_CHAT_CODE_LIST_SERVER "code_004" //SAME AS WHY2_CHAT_CODE_LIST BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_VERSION_SERVER "code_005" //SAME AS WHY2_CHAT_CODE_VERSION BUT BACK TO THE CLIENT #define WHY2_CHAT_CODE_VERSION_SERVER "code_005" //SAME AS WHY2_CHAT_CODE_VERSION BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_PM_SERVER "code_006" //SAME AS WHY2_CHAT_CODE_PM BUT BACK TO THE CLIENT #define WHY2_CHAT_CODE_PM_SERVER "code_006" //SAME AS WHY2_CHAT_CODE_PM BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_ENTER_PASSWORD "code_007" //RECEIVE PASSWORD FROM USER
#define WHY2_CHAT_CODE_INVALID_PASSWORD "code_008"//🌸ꗥ~ꗥ🌸 𝐢 𝐡𝐚𝐭𝐞 𝐲𝐨𝐮 🌸ꗥ~ꗥ🌸
//(CLIENT -> SERVER) CODES //(CLIENT -> SERVER) CODES
#define WHY2_CHAT_CODE_EXIT "code_999" //TELL SERVER YOU ARE ENDING COMMUNICATION #define WHY2_CHAT_CODE_EXIT "code_999" //TELL SERVER YOU ARE ENDING COMMUNICATION
@ -52,14 +56,15 @@ extern "C" {
#define WHY2_CHAT_COMMAND_EXIT "exit" //QUIT THE PROGRAM CMD #define WHY2_CHAT_COMMAND_EXIT "exit" //QUIT THE PROGRAM CMD
#define WHY2_CHAT_COMMAND_HELP "help" //PRINT ALL COMMANDS #define WHY2_CHAT_COMMAND_HELP "help" //PRINT ALL COMMANDS
#define WHY2_CHAT_COMMAND_LIST "list" //LIST ALL CONNECTIONS #define WHY2_CHAT_COMMAND_LIST "list" //LIST ALL CONNECTIONS
#define WHY2_CHAT_COMMAND_PM "pm" //PRIVATE MESSAGES #define WHY2_CHAT_COMMAND_DM "dm" //DIRECT (UNENCRYPTED) MESSAGES
#define WHY2_CHAT_COMMAND_VERSION "version" //COMPARE CLIENT VERSION AND SERVER VERSION #define WHY2_CHAT_COMMAND_VERSION "version" //COMPARE CLIENT VERSION AND SERVER VERSION
//SHORTCUTS CAUSE I'M LAZY BITCH //SHORTCUTS CAUSE I'M LAZY BITCH
#define WHY2_CHAT_CODE_SSQC WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION #define WHY2_CHAT_CODE_SSQC WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION
char *why2_chat_client_get_server_exit_cmd(); //GETTER AND SETTER FOR !exit FROM SERVER //FUNCTIONS
void why2_chat_client_set_server_exit_cmd(char *cmd); void __why2_set_asking_password(why2_bool value); //IF HASH SHOULD BE SENT INSTEAD OF NORMAL MESSAGE
why2_bool __why2_get_asking_password();
#ifdef __cplusplus #ifdef __cplusplus
} }

48
include/crypto.h Normal file
View File

@ -0,0 +1,48 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_CRYPTO_H
#define WHY2_CRYPTO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <why2/flags.h>
//MACROS
#define WHY2_SUM_SEGMENT_SIZE 32 //SEGMENT SIZE FOR CALCULATING SUM
#define WHY2_SUM_BASE_PRIME 31 //PRIME FOR SUM BASE
#define WHY2_SUM_MOD_PRIME 4294967295UL //PRIME FOR SUM MODULUS; 2^32 - 1
#define WHY2_RECOMMENDED_PADDING_RATE(input_len) ((unsigned long) input_len / 3)
#define WHY2_PADDING_NONZERO_TRIES 1024 //HOW MANY RANDOM NUMBERS TO TRY TO GENERATE WHEN PREVENTING 0s
//FUNCTIONS
unsigned long long why2_sum_segment(char *input); //CALCULATE SUM++ FOR input; USED FOR PADDING SEED
why2_bool why2_random(void *dest, size_t size); //WRITE CRYPTO-SECURE RANDOM NUMBER INTO dest
void why2_seed_random(unsigned long seed); //SEED why2_seeded_random OUTPUT
int why2_seeded_random(); //GENERATE RANDOM NUMBER BASED ON SEED PASSED IN why2_seed_random
#ifdef __cplusplus
}
#endif
#endif

View File

@ -25,7 +25,7 @@ extern "C" {
#include <why2/flags.h> #include <why2/flags.h>
why2_output_flags why2_decrypt_text(char *text, char *key_new); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED why2_output_flags why2_decrypt_text(char *text, char *key); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,7 +25,7 @@ extern "C" {
#include <why2/flags.h> #include <why2/flags.h>
why2_output_flags why2_encrypt_text(char *text, char *key_new); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED why2_output_flags why2_encrypt_text(char *text, char *key); //TEXT from WILL BE ENCRYPTED WITH key AND RETURNED
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -34,12 +34,13 @@ enum WHY2_EXIT_CODES //exit codes you fucking idiot
}; };
//THESE ARE 'HISTORIC' VERSION FOR GENERATING tkch, SO YOU CAN DECRYPT OLD TEXT //THESE ARE LEGACY VERSIONS FOR GENERATING tkch, SO YOU CAN DECRYPT OLD TEXT
enum WHY2_TEXT_KEY_CHAIN_VERSIONS enum WHY2_TEXT_KEY_CHAIN_VERSIONS
{ {
WHY2_v1, //FIRST VERSION. Replaced on May 28th 17:45:26 2022 UTC in commit 0d64f4fa7c37f0b57914db902258e279a71c7f9a. WHY2_v1, //FIRST VERSION. Replaced on May 28th 17:45:26 2022 UTC in commit 0d64f4fa7c37f0b57914db902258e279a71c7f9a.
WHY2_v2, //SECOND VERSION. Replaced on July 11th 17:12:41 2022 UTC in commit 0f01cde0f1e1a9210f4eef7b949e6d247072d3a6. WHY2_v2, //SECOND VERSION. Replaced on July 11th 17:12:41 2022 UTC in commit 0f01cde0f1e1a9210f4eef7b949e6d247072d3a6.
WHY2_v3 //THIRD VERSION. THE LATEST ONE WHY2_v3, //THIRD VERSION. Replaced on Nov 17 19:55:13 2024 UTC in commit f917140ae54e4f5e601a089fbbea33817233e534.
WHY2_v4 //LATEST VERSION, MOST SECURE (how unexpected)
}; };
enum WHY2_OUTPUT_FORMAT enum WHY2_OUTPUT_FORMAT
@ -50,7 +51,8 @@ enum WHY2_OUTPUT_FORMAT
#define WHY2_VERSION "v5.0" //WHY2_VERSION OF CURRENT BUILD > DO NOT TOUCH THIS < #define WHY2_VERSION "v5.0" //WHY2_VERSION OF CURRENT BUILD > DO NOT TOUCH THIS <
#define WHY2_VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json #define WHY2_VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json
#define WHY2_CONFIG_DIR "/home/{USER}/.config/WHY2" #define WHY2_USER_CONFIG_DIR "{HOME}/.config"
#define WHY2_CONFIG_DIR WHY2_USER_CONFIG_DIR "/WHY2"
#define WHY2_VERSIONS_NAME WHY2_CONFIG_DIR "/.versions.json" //do I have to explain this? #define WHY2_VERSIONS_NAME WHY2_CONFIG_DIR "/.versions.json" //do I have to explain this?
#define WHY2_UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY) #define WHY2_UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY)
@ -63,7 +65,7 @@ enum WHY2_OUTPUT_FORMAT
#define WHY2_CLEAR_SCREEN "\e[1;1H\e[2J" //TEXT FOR UNIX CLEAR SCREEN #define WHY2_CLEAR_SCREEN "\e[1;1H\e[2J" //TEXT FOR UNIX CLEAR SCREEN
#define WHY2_CURL_TIMEOUT 3 //if you need comment explaining, what the fuck is timeout, don't change WHY2's code, alright? thx, love ya #define WHY2_CURL_TIMEOUT 10 //if you need comment explaining, what the fuck is timeout, don't change WHY2's code, alright? thx, love ya
#define WHY2_NOT_FOUND_TRIES 10 //NUMBER OF TRIES FOR DOWNLOADING versions.json #define WHY2_NOT_FOUND_TRIES 10 //NUMBER OF TRIES FOR DOWNLOADING versions.json
#define WHY2_DEPRECATED __attribute__((deprecated)) //SAME COMMENT AS WHY2_VERSIONS_NAME'S #define WHY2_DEPRECATED __attribute__((deprecated)) //SAME COMMENT AS WHY2_VERSIONS_NAME'S
@ -79,6 +81,7 @@ typedef struct
why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED
enum WHY2_TEXT_KEY_CHAIN_VERSIONS version; //VERSION OF tkch enum WHY2_TEXT_KEY_CHAIN_VERSIONS version; //VERSION OF tkch
enum WHY2_OUTPUT_FORMAT format; //VERSION OF tkch enum WHY2_OUTPUT_FORMAT format; //VERSION OF tkch
unsigned long padding; //HOW MUCH PADDING CHARS TO INSERT
} why2_input_flags; } why2_input_flags;
typedef struct typedef struct
@ -101,15 +104,20 @@ why2_input_flags why2_get_flags(void); //RETURNS USED FLAGS
why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code); //SAME AS why2_get_default_flags() BUT FOR why2_output_flags why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code); //SAME AS why2_get_default_flags() BUT FOR why2_output_flags
why2_encryption_operation_cb why2_get_encryption_operation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION why2_encryption_operation_cb why2_get_encryption_operation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION
why2_bool why2_get_flags_changed(void); why2_bool why2_get_flags_changed(void);
why2_bool why2_get_padding_changed(void);
char *why2_get_memory_identifier(void); //RETURNS STRING USED IN LINKED LIST (IN memory.c) FOR IDENTIFYING NODES WHEN RUNNING GARBAGE COLLECTOR char *why2_get_memory_identifier(void); //RETURNS STRING USED IN LINKED LIST (IN memory.c) FOR IDENTIFYING NODES WHEN RUNNING GARBAGE COLLECTOR
char *why2_get_default_memory_identifier(void); char *why2_get_default_memory_identifier(void);
//SETTERS //SETTERS
void why2_set_encryption_separator(char encryption_separator_new); void why2_set_encryption_separator(char encryption_separator_new);
void why2_set_key_length(int keyLengthNew); void why2_set_key_length(int keyLengthNew);
void why2_set_flags(why2_input_flags newFlags); //.... whatcha think? void why2_set_flags(why2_input_flags new_flags); //.... whatcha think?
void __why2_set_flags_anon(why2_input_flags new_flags); //DO NOT CHANGE flags_changed ON USAGE
void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation); //are you that dumb? void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation); //are you that dumb?
void why2_set_memory_identifier(char *new_memory_identifier); void why2_set_memory_identifier(char *new_memory_identifier);
void why2_set_padding(unsigned long padding); //SET PADDING RATE WITHOUT REWRITING INPUT FLAGS
void __why2_set_padding_anon(unsigned long padding);
void why2_reset_memory_identifier(void); //hmmm, what could reset mean.... huh void why2_reset_memory_identifier(void); //hmmm, what could reset mean.... huh
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -40,10 +40,13 @@ typedef struct
//FUNCTIONS //FUNCTIONS
void why2_list_push(why2_list_t *list, void *value, unsigned long size); //PUSH ELEMENT TO LIST BACK void why2_list_push(why2_list_t *list, void *value, unsigned long size); //PUSH ELEMENT TO LIST BACK
void why2_list_push_at(why2_list_t *list, unsigned long index, void *value, unsigned long size); //PUSH ELEMENT TO INDEX index of LIST
void why2_list_remove(why2_list_t *list, why2_node_t *node); //REMOVE ELEMENT void why2_list_remove(why2_list_t *list, why2_node_t *node); //REMOVE ELEMENT
void why2_list_remove_at(why2_list_t *list, unsigned long index); //REMOVE ELEMENT WITH INDEX index
void why2_list_remove_back(why2_list_t *list); //REMOVE LAST ELEMENT void why2_list_remove_back(why2_list_t *list); //REMOVE LAST ELEMENT
why2_node_t *why2_list_find(why2_list_t *list, void *value); //FIND ELEMENT IN LIST why2_node_t *why2_list_find(why2_list_t *list, void *value); //FIND ELEMENT IN LIST
unsigned long why2_list_get_size(why2_list_t *list); //GET SIZE unsigned long why2_list_get_size(why2_list_t *list); //GET SIZE
void why2_list_reverse(why2_list_t *list, unsigned long size); //REVERSES list
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -27,7 +27,8 @@ extern "C" {
void *why2_malloc(unsigned long size); void *why2_malloc(unsigned long size);
void *why2_calloc(unsigned long element, unsigned long size); void *why2_calloc(unsigned long element, unsigned long size);
void *why2_realloc(void *pointer, unsigned long size); void *why2_realloc(void *pointer, unsigned long size); //THIS DOESN'T PRESERVE CONTENT OF pointer!
void *why2_recalloc(void *pointer, unsigned long size, unsigned long block_size); //SAME AS why2_realloc BUT FILLS THE pointer WITH NULL-TERMS
char *why2_strdup(char *string); char *why2_strdup(char *string);

View File

@ -30,6 +30,7 @@ extern "C" {
#endif #endif
//CORE //CORE
#include <why2/crypto.h>
#include <why2/decrypter.h> #include <why2/decrypter.h>
#include <why2/encrypter.h> #include <why2/encrypter.h>
#include <why2/flags.h> #include <why2/flags.h>

View File

@ -46,11 +46,11 @@ void init_config(char *filename)
char *buffer = why2_malloc(strlen(WHY2_CONFIG_DIR) + strlen(filename) + 2); char *buffer = why2_malloc(strlen(WHY2_CONFIG_DIR) + strlen(filename) + 2);
sprintf(buffer, "%s/%s", WHY2_CONFIG_DIR, filename); sprintf(buffer, "%s/%s", WHY2_CONFIG_DIR, filename);
char *path = why2_replace(buffer, "{USER}", getenv("USER")); char *path = why2_replace(buffer, "{HOME}", getenv("HOME"));
if (access(path, R_OK) != 0) //CONFIG DOESN'T EXIST if (access(path, R_OK) != 0) //CONFIG DOESN'T EXIST
{ {
char *config_dir = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER")); char *config_dir = why2_replace(WHY2_CONFIG_DIR, "{HOME}", getenv("HOME"));
//CREATE CONFIG DIRECTORY //CREATE CONFIG DIRECTORY
mkdir(config_dir, 0700); mkdir(config_dir, 0700);
@ -85,11 +85,11 @@ char *config(char *key, enum CONFIG_TYPES type)
switch (type) //GET path switch (type) //GET path
{ {
case CLIENT: case CLIENT:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER")); path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{HOME}", getenv("HOME"));
break; break;
case SERVER: case SERVER:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER")); path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{HOME}", getenv("HOME"));
break; break;
default: default:
@ -113,7 +113,7 @@ void why2_chat_init_server_config(void)
//CHECK FOR USER CONFIG //CHECK FOR USER CONFIG
char *user_pick_username = why2_chat_server_config("user_pick_username"); char *user_pick_username = why2_chat_server_config("user_pick_username");
char *config_path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{USER}", getenv("USER")); char *config_path = why2_get_server_users_path();
if (strcmp(user_pick_username, "true") == 0 && access(config_path, R_OK) != 0) if (strcmp(user_pick_username, "true") == 0 && access(config_path, R_OK) != 0)
{ {
@ -146,3 +146,8 @@ char *why2_chat_client_config(char *key)
{ {
return config(key, CLIENT); return config(key, CLIENT);
} }
char *why2_get_server_users_path(void)
{
return why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{HOME}", getenv("HOME"));
}

View File

@ -24,5 +24,6 @@ communication_time = 300 # Seconds waiting for client message before stopping co
max_username_length = 20 # Maximal username length max_username_length = 20 # Maximal username length
min_username_length = 4 # Minimal username length min_username_length = 4 # Minimal username length
max_username_tries = 3 # Times asking client for username (if client tries to use invalid username) max_username_tries = 3 # Times asking client for username (if client tries to use invalid username)
max_password_tries = 3 # Same as above but for invalid password
max_message_length = 100 # Maximal message length max_message_length = 100 # Maximal message length

View File

@ -34,13 +34,8 @@ use std::
use toml::Value; use toml::Value;
#[no_mangle] fn toml_read(path_r: String, key_r: String) -> String
pub extern "C" fn why2_toml_read(path: *const c_char, key: *const c_char) -> *mut c_char
{ {
//CONVERT C STRINGS TO RUST STRINGS
let path_r = unsafe { CStr::from_ptr(path).to_string_lossy().into_owned() };
let key_r = unsafe { CStr::from_ptr(key).to_string_lossy().into_owned() };
//GET FILE CONTENT //GET FILE CONTENT
let file_raw = match read_to_string(&path_r) let file_raw = match read_to_string(&path_r)
{ {
@ -56,15 +51,21 @@ pub extern "C" fn why2_toml_read(path: *const c_char, key: *const c_char) -> *mu
}; };
//GET VALUE BY key_r //GET VALUE BY key_r
let mut value = match data.get(&key_r) match data.get(&key_r)
{ {
Some(value) => value.to_string(), Some(value) => value.to_string().replace("\"", "").trim().to_string(), //TRIM AND SHIT
None => panic!("Key \"{}\" not found in TOML config: {}", key_r, path_r), None => panic!("Key \"{}\" not found in TOML config: {}", key_r, path_r),
}; }
}
value = value.replace("\"", "").trim().to_string(); //REMOVE QUOTES #[no_mangle]
pub extern "C" fn why2_toml_read(path: *const c_char, key: *const c_char) -> *mut c_char
{
//CONVERT C STRINGS TO RUST STRINGS
let path_r = unsafe { CStr::from_ptr(path).to_string_lossy().into_owned() };
let key_r = unsafe { CStr::from_ptr(key).to_string_lossy().into_owned() };
CString::new(value).unwrap().into_raw() CString::new(toml_read(path_r, key_r)).unwrap().into_raw() //GET
} }
#[no_mangle] #[no_mangle]
@ -157,6 +158,17 @@ pub extern "C" fn why2_toml_contains(path: *const c_char, key: *const c_char) ->
data.get(&key_r).is_some() data.get(&key_r).is_some()
} }
#[no_mangle]
pub extern "C" fn why2_toml_equals(path: *const c_char, key: *const c_char, value: *const c_char) -> bool
{
//CONVERT C STRINGS TO RUST STRINGS
let path_r = unsafe { CStr::from_ptr(path).to_string_lossy().into_owned() };
let key_r = unsafe { CStr::from_ptr(key).to_string_lossy().into_owned() };
let value_r = unsafe { CStr::from_ptr(value).to_string_lossy().into_owned() };
toml_read(path_r, key_r) == value_r //RESULT
}
#[no_mangle] #[no_mangle]
pub extern "C" fn why2_toml_read_free(s: *mut c_char) //BECAUSE THIS IS RUST MODULE I HAVE TO CREATE A DEALLOCATING FUNCTION pub extern "C" fn why2_toml_read_free(s: *mut c_char) //BECAUSE THIS IS RUST MODULE I HAVE TO CREATE A DEALLOCATING FUNCTION
{ {

View File

@ -23,183 +23,194 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/random.h>
#include <why2/memory.h> #include <why2/memory.h>
#include <why2/misc.h> #include <why2/misc.h>
#include <gmp.h> #include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/ec.h>
//DO NOT TOUCH THESE PLS :3 EVP_PKEY *keypair = NULL; //KEYPAIR
char *rsa_modulus = NULL; //THE RSA MODULUS
char *rsa_d = NULL; //THE RSA d
//LOCAL //LOCAL
void generate_prime(mpz_t x) char *base64_encode(char *message, size_t length)
{
//RANDOM
gmp_randstate_t state;
gmp_randinit_default(state);
unsigned long random_buffer; //SEED
do
{
if (getrandom(&random_buffer, sizeof(unsigned long), GRND_NONBLOCK) == -1) why2_die("getrandom fn failed!");
//GENERATE RANDOM PRIME USING random_buffer SEED
gmp_randseed_ui(state, random_buffer);
mpz_urandomb(x, state, WHY2_CHAT_KEY_BITS);
mpz_nextprime(x, x);
} while (mpz_probab_prime_p(x, WHY2_CHAT_PRIME_ITERS) == 0); //CHECK FOR PRIME PROBABILITY
//DEALLOCATION
gmp_randclear(state);
}
void read_file(FILE *file, char **output)
{ {
//VARIABLES //VARIABLES
int buffer_size; BIO *bio;
char *buffer; BIO *b64;
BUF_MEM *buffer_ptr;
char* encoded_message;
//GET LENGTH //INIT BIOs
fseek(file, 0, SEEK_END); b64 = BIO_new(BIO_f_base64());
buffer_size = ftell(file); BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //DISABLE NEWLINES
rewind(file); bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);
//READ //ENCODE
buffer = why2_calloc(buffer_size + 1, sizeof(char)); BIO_write(bio, message, length);
if (fread(buffer, buffer_size, 1, file) != 1) why2_die("Reading keyfile failed!"); BIO_flush(bio);
buffer[buffer_size] = '\0'; BIO_get_mem_ptr(bio, &buffer_ptr);
//ASSIGN OUTPUT //COPY
*output = buffer; encoded_message = why2_malloc(buffer_ptr -> length + why2_count_int_length((int) length) + 2);
} memcpy(encoded_message, buffer_ptr -> data, buffer_ptr -> length);
char *exp_mod(char *to_exp, char *exponent) sprintf(encoded_message + buffer_ptr -> length, "%c%zu%c", WHY2_CHAT_BASE64_LENGTH_DELIMITER, length, '\0'); //APPEND LENGTH
{
//VARIABLES
char *output;
mpz_t m, c, n, e;
mpz_init(c);
//GET ALL STUFF
mpz_init_set_str(m, to_exp, 10);
mpz_init_set_str(n, why2_get_chat_modulus(), WHY2_CHAT_KEY_BASE);
mpz_init_set_str(e, exponent, WHY2_CHAT_KEY_BASE);
//ENCRYPT MESSAGE
mpz_powm(c, m, e, n);
output = why2_malloc(mpz_sizeinbase(c, 10) + 2); //ALLOCATE OUTPUT
mpz_get_str(output, 10, c); //GET OUTPUT
//DEALLOCATION //DEALLOCATION
mpz_clears(m, c, n, e, NULL); BIO_free_all(bio);
return output; return encoded_message;
}
char *base64_decode(char *encoded_message, size_t *length)
{
//VARIABLES
BIO *bio;
BIO *b64;
char *separator_ptr = strrchr(encoded_message, WHY2_CHAT_BASE64_LENGTH_DELIMITER); //GET THE DELIMITER POINTER
*length = strtoull(separator_ptr + 1, NULL, 10);
char* decoded_message = why2_malloc(*length + 1);
int decoded_length;
//INIT BIOs
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //DISABLE NEWLINES
bio = BIO_new_mem_buf(encoded_message, separator_ptr - encoded_message);
bio = BIO_push(b64, bio);
//DECODE
decoded_length = BIO_read(bio, decoded_message, *length);
//NULL-TERM
decoded_message[decoded_length] = '\0';
//DEALLOCATION
BIO_free_all(bio);
return decoded_message;
} }
//GLOBAL //GLOBAL
void why2_chat_init_keys(void) void why2_chat_init_keys(void)
{ {
//KEY FILES FILE *key; //KEY FILE
FILE *public; //TECHNICALLY, PUBLIC KEY CONTAINS ONLY THE MODULUS AND PRIVATE CONTAINS ONLY THE d
FILE *private;
//GET PATH TO KEY DIR char *path = why2_replace(WHY2_CHAT_KEY_LOCATION, "{HOME}", getenv("HOME")); //GET PATH TO KEY DIR
char *path = why2_replace(WHY2_CHAT_KEY_LOCATION, "{USER}", getenv("USER")); char *key_path = why2_malloc(strlen(path) + strlen(WHY2_CHAT_KEY) + 3); //ALLOCATE THE KEY PATH
//ALLOCATE THE KEY PATHS //GET THE ACTUAL KEY PATH
char *public_path = why2_malloc(strlen(path) + strlen(WHY2_CHAT_PUB_KEY) + 3); sprintf(key_path, "%s/%s%c", path, WHY2_CHAT_KEY, '\0');
char *private_path = why2_malloc(strlen(path) + strlen(WHY2_CHAT_PRI_KEY) + 3);
//GET THE ACTUAL KEY PATHS //CHECK IF KEY EXIST
sprintf(public_path, "%s/%s%c", path, WHY2_CHAT_PUB_KEY, '\0'); if (access(path, R_OK) != 0) //NOT FOUND - CREATE IT
sprintf(private_path, "%s/%s%c", path, WHY2_CHAT_PRI_KEY, '\0');
//CHECK IF KEYS EXIST
if (access(path, R_OK) != 0)
{ {
mkdir(path, 0700); mkdir(path, 0700);
//SOME USER OUTPUT //SOME USER OUTPUT
printf("You are probably running WHY2-Chat for the first time now.\nGenerating RSA keys...\n"); printf("No ECC key found.\nGenerating...\n\n");
//VARIABLES EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); //CREATE CTX
mpz_t p, q, e, d, n, phi_n, buffer_1, buffer_2; EVP_PKEY_keygen_init(ctx); //INIT KEYGEN
mpz_inits(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL);
//GENERATE PRIMES EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, WHY2_CHAT_ECC); //SETUP ECC
generate_prime(p); EVP_PKEY_keygen(ctx, &keypair); //GENERATE ECC KEYPAIR
generate_prime(q);
//SET e //WRITE THE KEYS INTO KEY-FILE
mpz_set_str(e, WHY2_CHAT_RSA_EXPONENT, 10); key = why2_fopen(key_path, "w+");
PEM_write_PrivateKey(key, keypair, NULL, NULL, 0, NULL, NULL); //WRITE THE KEY
//GET n //DEALLOCATION
mpz_mul(n, p, q); EVP_PKEY_CTX_free(ctx);
//GET phi
mpz_sub_ui(buffer_1, p, 1);
mpz_sub_ui(buffer_2, q, 1);
mpz_mul(phi_n, buffer_1, buffer_2);
//COUNT d
mpz_invert(d, e, phi_n);
printf("Saving keys...\n");
//WRITE THE KEYS INTO KEY-FILES
public = why2_fopen(public_path, "w+");
private = why2_fopen(private_path, "w+");
mpz_out_str(public, WHY2_CHAT_KEY_BASE, n);
mpz_out_str(private, WHY2_CHAT_KEY_BASE, d);
//KEYGEN DEALLOCATION
mpz_clears(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL);
} else } else
{ {
//OPEN FILES key = why2_fopen(key_path, "r"); //OPEN KEY FILE
public = why2_fopen(public_path, "r"); keypair = PEM_read_PrivateKey(key, NULL, NULL, NULL); //LOAD KEYPAIR
private = why2_fopen(private_path, "r");
//READ THE KEYS
read_file(public, &rsa_modulus);
read_file(private, &rsa_d);
} }
//DEALLOCATION //DEALLOCATION
why2_deallocate(path); why2_deallocate(path);
why2_deallocate(public_path); why2_deallocate(key_path);
why2_deallocate(private_path); why2_deallocate(key);
why2_deallocate(public); }
why2_deallocate(private);
char *why2_chat_ecc_sign(char *message)
{
//VARIABLES
EVP_MD_CTX *mdctx = NULL; //SIGNING CONTEXT
size_t siglen;
char *sig; //SIGNATURE
char *encoded_sig; //FINAL (ENCODED) SIGNATURE
//INIT mdctx
mdctx = EVP_MD_CTX_new();
EVP_DigestSignInit(mdctx, NULL, EVP_sha256(), NULL, keypair);
EVP_DigestSignUpdate(mdctx, message, strlen(message)); //UPDATE MESSAGE TO SIGN
EVP_DigestSignFinal(mdctx, NULL, &siglen); //COUNT LENGTH
//GENERATE SIGNATURE
sig = why2_malloc(siglen); //ALLOCATE SIGNATURE
EVP_DigestSignFinal(mdctx, (unsigned char*) sig, &siglen);
encoded_sig = base64_encode(sig, siglen); //CONVERT sig TO BASE64
//DEALLOCATION
why2_deallocate(sig);
EVP_MD_CTX_free(mdctx);
return encoded_sig;
}
why2_bool why2_chat_ecc_verify_signature(char *message, char *signature, EVP_PKEY *key)
{
//VARIABLES
size_t length;
char *decoded_signature = base64_decode(signature, &length); //DECODE SIGNATURE
why2_bool returning;
//INIT CONTEXT
EVP_MD_CTX* ctx = EVP_MD_CTX_new();
//INIT VERIFICATION CONTEXT
EVP_DigestVerifyInit(ctx, NULL, EVP_sha256(), NULL, key);
//VERIFY MESSAGE
EVP_DigestVerifyUpdate(ctx, message, strlen(message));
returning = EVP_DigestVerifyFinal(ctx, (unsigned char*) decoded_signature, length) == 1;
//DEALLOCATION
EVP_MD_CTX_free(ctx);
why2_deallocate(decoded_signature);
return returning;
} }
void why2_chat_deallocate_keys(void) void why2_chat_deallocate_keys(void)
{ {
why2_deallocate(rsa_modulus); //DEALLOCATE THE pkey
why2_deallocate(rsa_d); EVP_PKEY_free(keypair);
} }
char *why2_get_chat_modulus(void) char *why2_sha256(char *input)
{ {
return rsa_modulus; unsigned char *output = why2_malloc(SHA256_DIGEST_LENGTH + 1);
} char *formatted_output = why2_malloc(SHA256_DIGEST_LENGTH * 2 + 2);
char *why2_get_chat_d(void) SHA256((unsigned char*) input, strlen(input), output);
{
return rsa_d;
}
char *why2_chat_rsa_pub_encrypt(char *to_encrypt) //SAVE AS STRING IN HEX
{ for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
return exp_mod(to_encrypt, WHY2_CHAT_RSA_EXPONENT); {
} sprintf(formatted_output + (i * 2), "%02x", output[i]);
}
formatted_output[SHA256_DIGEST_LENGTH * 2] = '\0';
char *why2_chat_rsa_pri_decrypt(char *to_decrypt) //DEALLOCATION
{ why2_deallocate(output);
return exp_mod(to_decrypt, why2_get_chat_d());
return formatted_output;
} }

47
src/chat/flags.c Normal file
View File

@ -0,0 +1,47 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <why2/chat/flags.h>
#include <unistd.h>
#include <termios.h>
why2_bool asking_password = 0;
void __why2_set_asking_password(why2_bool value)
{
asking_password = value;
struct termios tty;
tcgetattr(STDIN_FILENO, &tty); //GET ATTRS
if (!value)
{
tty.c_lflag |= ECHO; //DISABLE
} else
{
tty.c_lflag &= ~ECHO; //ENABLE
}
tcsetattr(STDIN_FILENO, TCSANOW, &tty); //SET ATTRS
}
why2_bool __why2_get_asking_password()
{
return asking_password;
}

View File

@ -98,7 +98,7 @@ int main(void)
why2_check_version(); //CHECK FOR UPDATES why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_client_config(); //CREATE client.toml CONFIGURATION why2_chat_init_client_config(); //CREATE client.toml CONFIGURATION
why2_chat_init_keys(); //CREATE RSA KEYS why2_chat_init_keys(); //CREATE ECC KEY
listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
char *line = NULL; char *line = NULL;
@ -188,17 +188,17 @@ int main(void)
"\nCommands:\n---------\n%s\n\n>>> ", "\nCommands:\n---------\n%s\n\n>>> ",
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_HELP "\t\tPrints out all the commands. :)\n" WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_HELP "\t\tPrints out all the commands. :)\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_PM " <ID> <MSG>\tSends private message to user.\n" WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_DM " <ID> <MSG>\tSends direct message to user.\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_LIST "\t\tLists all users and their IDs.\n" WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_LIST "\t\tLists all users and their IDs.\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_VERSION "\tCheck server version.\n" WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_VERSION "\tCheck server version.\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT "\t\tExits the program." WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT "\t\tExits the program."
); );
fflush(stdout); fflush(stdout);
} else if (command(line, WHY2_CHAT_COMMAND_PM, &cmd_arg)) } else if (command(line, WHY2_CHAT_COMMAND_DM, &cmd_arg))
{ {
char *id; //PM RECEIVER char *id; //PM RECEIVER
WHY2_UNUSED char *msg; //something racial char *msg; //something racial
//CHECK ARGS VALIDITY //CHECK ARGS VALIDITY
why2_bool valid_param = cmd_arg != NULL && strlen(cmd_arg) >= 3; why2_bool valid_param = cmd_arg != NULL && strlen(cmd_arg) >= 3;
@ -259,8 +259,24 @@ int main(void)
invalid("command"); invalid("command");
} }
} else } else
{
if (__why2_get_asking_password())
{
//REMOVE \n AT THE END OF line
line[strlen(line) - 1] = '\0';
char *hash = why2_sha256(line); //HASHISH
why2_send_socket(hash, NULL, listen_socket); //SEND BUT HASHED
//DEALLOCATION
why2_deallocate(hash);
__why2_set_asking_password(0);
} else
{ {
why2_send_socket(line, NULL, listen_socket); //NULL IS SENT BECAUSE IT IS USELESS TO SEND USER FROM CLIENT - SERVER WON'T USE IT why2_send_socket(line, NULL, listen_socket); //NULL IS SENT BECAUSE IT IS USELESS TO SEND USER FROM CLIENT - SERVER WON'T USE IT
}
free(line); free(line);
} }
} }

View File

@ -142,7 +142,7 @@ void add_brackets(char **json)
why2_bool is_ascii(char c) why2_bool is_ascii(char c)
{ {
return 33 <= c && c <= 126; return 32 <= c && c <= 126;
} }
void remove_non_ascii(char **text) void remove_non_ascii(char **text)
@ -180,34 +180,16 @@ char *read_socket_raw(int socket)
if (ioctl(socket, FIONREAD, &content_size) < 0 || content_size <= 0) continue; if (ioctl(socket, FIONREAD, &content_size) < 0 || content_size <= 0) continue;
//ALLOCATE //ALLOCATE
content_buffer = why2_malloc(content_size + 1); content_buffer = why2_realloc(content_buffer, content_size + 1);
//READ JSON MESSAGE //READ JSON MESSAGE
if (recv(socket, content_buffer, content_size, MSG_PEEK) != content_size) //READ THE MESSAGE BY CHARACTERS if (recv(socket, content_buffer, content_size, 0) != content_size) //READ THE MESSAGE BY CHARACTERS
{ {
fprintf(stderr, "Socket probably read wrongly!\n"); fprintf(stderr, "Socket probably read wrongly!\n");
} }
why2_deallocate(content_buffer); //CLEANUP
} while (content_buffer == NULL || strncmp(content_buffer + (content_size - 2), "\"}", 2) != 0); } while (content_buffer == NULL || strncmp(content_buffer + (content_size - 2), "\"}", 2) != 0);
//ACTUALLY READ content_buffer[content_size] = '\0'; //NULL TERM
content_buffer = why2_calloc(content_size + 1, sizeof(char)); //ALLOCATE
int i;
for (i = 0; i < content_size; i++)
{
//READ
if (recv(socket, content_buffer + i, 1, 0) != 1) //READ BY CHARS
{
fprintf(stderr, "Socket probably read wrongly!\n");
}
//REMOVE NON-ASCII
if (!is_ascii(content_buffer[i])) i--; //(REWRITE THE CURRENT CHAR)
}
content_buffer[i] = '\0'; //NULL TERM
//VALIDATE JSON FORMAT //VALIDATE JSON FORMAT
struct json_object *json = json_tokener_parse(content_buffer); struct json_object *json = json_tokener_parse(content_buffer);
@ -590,6 +572,59 @@ void *why2_communicate_thread(void *arg)
continue; continue;
} }
//USER CONFIG
char *password = NULL;
char *user_config_path = why2_get_server_users_path();
if (!why2_toml_contains(user_config_path, decoded_buffer)) //REGISTRATION
{
send_socket_deallocate(WHY2_CHAT_CODE_ENTER_PASSWORD, why2_chat_server_config("server_username"), connection);
if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ
{
force_exiting = 1; //FAILURE
goto deallocation;
}
password = get_string_from_json_string(raw, "message"); //DECODE
why2_toml_write(user_config_path, username, password); //SAVE PASSWORD
} else //LOGIN
{
send_socket_deallocate(WHY2_CHAT_CODE_ENTER_PASSWORD, why2_chat_server_config("server_username"), connection);
unsigned char max_tries = (unsigned char) server_config_int("max_password_tries");
for (unsigned char i = 0; i < max_tries; i++)
{
if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ
{
force_exiting = 1; //FAILURE
goto deallocation;
}
password = get_string_from_json_string(raw, "message"); //DECODE
if (why2_toml_equals(user_config_path, decoded_buffer, password)) break;
if (i == max_tries - 1) //NOP, TOO MANY INVALID PASSWORDS
{
why2_deallocate(password);
exiting = 1;
goto deallocation;
}
send_socket_deallocate(WHY2_CHAT_CODE_INVALID_PASSWORD, why2_chat_server_config("server_username"), connection);
}
}
//CLEANUP
why2_deallocate(user_config_path);
why2_deallocate(password);
why2_deallocate(raw);
//INFO
printf("User set username.\t%d\t%s\n", connection, decoded_buffer); printf("User set username.\t%d\t%s\n", connection, decoded_buffer);
} }
} }
@ -880,6 +915,7 @@ void *why2_listen_server(void *socket)
why2_bool exiting = 0; why2_bool exiting = 0;
why2_bool continuing; why2_bool continuing;
unsigned char asking_username = 0; unsigned char asking_username = 0;
unsigned char asking_password = 0;
char *server_uname = NULL; char *server_uname = NULL;
//CONTENT //CONTENT
@ -916,7 +952,7 @@ void *why2_listen_server(void *socket)
max_tries = get_int_from_json_string(read, "max_tries"); max_tries = get_int_from_json_string(read, "max_tries");
server_name = get_string_from_json_string(read, "server_name"); server_name = get_string_from_json_string(read, "server_name");
printf(WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP "Successfully connected to %s.\n\n\n", server_name); //WELCOME printf(WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP "Successfully connected to %s.\nUse !help for commands.\n\n\n", server_name); //WELCOME
why2_deallocate(server_name); why2_deallocate(server_name);
continuing = 1; continuing = 1;
@ -1020,6 +1056,19 @@ void *why2_listen_server(void *socket)
why2_deallocate(pm_info[i]); why2_deallocate(pm_info[i]);
} }
why2_deallocate(pm_info); why2_deallocate(pm_info);
} else if (strcmp(message, WHY2_CHAT_CODE_ENTER_PASSWORD) == 0 || strcmp(message, WHY2_CHAT_CODE_INVALID_PASSWORD) == 0) //PICK USERNAME (COULD BE CAUSE BY INVALID USERNAME)
{
__why2_set_asking_password(1);
if (strcmp(message, WHY2_CHAT_CODE_INVALID_PASSWORD) == 0) //INVALID USERNAME
{
printf(WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP "%s\nInvalid password!\n\n\n", asking_password > 1 ? WHY2_CLEAR_AND_GO_UP : "");
fflush(stdout);
}
printf("%s%s\nEnter password:\n", asking_password++ > 0 ? WHY2_CLEAR_AND_GO_UP : "", WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP);
fflush(stdout);
//TODO! THIS SOMEHOW BREAKS THE CLIENT INPUT
} }
} else if (!continuing) } else if (!continuing)
{ {

View File

@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void) int main(void)
{ {
//SET FLAGS //SET FLAGS
why2_set_flags((why2_input_flags) { 1, 1, 0, WHY2_v3, WHY2_OUTPUT_TEXT }); why2_set_flags((why2_input_flags) { 1, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 0 });
//RUN ENCRYPTION WITH WHY2_TEXT_TO_ENCRYPT, GENERATE NEW KEY AND DO NOT CHECK FOR ACTIVE WHY2_VERSION & PREVENT ANY OUTPUT //RUN ENCRYPTION WITH WHY2_TEXT_TO_ENCRYPT, GENERATE NEW KEY AND DO NOT CHECK FOR ACTIVE WHY2_VERSION & PREVENT ANY OUTPUT
why2_output_flags encryptedText = why2_encrypt_text(WHY2_TEXT_TO_ENCRYPT, NULL); why2_output_flags encryptedText = why2_encrypt_text(WHY2_TEXT_TO_ENCRYPT, NULL);

View File

@ -23,11 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <why2/crypto.h>
#include <why2/flags.h> #include <why2/flags.h>
#include <why2/llist.h>
#include <why2/memory.h> #include <why2/memory.h>
#include <why2/misc.h> #include <why2/misc.h>
why2_output_flags why2_decrypt_text(char *text, char *key_new) why2_output_flags why2_decrypt_text(char *text, char *key)
{ {
//CHECK VARIABLE //CHECK VARIABLE
unsigned char check_exit_code; unsigned char check_exit_code;
@ -50,13 +52,13 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
} }
//CHECK FOR INVALID key //CHECK FOR INVALID key
if ((check_exit_code = why2_check_key(key_new)) != WHY2_SUCCESS) if ((check_exit_code = why2_check_key(key)) != WHY2_SUCCESS)
{ {
return why2_no_output(check_exit_code); return why2_no_output(check_exit_code);
} }
//REDEFINE keyLength //REDEFINE keyLength
why2_set_key_length(strlen(key_new)); why2_set_key_length(strlen(key));
//VARIABLES //VARIABLES
char *returning_text; char *returning_text;
@ -65,7 +67,7 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
char *text_buffer = NULL; char *text_buffer = NULL;
int text_key_chainLength; int text_key_chainLength;
int *text_key_chain; int *text_key_chain;
char *key = why2_strdup(key_new); //COPY key_new TO key char *key_new = why2_strdup(key); //COPY key TO key_new
int *encrypted_text_key_chain; int *encrypted_text_key_chain;
char *used_text = NULL; //COPY text TO used_text char *used_text = NULL; //COPY text TO used_text
@ -78,12 +80,6 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
//GET ENCRYPTED NUMBERS //GET ENCRYPTED NUMBERS
for (unsigned short i = 0; i < why2_byte_format_length(text_copy); i++) for (unsigned short i = 0; i < why2_byte_format_length(text_copy); i++)
{ {
for (unsigned short j = 2 + (i * 2); j <= 3 + (i * 2); j++)
{
//ENSURE THERE IS NO \0 (REVERSED)
if (text_copy[j] == -128) text_copy[j] = 0;
}
//PUT TOGETHER //PUT TOGETHER
encrypted_input[i] = (text_copy[3 + (i * 2)] << 7) | text_copy[2 + (i * 2)]; encrypted_input[i] = (text_copy[3 + (i * 2)] << 7) | text_copy[2 + (i * 2)];
@ -132,7 +128,7 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
text_key_chainLength = number_buffer; text_key_chainLength = number_buffer;
//LOAD text_key_chain //LOAD text_key_chain
why2_generate_text_key_chain(key, text_key_chain, number_buffer); why2_generate_text_key_chain(key_new, text_key_chain, number_buffer);
//LOAD encrypted_text_key_chain //LOAD encrypted_text_key_chain
for (int i = 0; i < text_key_chainLength; i++) for (int i = 0; i < text_key_chainLength; i++)
@ -181,6 +177,59 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
returning_text[i] = text_key_chain[i]; returning_text[i] = text_key_chain[i];
} }
//REMOVE PADDING
if (why2_get_flags().padding > 0)
{
why2_list_t split_text = WHY2_LIST_EMPTY; //LIST OF returning_text SPLIT INTO CHARS
//ADD CHARS
for (unsigned long i = 0; i < strlen(returning_text); i++)
{
why2_list_push(&split_text, &(returning_text[i]), sizeof(returning_text[i])); //ADD
}
//OBTAIN SEED FROM key_new
why2_seed_random(why2_sum_segment(key_new));
//GET RANDOM SEQUENCE USED IN ENCRYPTION
why2_list_t random_sequence = WHY2_LIST_EMPTY;
for (unsigned long i = 0; i < why2_get_flags().padding; i++)
{
int rand_buffer = why2_seeded_random();
why2_list_push(&random_sequence, &rand_buffer, sizeof(int)); //ADD
}
why2_list_reverse(&random_sequence, sizeof(int)); //REVERSE
//REMOVE PADDING FROM split_text LIST
for (unsigned long i = 0; i < why2_get_flags().padding; i++)
{
unsigned long random_position = (unsigned long) (*(int*) random_sequence.head -> value % (why2_list_get_size(&split_text) - 1)); //GET RANDOM POSITION
//REMOVE FROM THE LIST
why2_list_remove_at(&split_text, random_position);
//DEALLOCATION
why2_list_remove_at(&random_sequence, 0);
}
//PUT PADDED TEXT INTO text_new
returning_text = why2_recalloc(returning_text, why2_list_get_size(&split_text) + 1, sizeof(char));
why2_node_t *buffer = split_text.head;
why2_node_t *buffer_2;
unsigned long index_buffer = 0;
do
{
returning_text[index_buffer++] = *(char*) buffer -> value; //COPY VALUE
buffer_2 = buffer;
buffer = buffer -> next; //ITER
why2_deallocate(buffer_2 -> value); //DEALLOCATION
why2_deallocate(buffer_2); //DEALLOCATION
} while (buffer != NULL);
}
//GET FINISH TIME //GET FINISH TIME
gettimeofday(&finish_time, NULL); gettimeofday(&finish_time, NULL);
@ -188,9 +237,9 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
why2_output_flags output = why2_output_flags output =
{ {
returning_text, //DECRYPTED TEXT returning_text, //DECRYPTED TEXT
key, //USED KEY key_new, //USED KEY
why2_count_unused_key_size(returning_text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY why2_count_unused_key_size(returning_text, key_new), // NUMBER OF WHY2_UNUSED CHARS IN KEY
why2_count_repeated_key_size(returning_text, key), //NUMBER OF REPEATED CHARS IN KEY why2_count_repeated_key_size(returning_text, key_new), //NUMBER OF REPEATED CHARS IN KEY
why2_compare_time_micro(start_time, finish_time), // ELAPSED TIME why2_compare_time_micro(start_time, finish_time), // ELAPSED TIME
WHY2_SUCCESS //EXIT CODE WHY2_SUCCESS //EXIT CODE
}; };

View File

@ -19,14 +19,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/encrypter.h> #include <why2/encrypter.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <limits.h>
#include <why2/crypto.h>
#include <why2/flags.h> #include <why2/flags.h>
#include <why2/llist.h>
#include <why2/memory.h> #include <why2/memory.h>
#include <why2/misc.h> #include <why2/misc.h>
why2_output_flags why2_encrypt_text(char *text, char *key_new) why2_output_flags why2_encrypt_text(char *text, char *key)
{ {
//CHECK VARIABLE //CHECK VARIABLE
unsigned char check_exit_code; unsigned char check_exit_code;
@ -51,53 +55,104 @@ why2_output_flags why2_encrypt_text(char *text, char *key_new)
why2_set_memory_identifier("core_decrypt"); why2_set_memory_identifier("core_decrypt");
//VARIABLES //VARIABLES
char *key = NULL; char *key_new = NULL;
char *text_new = NULL;
char *returning_text = NULL; char *returning_text = NULL;
char *text_buffer = NULL; char *text_buffer = NULL;
int *text_key_chain = why2_malloc(sizeof(int) * strlen(text)); int *text_key_chain;
int number_buffer = 0; int number_buffer = 0;
if (key_new != NULL) if (key != NULL)
{ {
//CHECK FOR INVALID key //CHECK FOR INVALID key_new
if ((check_exit_code = why2_check_key(key_new)) != WHY2_SUCCESS) if ((check_exit_code = why2_check_key(key)) != WHY2_SUCCESS)
{ {
why2_clean_memory("core_decrypt"); why2_clean_memory("core_decrypt");
return why2_no_output(check_exit_code); return why2_no_output(check_exit_code);
} }
key = why2_strdup(key_new); key_new = why2_strdup(key);
//REDEFINE keyLength //REDEFINE keyLength
why2_set_key_length(strlen(key)); why2_set_key_length(strlen(key_new));
} else //LOAD KEY } else //LOAD KEY
{ {
key = why2_generate_key(why2_get_key_length()); key_new = why2_generate_key(why2_get_key_length());
} }
//PADDING
if (why2_get_flags().padding > 0)
{
why2_list_t split_text = WHY2_LIST_EMPTY; //LIST OF text SPLIT INTO CHARS
//ADD CHARS
for (unsigned long i = 0; i < strlen(text); i++)
{
why2_list_push(&split_text, &(text[i]), sizeof(text[i])); //ADD
}
//OBTAIN SEED FROM key_new
why2_seed_random(why2_sum_segment(key_new));
//ADD PADDING TO split_text LIST
for (unsigned long i = 0; i < why2_get_flags().padding; i++)
{
unsigned long random_position = (unsigned long) (why2_seeded_random() % (why2_list_get_size(&split_text))); //GET RANDOM POSITION
char random_char = 0;
for (int j = 0; j < WHY2_PADDING_NONZERO_TRIES && random_char == 0 ; j++) //GET RANDOM (EXCLUDING 0)
{
why2_random(&random_char, sizeof(random_char)); //GENERATE COMPLETELY RANDOM CHARACTER
}
if (random_char == 0) random_char = 1;
//INSERT RANDOM VALUE
why2_list_push_at(&split_text, random_position, &random_char, sizeof(random_char));
}
//PUT PADDED TEXT INTO text_new
text_new = why2_calloc(why2_list_get_size(&split_text) + 1, sizeof(char));
why2_node_t *buffer = split_text.head;
why2_node_t *buffer_2;
unsigned long index_buffer = 0;
do
{
text_new[index_buffer++] = *(char*) buffer -> value; //COPY VALUE
buffer_2 = buffer;
buffer = buffer -> next; //ITER
why2_deallocate(buffer_2 -> value); //DEALLOCATION
why2_deallocate(buffer_2); //DEALLOCATION
} while (buffer != NULL);
} else text_new = why2_strdup(text); //USE TEXT WITHOUT PADDING
text_key_chain = why2_malloc(sizeof(int) * strlen(text_new));
//LOAD text_key_chain //LOAD text_key_chain
why2_generate_text_key_chain(key, text_key_chain, strlen(text)); why2_generate_text_key_chain(key_new, text_key_chain, strlen(text_new));
//ACTUALLY ENCRYPT TEXT //ACTUALLY ENCRYPT TEXT
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; i < (int) strlen(text_new); i++)
{ {
text_key_chain[i] = why2_get_encryption_operation()(text_key_chain[i], (int) text[i]); text_key_chain[i] = why2_get_encryption_operation()(text_key_chain[i], (int) text_new[i]);
} }
//OUTPUT FORMATS //OUTPUT FORMATS
if (why2_get_flags().format == WHY2_OUTPUT_TEXT) //NORMAL 420.-69 FORMAT if (why2_get_flags().format == WHY2_OUTPUT_TEXT) //NORMAL 420.-69 FORMAT
{ {
//COUNT REQUIRED SIZE FOR returning_text //COUNT REQUIRED SIZE FOR returning_text
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; i < (int) strlen(text_new); i++)
{ {
number_buffer += why2_count_int_length(text_key_chain[i]); number_buffer += why2_count_int_length(text_key_chain[i]);
} }
//ALLOCATE returning_text (WITH THE SEPARATORS) //ALLOCATE returning_text (WITH THE SEPARATORS)
returning_text = why2_calloc(number_buffer + strlen(text), sizeof(char)); returning_text = why2_calloc(number_buffer + strlen(text_new), sizeof(char));
//LOAD returning_text //LOAD returning_text
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; i < (int) strlen(text_new); i++)
{ {
number_buffer = sizeof(int) * why2_count_int_length(text_key_chain[i]); number_buffer = sizeof(int) * why2_count_int_length(text_key_chain[i]);
@ -107,23 +162,23 @@ why2_output_flags why2_encrypt_text(char *text, char *key_new)
strcat(returning_text, text_buffer); strcat(returning_text, text_buffer);
if (i != (int) strlen(text) - 1) if (i != (int) strlen(text_new) - 1)
{ {
returning_text[strlen(returning_text)] = why2_get_encryption_separator(); returning_text[strlen(returning_text)] = why2_get_encryption_separator();
} }
} }
} else if (why2_get_flags().format == WHY2_OUTPUT_BYTE) //FUCKED BUT SHORT(ER) OUTPUT } else if (why2_get_flags().format == WHY2_OUTPUT_BYTE) //FUCKED BUT SHORT(ER) OUTPUT
{ {
number_buffer = (strlen(text) + 1) * 2; //EACH CHARACTER WILL BE SPLIT INTO TWO CHARS AND FIRST TWO WILL BE LENGTH OF text number_buffer = (strlen(text_new) + 1) * 2; //EACH CHARACTER WILL BE SPLIT INTO TWO CHARS AND FIRST TWO WILL BE LENGTH OF text_new
returning_text = why2_calloc(number_buffer + 1, sizeof(char)); //ALLOCATE returning_text = why2_calloc(number_buffer + 1, sizeof(char)); //ALLOCATE
//SET LENGTH //SET LENGTH
returning_text[0] = (strlen(text) & 0x7f) + 1; //+1 BECAUSE WE DON'T WANT \0 returning_text[0] = (strlen(text_new) & 0x7f) + 1; //+1 BECAUSE WE DON'T WANT \0
returning_text[1] = (strlen(text) >> 7) + 1; returning_text[1] = (strlen(text_new) >> 7) + 1;
//PUT THE text_key_chain INTO returning_text DIRECTLY //PUT THE text_key_chain INTO returning_text DIRECTLY
for (unsigned long i = 0; i < strlen(text); i++) for (unsigned long i = 0; i < strlen(text_new); i++)
{ {
//BUILD returning_text //BUILD returning_text
returning_text[2 + (i * 2)] = text_key_chain[i] & 0x7f; returning_text[2 + (i * 2)] = text_key_chain[i] & 0x7f;
@ -144,9 +199,9 @@ why2_output_flags why2_encrypt_text(char *text, char *key_new)
why2_output_flags output = why2_output_flags output =
{ {
returning_text, //ENCRYPTED TEXT returning_text, //ENCRYPTED TEXT
key, //GENERATED/USED KEY key_new, //GENERATED/USED KEY
why2_count_unused_key_size(text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY why2_count_unused_key_size(text_new, key_new), // NUMBER OF WHY2_UNUSED CHARS IN KEY
why2_count_repeated_key_size(text, key), //NUMBER OF REPEATED CHARS IN KEY why2_count_repeated_key_size(text_new, key_new), //NUMBER OF REPEATED CHARS IN KEY
why2_compare_time_micro(start_time, finish_time), // ELAPSED TIME why2_compare_time_micro(start_time, finish_time), // ELAPSED TIME
WHY2_SUCCESS //EXIT CODE WHY2_SUCCESS //EXIT CODE
}; };
@ -154,6 +209,7 @@ why2_output_flags why2_encrypt_text(char *text, char *key_new)
//DEALLOCATION //DEALLOCATION
why2_deallocate(text_key_chain); why2_deallocate(text_key_chain);
why2_deallocate(text_buffer); why2_deallocate(text_buffer);
why2_deallocate(text_new);
why2_reset_memory_identifier(); why2_reset_memory_identifier();

View File

@ -25,7 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/memory.h> #include <why2/memory.h>
//CONSTS (this is just local) //CONSTS (this is just local)
#define DEFAULT_FLAGS (why2_input_flags) { 0, 0, 0, WHY2_v3, WHY2_OUTPUT_TEXT } #define DEFAULT_FLAGS (why2_input_flags) { 0, 0, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 64 }
#define DEFAULT_MEMORY_IDENTIFIER "" #define DEFAULT_MEMORY_IDENTIFIER ""
int encryptionOperation(int text, int encryptedText); int encryptionOperation(int text, int encryptedText);
@ -33,9 +33,10 @@ int encryptionOperation(int text, int encryptedText);
//VARIABLES //VARIABLES
char encryption_separator = '.'; //NOPE > DO NOT TOUCH THIS, USE why2_set_encryption_separator instead < char encryption_separator = '.'; //NOPE > DO NOT TOUCH THIS, USE why2_set_encryption_separator instead <
unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE why2_set_key_length instead < unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE why2_set_key_length instead <
why2_input_flags flagsAllah = DEFAULT_FLAGS; //IT IS CALLED flagsAllah CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS why2_input_flags used_flags = DEFAULT_FLAGS; //IT IS CALLED used_flags CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS
why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation; why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation;
why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags why2_bool flags_changed = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
why2_bool padding_changed = 0; //SAME AS flags_changed BUT FOR PADDING
char *memory_identifier = DEFAULT_MEMORY_IDENTIFIER; char *memory_identifier = DEFAULT_MEMORY_IDENTIFIER;
why2_list_t identifier_list = WHY2_LIST_EMPTY; why2_list_t identifier_list = WHY2_LIST_EMPTY;
@ -68,7 +69,7 @@ why2_input_flags why2_get_default_flags(void)
why2_input_flags why2_get_flags(void) why2_input_flags why2_get_flags(void)
{ {
return flagsAllah; return used_flags;
} }
why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code) why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exit_code)
@ -93,7 +94,12 @@ why2_encryption_operation_cb why2_get_encryption_operation(void)
why2_bool why2_get_flags_changed(void) why2_bool why2_get_flags_changed(void)
{ {
return flagsChanged; return flags_changed;
}
why2_bool why2_get_padding_changed(void)
{
return padding_changed;
} }
char *why2_get_memory_identifier(void) char *why2_get_memory_identifier(void)
@ -126,11 +132,20 @@ void why2_set_key_length(int keyLengthNew)
keyLength = keyLengthNew; keyLength = keyLengthNew;
} }
void why2_set_flags(why2_input_flags newFlags) void why2_set_flags(why2_input_flags new_flags)
{ {
flagsAllah = newFlags; __why2_set_flags_anon(new_flags);
if (!flagsChanged) flagsChanged = 1; if (!flags_changed)
{
flags_changed = 1;
padding_changed = 1;
}
}
void __why2_set_flags_anon(why2_input_flags new_flags)
{
used_flags = new_flags;
} }
void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation) void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation)
@ -145,6 +160,17 @@ void why2_set_memory_identifier(char *new_memory_identifier)
memory_identifier = new_memory_identifier; memory_identifier = new_memory_identifier;
} }
void why2_set_padding(unsigned long padding)
{
__why2_set_padding_anon(padding);
if (!padding_changed) padding_changed = 1;
}
void __why2_set_padding_anon(unsigned long padding)
{
used_flags.padding = padding;
}
void why2_reset_memory_identifier(void) void why2_reset_memory_identifier(void)
{ {
why2_list_remove_back(&identifier_list); why2_list_remove_back(&identifier_list);

View File

@ -44,8 +44,9 @@ int main(void)
0, //SKIP CHECK 0, //SKIP CHECK
0, //NO OUTPUT 0, //NO OUTPUT
0, //UPDATE 0, //UPDATE
WHY2_v3, //LATEST VERSION WHY2_v4, //LATEST VERSION
WHY2_OUTPUT_TEXT //READABLE TEXT OUTPUT WHY2_OUTPUT_TEXT, //READABLE TEXT OUTPUT
WHY2_RECOMMENDED_PADDING_RATE(strlen(WHY2_TEST_TEXT)) //PADDING RATE
}; };
//SET FLAGS //SET FLAGS

101
src/core/lib/utils/crypto.c Normal file
View File

@ -0,0 +1,101 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <why2/crypto.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/random.h>
#include <openssl/rand.h>
#include <openssl/hmac.h>
#include <why2/flags.h>
typedef struct
{
unsigned long seed; //DA SEED
unsigned long counter; //COUNTER FOR DETERMINISTIC OUTPUT
} PRNG_CTX; //GENERATOR
//LOCAL
PRNG_CTX generator = { 0, 0 }; //SEEDED RANDOM GENERATOR
//GLOBAL
unsigned long long why2_sum_segment(char *input) //THE OUTPUT IS GOING TO GROW A LOT WITH LONG input, BUT IT SHOULDN'T BE A BIG PROBLEM. I TESTED FOR OVERFLOWS UP TO 4096-CHAR input AND ONLY GOT TO (14*10^(-7))% OF FULL ULL RANGE LMAO
{
unsigned long input_size = strlen(input);
unsigned long segmented_input_size = ceil(input_size / (double) WHY2_SUM_SEGMENT_SIZE) * WHY2_SUM_SEGMENT_SIZE; //CALCULATE CLOSEST 32*n (OR WHY2_SUM_SEGMENT_SIZE*n, IF YOU WILL) TO input
unsigned long long output = 0;
for (unsigned long i = 0; i < segmented_input_size / WHY2_SUM_SEGMENT_SIZE; i++) //DIVIDE buffer INTO SEGMENTS, XOR EACH OTHER AND ADD TO output
{
unsigned long output_buffer = 0;
for (unsigned long j = 0; j < WHY2_SUM_SEGMENT_SIZE; j++)
{
unsigned long index_buffer = i * WHY2_SUM_SEGMENT_SIZE + j;
char value_buffer = (input_size > index_buffer) ? input[index_buffer] : 0;
output_buffer ^= value_buffer; //XORING
output_buffer = (output_buffer * WHY2_SUM_BASE_PRIME + value_buffer) % WHY2_SUM_MOD_PRIME;
}
output += output_buffer; //ADD
}
return output;
}
why2_bool why2_random(void *dest, size_t size)
{
return RAND_bytes((unsigned char*) dest, size) == 1;
}
void why2_seed_random(unsigned long seed)
{
memset(&generator, 0, sizeof(PRNG_CTX)); //INIT GENERATOR
memcpy(&(generator.seed), &seed, sizeof(generator.seed)); //COPY SEED
generator.counter = 0; //INIT COUNTER
}
int why2_seeded_random()
{
int output;
unsigned char counter_bytes[4];
unsigned char hmac_output[EVP_MAX_MD_SIZE];
unsigned int hmac_len;
//CONVERT COUNTER TO BYTES
counter_bytes[0] = (generator.counter >> 24) & 0xFF;
counter_bytes[1] = (generator.counter >> 16) & 0xFF;
counter_bytes[2] = (generator.counter >> 8) & 0xFF;
counter_bytes[3] = generator.counter & 0xFF;
//HMAC (seed || counter)
HMAC(EVP_sha256(), &(generator.seed), sizeof(generator.seed), counter_bytes, sizeof(counter_bytes), hmac_output, &hmac_len);
//USE THE FIRST 4 BYTES OF THE HMAC OUTPUT AS DETERMINISTIC RANDOM INTEGER
memcpy(&output, hmac_output, sizeof(output));
//INCREMENT COUNTER
generator.counter++;
return output;
}

View File

@ -22,12 +22,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <why2/memory.h>
void why2_list_push(why2_list_t *list, void *value, unsigned long size) void why2_list_push(why2_list_t *list, void *value, unsigned long size)
{ {
//CREATE NODE //CREATE NODE
why2_node_t *head = list -> head; why2_node_t *head = list -> head;
why2_node_t *new_node = malloc(sizeof(why2_node_t)); why2_node_t *new_node = why2_malloc(sizeof(why2_node_t));
new_node -> value = malloc(size); new_node -> value = why2_malloc(size);
why2_node_t *buffer = head; why2_node_t *buffer = head;
//INSERT DATA //INSERT DATA
@ -51,6 +53,31 @@ void why2_list_push(why2_list_t *list, void *value, unsigned long size)
list -> head = buffer; list -> head = buffer;
} }
void why2_list_push_at(why2_list_t *list, unsigned long index, void *value, unsigned long size)
{
//CREATE NODE
why2_node_t *head = list -> head;
why2_node_t *new_node = why2_malloc(sizeof(why2_node_t));
new_node -> value = why2_malloc(size);
//INSERT DATA
memcpy(new_node -> value, value, size);
if (index != 0 && head != NULL) //ISN'T FIRST
{
why2_node_t *node_before = head;
for (unsigned long j = 0; j < index - 1 && j < why2_list_get_size(list); j++) node_before = node_before -> next; //SCROLL TO THE POSITION
new_node -> next = node_before -> next; //SEW THE LIST BACK
node_before -> next = new_node;
} else //ADD BEFORE THE WHOLE LIST
{
new_node -> next = head;
list -> head = new_node;
}
}
void why2_list_remove(why2_list_t *list, why2_node_t *node) void why2_list_remove(why2_list_t *list, why2_node_t *node)
{ {
if (node == NULL) return; //NULL NODE if (node == NULL) return; //NULL NODE
@ -86,8 +113,31 @@ void why2_list_remove(why2_list_t *list, why2_node_t *node)
list -> head = head; list -> head = head;
//DEALLOCATION //DEALLOCATION
free(node -> value); why2_deallocate(node -> value);
free(node); why2_deallocate(node);
}
void why2_list_remove_at(why2_list_t *list, unsigned long index)
{
if (list -> head == NULL) return; //EMPTY LIST
why2_node_t *node_to_remove;
if (index != 0) //SHOULDN'T BE FIRST
{
why2_node_t *node_before = list -> head;
for (unsigned long j = 0; j < index - 1; j++) node_before = node_before -> next; //SCROLL TO THE POSITION
node_to_remove = node_before -> next;
node_before -> next = node_to_remove -> next;
} else //ADD BEFORE THE WHOLE LIST
{
node_to_remove = list -> head;
list -> head = node_to_remove -> next;
}
why2_deallocate(node_to_remove -> value);
why2_deallocate(node_to_remove);
} }
void why2_list_remove_back(why2_list_t *list) void why2_list_remove_back(why2_list_t *list)
@ -112,8 +162,8 @@ void why2_list_remove_back(why2_list_t *list)
buffer -> next = NULL; //UNLINK buffer -> next = NULL; //UNLINK
} }
free(deallocating_node -> value); why2_deallocate(deallocating_node -> value);
free(deallocating_node); why2_deallocate(deallocating_node);
} }
why2_node_t *why2_list_find(why2_list_t *list, void *value) why2_node_t *why2_list_find(why2_list_t *list, void *value)
@ -152,3 +202,35 @@ unsigned long why2_list_get_size(why2_list_t *list)
return n; return n;
} }
void why2_list_reverse(why2_list_t *list, unsigned long size)
{
if (list -> head == NULL) return; //LIST IS EMPTY
why2_list_t reversed_list = WHY2_LIST_EMPTY;
why2_node_t *buffer = list -> head;
why2_node_t *buffer2;
//REVERSE INTO reversed_list AND DEALLOCATE list
do
{
//COPY
why2_node_t *current_node = why2_malloc(sizeof(why2_node_t));
current_node -> value = why2_malloc(size);
memcpy(current_node -> value, buffer -> value, size);
//INSERT INTO reversed_list
current_node -> next = reversed_list.head; //CHANGE NEXT POINTER
reversed_list.head = current_node; //INSERT
buffer2 = buffer;
buffer = buffer -> next; //ITER
//DEALLOCATE
why2_deallocate(buffer2 -> value);
why2_deallocate(buffer2);
} while (buffer != NULL);
//SET list TO reversed_list
list -> head = reversed_list.head;
}

View File

@ -153,6 +153,17 @@ void *why2_realloc(void *pointer, unsigned long size)
return allocated; return allocated;
} }
void *why2_recalloc(void *pointer, unsigned long size, unsigned long block_size)
{
if (pointer != NULL) why2_deallocate(pointer);
void *allocated = calloc(size, block_size);
push_to_list(allocated, ALLOCATION);
return allocated;
}
char *why2_strdup(char *string) char *why2_strdup(char *string)
{ {
char *allocated = strdup(string); char *allocated = strdup(string);

View File

@ -24,16 +24,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/random.h>
#include <ftw.h> #include <ftw.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <json-c/json.h> #include <json-c/json.h>
#include <git2.h> #include <git2.h>
#include <why2/crypto.h>
#include <why2/flags.h> #include <why2/flags.h>
#include <why2/memory.h> #include <why2/memory.h>
int mod_cb(int a, int b) { return a % (b == 0 ? 1 : b); }
int multiply_cb(int a, int b) { return a * b; } int multiply_cb(int a, int b) { return a * b; }
int subtract_cb(int a, int b) { return a - b; } int subtract_cb(int a, int b) { return a - b; }
int sum_cb(int a, int b) { return a + b; } int sum_cb(int a, int b) { return a + b; }
@ -55,15 +56,23 @@ int removeDirectory(char *path)
void why2_directory(void) void why2_directory(void)
{ {
struct stat st; struct stat st;
char *buffer = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER")); char *buffer_2 = why2_replace(WHY2_USER_CONFIG_DIR, "{HOME}", getenv("HOME"));
char *buffer = why2_replace(WHY2_CONFIG_DIR, "{HOME}", getenv("HOME"));
//CREATE USER CONFIG FOLDER //CREATE USER CONFIG FOLDER
if (stat(buffer_2, &st) == -1)
{
mkdir(buffer_2, 0700);
}
//CREATE WHY2 CONFIG FOLDER
if (stat(buffer, &st) == -1) if (stat(buffer, &st) == -1)
{ {
mkdir(buffer, 0700); mkdir(buffer, 0700);
} }
//DEALLOCATION //DEALLOCATION
why2_deallocate(buffer_2);
why2_deallocate(buffer); why2_deallocate(buffer);
} }
@ -78,7 +87,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
int not_found_buffer = 0; int not_found_buffer = 0;
//GET VERSION FILE //GET VERSION FILE
char *version_file = why2_replace(WHY2_VERSIONS_NAME, "{USER}", getenv("USER")); char *version_file = why2_replace(WHY2_VERSIONS_NAME, "{HOME}", getenv("HOME"));
//CURL VARIABLES //CURL VARIABLES
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
@ -90,7 +99,14 @@ enum WHY2_EXIT_CODES why2_check_version(void)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT); curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
//DOWNLOAD versions.json //DOWNLOAD versions.json
curl_easy_perform(curl); CURLcode curl_res = curl_easy_perform(curl);
if (curl_res != CURLE_OK && !why2_get_flags().no_output) //ERR
{
fprintf(stderr, "%sDownloading version failed!\n(%s)\n\nExiting...\n", WHY2_CLEAR_SCREEN, curl_easy_strerror(curl_res));
why2_clean_memory("core_version_check");
return WHY2_DOWNLOAD_FAILED;
}
//CLEANUP //CLEANUP
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -273,17 +289,13 @@ void why2_generate_text_key_chain(char *key, int *text_key_chain, int text_key_c
int number_buffer; int number_buffer;
int number_buffer_2 = 0; int number_buffer_2 = 0;
int number_buffer_3 = 0; int number_buffer_3 = 0;
const unsigned long key_length = why2_get_key_length();
int (*cb)(int, int); int (*cb)(int, int);
for (int i = 0; i < text_key_chain_size; i++) for (int i = 0; i < text_key_chain_size; i++)
{ {
number_buffer = i;
//CHECK, IF number_buffer ISN'T GREATER THAN keyLength AND CUT WHY2_UNUSED LENGTH //CHECK, IF number_buffer ISN'T GREATER THAN keyLength AND CUT WHY2_UNUSED LENGTH
while (number_buffer >= (int) why2_get_key_length()) number_buffer = i % why2_get_key_length();
{
number_buffer -= why2_get_key_length();
}
//SET tkch VERSION //SET tkch VERSION
switch (why2_get_flags().version) switch (why2_get_flags().version)
@ -295,25 +307,31 @@ void why2_generate_text_key_chain(char *key, int *text_key_chain, int text_key_c
case WHY2_v2: case WHY2_v2:
number_buffer_2 = i; number_buffer_2 = i;
number_buffer_3 = why2_get_key_length() - (number_buffer + (i < text_key_chain_size)); number_buffer_3 = key_length - (number_buffer + (i < text_key_chain_size));
break; break;
case WHY2_v3: case WHY2_v3:
number_buffer_2 = text_key_chain_size - (i + 1); number_buffer_2 = text_key_chain_size - (i + 1);
number_buffer_3 = why2_get_key_length() - (number_buffer + (i < text_key_chain_size)); number_buffer_3 = key_length - (number_buffer + (i < text_key_chain_size));
break;
case WHY2_v4:
number_buffer_2 = text_key_chain_size - (i + 1);
number_buffer_3 = ((((((i ^ number_buffer_2) + ((number_buffer << 3) ^ (number_buffer_2 & 0xF))) * (text_key_chain_size ^ (key_length >> 2))) ^ ((~(number_buffer + text_key_chain_size)) & 0xA7)) + (i % 7)) * (((number_buffer_2 | (i & 0xF)) + (key_length >> 3)) ^ (text_key_chain_size * (number_buffer & 0x3F))) + (((i << 4) ^ (text_key_chain_size >> 1)) & 0x1234) - ((i * number_buffer_2) % (key_length | text_key_chain_size))) % key_length; //gl fucker
break; break;
} }
//FILL textKeyChain //FILL textKeyChain
if ((number_buffer + 1) % 3 == 0) if (why2_get_flags().version == WHY2_v4 && (number_buffer + 1) % 4 == 0)
{
cb = mod_cb;
} else if ((number_buffer + 1) % 3 == 0)
{ {
cb = multiply_cb; cb = multiply_cb;
} } else if ((number_buffer + 1) % 2 == 0)
else if ((number_buffer + 1) % 2 == 0)
{ {
cb = subtract_cb; cb = subtract_cb;
} } else
else
{ {
cb = sum_cb; cb = sum_cb;
} }
@ -420,7 +438,7 @@ char *why2_generate_key(int key_length)
for (int i = 0; i < key_length; i++) for (int i = 0; i < key_length; i++)
{ {
//GET RANDOM NUMBER //GET RANDOM NUMBER
if (getrandom(&random_buffer, sizeof(unsigned int), GRND_NONBLOCK) == -1) why2_die("getrandom fn failed!"); if (!why2_random(&random_buffer, sizeof(unsigned int))) why2_die("getrandom fn failed!");
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52 //SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
number_buffer = (random_buffer % 52) + 1; number_buffer = (random_buffer % 52) + 1;

View File

@ -16,8 +16,9 @@ int main(void)
1, 1,
1, 1,
0, 0,
WHY2_v3, WHY2_v4,
WHY2_OUTPUT_TEXT WHY2_OUTPUT_TEXT,
WHY2_RECOMMENDED_PADDING_RATE(strlen(WHY2_LOGGER_TEST_TEXT))
} }
); );

View File

@ -29,7 +29,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/logger/flags.h> #include <why2/logger/flags.h>
#include <why2/logger/utils.h> #include <why2/logger/utils.h>
#include <why2/crypto.h>
#include <why2/encrypter.h> #include <why2/encrypter.h>
#include <why2/flags.h>
#include <why2/memory.h> #include <why2/memory.h>
#include <why2/misc.h> #include <why2/misc.h>
@ -94,6 +96,9 @@ why2_log_file why2_init_logger(char *directoryPath)
} }
} }
//SET ENCRYPTER FLAGS
if (!why2_get_flags_changed()) __why2_set_flags_anon((why2_input_flags) { 0, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 64 });
//DEALLOCATION //DEALLOCATION
why2_deallocate(dateBuffer); why2_deallocate(dateBuffer);
why2_deallocate(latestBuffer); why2_deallocate(latestBuffer);
@ -121,7 +126,7 @@ void why2_write_log(int loggerFile, char *logMessage)
char *logMessageUsed = why2_strdup(logMessage); char *logMessageUsed = why2_strdup(logMessage);
for (int i = 0; i < (int) strlen(logMessageUsed); i++) for (int i = 0; i < (int) strlen(logMessageUsed); i++)
{ {
if (logMessageUsed[i] == '\n') logMessageUsed[i] = '\0'; if (logMessageUsed[i] == '\n') logMessageUsed[i] = ' ';
} }
//VARIABLES //VARIABLES
@ -131,8 +136,7 @@ void why2_write_log(int loggerFile, char *logMessage)
struct tm tm = *localtime(&timeL); struct tm tm = *localtime(&timeL);
why2_log_flags flags = why2_get_log_flags(); why2_log_flags flags = why2_get_log_flags();
//SET ENCRYPTER FLAGS if (!why2_get_padding_changed()) __why2_set_padding_anon(WHY2_RECOMMENDED_PADDING_RATE(strlen(logMessageUsed)));
if (!why2_get_flags_changed()) why2_set_flags((why2_input_flags) { 0, 1, 0, WHY2_v3, WHY2_OUTPUT_TEXT });
if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED
{ {

View File

@ -107,6 +107,17 @@ why2_decrypted_output why2_decrypt_logger(why2_log_file logger)
for (int i = 0; i < lines; i++) //DECRYPT content for (int i = 0; i < lines; i++) //DECRYPT content
{ {
if (!why2_get_padding_changed())
{
printf("A\n");
unsigned long length_buffer = 1;
for (unsigned long j = 0; j < strlen(content[i]); j++)
{
if (content[i][j] == why2_get_encryption_separator()) length_buffer++;
}
__why2_set_padding_anon(length_buffer / 4);
}
outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT
contentDecrypted[i] = why2_strdup(outputBuffer.output_text); //COPY contentDecrypted[i] = why2_strdup(outputBuffer.output_text); //COPY