Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f90555ba4d | ||
![]() |
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 |
66
.github/workflows/sync.yaml
vendored
Normal file
66
.github/workflows/sync.yaml
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
# GitHub Actions workflow file to sync an external repository to this GitHub mirror.
|
||||
# This file was automatically generated by go-github-sync.
|
||||
#
|
||||
# The workflow does the following:
|
||||
# - Runs on a scheduled basis (and can also be triggered manually)
|
||||
# - Clones the GitHub mirror repository
|
||||
# - Fetches changes from the primary external repository
|
||||
# - Applies those changes to the mirror repository
|
||||
# - Pushes the updated content back to the GitHub mirror
|
||||
#
|
||||
# Authentication is handled by the GITHUB_TOKEN secret provided by GitHub Actions.
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Validate Github Actions Environment
|
||||
run: if [ "$GITHUB_ACTIONS" != "true" ]; then echo 'This script must be run in a GitHub Actions environment.'; exit 1; fi
|
||||
- name: Checkout GitHub Mirror
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Configure Git
|
||||
run: |-
|
||||
git config user.name 'GitHub Actions'
|
||||
git config user.email 'actions@github.com'
|
||||
- env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
name: Sync Primary Repository
|
||||
run: |-
|
||||
# Add the primary repository as a remote
|
||||
git remote add primary https://i2pgit.org/I2P_Developers/libsam3.git
|
||||
|
||||
# Fetch the latest changes from the primary repository
|
||||
git fetch primary
|
||||
|
||||
# Check if the primary branch exists in the primary repository
|
||||
if git ls-remote --heads primary master | grep -q master; then
|
||||
echo "Primary branch master found in primary repository"
|
||||
else
|
||||
echo "Error: Primary branch master not found in primary repository"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if we're already on the mirror branch
|
||||
if git rev-parse --verify --quiet master; then
|
||||
git checkout master
|
||||
else
|
||||
# Create the mirror branch if it doesn't exist
|
||||
git checkout -b master
|
||||
fi
|
||||
|
||||
|
||||
# Force-apply all changes from primary, overriding any conflicts
|
||||
echo "Performing force sync from primary/master to master"
|
||||
git reset --hard primary/master
|
||||
|
||||
|
||||
# Push changes back to the mirror repository
|
||||
git push origin master
|
||||
name: Sync Primary Repository to GitHub Mirror
|
||||
"on":
|
||||
push: {}
|
||||
schedule:
|
||||
- cron: 0 * * * *
|
||||
workflow_dispatch: {}
|
13
.gitignore
vendored
13
.gitignore
vendored
@@ -1,3 +1,14 @@
|
||||
*.o
|
||||
libsam3-tests
|
||||
*.a
|
||||
*.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 $@
|
||||
|
||||
|
@@ -28,9 +28,14 @@ ssclient:
|
||||
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>
|
||||
|
@@ -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 <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,19 +642,27 @@ static inline uint32_t hashint(uint32_t a) {
|
||||
}
|
||||
|
||||
static uint32_t genSeed(void) {
|
||||
volatile uint32_t seed = 1;
|
||||
uint32_t res;
|
||||
#ifndef WIN32
|
||||
struct sysinfo sy;
|
||||
pid_t pid = getpid();
|
||||
//
|
||||
sysinfo(&sy);
|
||||
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);
|
||||
#ifndef __APPLE__
|
||||
struct sysinfo sy;
|
||||
pid_t pid = getpid();
|
||||
//
|
||||
sysinfo(&sy);
|
||||
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) {
|
||||
strcpy(ses->pubkey, pub);
|
||||
strcpy(ses->privkey, priv);
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
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
|
||||
@@ -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)
|
||||
|
@@ -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,13 +689,18 @@ static uint32_t genSeed(void) {
|
||||
volatile uint32_t seed = 1;
|
||||
uint32_t res;
|
||||
#ifndef WIN32
|
||||
struct sysinfo sy;
|
||||
pid_t pid = getpid();
|
||||
//
|
||||
sysinfo(&sy);
|
||||
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);
|
||||
#ifndef __APPLE__
|
||||
struct sysinfo sy;
|
||||
pid_t pid = getpid();
|
||||
//
|
||||
sysinfo(&sy);
|
||||
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