Compare commits
47 Commits
windows-li
...
v0.31.2
Author | SHA1 | Date | |
---|---|---|---|
ea52a3251d | |||
03954db321 | |||
c8185f0ea8 | |||
02b3826685 | |||
a71a49800f | |||
3166418a2d | |||
b5ae6552d0 | |||
344c62307d | |||
7edf37b893 | |||
140adb2141 | |||
b6d51e6284 | |||
b84a3caddf | |||
7dbc7c1aae | |||
c38987ac1c | |||
92b38de9cb | |||
8b554c13b5 | |||
390793bdb8 | |||
e567bb463c | |||
883932c073 | |||
64d85291fd | |||
6bee253ca6 | |||
94478efec2 | |||
2226ef0a20 | |||
cd24279c2a | |||
35754667d8 | |||
4843b0b624 | |||
27fabf8a82 | |||
36528099fd | |||
3b004ee4c7 | |||
1920a37572 | |||
ebf7d0b012 | |||
b410da5986 | |||
1b7b8cf8ba | |||
9ca783a022 | |||
8623304b62 | |||
3f14a30065 | |||
ce0d1bfdfa | |||
749519ab1f | |||
a04bb557c7 | |||
4bcaa17adb | |||
ca20286c6b | |||
0aebf5a20a | |||
baf1b3e580 | |||
e6b8f5e231 | |||
b324eb1e21 | |||
610e6c106e | |||
03ccfe263b |
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,3 +1,14 @@
|
||||
*.o
|
||||
libsam3-tests
|
||||
*.a
|
||||
examples/libsam3
|
||||
examples/sam3/dgrams
|
||||
examples/sam3/dgramc
|
||||
examples/sam3/keys
|
||||
examples/sam3/keysp
|
||||
examples/sam3namelookup
|
||||
examples/sam3/streamss
|
||||
examples/sam3/streamcs
|
||||
examples/sam3/log
|
||||
examples/sam3/err
|
||||
|
||||
|
4
Makefile
4
Makefile
@ -32,6 +32,10 @@ libsam3-tests: ${TEST_OBJS} ${LIB}
|
||||
clean:
|
||||
rm -f libsam3-tests ${LIB} ${OBJS} examples/sam3/samtest
|
||||
|
||||
# TODO: this does not work yet because I don't know how to do it.
|
||||
boost:
|
||||
gcc -Werror -Wall -Wextra -Wno-unused-parameter -std=c++11 -g -lboost_system -lboost_thread -lpthread examples/boost/boost.cpp -o boost
|
||||
|
||||
%.o: %.c Makefile
|
||||
${CC} ${CFLAGS} $(LDFLAGS) -c $< -o $@
|
||||
|
||||
|
@ -2,7 +2,7 @@ CFLAGS := -Wall -g -O2 -std=gnu99
|
||||
|
||||
all: clean examples
|
||||
|
||||
examples: example lookup dclient dserver sclient sserver
|
||||
examples: example lookup dclient dserver sclient sserver ssserver ssclient
|
||||
|
||||
example:
|
||||
${CC} ${CFLAGS} samtest.c -o samtest ../libsam3/libsam3.o
|
||||
@ -22,8 +22,20 @@ sclient:
|
||||
sserver:
|
||||
${CC} ${CFLAGS} streams.c -o streams ../libsam3/libsam3.o
|
||||
|
||||
ssclient:
|
||||
${CC} ${CFLAGS} streamcs.c -o streamcs ../libsam3/libsam3.o
|
||||
|
||||
ssserver:
|
||||
${CC} ${CFLAGS} streamss.c -o streamss ../libsam3/libsam3.o
|
||||
|
||||
keysp:
|
||||
${CXX} ${CFLAGS} keys.cc -o keysp ../libsam3/libsam3.o
|
||||
|
||||
keys:
|
||||
${CC} ${CFLAGS} keys.c -o keys ../libsam3/libsam3.o
|
||||
|
||||
clean:
|
||||
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup
|
||||
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup keys keysp
|
||||
|
||||
debug:
|
||||
sed -i 's|// libsam3_debug = 1;|libsam3_debug = 1;|g' *.c
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -25,8 +41,9 @@
|
||||
int main(int argc, char *argv[]) {
|
||||
Sam3Session ses;
|
||||
char buf[1024];
|
||||
char destkey[517] = {0}; // 516 chars + \0
|
||||
char destkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE + 1] = {0};
|
||||
int sz;
|
||||
size_t sizeread;
|
||||
//
|
||||
libsam3_debug = 1;
|
||||
//
|
||||
@ -34,17 +51,27 @@ int main(int argc, char *argv[]) {
|
||||
FILE *fl = fopen(KEYFILE, "rb");
|
||||
//
|
||||
if (fl != NULL) {
|
||||
if (fread(destkey, 516, 1, fl) == 1) {
|
||||
fprintf(stderr, "Reading key file...\n");
|
||||
sizeread = fread(destkey, sizeof(char), sizeof(destkey), fl);
|
||||
fprintf(stderr, "Read %li bytes\n", sizeread);
|
||||
if (ferror(fl) != 0) {
|
||||
fprintf(stderr, "I/O Error\n");
|
||||
return 1;
|
||||
}
|
||||
// Insure that the bytes read safely fits into destkey
|
||||
if (sizeread == sizeof(destkey)) {
|
||||
fprintf(stderr, "Error, key file is to large (> %li)\n", sizeread);
|
||||
fclose(fl);
|
||||
goto ok;
|
||||
return 1;
|
||||
}
|
||||
fclose(fl);
|
||||
goto ok;
|
||||
}
|
||||
printf("usage: dgramc PUBKEY\n");
|
||||
return 1;
|
||||
} else {
|
||||
if (strlen(argv[1]) != 516) {
|
||||
fprintf(stderr, "FATAL: invalid key length!\n");
|
||||
if (strlen(argv[1]) > (SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE)) {
|
||||
fprintf(stderr, "FATAL: invalid key length (%li)!\n", strlen(argv[1]));
|
||||
return 1;
|
||||
}
|
||||
strcpy(destkey, argv[1]);
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -19,7 +35,9 @@
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Sam3Session ses;
|
||||
char privkey[1024], pubkey[1024], buf[33 * 1024];
|
||||
char privkey[SAM3_PRIVKEY_MAX_SIZE + 1],
|
||||
pubkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE + 1],
|
||||
buf[33 * 1024];
|
||||
|
||||
/** quit command */
|
||||
const char *quitstr = "quit";
|
||||
@ -46,7 +64,7 @@ int main(int argc, char *argv[]) {
|
||||
/** create sam session */
|
||||
printf("creating session...\n");
|
||||
if (sam3CreateSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, privkey,
|
||||
SAM3_SESSION_DGRAM, 5, NULL) < 0) {
|
||||
SAM3_SESSION_DGRAM, 4, NULL) < 0) {
|
||||
fprintf(stderr, "FATAL: can't create session\n");
|
||||
return 1;
|
||||
}
|
||||
@ -58,7 +76,8 @@ int main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
/** print destination to stdout */
|
||||
printf("PUB KEY\n=======\n%s\n=======\n", ses.pubkey);
|
||||
printf("PUB KEY (length = %li)\n=======\n%s\n=======\n",
|
||||
strlen(ses.pubkey), ses.pubkey);
|
||||
if ((fl = fopen(KEYFILE, "wb")) != NULL) {
|
||||
/** write public key to keyfile */
|
||||
fwrite(pubkey, strlen(pubkey), 1, fl);
|
||||
@ -74,7 +93,8 @@ int main(int argc, char *argv[]) {
|
||||
int sz, isquit;
|
||||
printf("waiting for datagram...\n");
|
||||
/** blocks until we get a UDP packet */
|
||||
if ((sz = sam3DatagramReceive(&ses, datagramBuf, datagramMaxLen) < 0)) {
|
||||
sz = sam3DatagramReceive(&ses, datagramBuf, datagramMaxLen);
|
||||
if (sz < 0) {
|
||||
fprintf(stderr, "ERROR: %s\n", ses.error);
|
||||
goto error;
|
||||
}
|
||||
|
20
examples/sam3/keys.c
Normal file
20
examples/sam3/keys.c
Normal file
@ -0,0 +1,20 @@
|
||||
//#include <string>
|
||||
//#include <iostream>
|
||||
#include "../libsam3/libsam3.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// The session is only usef for transporting the data
|
||||
Sam3Session ss;
|
||||
|
||||
if (0 > sam3GenerateKeys(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, 4)) {
|
||||
printf("got error");
|
||||
return -1;
|
||||
}
|
||||
printf("\tpubkey: %s \n \tprivkey: %s", ss.pubkey, ss.privkey);
|
||||
/*auto pub = std::string(ss.pubkey);
|
||||
auto priv = std::string(ss.privkey);
|
||||
|
||||
std::cout << "pub " << pub << std::endl << "priv " << priv << std::endl;*/
|
||||
return 0;
|
||||
}
|
19
examples/sam3/keys.cc
Normal file
19
examples/sam3/keys.cc
Normal file
@ -0,0 +1,19 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include "../libsam3/libsam3.h"
|
||||
|
||||
int main() {
|
||||
// The session is only usef for transporting the data
|
||||
Sam3Session ss;
|
||||
|
||||
if (0 > sam3GenerateKeys(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, Sam3SigType::EdDSA_SHA512_Ed25519)) {
|
||||
printf("got error");
|
||||
return -1;
|
||||
}
|
||||
auto pub = std::string(ss.pubkey);
|
||||
auto priv = std::string(ss.privkey);
|
||||
|
||||
std::cout << "pub " << pub << std::endl << "priv " << priv << std::endl;
|
||||
return 0;
|
||||
}
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
103
examples/sam3/streamcs.c
Normal file
103
examples/sam3/streamcs.c
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../libsam3/libsam3.h"
|
||||
|
||||
#define KEYFILE "streams.key"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Sam3Session ses;
|
||||
Sam3Connection *conn;
|
||||
char cmd[1024], destkey[617]; // 616 chars + \0
|
||||
//
|
||||
libsam3_debug = 1;
|
||||
//
|
||||
memset(destkey, 0, sizeof(destkey));
|
||||
//
|
||||
if (argc < 2) {
|
||||
FILE *fl = fopen(KEYFILE, "rb");
|
||||
//
|
||||
if (fl != NULL) {
|
||||
if (fread(destkey, 616, 1, fl) == 1) {
|
||||
fclose(fl);
|
||||
goto ok;
|
||||
}
|
||||
fclose(fl);
|
||||
}
|
||||
printf("usage: streamc PUBKEY\n");
|
||||
return 1;
|
||||
} else {
|
||||
if (!sam3CheckValidKeyLength(argv[1])) {
|
||||
fprintf(stderr, "FATAL: invalid key length! %s %lu\n", argv[1],
|
||||
strlen(argv[1]));
|
||||
return 1;
|
||||
}
|
||||
strcpy(destkey, argv[1]);
|
||||
}
|
||||
//
|
||||
ok:
|
||||
printf("creating session...\n");
|
||||
// create TRANSIENT session
|
||||
if (sam3CreateSilentSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT,
|
||||
SAM3_DESTINATION_TRANSIENT, SAM3_SESSION_STREAM,
|
||||
4, NULL) < 0) {
|
||||
fprintf(stderr, "FATAL: can't create session\n");
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
printf("connecting...\n");
|
||||
if ((conn = sam3StreamConnect(&ses, destkey)) == NULL) {
|
||||
fprintf(stderr, "FATAL: can't connect: %s\n", ses.error);
|
||||
sam3CloseSession(&ses);
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
// now waiting for incoming connection
|
||||
printf("sending test command...\n");
|
||||
if (sam3tcpPrintf(conn->fd, "test\n") < 0)
|
||||
goto error;
|
||||
if (sam3tcpReceiveStr(conn->fd, cmd, sizeof(cmd)) < 0)
|
||||
goto error;
|
||||
printf("echo: %s\n", cmd);
|
||||
//
|
||||
printf("sending quit command...\n");
|
||||
if (sam3tcpPrintf(conn->fd, "quit\n") < 0)
|
||||
goto error;
|
||||
//
|
||||
sam3CloseConnection(conn);
|
||||
sam3CloseSession(&ses);
|
||||
return 0;
|
||||
error:
|
||||
fprintf(stderr, "FATAL: some error occured!\n");
|
||||
sam3CloseConnection(conn);
|
||||
sam3CloseSession(&ses);
|
||||
return 1;
|
||||
}
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
88
examples/sam3/streamss.c
Normal file
88
examples/sam3/streamss.c
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../libsam3/libsam3.h"
|
||||
|
||||
#define KEYFILE "streams.key"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Sam3Session ses;
|
||||
Sam3Connection *conn;
|
||||
FILE *fl;
|
||||
//
|
||||
libsam3_debug = 1;
|
||||
//
|
||||
printf("creating session...\n");
|
||||
// create TRANSIENT session
|
||||
if (sam3CreateSilentSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT,
|
||||
SAM3_DESTINATION_TRANSIENT, SAM3_SESSION_STREAM,
|
||||
4, NULL) < 0) {
|
||||
fprintf(stderr, "FATAL: can't create session\n");
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
printf("PUB KEY\n=======\n%s\n=======\n", ses.pubkey);
|
||||
if ((fl = fopen(KEYFILE, "wb")) != NULL) {
|
||||
fwrite(ses.pubkey, strlen(ses.pubkey), 1, fl);
|
||||
fclose(fl);
|
||||
}
|
||||
//
|
||||
printf("starting stream acceptor...\n");
|
||||
if ((conn = sam3StreamAccept(&ses)) == NULL) {
|
||||
fprintf(stderr, "FATAL: can't accept: %s\n", ses.error);
|
||||
sam3CloseSession(&ses);
|
||||
return 1;
|
||||
}
|
||||
printf("FROM\n====\n%s\n====\n", conn->destkey);
|
||||
//
|
||||
printf("starting main loop...\n");
|
||||
for (;;) {
|
||||
char cmd[256];
|
||||
//
|
||||
if (sam3tcpReceiveStr(conn->fd, cmd, sizeof(cmd)) < 0)
|
||||
goto error;
|
||||
printf("cmd: [%s]\n", cmd);
|
||||
if (strcmp(cmd, "quit") == 0)
|
||||
break;
|
||||
// echo command
|
||||
if (sam3tcpPrintf(conn->fd, "re: %s\n", cmd) < 0)
|
||||
goto error;
|
||||
}
|
||||
//
|
||||
sam3CloseSession(&ses);
|
||||
unlink(KEYFILE);
|
||||
return 0;
|
||||
error:
|
||||
fprintf(stderr, "FATAL: some error occured!\n");
|
||||
sam3CloseSession(&ses);
|
||||
unlink(KEYFILE);
|
||||
return 1;
|
||||
}
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include "libsam3.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@ -32,14 +48,31 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __unix__
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#if defined(__unix__) && !defined(__APPLE__)
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
#include <mach/mach_time.h>
|
||||
uint32_t TickCount() {
|
||||
uint64_t mat = mach_absolute_time();
|
||||
uint32_t mul = 0x80d9594e;
|
||||
return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int libsam3_debug = 0;
|
||||
|
||||
@ -609,8 +642,10 @@ static inline uint32_t hashint(uint32_t a) {
|
||||
}
|
||||
|
||||
static uint32_t genSeed(void) {
|
||||
volatile uint32_t seed = 1;
|
||||
uint32_t res;
|
||||
#ifndef WIN32
|
||||
#ifndef __APPLE__
|
||||
struct sysinfo sy;
|
||||
pid_t pid = getpid();
|
||||
//
|
||||
@ -618,10 +653,16 @@ static uint32_t genSeed(void) {
|
||||
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
|
||||
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
|
||||
hashint((uint32_t)sy.uptime);
|
||||
#else
|
||||
res = hashint((uint32_t)getpid()) ^
|
||||
hashint((uint32_t)TickCount());
|
||||
#endif
|
||||
#else
|
||||
res = hashint((uint32_t)GetCurrentProcessId()) ^
|
||||
hashint((uint32_t)GetTickCount());
|
||||
#endif
|
||||
res += __sync_fetch_and_add(&seed, 1);
|
||||
//
|
||||
return hashint(res);
|
||||
}
|
||||
|
||||
@ -716,20 +757,23 @@ int sam3GenerateKeys(Sam3Session *ses, const char *hostname, int port,
|
||||
return -1;
|
||||
}
|
||||
//
|
||||
if (sam3tcpPrintf(fd, "DEST GENERATE %s\n", sigtypes[sigType]) >= 0) {
|
||||
if ((rep = sam3ReadReply(fd)) != NULL &&
|
||||
sam3IsGoodReply(rep, "DEST", "REPLY", NULL, NULL)) {
|
||||
const char *pub = sam3FindField(rep, "PUB"),
|
||||
*priv = sam3FindField(rep, "PRIV");
|
||||
//
|
||||
if (pub != NULL && sam3CheckValidKeyLength(pub) && priv != NULL &&
|
||||
strlen(priv) >= SAM3_PRIVKEY_MIN_SIZE) {
|
||||
if (sam3tcpPrintf(fd, "DEST GENERATE %s\n", sigtypes[(int)sigType]) < 0) {
|
||||
strcpyerr(ses, "DEST_ERROR");
|
||||
}
|
||||
|
||||
rep = sam3ReadReply(fd);
|
||||
// sam3DumpFieldList(rep);
|
||||
if (!sam3IsGoodReply(rep, "DEST", "REPLY", "PUB", NULL)) {
|
||||
strcpyerr(ses, "PUBKEY_ERROR");
|
||||
}
|
||||
if (!sam3IsGoodReply(rep, "DEST", "REPLY", "PRIV", NULL)) {
|
||||
strcpyerr(ses, "PRIVKEY_ERROR");
|
||||
}
|
||||
const char *pub = sam3FindField(rep, "PUB");
|
||||
strcpy(ses->pubkey, pub);
|
||||
const char *priv = sam3FindField(rep, "PRIV");
|
||||
strcpy(ses->privkey, priv);
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
sam3FreeFieldList(rep);
|
||||
sam3tcpDisconnect(fd);
|
||||
@ -893,6 +937,10 @@ int sam3CreateSession(Sam3Session *ses, const char *hostname, int port,
|
||||
goto error;
|
||||
}
|
||||
// save our keys
|
||||
if (strlen(v) > SAM3_PRIVKEY_MAX_SIZE) {
|
||||
fprintf(stderr, "ERROR, Unexpected key size (%li)!\n", strlen(v));
|
||||
goto error;
|
||||
}
|
||||
strcpy(ses->privkey, v);
|
||||
sam3FreeFieldList(rep);
|
||||
// get public key
|
||||
@ -949,11 +997,9 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
|
||||
strcpyerr(ses, "IO_ERROR_SK");
|
||||
goto error;
|
||||
}
|
||||
char silent[6];
|
||||
checkIsSilent(ses, silent);
|
||||
if (sam3tcpPrintf(conn->fd,
|
||||
"STREAM CONNECT ID=%s DESTINATION=%s SILENT=%s\n",
|
||||
ses->channel, destkey, silent) < 0) {
|
||||
ses->channel, destkey, checkIsSilent(ses)) < 0) {
|
||||
strcpyerr(ses, "IO_ERROR");
|
||||
goto error;
|
||||
}
|
||||
@ -961,6 +1007,7 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
|
||||
strcpyerr(ses, "IO_ERROR");
|
||||
goto error;
|
||||
}
|
||||
if (!ses->silent) {
|
||||
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
|
||||
const char *v = sam3FindField(rep, "RESULT");
|
||||
//
|
||||
@ -972,6 +1019,7 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
|
||||
// no error
|
||||
strcpyerr(ses, NULL);
|
||||
}
|
||||
}
|
||||
sam3FreeFieldList(rep);
|
||||
if (conn != NULL) {
|
||||
strcpy(conn->destkey, destkey);
|
||||
@ -1018,12 +1066,14 @@ Sam3Connection *sam3StreamAccept(Sam3Session *ses) {
|
||||
strcpyerr(ses, "IO_ERROR_RP");
|
||||
goto error;
|
||||
}
|
||||
if (!ses->silent) {
|
||||
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
|
||||
const char *v = sam3FindField(rep, "RESULT");
|
||||
//
|
||||
strcpyerr(ses, (v != NULL && v[0] ? v : "I2P_ERROR_RES"));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (sam3tcpReceiveStr(conn->fd, repstr, sizeof(repstr)) < 0) {
|
||||
strcpyerr(ses, "IO_ERROR_RP1");
|
||||
goto error;
|
||||
@ -1056,11 +1106,11 @@ Sam3Connection *sam3StreamAccept(Sam3Session *ses) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void checkIsSilent(Sam3Session *ses, char *str) {
|
||||
const char *checkIsSilent(Sam3Session *ses) {
|
||||
if (ses->silent == true) {
|
||||
str = "true ";
|
||||
return "true";
|
||||
} else {
|
||||
str = "false";
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1084,11 +1134,9 @@ int sam3StreamForward(Sam3Session *ses, const char *hostname, int port) {
|
||||
strcpyerr(ses, "IO_ERROR_SK");
|
||||
goto error;
|
||||
}
|
||||
char silent[6];
|
||||
checkIsSilent(ses, silent);
|
||||
if (sam3tcpPrintf(ses->fwd_fd,
|
||||
"STREAM FORWARD ID=%s PORT=%d HOST=%s SILENT=%s\n",
|
||||
ses->channel, port, hostname, silent) < 0) {
|
||||
ses->channel, port, hostname, checkIsSilent(ses)) < 0) {
|
||||
strcpyerr(ses, "IO_ERROR_PF");
|
||||
goto error;
|
||||
}
|
||||
@ -1135,11 +1183,12 @@ int sam3DatagramSend(Sam3Session *ses, const char *destkey, const void *buf,
|
||||
strcpyerr(ses, "INVALID_DATA");
|
||||
return -1;
|
||||
}
|
||||
dbufsz = bufsize + 4 + SAM3_PUBKEY_SIZE + 1 + strlen(ses->channel) + 1;
|
||||
dbufsz = bufsize + 4 + strlen(destkey) + 1 + strlen(ses->channel) + 1;
|
||||
if ((dbuf = malloc(dbufsz)) == NULL) {
|
||||
strcpyerr(ses, "OUT_OF_MEMORY");
|
||||
return -1;
|
||||
}
|
||||
memset(dbuf, 0, dbufsz);
|
||||
sprintf(dbuf, "3.0 %s %s\n", ses->channel, destkey);
|
||||
memcpy(dbuf + strlen(dbuf), buf, bufsize);
|
||||
res = sam3udpSendToIP(ses->ip, ses->port, dbuf, dbufsz);
|
||||
|
@ -1,18 +1,34 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
#ifndef LIBSAM3_H
|
||||
#define LIBSAM3_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef _SSIZE_T_DEFINED
|
||||
#define _SSIZE_T_DEFINED
|
||||
@ -39,6 +55,7 @@ extern int libsam3_debug;
|
||||
#define SAM3_PUBKEY_SIZE (516)
|
||||
#define SAM3_CERT_SIZE (100)
|
||||
#define SAM3_PRIVKEY_MIN_SIZE (884)
|
||||
#define SAM3_PRIVKEY_MAX_SIZE (1024)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/* returns fd or -1 */
|
||||
@ -136,7 +153,7 @@ typedef struct Sam3Session {
|
||||
Sam3SessionType type;
|
||||
Sam3SigType sigType;
|
||||
int fd;
|
||||
char privkey[SAM3_PRIVKEY_MIN_SIZE + 1]; // destination private key (asciiz)
|
||||
char privkey[SAM3_PRIVKEY_MAX_SIZE + 1]; // destination private key (asciiz)
|
||||
char pubkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE +
|
||||
1]; // destination public key (asciiz)
|
||||
char channel[66]; // name of this sam session (asciiz)
|
||||
@ -205,7 +222,7 @@ extern int sam3CloseSession(Sam3Session *ses);
|
||||
* characters for use with sam3tcpPrintf() checkIsSilent
|
||||
*/
|
||||
|
||||
void checkIsSilent(Sam3Session *ses, char *str);
|
||||
const char *checkIsSilent(Sam3Session *ses);
|
||||
|
||||
/*
|
||||
* Check to make sure that the destination in use is of a valid length, returns
|
||||
|
@ -1,14 +1,28 @@
|
||||
/* async SAMv3 library
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include "libsam3a.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@ -34,15 +48,39 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __unix__
|
||||
#if defined(__unix__) && !defined(__APPLE__)
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <mach/mach_time.h>
|
||||
#include <netinet/tcp.h>
|
||||
#ifndef SOCK_CLOEXEC
|
||||
#define SOCK_CLOEXEC 0
|
||||
#endif
|
||||
#ifndef SOCK_NONBLOCK
|
||||
#include <fcntl.h>
|
||||
#define SOCK_NONBLOCK O_NONBLOCK
|
||||
#endif
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
uint32_t TickCount() {
|
||||
uint64_t mat = mach_absolute_time();
|
||||
uint32_t mul = 0x80d9594e;
|
||||
return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int libsam3a_debug = 0;
|
||||
|
||||
@ -50,11 +88,11 @@ int libsam3a_debug = 0;
|
||||
#define DEFAULT_UDP_PORT (7655)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
uint64_t sam3atimeval2ms(const struct timeval *tv) {
|
||||
extern uint64_t sam3atimeval2ms(const struct timeval *tv) {
|
||||
return ((uint64_t)tv->tv_sec) * 1000 + ((uint64_t)tv->tv_usec) / 1000;
|
||||
}
|
||||
|
||||
void sam3ams2timeval(struct timeval *tv, uint64_t ms) {
|
||||
extern void sam3ams2timeval(struct timeval *tv, uint64_t ms) {
|
||||
tv->tv_sec = ms / 1000;
|
||||
tv->tv_usec = (ms % 1000) * 1000;
|
||||
}
|
||||
@ -651,6 +689,7 @@ static uint32_t genSeed(void) {
|
||||
volatile uint32_t seed = 1;
|
||||
uint32_t res;
|
||||
#ifndef WIN32
|
||||
#ifndef __APPLE__
|
||||
struct sysinfo sy;
|
||||
pid_t pid = getpid();
|
||||
//
|
||||
@ -658,6 +697,10 @@ static uint32_t genSeed(void) {
|
||||
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
|
||||
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
|
||||
hashint((uint32_t)sy.uptime);
|
||||
#else
|
||||
res = hashint((uint32_t)getpid()) ^
|
||||
hashint((uint32_t)TickCount());
|
||||
#endif
|
||||
#else
|
||||
res = hashint((uint32_t)GetCurrentProcessId()) ^
|
||||
hashint((uint32_t)GetTickCount());
|
||||
|
@ -1,14 +1,28 @@
|
||||
/* async SAMv3 library
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#ifndef LIBSAM3A_H
|
||||
#define LIBSAM3A_H
|
||||
|
||||
@ -17,6 +31,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
//#include <winsock.h>
|
||||
|
@ -1,12 +1,28 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
/*
|
||||
* Copyright © 2023 I2P
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the âSoftwareâ), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://git.idk.i2p/i2p-hackers/libsam3/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
Reference in New Issue
Block a user