Compare commits

...

267 Commits

Author SHA1 Message Date
adf8efb6ab
fix client ip liner tui 2025-02-05 16:55:22 +01:00
55b96af92e
showing login/register on password prompt 2025-02-05 15:55:38 +01:00
cfa58a52db
revert "optimized ifs in why2_listen_server"
this reverts commit 240e7a79af766ad714ab6609615880b4f5c126a0

it is broken lol
2025-02-04 22:38:53 +01:00
d23fe1de78
fixed missing env in chat-build workflow 2025-02-04 22:31:41 +01:00
667eac9faa
using upload-artifact only on github 2025-02-04 22:28:07 +01:00
45accc4b97
revert "using upload-artifact v3 instead of v4"
this reverts commit f903d265d97ef3269dd2632f00fb6a456ae05040

github made v3 deprecated, so yeahhhh, uhmmm... basically...
2025-02-04 22:12:59 +01:00
af1a1d8855
showing client whether he is logging in or registering 2025-02-04 22:07:18 +01:00
240e7a79af
optimized ifs in why2_listen_server 2025-02-04 22:06:47 +01:00
037bd2a966
changed authority_ip address 2025-02-04 20:15:46 +01:00
4e04b89221
checking for invalid base64 in read_socket_raw 2025-02-04 20:00:14 +01:00
429e0cfeaa
implemented message delays in read_socket_raw 2025-02-04 18:34:22 +01:00
01455eab12
created max_message_delay_violations in server cfg 2025-02-04 18:04:49 +01:00
05ed50ddfd
declaring find_connection at the file top 2025-02-03 21:33:17 +01:00
fa6826ca05
using set_server fn in server-side programs 2025-02-03 21:12:10 +01:00
ffcdfa0657
created is_server & set_server functions 2025-02-03 21:11:18 +01:00
7fe2172ce9
created min_message_delay in server cfg 2025-02-03 21:08:36 +01:00
6daf74d0be
removing non-ascii characters at read_socket_raw 2025-02-03 20:33:23 +01:00
97248c3772
using domains in client config 2025-02-03 18:07:10 +01:00
d1142b469b
resolving domains on client connect 2025-02-03 18:02:21 +01:00
b6dff4d2f3
included stddef in crypto header
cause github actions are way too stupid...
2025-02-02 21:58:23 +01:00
44be9ad2f6
proccessing fread output on CA 2025-02-02 21:55:07 +01:00
6c080a438c
implemented WHY2_CHAT_MESSAGE_DELIMITER in read/send fns 2025-02-02 21:05:14 +01:00
97ee13591e
created WHY2_CHAT_MESSAGE_DELIMITER macro 2025-02-02 18:08:30 +01:00
2586f1a937
returning NULL on invalid packet in read_socket_raw 2025-02-02 16:50:16 +01:00
e688023383
allocating correct size in why2_chat_base64_encode 2025-02-02 16:49:54 +01:00
06d835e2b9
implemented encrypt_decrypt_message in send/receive fns 2025-02-02 15:48:18 +01:00
6e67e6225f
fixed encrypt_decrypt_message base64 problems 2025-02-02 15:47:40 +01:00
ee104f3208
created encrypt_decrypt_message fn
with ENCRYPTION_DECRYPTION enum
2025-02-02 15:16:17 +01:00
5cbb9375dd
implicit declaration of base64_decode fix 2025-02-02 15:15:08 +01:00
2649709c41
added length to why2_output_flags 2025-02-02 15:11:56 +01:00
4c7100760b
changed base64_encode length to size_t* 2025-02-02 15:01:20 +01:00
0a9a716ffe
moved base64 fns to crypto header 2025-02-02 14:59:52 +01:00
06b1c8728c
deallocating CS key on client exit 2025-02-02 14:29:14 +01:00
cdbbdce47c
fixed invalid read on double json in buffer 2025-02-02 14:28:08 +01:00
90be3ebc21
passing key to send/receive functions 2025-02-02 00:02:56 +01:00
35ec44ae68
saving shared client-server key 2025-02-01 22:13:32 +01:00
7b2f55e3ae
created client_server_key fns 2025-02-01 22:11:39 +01:00
8a7c389a74
generating ECC keys on server startup 2025-02-01 22:00:07 +01:00
481bce366c
removed message parameter from why2_chat_ecc_shared_key 2025-02-01 21:54:43 +01:00
4d8f61259d
removed encryption from why2_chat_ecc_shared_key 2025-02-01 21:51:58 +01:00
4317c9fa5d
renamed why2_chat_ecc_encrypt to why2_chat_ecc_shared_key
it will be used only for encrypting WHY2 key
2025-02-01 21:49:42 +01:00
f3f5533763
exchanging ecc keys on client connect 2025-02-01 21:44:37 +01:00
c1ee049f32
fixed username/password server memory leak 2025-02-01 21:32:41 +01:00
ca6b81943a
moved SC codes one up 2025-02-01 21:18:20 +01:00
a242fbea95
added cs/sc key exchange macros 2025-02-01 21:06:50 +01:00
a4b8bf2f4c
implemented WHY2_CHAT_CODE_PASSWORD 2025-02-01 21:03:49 +01:00
ee309b2cbb
created WHY2_CHAT_CODE_USERNAME macro 2025-02-01 21:01:13 +01:00
767f78a554
fixed server connection problems on client 2025-02-01 20:58:03 +01:00
7daa9aa124
sending WHY2_CHAT_CODE_USERNAME from client 2025-02-01 20:57:42 +01:00
4d64d73c07
waiting for WHY2_CHAT_CODE_USERNAME 2025-02-01 20:57:07 +01:00
6c53169f09
added askin_username getter & setter 2025-02-01 20:47:45 +01:00
2970878bce
created WHY2_CHAT_CODE_USERNAME macro 2025-02-01 20:39:36 +01:00
e99f0115d6
disconnecting user on ca auth end 2025-02-01 19:23:24 +01:00
a0bb314010
implemented CA code in client 2025-02-01 18:07:33 +01:00
7377b672bf
returing code from why2_listen_authority 2025-02-01 18:07:13 +01:00
bd986f5327
saving user certificate 2025-02-01 17:32:27 +01:00
d799ff1e0c
allocating correct size in why2_get_authority_cert_path 2025-02-01 17:32:06 +01:00
a42764f6d6
created WHY2_CHAT_CODE_SUCCESS and WHY2_CHAT_CODE_FAILURE macros 2025-02-01 16:32:58 +01:00
61c06dc25a
created why2_get_authority_cert_path fn 2025-02-01 16:26:32 +01:00
43f4d31023
created WHY2_CHAT_AUTHORITY_CERTS_EXTENSION macro 2025-02-01 16:23:33 +01:00
9099192c8a
sending ca pubkey unencrypted to client 2025-02-01 16:12:46 +01:00
cb9ec62b94
sending authority_username from client during ca 2025-02-01 16:05:29 +01:00
82a572bda1
created why2_toml_write_preserve rust fn
same as why2_toml_write but does not remove comments
2025-02-01 16:04:04 +01:00
3227814edf
created why2_get_client_config_path fn 2025-02-01 15:24:23 +01:00
99ae6a7106
simplified config using config_path fn 2025-02-01 15:23:04 +01:00
44ddd6b3d1
sending server client's public key 2025-02-01 15:11:26 +01:00
56bd7c664d
fixed double read from authority 2025-02-01 15:09:44 +01:00
89c0f87678
created WHY2_CHAT_CODE_CLIENT_KEY_EXCHANGE macro 2025-02-01 14:58:39 +01:00
e51a6bf4e8
created why2_chat_ecc_encrypt fn 2025-02-01 14:54:11 +01:00
bf583fd495
created calculate_ecdh_secret fn
calculates shared secret (ECDH)
2025-02-01 14:53:46 +01:00
145f8d790f
created WHY2_CHAT_PADDING macro
how much padding should be used in chat encryption
2025-02-01 14:53:05 +01:00
be15fcd2f6
implemented new why2_sha256 in client 2025-02-01 14:38:14 +01:00
ea1bb6789e
added length parameter to why2_sha256 2025-02-01 14:37:53 +01:00
f404da5e2d
sending ca pubkey to client 2025-02-01 14:00:59 +01:00
9d40603741
added missing crypto include to authority 2025-02-01 14:00:04 +01:00
b9651a6749
connecting to CA on client startup 2025-02-01 13:44:29 +01:00
c10677c29c
added plain why2_listen_authority fn 2025-02-01 13:41:59 +01:00
22bf36481a
removed unused connectStatus variable from client 2025-02-01 13:34:05 +01:00
103d5d5385
added authority_ip to client config 2025-02-01 13:27:52 +01:00
7eaee3a89c
created WHY2_CHAT_CODE_KEY_EXCHANGE macro 2025-02-01 13:21:48 +01:00
bf354372ff
created why2_chat_ecc_deserialize_public_key fn 2025-02-01 13:03:21 +01:00
313c2930e9
allowing NULL length in base64_decode 2025-02-01 13:00:21 +01:00
7bb6e38a99
created why2_chat_ecc_serialize_public_key fn 2025-02-01 12:55:39 +01:00
7eb7940701
generating ecc keys on authority startup 2025-01-31 17:15:13 +01:00
aa037bce74
WHY2_UPDATE_FAILED identifier fix 2025-01-31 17:12:04 +01:00
86c804b6c0
changed __WHY2_ACCEPT_THREAD_PARAMS identifier to lowercase
i forgot it isn't macro
2025-01-31 17:10:30 +01:00
2e53e63345
changed codes to shorter forms
also rename PM codes to DM codes but I already staged it and i am too lazy to redo it
2025-01-31 17:04:53 +01:00
f7e71324f4
implemented _WHY2_ACCEPT_THREAD_PARAMS in servers 2025-01-31 16:57:57 +01:00
4b6ca483c8
using _WHY2_ACCEPT_THREAD_PARAMS in why2_accept_thread 2025-01-31 16:57:33 +01:00
316bdcc778
created _WHY2_ACCEPT_THREAD_PARAMS struct 2025-01-31 16:52:25 +01:00
1928519757
created WHY2_CHAT_SERVER_TYPE enum 2025-01-31 16:32:20 +01:00
8c80d3b815
added plain why2_authority_communicate_thread fn 2025-01-31 16:29:06 +01:00
7f76a43ea4
added make rules for ca server 2025-01-31 16:24:56 +01:00
1d0dc26f87
created ca server file
it is slightly modified server file - gonna change stuff in future commits
2025-01-31 16:21:17 +01:00
d01ba3e141
defined why2_chat_init_authority 2025-01-31 16:20:28 +01:00
78fc77cd69
created WHY2_CHAT_AUTHORITY_DIR macro 2025-01-31 15:59:14 +01:00
ee1c784b84
removed WHY_SA macro
first of all, its stupid. second thing - sa? seriously?
2025-01-31 15:56:17 +01:00
0994558a39
created WHY2_CHAT_AUTHORITY_PORT macro 2025-01-31 15:53:42 +01:00
2768280e7f
declared why2_chat_init_authority 2025-01-31 15:52:00 +01:00
07eb596180
checking for WHY2_CHAT_CODE_ACCEPT_MESSAGES from client
it was using the first received message
2025-01-31 14:49:37 +01:00
15e36f5919
added key to connection_node_t 2025-01-31 14:42:30 +01:00
b392451486
fixed server receive code param error 2025-01-31 14:31:30 +01:00
c0c0ad6894
using codes in exit_client fn 2025-01-31 14:11:27 +01:00
0781fc4caf
fixed uninitialized variable 2025-01-31 14:07:29 +01:00
a3c54207db
sending WHY2_CHAT_CODE_VERSION as a code
this is the last one. now time for 20 hours of debugging.... yay
2025-01-31 14:05:30 +01:00
c120d38804
sending WHY2_CHAT_CODE_PM as a code 2025-01-31 14:04:40 +01:00
9ab4f50fc6
sending WHY2_CHAT_CODE_LIST as a code 2025-01-31 14:01:41 +01:00
cf70fb0367
proccessing codes in server receive 2025-01-31 14:00:37 +01:00
771e0de333
sending WHY2_CHAT_CODE_INVALID_PASSWORD as a code 2025-01-31 13:54:13 +01:00
2394006d76
sending WHY2_CHAT_CODE_ENTER_PASSWORD as a code 2025-01-31 13:53:39 +01:00
b96852606e
sending WHY2_CHAT_CODE_PM_SERVER as a code 2025-01-31 13:53:00 +01:00
06f5d434c1
sending WHY2_CHAT_CODE_VERSION_SERVER as a code 2025-01-31 13:51:13 +01:00
e66109c262
sending WHY2_CHAT_CODE_LIST_SERVER as a code
not sure if it will work (there's no way for me to test it rn...)
2025-01-31 13:49:55 +01:00
1978ed4cd8
sending WHY2_CHAT_CODE_INVALID_USERNAME as a code 2025-01-31 13:40:25 +01:00
3b603f25e8
sending WHY2_CHAT_CODE_SSQC as a code 2025-01-31 13:39:47 +01:00
fa8560d51a
sending WHY2_CHAT_CODE_PICK_USERNAME as a code 2025-01-31 13:38:21 +01:00
4ca411f32b
prepared client's receive for codes 2025-01-31 13:37:30 +01:00
db032d3066
added send_socket_code_deallocate fn
sends code with params
2025-01-31 13:36:38 +01:00
1f9df8363a
added why2_send_socket_code fn 2025-01-31 12:39:55 +01:00
2e63191085
sending welcome packet code in code field 2025-01-31 12:37:57 +01:00
ea018644f2
skipping strdup on NULL string param 2025-01-31 12:37:08 +01:00
4649b7ccf6
added WHY2_CHAT_COMMAND_PM to client help page 2025-01-30 22:51:41 +01:00
61fdb17018
created WHY2_CHAT_COMMAND_PM macro 2025-01-30 22:49:38 +01:00
e34f92b0d8
renamed WHY2_CHAT_COMMAND_PM to WHY2_CHAT_COMMAND_DM
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
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
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 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
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"
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
moo
2025-01-25 10:50:52 +01:00
6eeddbd14e
replaced lsb_release with os-release file
also supporting X-based distributions
2025-01-25 10:45:35 +01:00
17a73d9157
implemented anon flags in logger 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 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
crazy
2025-01-09 20:00:47 +01:00
24e5d1b8c2
checking bramborak secret on codacy start instead 2025-01-09 19:56:20 +01:00
fba541d354
checking GITHUB_ACTIONS envvar on codacy start 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
NOT GITEA FOR FUCK SAKE
2025-01-09 19:36:58 +01:00
90ac513be1
replaced GDB variable with duplicate code in gitlab-ci
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 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 2025-01-09 19:09:33 +01:00
25561ca800
invalid gitlab-ci syntax fix 2025-01-09 19:04:04 +01:00
44ce767709
applied workflow changes to gitlab-ci 2025-01-09 19:01:58 +01:00
f903d265d9
using upload-artifact v3 instead of v4
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 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
good luck
2025-01-09 18:23:57 +01:00
119899f714
added gitea to MIRRORS 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
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 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 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 2025-01-09 15:21:07 +01:00
360d581084
replaced apt usage with apt-get
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 2025-01-08 18:56:07 +01:00
9feca42ec5
fixed bs in workflows 2025-01-08 18:01:54 +01:00
f8892b03bf
moved rust-toolchain to WHY2 install step 2025-01-08 17:55:06 +01:00
be94830e84
added rust-toolchain to github workflows 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 2025-01-08 17:19:28 +01:00
a52031ad52
removed exit from anti-root check in makefile 2025-01-08 17:11:43 +01:00
c72eb44ab0 corrected output path in make 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
44 changed files with 2217 additions and 596 deletions

@ -25,6 +25,9 @@ on:
permissions: permissions:
contents: read contents: read
env:
bramborak: ${{ secrets.BRAMBORAK }}
jobs: jobs:
codacy-security-scan: codacy-security-scan:
permissions: permissions:
@ -34,11 +37,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 +52,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

@ -23,6 +23,9 @@ on:
schedule: schedule:
- cron: '40 22 12 4 2' - cron: '40 22 12 4 2'
env:
bramborak: ${{ secrets.BRAMBORAK }}
jobs: jobs:
test-why2: test-why2:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@ -34,7 +37,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 +48,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,19 +57,24 @@ 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
- name: Build Chat - name: Build Chat
run: make build_chat run: make build_chat
- name: Upload Client - if: env.bramborak == 'ted jsem tam mel jednu slapku' # Ensure this runs only on GitHub
name: Upload Client
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: WHY2 Chat Client name: WHY2 Chat Client
path: ${{ matrix.client }} path: ${{ matrix.client }}
- name: Upload Server - if: env.bramborak == 'ted jsem tam mel jednu slapku' # Ensure this runs only on GitHub
name: Upload Server
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: WHY2 Chat Server name: WHY2 Chat Server

@ -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 }}

@ -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 }}

@ -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

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

@ -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

@ -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.

@ -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
@ -34,6 +34,7 @@ OUTPUT_APP_LOGGER=$(OUTPUT)/$(PROJECT_NAME)-logger-app
OUTPUT_CHAT_CLIENT=$(OUTPUT)/$(PROJECT_NAME)-chat-client OUTPUT_CHAT_CLIENT=$(OUTPUT)/$(PROJECT_NAME)-chat-client
OUTPUT_CHAT_SERVER=$(OUTPUT)/$(PROJECT_NAME)-chat-server OUTPUT_CHAT_SERVER=$(OUTPUT)/$(PROJECT_NAME)-chat-server
OUTPUT_CHAT_AUTHORITY=$(OUTPUT)/$(PROJECT_NAME)-chat-authority
LIB_CHAT_CONFIG_OUT=./src/chat/config/target/release LIB_CHAT_CONFIG_OUT=./src/chat/config/target/release
@ -44,6 +45,7 @@ SRC_LOGGER=./src/logger/lib/*.c
SRC_LOGGER_APP=./src/logger/app/*.c SRC_LOGGER_APP=./src/logger/app/*.c
SRC_CHAT_CLIENT=./src/chat/main/client.c SRC_CHAT_CLIENT=./src/chat/main/client.c
SRC_CHAT_SERVER=./src/chat/main/server.c SRC_CHAT_SERVER=./src/chat/main/server.c
SRC_CHAT_AUTHORITY=./src/chat/main/authority.c
SRC_CHAT_MISC=./src/chat/*.c SRC_CHAT_MISC=./src/chat/*.c
INCLUDE_DIR=./include INCLUDE_DIR=./include
@ -59,7 +61,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 +83,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
@ -111,6 +112,9 @@ build_chat_client:
build_chat_server: build_chat_server:
$(CC) $(CFLAGS) $(SRC_CHAT_SERVER) -o $(OUTPUT_CHAT_SERVER) $(LIBS_CHAT) $(CC) $(CFLAGS) $(SRC_CHAT_SERVER) -o $(OUTPUT_CHAT_SERVER) $(LIBS_CHAT)
build_chat_authority:
$(CC) $(CFLAGS) $(SRC_CHAT_AUTHORITY) -o $(OUTPUT_CHAT_AUTHORITY) $(LIBS_CHAT)
build_lib_chat: build_lib_chat:
$(MAKE) clean $(MAKE) clean
$(CC) $(CFLAGS) -fPIC -c $(SRC_CHAT_MISC) $(CC) $(CFLAGS) -fPIC -c $(SRC_CHAT_MISC)
@ -149,7 +153,7 @@ clean:
$(RC) clean $(RFLAGS) $(RC) clean $(RFLAGS)
rm -rf $(OUTPUT)/* $(LOGS)/* *.o *.so vgcore.* rm -rf $(OUTPUT)/* $(LOGS)/* *.o *.so vgcore.*
build_chat: build_chat_server build_chat_client build_chat: build_chat_server build_chat_client build_chat_authority
install_header: install_header_core install_header_logger install_header_chat install_header: install_header_core install_header_logger install_header_chat
install_libs: install_lib_core install_lib_logger install_lib_chat install_libs: install_lib_core install_lib_logger install_lib_chat

@ -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

@ -31,17 +31,28 @@ extern "C" {
#define WHY2_CHAT_CONFIG_CLIENT "client.toml" #define WHY2_CHAT_CONFIG_CLIENT "client.toml"
#define WHY2_CHAT_CONFIG_SERVER_USERS "server_users.toml" //LOGIN INFO CONFIG #define WHY2_CHAT_CONFIG_SERVER_USERS "server_users.toml" //LOGIN INFO CONFIG
#define WHY2_CHAT_AUTHORITY_DIR "certs" //AUTHORITY DIRECTORY
#define WHY2_CHAT_AUTHORITY_CERTS_EXTENSION ".cert"
void why2_chat_init_server_config(void); //CHECK IF SERVER CONFIG EXISTS, CREATE IT void why2_chat_init_server_config(void); //CHECK IF SERVER CONFIG EXISTS, CREATE IT
void why2_chat_init_client_config(void); //Dementia is a term used to describe a group of symptoms affecting memory, thinking and social abilities. In people who have dementia, the symptoms interfere with their daily lives. Dementia isn't one specific disease. Several diseases can cause dementia. ... void why2_chat_init_client_config(void); //Dementia is a term used to describe a group of symptoms affecting memory, thinking and social abilities. In people who have dementia, the symptoms interfere with their daily lives. Dementia isn't one specific disease. Several diseases can cause dementia. ...
void why2_chat_init_authority(void); //CREATE WHY2_CHAT_AUTHORITY_DIR
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
void why2_toml_write_preserve(const char *path, const char *key, const char *value); //WRITE value AS key INTO path TOML FILE WITHOUT REMOVING COMMENTS
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
char *why2_get_client_config_path(void); //RETURNS WHY2_CHAT_CONFIG_CLIENT LOCATION
char *why2_get_authority_cert_path(char *username); //RETURNS PATH TO CA CERTS
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -23,26 +23,40 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
#include <stddef.h>
#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)
#define WHY2_CHAT_PADDING(input_len) ((unsigned long) input_len / 2)
//FUNCTIONS
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_base64_encode(char *message, size_t *length); //ENCODE message OF length INTO BASE64 WITH LENGTH DELIMITER (WHY2_CHAT_BASE64_LENGTH_DELIMITER)
char *why2_get_chat_d(void); //GET THE RSA d char *why2_chat_base64_decode(char *encoded_message, size_t *length); //DECODE encoded_message AND SET length TO OUTPUT LENGTH
char *why2_chat_rsa_pub_encrypt(char *to_encrypt); //RSA ENCRYPT USING PUBLIC KEY char *why2_chat_ecc_sign(char *message); //SIGN message WITH ECC KEY
char *why2_chat_rsa_pri_decrypt(char *to_decrypt); //RSA DECRYPT USING PRIVATE KEY why2_bool why2_chat_ecc_verify_signature(char *message, char *signature, EVP_PKEY *key);
char *why2_chat_ecc_serialize_public_key(); //GET PUBLIC ECC KEY IN BASE64
EVP_PKEY* why2_chat_ecc_deserialize_public_key(char *pubkey); //GET EVP_PKEY FROM BASE64 PUBLIC ECC KEY
char *why2_chat_ecc_shared_key(char *ecc_key); //ENCRYPT message WITH ECC key
char *why2_sha256(char *input, size_t length); //HASH input USING SHA256 AND RETURN IN STRING
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -23,43 +23,81 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
#include <why2/flags.h>
//ENUMS
enum WHY2_CHAT_SERVER_TYPE //TYPE OF SERVER
{
WHY2_CHAT_SERVER, //CLASSIC COMMUNICATION SERVER
WHY2_CHAT_AUTHORITY //CA
};
//MACROS //MACROS
#define WHY2_SA struct sockaddr #define WHY2_CHAT_SERVER_PORT 1204 //PORT FOR SERVER
#define WHY2_CHAT_SERVER_PORT 1204 //PORT #define WHY2_CHAT_AUTHORITY_PORT 1203 //PORT FOR CA
#define WHY2_MAX_CONNECTIONS 1000 //MAX USERS CONNECTED AT ONE TIME #define WHY2_MAX_CONNECTIONS 1000 //MAX USERS CONNECTED AT ONE TIME
#define WHY2_CLEAR_AND_GO_UP "\33[2K\r\033[A" //i mean read the name #define WHY2_CLEAR_AND_GO_UP "\33[2K\r\033[A" //i mean read the name
#define WHY2_INVALID_POINTER (void*) 0xffffffffffffffff #define WHY2_INVALID_POINTER (void*) 0xffffffffffffffff
#define WHY2_CHAT_MESSAGE_DELIMITER ';' //SEPARATES RECEIVED MESSAGES
//(SERVER -> CLIENT) CODES //(SERVER -> CLIENT) CODES
#define WHY2_CHAT_CODE_ACCEPT_MESSAGES "code_000" //TELL CLIENT THEY CAN SEND MESSAGES #define WHY2_CHAT_CODE_SERVER_CLIENT_KEY_EXCHANGE "SC0" //TELL CLIENT YOU ARE SHARING YOUR PUBLIC KEY
#define WHY2_CHAT_CODE_PICK_USERNAME "code_001" //TELL CLIENT TO PICK USERNAME #define WHY2_CHAT_CODE_ACCEPT_MESSAGES "SC1" //TELL CLIENT THEY CAN SEND MESSAGES
#define WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION "code_002" //TELL CLIENT TO END COMMUNICATION (just so they don't get segfault on server-side disconnect) #define WHY2_CHAT_CODE_PICK_USERNAME "SC2" //TELL CLIENT TO PICK USERNAME
#define WHY2_CHAT_CODE_INVALID_USERNAME "code_003" //haha #define WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION "SC3" //TELL CLIENT TO END COMMUNICATION (just so they don't get segfault on server-side disconnect)
#define WHY2_CHAT_CODE_LIST_SERVER "code_004" //SAME AS WHY2_CHAT_CODE_LIST BUT BACK TO THE CLIENT #define WHY2_CHAT_CODE_INVALID_USERNAME "SC4" //haha
#define WHY2_CHAT_CODE_VERSION_SERVER "code_005" //SAME AS WHY2_CHAT_CODE_VERSION BUT BACK TO THE CLIENT #define WHY2_CHAT_CODE_LIST_SERVER "SC5" //SAME AS WHY2_CHAT_CODE_LIST 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_VERSION_SERVER "SC6" //SAME AS WHY2_CHAT_CODE_VERSION BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_DM_SERVER "SC7" //SAME AS WHY2_CHAT_CODE_DM BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_REGISTER "SC8" //RECEIVE PASSWORD FROM USER (REGISTER)
#define WHY2_CHAT_CODE_LOGIN "SC9" //RECEIVE PASSWORD FROM USER (LOGIN)
#define WHY2_CHAT_CODE_INVALID_PASSWORD "SCA"//🌸ꗥ~ꗥ🌸 𝐢 𝐡𝐚𝐭𝐞 𝐲𝐨𝐮 🌸ꗥ~ꗥ🌸
//(CLIENT -> SERVER) CODES //(CLIENT -> SERVER) CODES
#define WHY2_CHAT_CODE_EXIT "code_999" //TELL SERVER YOU ARE ENDING COMMUNICATION #define WHY2_CHAT_CODE_CLIENT_SERVER_KEY_EXCHANGE "CS0" //TELL SERVER YOU ARE SHARING YOUR PUBLIC KEY
#define WHY2_CHAT_CODE_LIST "code_998" //TELL SERVER TO GIVE YOU ALL CONNECTED USERS #define WHY2_CHAT_CODE_EXIT "CS1" //TELL SERVER YOU ARE ENDING COMMUNICATION
#define WHY2_CHAT_CODE_PM "code_997" //TELL SERVER TO SEND MESSAGE ONLY TO SPECIFIC ID #define WHY2_CHAT_CODE_LIST "CS2" //TELL SERVER TO GIVE YOU ALL CONNECTED USERS
#define WHY2_CHAT_CODE_VERSION "code_996" //TELL SERVER TO GIVE YOU ITS VERSION #define WHY2_CHAT_CODE_DM "CS3" //TELL SERVER TO SEND MESSAGE ONLY TO SPECIFIC ID
#define WHY2_CHAT_CODE_VERSION "CS4" //TELL SERVER TO GIVE YOU ITS VERSION
#define WHY2_CHAT_CODE_USERNAME "CS5" //TELL SERVER YOU ARE GIVING IT YOUR USERNAME
#define WHY2_CHAT_CODE_PASSWORD "CS6" //TELL SERVER YOU ARE GIVING IT YOUR PASSWORD (HASHED)
//(AUTHORITY -> CLIENT) CODES
#define WHY2_CHAT_CODE_KEY_EXCHANGE "AC0" //TELL CLIENT TO SEND CA THEIR PUBKEY
#define WHY2_CHAT_CODE_SUCCESS "AC1" //TELL CLIENT THEY ARE GOOD TO GO
#define WHY2_CHAT_CODE_FAILURE "AC2" //TELL CLIENT THEY FUCKED UP
//(CLIENT -> AUTHORITY) CODES
#define WHY2_CHAT_CODE_CLIENT_KEY_EXCHANGE "CA0" //TELL AUTHORITY YOU ARE SENDING YOUR PUBLIC KEY
//COMMANDS //COMMANDS
#define WHY2_CHAT_COMMAND_PREFIX "!" //the little thingy you write before the command names to make the program recognise them boy. You know? Like in minecraft you use /kill... Also, are you dumb? #define WHY2_CHAT_COMMAND_PREFIX "!" //the little thingy you write before the command names to make the program recognise them boy. You know? Like in minecraft you use /kill... Also, are you dumb?
#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
#define WHY2_CHAT_COMMAND_PM "pm" //PRIVATE (ENCRYPTED) MESSAGES
//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_chat_set_client_server_key(char *key); //SET KEY USED FOR ENCRYPTION BETWEEN CLIENT AND SERVER
char *why2_chat_get_client_server_key(void);
void why2_chat_deallocate_client_server_key(void);
void __why2_chat_set_server(why2_bool value); //IF PROGRAM IS SERVER-SIDE
why2_bool __why2_chat_is_server(void); //IF PROGRAM IS SERVER-SIDE
void __why2_set_asking_password(why2_bool value); //IF HASH SHOULD BE SENT INSTEAD OF NORMAL MESSAGE
why2_bool __why2_get_asking_password(void);
void __why2_set_asking_username(why2_bool value);
why2_bool __why2_get_asking_username(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -23,14 +23,27 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
#include <why2/flags.h> //TODO: fuck this #include <why2/flags.h>
void why2_send_socket(char *text, char *username, int socket); //send socket.... wtf did you expect #include <why2/chat/flags.h>
//STRUCTS
typedef struct
{
int socket; //SOCKET POINTER
enum WHY2_CHAT_SERVER_TYPE type; //TYPE OF SERVER
} __why2_accept_thread_params;
//FUNCTIONS
void why2_send_socket(char *text, char *username, char *key, int socket); //send socket.... wtf did you expect
void why2_send_socket_code(char *params, char *username, char *key, int socket, char *code); //SEND SOCKET BUT WITH CODE
void *why2_communicate_thread(void *arg); //COMMUNICATION THREAD void *why2_communicate_thread(void *arg); //COMMUNICATION THREAD
void *why2_accept_thread(void *socket); //LOOP ACCEPTING CONNECTIONS void *why2_authority_communicate_thread(void *arg); //CA COMMUNICATION THREAD
void *why2_accept_thread(void *params); //LOOP ACCEPTING CONNECTIONS
void why2_clean_connections(void); //CLOSE EVERY CONNECTION void why2_clean_connections(void); //CLOSE EVERY CONNECTION
void why2_clean_threads(void); //CLOSE EVERY RUNNING MESSAGE THREAD void why2_clean_threads(void); //CLOSE EVERY RUNNING MESSAGE THREAD
void *why2_listen_server(void *socket); //LISTEN FOR OTHER's USERS MESSAGES void *why2_listen_server(void *socket); //LISTEN FOR OTHER's USERS MESSAGES
void *why2_listen_authority(void *socket); //LISTEN TO AUTHORITY
void *why2_getline_thread(WHY2_UNUSED void* arg); //START getline IN SEPARATE THREAD void *why2_getline_thread(WHY2_UNUSED void* arg); //START getline IN SEPARATE THREAD
void why2_trim_string(char **s); //REMOVES SPACES FROM END AND START OF *s void why2_trim_string(char **s); //REMOVES SPACES FROM END AND START OF *s

48
include/crypto.h Normal 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

@ -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
} }

@ -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
} }

@ -30,16 +30,17 @@ enum WHY2_EXIT_CODES //exit codes you fucking idiot
WHY2_INVALID_KEY = 1, //EXIT VALUE FOR INVALID KEY WHY2_INVALID_KEY = 1, //EXIT VALUE FOR INVALID KEY
WHY2_INVALID_TEXT = 4, //EXIT VALUE FOR INVALID TEXT WHY2_INVALID_TEXT = 4, //EXIT VALUE FOR INVALID TEXT
WHY2_DOWNLOAD_FAILED = 2, //EXIT VALUE FOR versions.json DOWNLOAD FAILED WHY2_DOWNLOAD_FAILED = 2, //EXIT VALUE FOR versions.json DOWNLOAD FAILED
WHY2_WHY2_UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED WHY2_UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED
}; };
//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,11 +81,13 @@ 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
{ {
char *output_text; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT char *output_text; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT
unsigned long output_text_length; //LENGTH OF ENCRYPTED/DECRYPTED TEXT
char *used_key; //VARIABLE FOR USED/GENERATED KEY char *used_key; //VARIABLE FOR USED/GENERATED KEY
unsigned long unused_key_size; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY unsigned long unused_key_size; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY
unsigned long repeated_key_size; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unused_key_size) unsigned long repeated_key_size; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unused_key_size)
@ -101,15 +105,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

@ -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
} }

@ -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);

@ -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>

@ -34,7 +34,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
enum CONFIG_TYPES enum CONFIG_TYPES
{ {
CLIENT, CLIENT,
SERVER SERVER,
SERVER_USERS,
AUTHORITY
}; };
void init_config(char *filename) void init_config(char *filename)
@ -46,11 +48,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);
@ -78,18 +80,26 @@ void init_config(char *filename)
why2_deallocate(buffer); why2_deallocate(buffer);
} }
char *config(char *key, enum CONFIG_TYPES type) char *config_path(enum CONFIG_TYPES type)
{ {
char *path = NULL; char *path = NULL;
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;
case SERVER_USERS:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{HOME}", getenv("HOME"));
break;
case AUTHORITY:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_AUTHORITY_DIR, "{HOME}", getenv("HOME"));
break; break;
default: default:
@ -97,6 +107,14 @@ char *config(char *key, enum CONFIG_TYPES type)
break; break;
} }
return path;
}
char *config(char *key, enum CONFIG_TYPES type)
{
//GET CONFIGURATION PATH
char *path = config_path(type);
//VALUE //VALUE
char *value = why2_toml_read(path, key); char *value = why2_toml_read(path, key);
@ -113,7 +131,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)
{ {
@ -137,6 +155,19 @@ void why2_chat_init_client_config(void)
init_config(WHY2_CHAT_CONFIG_CLIENT); init_config(WHY2_CHAT_CONFIG_CLIENT);
} }
void why2_chat_init_authority(void)
{
//CREATE USER CONFIG FOLDER [THIS SHOULDN'T HAPPEN ON CLIENT, BUT IT'S NEEDED ON FRESH SERVERS]
why2_directory();
//GET THE CONFIG TYPE
char *path = config_path(AUTHORITY);
if (access(path, R_OK) != 0) mkdir(path, 0700); //DIRECTORY DOESN'T EXIST; CREATE IT
//DEALLOCATION
why2_deallocate(path);
}
char *why2_chat_server_config(char *key) char *why2_chat_server_config(char *key)
{ {
return config(key, SERVER); return config(key, SERVER);
@ -146,3 +177,27 @@ char *why2_chat_client_config(char *key)
{ {
return config(key, CLIENT); return config(key, CLIENT);
} }
char *why2_get_server_users_path(void)
{
return config_path(SERVER_USERS);
}
char *why2_get_client_config_path(void)
{
return config_path(CLIENT);
}
char *why2_get_authority_cert_path(char *username)
{
char *buffer = config_path(AUTHORITY);
char *path = why2_malloc(strlen(buffer) + strlen(username) + strlen(WHY2_CHAT_AUTHORITY_CERTS_EXTENSION) + 3);
//GET THE FILE
sprintf(path, "%s/%s%s%c", buffer, username, WHY2_CHAT_AUTHORITY_CERTS_EXTENSION, '\0');
//DEALLOCATION
why2_deallocate(buffer);
return path;
}

@ -25,3 +25,4 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
toml = "*" toml = "*"
toml_edit = "*"

@ -15,4 +15,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
auto_connect = false # Automatic connection to 'auto_connect_ip' auto_connect = false # Automatic connection to 'auto_connect_ip'
auto_connect_ip = "109.123.243.163" # See 'auto_connect' auto_connect_ip = "chat.coquette.baby" # See 'auto_connect'
authority_ip = "chat.coquette.baby" # CA Address; Feel free to change if you don't trust the developer, but be aware that both client and server must use the same CA

@ -24,5 +24,8 @@ 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
min_message_delay = 250 # Minimal ms delay between user messages (to prevent spamming)
max_message_delay_violations = 4 # Maximal 'spam' messages that can be sent in row without getting disconnected

@ -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]
@ -125,6 +126,48 @@ pub extern "C" fn why2_toml_write(path: *const c_char, key: *const c_char, value
} }
} }
#[no_mangle]
pub extern "C" fn why2_toml_write_preserve(path: *const c_char, key: *const c_char, value: *const 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() };
let value_r = unsafe { CStr::from_ptr(value).to_string_lossy().into_owned() };
//READ FILE
let file_raw = match read_to_string(&path_r)
{
Ok(raw) => raw,
Err(e) =>
{
eprintln!("Could not read TOML config '{}': {}", path_r, e);
return;
}
};
//PARSE TO A toml_edit Document
let mut doc: toml_edit::Document = match file_raw.parse()
{
Ok(doc) => doc,
Err(e) =>
{
eprintln!("Could not parse TOML config '{}': {}", path_r, e);
return;
}
};
doc[&key_r] = toml_edit::value(value_r);
//CONVERT DOCUMENT TO STRING
let updated_data = doc.to_string();
//WRITE
if let Err(e) = write(&path_r, updated_data)
{
eprintln!("Could not write to TOML config '{}': {}", path_r, e);
}
}
#[no_mangle] #[no_mangle]
pub extern "C" fn why2_toml_contains(path: *const c_char, key: *const c_char) -> bool pub extern "C" fn why2_toml_contains(path: *const c_char, key: *const c_char) -> bool
{ {
@ -157,6 +200,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
{ {

@ -23,183 +23,294 @@ 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 <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/ec.h>
#include <why2/encrypter.h>
#include <why2/memory.h> #include <why2/memory.h>
#include <why2/misc.h> #include <why2/misc.h>
#include <gmp.h> EVP_PKEY *keypair = NULL; //KEYPAIR
//DO NOT TOUCH THESE PLS :3
char *rsa_modulus = NULL; //THE RSA MODULUS
char *rsa_d = NULL; //THE RSA d
//LOCAL //LOCAL
void generate_prime(mpz_t x) void calculate_ecdh_secret(EVP_PKEY *pri, EVP_PKEY *pub, char **secret, size_t *len)
{ {
//RANDOM EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(pri, NULL);
gmp_randstate_t state; EVP_PKEY_derive_init(ctx); //INIT DERIVE CONTEXT
gmp_randinit_default(state);
unsigned long random_buffer; //SEED
do EVP_PKEY_derive_set_peer(ctx, pub); //CONFIG
{
if (getrandom(&random_buffer, sizeof(unsigned long), GRND_NONBLOCK) == -1) why2_die("getrandom fn failed!");
//GENERATE RANDOM PRIME USING random_buffer SEED //ALLOCATE
gmp_randseed_ui(state, random_buffer); EVP_PKEY_derive(ctx, NULL, len); //CALCULATE LENGTH
mpz_urandomb(x, state, WHY2_CHAT_KEY_BITS); *secret = why2_malloc(*len);
mpz_nextprime(x, x);
} while (mpz_probab_prime_p(x, WHY2_CHAT_PRIME_ITERS) == 0); //CHECK FOR PRIME PROBABILITY EVP_PKEY_derive(ctx, (unsigned char*) *secret, len); //GET SHARED SECRET
//DEALLOCATION //DEALLOCATION
gmp_randclear(state); EVP_PKEY_CTX_free(ctx);
}
void read_file(FILE *file, char **output)
{
//VARIABLES
int buffer_size;
char *buffer;
//GET LENGTH
fseek(file, 0, SEEK_END);
buffer_size = ftell(file);
rewind(file);
//READ
buffer = why2_calloc(buffer_size + 1, sizeof(char));
if (fread(buffer, buffer_size, 1, file) != 1) why2_die("Reading keyfile failed!");
buffer[buffer_size] = '\0';
//ASSIGN OUTPUT
*output = buffer;
}
char *exp_mod(char *to_exp, char *exponent)
{
//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
mpz_clears(m, c, n, e, NULL);
return output;
} }
//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_base64_encode(char *message, size_t *length)
{
//VARIABLES
BIO *bio;
BIO *b64;
BUF_MEM *buffer_ptr;
char* encoded_message;
//INIT BIOs
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //DISABLE NEWLINES
bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);
//ENCODE
BIO_write(bio, message, *length);
BIO_flush(bio);
BIO_get_mem_ptr(bio, &buffer_ptr);
//COPY
encoded_message = why2_malloc(buffer_ptr -> length + why2_count_int_length((int) *length) + 3);
memcpy(encoded_message, buffer_ptr -> data, buffer_ptr -> length);
sprintf(encoded_message + buffer_ptr -> length, "%c%zu%c", WHY2_CHAT_BASE64_LENGTH_DELIMITER, *length, '\0'); //APPEND LENGTH
//DEALLOCATION
BIO_free_all(bio);
return encoded_message;
}
char *why2_chat_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
//INVALID BASE64
if (separator_ptr == NULL) return NULL;
size_t length_local = strtoull(separator_ptr + 1, NULL, 10);
char* decoded_message = why2_malloc(length_local + 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_local);
//NULL-TERM
decoded_message[decoded_length] = '\0';
//DEALLOCATION
BIO_free_all(bio);
//SET length
if (length != NULL) *length = length_local;
return decoded_message;
}
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 = why2_chat_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 = why2_chat_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;
}
//TODO: Remove PEM
char *why2_chat_ecc_serialize_public_key()
{
//VARIABLES
BIO *bio = BIO_new(BIO_s_mem());
char *data;
size_t length;
char *pubkey;
char *base64_encoded;
//SEPARATE PUBKEY
PEM_write_bio_PUBKEY(bio, keypair);
//ALLOCATE
length = BIO_get_mem_data(bio, &data);
pubkey = why2_malloc(length + 1);
//COPY
memcpy(pubkey, data, length);
pubkey[length] = '\0';
//ENCODE
base64_encoded = why2_chat_base64_encode(pubkey, &length);
//DEALLOCATION
BIO_free(bio);
why2_deallocate(pubkey);
return base64_encoded;
}
//TODO: Remove PEM
EVP_PKEY* why2_chat_ecc_deserialize_public_key(char *pubkey)
{
//VARIABLES
BIO *bio;
EVP_PKEY *key;
char *base64_decoded = why2_chat_base64_decode(pubkey, NULL);
//EXTRACT KEY
bio = BIO_new_mem_buf(base64_decoded, -1);
key = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
//DEALLOCATION
BIO_free(bio);
return key;
}
char *why2_chat_ecc_shared_key(char *ecc_key)
{
//VARIABLES
size_t key_length;
char *secret = NULL;
size_t secret_len;
char *recipient_pubkey_decoded = why2_chat_base64_decode(ecc_key, &key_length); //DECODE key
char *sym_key;
BIO *bio = BIO_new_mem_buf(recipient_pubkey_decoded, -1);
EVP_PKEY *recipient_pubkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
//CALCULATE SHARED SECRET
calculate_ecdh_secret(keypair, recipient_pubkey, &secret, &secret_len);
//DERIVE WHY2 KEY (SHA256)
sym_key = why2_sha256(secret, secret_len);
//DEALLOCATION
BIO_free(bio);
EVP_PKEY_free(recipient_pubkey);
why2_deallocate(secret);
why2_deallocate(recipient_pubkey_decoded);
return sym_key;
} }
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, size_t length)
{ {
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, length, 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;
} }

88
src/chat/flags.c Normal file

@ -0,0 +1,88 @@
/*
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>
#include <why2/memory.h>
why2_bool asking_password = 0;
why2_bool asking_username = 0;
why2_bool is_server = 0;
char *client_server_key = NULL;
void why2_chat_set_client_server_key(char *key)
{
client_server_key = key;
}
char *why2_chat_get_client_server_key(void)
{
return client_server_key;
}
void why2_chat_deallocate_client_server_key(void)
{
why2_deallocate(client_server_key);
client_server_key = NULL;
}
void __why2_chat_set_server(why2_bool value)
{
is_server = value;
}
why2_bool __why2_chat_is_server(void)
{
return is_server;
}
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(void)
{
return asking_password;
}
void __why2_set_asking_username(why2_bool value)
{
asking_username = value;
}
why2_bool __why2_get_asking_username(void)
{
return asking_username;
}

90
src/chat/main/authority.c Normal file

@ -0,0 +1,90 @@
/*
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
#include <why2/chat/config.h>
#include <why2/chat/crypto.h>
#include <why2/chat/flags.h>
#include <why2/chat/misc.h>
#include <why2/memory.h>
#include <why2/misc.h>
int main(void)
{
__why2_chat_set_server(1);
why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_authority(); //CREATE AUTHORITY DIRECTORY
why2_chat_init_keys(); //CREATE ECC KEY
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE CA SERVER SOCKET
pthread_t thread;
size_t line_length_buffer = 0;
char *line_buffer = NULL;
if (listen_socket < 0) why2_die("Failed creating socket.");
//DEFINE CA SERVER ADDRESS
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(WHY2_CHAT_AUTHORITY_PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
//BIND SOCKET
if (bind(listen_socket, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) why2_die("Failed binding socket.");
//LISTEN
if (listen(listen_socket, WHY2_MAX_CONNECTIONS) < 0) why2_die("Binding failed.");
printf("CA server enabled.\n\n");
__why2_accept_thread_params params = { listen_socket, WHY2_CHAT_AUTHORITY };
pthread_create(&thread, NULL, why2_accept_thread, &params);
for (;;)
{
if (getline(&line_buffer, &line_length_buffer, stdin) == -1) why2_die("Reading input failed.");
if (strcmp(line_buffer, WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT "\n") == 0) //USER REQUESTED PROGRAM EXIT
{
printf("Exiting...\n");
break;
}
}
//QUIT COMMUNICATION
why2_clean_connections(); //STOP LISTENING; DISCONNECT ALL USERS
why2_clean_threads(); //STOP WAITING FOR MESSAGES
//DEALLOCATION
free(line_buffer);
close(listen_socket);
pthread_cancel(thread);
why2_clean_memory(""); //RUN GARBAGE COLLECTOR
return 0;
}

@ -20,9 +20,11 @@ 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 <signal.h> #include <signal.h>
#include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h> #include <pthread.h>
@ -43,7 +45,7 @@ void exit_client(WHY2_UNUSED int i) //guess what
if (exited) return; if (exited) return;
exited = 1; exited = 1;
why2_send_socket(WHY2_CHAT_CODE_EXIT, NULL, listen_socket); why2_send_socket_code(NULL, NULL, why2_chat_get_client_server_key(), listen_socket, WHY2_CHAT_CODE_EXIT);
} }
why2_bool command(char *input, char *command, char **arg) why2_bool command(char *input, char *command, char **arg)
@ -92,15 +94,61 @@ void invalid(char *type)
fflush(stdout); fflush(stdout);
} }
struct sockaddr_in resolve_domain(char *domain, uint16_t port)
{
//VARIABLES
struct sockaddr_in server_addr = { 0 };
struct in_addr ipv4_buffer;
//SET STUFF
server_addr.sin_family = AF_INET; //SET FAMILY
server_addr.sin_port = htons(port); //SET PORT
domain[strcspn(domain, "\n")] = '\0'; //REMOVE NEWLINE
//ALREADY USING IPv4 ADDRESS
if (inet_pton(AF_INET, domain, &ipv4_buffer) == 1)
{
server_addr.sin_addr = ipv4_buffer;
return server_addr;
}
//DOMAIN-RESOLVE VARIABLES
struct addrinfo hints;
struct addrinfo *res = NULL;
struct sockaddr_in *ipv4;
//SET addrinfo STUFF
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
//CERO, NADA
if (getaddrinfo(domain, NULL, &hints, &res) != 0)
{
why2_die("Error resolving domain!");
}
//USE FIRST IPv4 ADDRESS FOUND
ipv4 = (struct sockaddr_in *) res -> ai_addr;
server_addr.sin_addr = ipv4 -> sin_addr;
//DEALLOCATION
freeaddrinfo(res);
return server_addr;
}
int main(void) int main(void)
{ {
signal(SIGINT, exit_client); //HANDLE ^C signal(SIGINT, exit_client); //HANDLE ^C
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 //VARIABLES
listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE AUTHORITY SOCKET
char *line = NULL; char *line = NULL;
void *return_line = NULL; void *return_line = NULL;
size_t line_length = 0; size_t line_length = 0;
@ -108,11 +156,28 @@ int main(void)
pthread_t thread_getline; pthread_t thread_getline;
why2_bool ssqc = 0; why2_bool ssqc = 0;
char *cmd_arg = NULL; char *cmd_arg = NULL;
why2_bool *ca_success;
//DEFINE SERVER ADDRESS
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(WHY2_CHAT_SERVER_PORT); //CA CONNECT
line = why2_chat_client_config("authority_ip"); //GET ADDRESS OF CA
//GET server_addr
server_addr = resolve_domain(line, WHY2_CHAT_AUTHORITY_PORT);
if (connect(listen_socket, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) why2_die("Connecting to CA failed."); //CONNECT TO CA
pthread_create(&thread_buffer, NULL, why2_listen_authority, &listen_socket); //LISTEN TO AUTHORITY (only in why2, fuck authorities irl [hi fbi, this is just a joke haha])
why2_deallocate(line); //DEALLOCATE ADDRESS
pthread_join(thread_buffer, (void**) &ca_success); //WAIT UNTIL CA AUTH IS COMPLETED
close(listen_socket); //CLOSE CONNECTION
if (!*ca_success) why2_die("CA Authentication failed!");
why2_deallocate(ca_success);
//SERVER CONNECT
listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
//GET IP //GET IP
printf("Welcome.\n\n"); printf("Welcome.\n\n");
@ -137,10 +202,11 @@ int main(void)
why2_toml_read_free(auto_connect); why2_toml_read_free(auto_connect);
server_addr.sin_addr.s_addr = inet_addr(line); //GET server_addr
server_addr = resolve_domain(line, WHY2_CHAT_SERVER_PORT);
//PRINT UNDERLINE //PRINT UNDERLINE
for (unsigned long i = 0; i < strlen(line) + line_length; i++) for (unsigned long i = 0; i < strlen(line) + line_length + 1; i++)
{ {
printf("#"); printf("#");
} }
@ -148,9 +214,7 @@ int main(void)
free(line); //PREVENT FROM MEMORY LEAK free(line); //PREVENT FROM MEMORY LEAK
int connectStatus = connect(listen_socket, (WHY2_SA *) &server_addr, sizeof(server_addr)); //CONNECT if (connect(listen_socket, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) why2_die("Connecting failed."); //CONNECT
if (connectStatus < 0) why2_die("Connecting failed.");
pthread_create(&thread_buffer, NULL, why2_listen_server, &listen_socket); //LISTEN TO OTHER USERS pthread_create(&thread_buffer, NULL, why2_listen_server, &listen_socket); //LISTEN TO OTHER USERS
@ -188,17 +252,18 @@ 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_PM " <ID> <MSG>\tSends encrypted message to user.\n" //TODO: Implement
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;
@ -240,27 +305,51 @@ int main(void)
} }
//BUILD MESSAGE TO SEND TO SERVER //BUILD MESSAGE TO SEND TO SERVER
char *final_message = why2_malloc(strlen(WHY2_CHAT_CODE_PM) + strlen(id) + strlen(msg) + 3); char *final_message = why2_malloc(strlen(id) + strlen(msg) + 2);
sprintf(final_message, WHY2_CHAT_CODE_PM ";%s;%s%c", id, msg, '\0'); sprintf(final_message, "%s;%s%c", id, msg, '\0');
why2_send_socket(final_message, NULL, listen_socket); //SEND why2_send_socket_code(final_message, NULL, why2_chat_get_client_server_key(), listen_socket, WHY2_CHAT_CODE_DM); //SEND
//DEALLOCATION //DEALLOCATION
why2_deallocate(id); why2_deallocate(id);
why2_deallocate(final_message); why2_deallocate(final_message);
} else if (command(line, WHY2_CHAT_COMMAND_LIST, &cmd_arg)) //LIST CMD } else if (command(line, WHY2_CHAT_COMMAND_LIST, &cmd_arg)) //LIST CMD
{ {
why2_send_socket(WHY2_CHAT_CODE_LIST, NULL, listen_socket); why2_send_socket_code(NULL, NULL, why2_chat_get_client_server_key(), listen_socket, WHY2_CHAT_CODE_LIST);
} else if (command(line, WHY2_CHAT_COMMAND_VERSION, &cmd_arg)) //VERSION CMD } else if (command(line, WHY2_CHAT_COMMAND_VERSION, &cmd_arg)) //VERSION CMD
{ {
why2_send_socket(WHY2_CHAT_CODE_VERSION, NULL, listen_socket); why2_send_socket_code(NULL, NULL, why2_chat_get_client_server_key(), listen_socket, WHY2_CHAT_CODE_VERSION);
} else } else
{ {
invalid("command"); invalid("command");
} }
} else } 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 if (__why2_get_asking_password())
{
//REMOVE \n AT THE END OF line
line[strlen(line) - 1] = '\0';
char *hash = why2_sha256(line, strlen(line)); //HASHISH
why2_send_socket_code(hash, NULL, why2_chat_get_client_server_key(), listen_socket, WHY2_CHAT_CODE_PASSWORD); //SEND BUT HASHED
//DEALLOCATION
why2_deallocate(hash);
__why2_set_asking_password(0);
} else
{
if (__why2_get_asking_username())
{
__why2_set_asking_username(0);
why2_send_socket_code(line, NULL, why2_chat_get_client_server_key(), listen_socket, WHY2_CHAT_CODE_USERNAME);
} else
{
why2_send_socket(line, NULL, why2_chat_get_client_server_key(), listen_socket); //NULL IS SENT BECAUSE IT IS USELESS TO SEND USER FROM CLIENT - SERVER WON'T USE IT
}
}
free(line); free(line);
} }
} }
@ -274,6 +363,7 @@ int main(void)
why2_deallocate(cmd_arg); why2_deallocate(cmd_arg);
why2_chat_deallocate_keys(); //DEALLOCATE GETTERS FOR KEYS why2_chat_deallocate_keys(); //DEALLOCATE GETTERS FOR KEYS
why2_chat_deallocate_client_server_key();
why2_clean_memory(""); //RUN GARBAGE COLLECTOR why2_clean_memory(""); //RUN GARBAGE COLLECTOR

@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <pthread.h> #include <pthread.h>
#include <why2/chat/config.h> #include <why2/chat/config.h>
#include <why2/chat/crypto.h>
#include <why2/chat/flags.h> #include <why2/chat/flags.h>
#include <why2/chat/misc.h> #include <why2/chat/misc.h>
@ -34,8 +35,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void) int main(void)
{ {
__why2_chat_set_server(1);
why2_check_version(); //CHECK FOR UPDATES why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_server_config(); //CREATE server.toml CONFIGURATION why2_chat_init_server_config(); //CREATE server.toml CONFIGURATION
why2_chat_init_keys(); //CREATE ECC KEY
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
pthread_t thread; pthread_t thread;
@ -51,14 +54,15 @@ int main(void)
server_addr.sin_addr.s_addr = INADDR_ANY; server_addr.sin_addr.s_addr = INADDR_ANY;
//BIND SOCKET //BIND SOCKET
if (bind(listen_socket, (WHY2_SA *) &server_addr, sizeof(server_addr)) < 0) why2_die("Failed binding socket."); if (bind(listen_socket, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) why2_die("Failed binding socket.");
//LISTEN //LISTEN
if (listen(listen_socket, WHY2_MAX_CONNECTIONS) < 0) why2_die("Binding failed."); if (listen(listen_socket, WHY2_MAX_CONNECTIONS) < 0) why2_die("Binding failed.");
printf("Server enabled.\n\n"); printf("Server enabled.\n\n");
pthread_create(&thread, NULL, why2_accept_thread, &listen_socket); __why2_accept_thread_params params = { listen_socket, WHY2_CHAT_SERVER };
pthread_create(&thread, NULL, why2_accept_thread, &params);
for (;;) for (;;)
{ {

File diff suppressed because it is too large Load Diff

@ -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);

@ -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,9 +67,10 @@ 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
unsigned long returning_len = 0;
if (why2_get_flags().format == WHY2_OUTPUT_BYTE) if (why2_get_flags().format == WHY2_OUTPUT_BYTE)
{ {
@ -78,12 +81,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)];
@ -126,13 +123,14 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
} }
//SET LENGTH (number_buffer) //SET LENGTH (number_buffer)
returning_text = why2_calloc(number_buffer + 1, sizeof(char)); returning_len = number_buffer + 1;
returning_text = why2_calloc(returning_len, sizeof(char));
text_key_chain = why2_malloc(sizeof(int) * number_buffer); text_key_chain = why2_malloc(sizeof(int) * number_buffer);
encrypted_text_key_chain = why2_malloc(sizeof(int) * number_buffer); encrypted_text_key_chain = why2_malloc(sizeof(int) * number_buffer);
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 +179,60 @@ 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_len = why2_list_get_size(&split_text) + 1;
returning_text = why2_recalloc(returning_text, returning_len, 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 +240,10 @@ 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 returning_len, //LENGTH
why2_count_unused_key_size(returning_text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY key_new, //USED KEY
why2_count_repeated_key_size(returning_text, key), //NUMBER OF REPEATED 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_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
}; };

@ -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,106 @@ 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;
unsigned long returning_len = 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_len = number_buffer + strlen(text_new);
returning_text = why2_calloc(returning_len, 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 +164,24 @@ 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_len = number_buffer + 1;
returning_text = why2_calloc(returning_len, 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 +202,10 @@ 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 returning_len, //LENGTH
why2_count_unused_key_size(text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY key_new, //GENERATED/USED KEY
why2_count_repeated_key_size(text, key), //NUMBER OF REPEATED 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_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 +213,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();

@ -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,22 +69,22 @@ 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)
{ {
char *emptyText = why2_malloc(1); //TEXT char *empty_text = why2_malloc(1); //TEXT
emptyText[0] = '\0'; empty_text[0] = '\0';
char *emptyKey = why2_malloc(why2_get_key_length() + 1); //KEY char *empty_key = why2_malloc(why2_get_key_length() + 1); //KEY
for (int i = 0; i < (int) why2_get_key_length(); i++) for (unsigned long i = 0; i < why2_get_key_length(); i++)
{ {
emptyKey[i] = 'x'; empty_key[i] = 'x';
} }
emptyKey[why2_get_key_length()] = '\0'; empty_key[why2_get_key_length()] = '\0';
return (why2_output_flags) { emptyText, emptyKey, 0, 0, 0, exit_code }; return (why2_output_flags) { empty_text, 0, empty_key, 0, 0, 0, exit_code };
} }
why2_encryption_operation_cb why2_get_encryption_operation(void) why2_encryption_operation_cb why2_get_encryption_operation(void)
@ -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);

@ -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

@ -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;
}

@ -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;
}

@ -153,8 +153,21 @@ 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)
{ {
if (string == NULL) return NULL;
char *allocated = strdup(string); char *allocated = strdup(string);
push_to_list(allocated, ALLOCATION); push_to_list(allocated, ALLOCATION);

@ -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);
@ -169,7 +185,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
if (!why2_get_flags().no_output) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n"); if (!why2_get_flags().no_output) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n");
why2_clean_memory("core_version_check"); why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED; return WHY2_UPDATE_FAILED;
} }
//VARIABLES //VARIABLES
@ -199,7 +215,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (cloning)\n"); if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (cloning)\n");
why2_clean_memory("core_version_check"); why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED; return WHY2_UPDATE_FAILED;
} }
//COUNT install_command LENGTH & ALLOCATE IT //COUNT install_command LENGTH & ALLOCATE IT
@ -218,7 +234,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (installing)\n"); if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (installing)\n");
why2_clean_memory("core_version_check"); why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED; return WHY2_UPDATE_FAILED;
} }
} else } else
{ {
@ -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;

@ -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))
} }
); );

@ -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
{ {

@ -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