mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
(back) ported win32 32bit compatibility along with lots of fixes
This commit is contained in:
2
INSTALL
2
INSTALL
@@ -1,7 +1,7 @@
|
||||
Installation Instructions
|
||||
*************************
|
||||
|
||||
Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation,
|
||||
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
|
||||
16
TODO
Normal file → Executable file
16
TODO
Normal file → Executable file
@@ -27,17 +27,11 @@ pcp_find_primary_secret() makes a copy ???
|
||||
|
||||
c++ destructor double free mess
|
||||
|
||||
size_t 32bit/64bit:
|
||||
buffer.c: In function 'buffer_info':
|
||||
buffer.c:268:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:268:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:269:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:269:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:270:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:270:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:271:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
buffer.c:271:3: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t' [-Werror=format]
|
||||
http://stackoverflow.com/questions/2426113/i-have-having-following-warning-in-gcc-compilation-in-32-bit-architecture-but-no
|
||||
win32 32bit ported so far, missing:
|
||||
[15.Mrz 17:23:58] --- [~/pcp/tests] ---
|
||||
scip@io: $ ../src/pcp1 -V v1 -K -I testkey-wrong-serial -x xxx
|
||||
zmq_z85_decode() failed, input size ! mod 5 (got 98)failed to decrypt the secret key file
|
||||
|
||||
|
||||
Python binding, e.g.:
|
||||
py % cdll.LoadLibrary("libsodium.so.8")
|
||||
|
||||
4
bindings/cpp/sign.cpp
Normal file → Executable file
4
bindings/cpp/sign.cpp
Normal file → Executable file
@@ -60,7 +60,7 @@ bool Signature::sign(std::vector<unsigned char> message) {
|
||||
Buffer *m = buffer_new(32, n);
|
||||
|
||||
for(size_t i=0; i<message.size(); ++i)
|
||||
buffer_add(m, (void *)message[i], 1);
|
||||
buffer_add8(m, message[i]);
|
||||
|
||||
Pcpstream *p = ps_new_inbuffer(m);
|
||||
bool ok = Signature::sign(p);
|
||||
@@ -121,7 +121,7 @@ bool Signature::verify(vector<unsigned char> message) {
|
||||
Buf _sig = Buf();
|
||||
|
||||
for(size_t i=0; i<message.size(); ++i)
|
||||
_sig.add((void *)message[i], 1);
|
||||
_sig.add8(message[i]);
|
||||
|
||||
return Signature::verify(_sig);
|
||||
}
|
||||
|
||||
@@ -158,9 +158,6 @@
|
||||
*/
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||
#undef NO_MINUS_C_MINUS_O
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
|
||||
8
include/pcp/platform.h
Normal file → Executable file
8
include/pcp/platform.h
Normal file → Executable file
@@ -183,6 +183,14 @@ strnstr(const char *s, const char *find, size_t slen)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* size_t format string */
|
||||
#ifdef __LP64__
|
||||
#define FMT_SIZE_T "llu"
|
||||
#define SIZE_T_CAST long long unsigned int
|
||||
#else
|
||||
#define FMT_SIZE_T "lu"
|
||||
#define SIZE_T_CAST long unsigned int
|
||||
#endif
|
||||
|
||||
#endif /* !_HAVE_PCP_PLATFORM_H */
|
||||
|
||||
|
||||
2
include/pcp/util.h
Normal file → Executable file
2
include/pcp/util.h
Normal file → Executable file
@@ -36,7 +36,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
|
||||
10
libpcp/buffer.c
Normal file → Executable file
10
libpcp/buffer.c
Normal file → Executable file
@@ -265,10 +265,10 @@ void buffer_dump(const Buffer *b) {
|
||||
|
||||
void buffer_info(const Buffer *b) {
|
||||
fprintf(stderr, " buffer: %s\n", b->name);
|
||||
fprintf(stderr, "blocksize: %ld\n", b->blocksize);
|
||||
fprintf(stderr, " size: %ld\n", b->size);
|
||||
fprintf(stderr, " offset: %ld\n", b->offset);
|
||||
fprintf(stderr, " end: %ld\n", b->end);
|
||||
fprintf(stderr, "blocksize: %"FMT_SIZE_T"\n", (SIZE_T_CAST)b->blocksize);
|
||||
fprintf(stderr, " size: %"FMT_SIZE_T"\n", (SIZE_T_CAST)b->size);
|
||||
fprintf(stderr, " offset: %"FMT_SIZE_T"\n", (SIZE_T_CAST)b->offset);
|
||||
fprintf(stderr, " end: %"FMT_SIZE_T"\n", (SIZE_T_CAST)b->end);
|
||||
fprintf(stderr, "allocated: %d\n\n", b->allocated);
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ size_t buffer_fd_read(Buffer *b, FILE *in, size_t len) {
|
||||
size_t s = fread(data, 1, len, in);
|
||||
|
||||
if(s < len) {
|
||||
fatal("[buffer %s] attempt to read %ld bytes from FILE, but got %ld bytes only\n", b->name, len, s);
|
||||
fatal("[buffer %s] attempt to read %"FMT_SIZE_T" bytes from FILE, but got %"FMT_SIZE_T" bytes only\n", b->name, (SIZE_T_CAST)len, (SIZE_T_CAST)s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
48
libpcp/key.c
Normal file → Executable file
48
libpcp/key.c
Normal file → Executable file
@@ -301,11 +301,55 @@ pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k) {
|
||||
}
|
||||
|
||||
void pcp_seckeyblob(void *blob, pcp_key_t *k) {
|
||||
memcpy(blob, k, PCP_RAW_KEYSIZE);
|
||||
//memcpy(blob, k, PCP_RAW_KEYSIZE);
|
||||
Buffer *b = buffer_new(PCP_RAW_KEYSIZE, "bs");
|
||||
|
||||
buffer_add(b, k->masterpub, 32);
|
||||
buffer_add(b, k->mastersecret, 64);
|
||||
|
||||
buffer_add(b, k->pub, 32);
|
||||
buffer_add(b, k->secret, 32);
|
||||
|
||||
buffer_add(b, k->edpub, 32);
|
||||
buffer_add(b, k->edsecret, 64);
|
||||
|
||||
buffer_add(b, k->nonce, 24);
|
||||
|
||||
buffer_add(b, k->encrypted, 176);
|
||||
|
||||
buffer_add(b, k->owner, 255);
|
||||
buffer_add(b, k->mail, 255);
|
||||
buffer_add(b, k->id, 17);
|
||||
|
||||
buffer_add8(b, k->type);
|
||||
buffer_add64(b, k->ctime);
|
||||
buffer_add32(b, k->version);
|
||||
buffer_add32(b, k->serial);
|
||||
// buffer_dump(b);
|
||||
buffer_get_chunk(b, blob, b->end - b->offset);
|
||||
buffer_free(b);
|
||||
}
|
||||
|
||||
void pcp_pubkeyblob(void *blob, pcp_pubkey_t *k) {
|
||||
memcpy(blob, k, PCP_RAW_PUBKEYSIZE);
|
||||
Buffer *b = buffer_new(PCP_RAW_PUBKEYSIZE, "bp");
|
||||
|
||||
buffer_add(b, k->masterpub, 32);
|
||||
buffer_add(b, k->sigpub, 32);
|
||||
buffer_add(b, k->pub, 32);
|
||||
buffer_add(b, k->edpub, 32);
|
||||
|
||||
buffer_add(b, k->owner, 255);
|
||||
buffer_add(b, k->mail, 255);
|
||||
buffer_add(b, k->id, 17);
|
||||
|
||||
buffer_add8(b, k->type);
|
||||
buffer_add64(b, k->ctime);
|
||||
buffer_add32(b, k->version);
|
||||
buffer_add32(b, k->serial);
|
||||
buffer_add8(b, k->valid);
|
||||
|
||||
buffer_get_chunk(b, blob, b->end - b->offset);
|
||||
buffer_free(b);
|
||||
}
|
||||
|
||||
void *pcp_keyblob(void *k, int type) {
|
||||
|
||||
0
libpcp/mgmt.c
Normal file → Executable file
0
libpcp/mgmt.c
Normal file → Executable file
2
libpcp/util.c
Normal file → Executable file
2
libpcp/util.c
Normal file → Executable file
@@ -61,7 +61,7 @@ void _xorbuf(byte *iv, byte *buf, size_t xlen) {
|
||||
/* print some binary data to stderr */
|
||||
void _dump(char *n, byte *d, size_t s) {
|
||||
int l = strlen(n) + 9;
|
||||
fprintf(stderr, "%s (%04ld): ", n, s);
|
||||
fprintf(stderr, "%s (%04"FMT_SIZE_T"): ", n, (SIZE_T_CAST)s);
|
||||
size_t i;
|
||||
int c;
|
||||
for (i=0; i<s; ++i) {
|
||||
|
||||
18
libpcp/vault.c
Normal file → Executable file
18
libpcp/vault.c
Normal file → Executable file
@@ -281,9 +281,12 @@ byte *pcpvault_create_checksum() {
|
||||
size_t datapos = 0;
|
||||
|
||||
pcp_key_t *k = NULL;
|
||||
void *blob = NULL;
|
||||
pcphash_iterate(k) {
|
||||
key2be(k);
|
||||
memcpy(&data[datapos], k, PCP_RAW_KEYSIZE);
|
||||
blob = pcp_keyblob(k, PCP_KEY_TYPE_SECRET);
|
||||
memcpy(&data[datapos], blob, PCP_RAW_KEYSIZE);
|
||||
ucfree(blob, PCP_RAW_KEYSIZE);
|
||||
key2native(k);
|
||||
datapos += PCP_RAW_KEYSIZE;
|
||||
}
|
||||
@@ -292,15 +295,17 @@ byte *pcpvault_create_checksum() {
|
||||
pcphash_iteratepub(p) {
|
||||
/* pcp_dumppubkey(p); */
|
||||
pubkey2be(p);
|
||||
memcpy(&data[datapos], p, PCP_RAW_PUBKEYSIZE);
|
||||
blob = pcp_keyblob(p, PCP_KEY_TYPE_PUBLIC);
|
||||
memcpy(&data[datapos], blob, PCP_RAW_PUBKEYSIZE);
|
||||
ucfree(blob, PCP_RAW_PUBKEYSIZE);
|
||||
pubkey2native(p);
|
||||
datapos += PCP_RAW_PUBKEYSIZE;
|
||||
}
|
||||
|
||||
/* scip
|
||||
/*
|
||||
printf("PUB: %d, SEC: %d\n", PCP_RAW_PUBKEYSIZE, PCP_RAW_KEYSIZE);
|
||||
printf("DATA (%d) (s: %d, p: %d):\n", (int)datasize, numskeys, numpkeys);
|
||||
pcpprint_bin(stdout, data, datasize); printf("\n");
|
||||
_dump("data", data, datasize);
|
||||
*/
|
||||
|
||||
crypto_hash_sha256(checksum, data, datasize);
|
||||
@@ -496,9 +501,10 @@ int pcpvault_fetchall(vault_t *vault) {
|
||||
|
||||
byte *checksum = NULL;
|
||||
checksum = pcpvault_create_checksum(vault);
|
||||
|
||||
/*
|
||||
printf(" calc checksum: "); pcpprint_bin(stdout, checksum, 32); printf("\n");
|
||||
printf("vault checksum: "); pcpprint_bin(stdout, vault->checksum, 32); printf("\n");
|
||||
_dump(" calc checksum", checksum, 32);
|
||||
_dump("vault checksum", vault->checksum, 32);
|
||||
*/
|
||||
|
||||
if(pcphash_count() + pcphash_countpub() > 0) {
|
||||
|
||||
10
src/encryption.c
Normal file → Executable file
10
src/encryption.c
Normal file → Executable file
@@ -126,9 +126,9 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
|
||||
if(dlen > 0) {
|
||||
if(verify)
|
||||
fprintf(stderr, "Decrypted and Verified %ld bytes successfully\n", dlen);
|
||||
fprintf(stderr, "Decrypted and Verified %"FMT_SIZE_T" bytes successfully\n", (SIZE_T_CAST)dlen);
|
||||
else
|
||||
fprintf(stderr, "Decrypted %ld bytes successfully\n", dlen);
|
||||
fprintf(stderr, "Decrypted %"FMT_SIZE_T" bytes successfully\n", (SIZE_T_CAST)dlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -291,11 +291,11 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
|
||||
if(clen > 0) {
|
||||
if(id == NULL && recipient == NULL)
|
||||
fprintf(stderr, "Encrypted %ld bytes symetrically\n", clen);
|
||||
fprintf(stderr, "Encrypted %"FMT_SIZE_T" bytes symetrically\n", (SIZE_T_CAST)clen);
|
||||
else if(id != NULL)
|
||||
fprintf(stderr, "Encrypted %ld bytes for 0x%s successfully\n", clen, id);
|
||||
fprintf(stderr, "Encrypted %"FMT_SIZE_T" bytes for 0x%s successfully\n", (SIZE_T_CAST)clen, id);
|
||||
else {
|
||||
fprintf(stderr, "Encrypted %ld bytes for:\n", clen);
|
||||
fprintf(stderr, "Encrypted %"FMT_SIZE_T" bytes for:\n", (SIZE_T_CAST)clen);
|
||||
pcp_pubkey_t *cur, *t;
|
||||
HASH_ITER(hh, pubhash, cur, t) {
|
||||
fprintf(stderr, "%s <%s>\n", cur->owner, cur->mail);
|
||||
|
||||
2
src/signature.c
Normal file → Executable file
2
src/signature.c
Normal file → Executable file
@@ -86,7 +86,7 @@ int pcpsign(char *infile, char *outfile, char *passwd, int z85, int detach) {
|
||||
if(sigsize == 0)
|
||||
goto errs1;
|
||||
|
||||
fprintf(stderr, "Signed %ld bytes successfully\n", sigsize);
|
||||
fprintf(stderr, "Signed %"FMT_SIZE_T" bytes successfully\n", (SIZE_T_CAST)sigsize);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
4
tests/collisions.c
Normal file → Executable file
4
tests/collisions.c
Normal file → Executable file
@@ -26,7 +26,7 @@
|
||||
|
||||
unsigned djb_hash ( void *key, int len ) {
|
||||
unsigned char *p = key;
|
||||
unsigned h = 0;
|
||||
unsigned h = 0U;
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < len; i++ )
|
||||
@@ -37,7 +37,7 @@ unsigned djb_hash ( void *key, int len ) {
|
||||
|
||||
unsigned fnv_hash ( void *key, int len ) {
|
||||
unsigned char *p = key;
|
||||
unsigned h = 2166136261;
|
||||
unsigned h = 2166136261U;
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < len; i++ )
|
||||
|
||||
5
tests/cpptest.cpp
Normal file → Executable file
5
tests/cpptest.cpp
Normal file → Executable file
@@ -60,8 +60,9 @@ void test0() {
|
||||
|
||||
DECRYPTED = _openrd("testcppdecrypted");
|
||||
char *got = (char *)ucmalloc(10);
|
||||
size_t h;
|
||||
h = fread(got, 1, 6, DECRYPTED);
|
||||
if(fread(got, 1, 6, DECRYPTED) < 6) {
|
||||
throw pcp::exception("read error, could not read decrypted content");
|
||||
}
|
||||
if(strncmp(got, "HALLO", 5) != 0) {
|
||||
throw pcp::exception();
|
||||
}
|
||||
|
||||
4
tests/gencheader.c
Normal file → Executable file
4
tests/gencheader.c
Normal file → Executable file
@@ -1,8 +1,8 @@
|
||||
#include <pcp.h>
|
||||
|
||||
void pr(char *var, unsigned char *d, size_t len) {
|
||||
printf("size_t %s_len = %ld;\n", var, len);
|
||||
printf("unsigned char %s[%ld] = {\n", var, len);
|
||||
printf("size_t %s_len = %"FMT_SIZE_T";\n", var, (SIZE_T_CAST)len);
|
||||
printf("unsigned char %s[%"FMT_SIZE_T"] = {\n", var, (SIZE_T_CAST)len);
|
||||
size_t i;
|
||||
for(i=0; i<len-1; ++i) {
|
||||
printf("0x%02x, ", (unsigned int)d[i]);
|
||||
|
||||
4
tests/sample.c
Normal file → Executable file
4
tests/sample.c
Normal file → Executable file
@@ -33,7 +33,7 @@ int main() {
|
||||
pcp_encrypt_stream(clear_in, crypt_out, alice, pubhash, 0);
|
||||
|
||||
/* now, print the encrypted result */
|
||||
fprintf(stderr, "Alice encrypted %ld bytes for Bob:\n", strlen(message));
|
||||
fprintf(stderr, "Alice encrypted %"FMT_SIZE_T" bytes for Bob:\n", (SIZE_T_CAST)strlen(message));
|
||||
buffer_dump(ps_buffer(crypt_out));
|
||||
|
||||
/* ---- encryption don, now decrypt ---- */
|
||||
@@ -52,7 +52,7 @@ int main() {
|
||||
fatals_ifany();
|
||||
else {
|
||||
/* and finally print out the decrypted message */
|
||||
fprintf(stderr, "Bob decrypted %ld bytes from Alice:\n", buffer_size(ps_buffer(crypt_out)));
|
||||
fprintf(stderr, "Bob decrypted %"FMT_SIZE_T" bytes from Alice:\n", (SIZE_T_CAST)buffer_size(ps_buffer(crypt_out)));
|
||||
printf("Decrypted message: %s\n", buffer_get_str(ps_buffer(clear_out)));
|
||||
}
|
||||
|
||||
|
||||
2
tests/unittests.cfg
Normal file → Executable file
2
tests/unittests.cfg
Normal file → Executable file
@@ -330,7 +330,7 @@ temporarily disabled
|
||||
</test>
|
||||
<test check-verify-decrypt-from-alicia>
|
||||
cmd = $pcp -V vb -c -d -I testsig -x b
|
||||
expect = /Verified.*Unittests/s
|
||||
expect = /Unittests.*Verified/s
|
||||
</test>
|
||||
|
||||
#
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
#
|
||||
use lib qw(lib);
|
||||
|
||||
BEGIN {
|
||||
eval {
|
||||
use IPC::Run qw( run timeout);
|
||||
};
|
||||
};
|
||||
|
||||
use Test::More;
|
||||
use IPC::Open3;
|
||||
use IO::Select;
|
||||
@@ -29,7 +35,7 @@ use Config::General qw(ParseConfig);
|
||||
use Tie::IxHash;
|
||||
use Data::Dumper;
|
||||
|
||||
sub run;
|
||||
sub run3;
|
||||
sub execute;
|
||||
sub final;
|
||||
|
||||
@@ -119,7 +125,7 @@ sub runtest {
|
||||
|
||||
print STDERR "\n$cfg->{cmd}\n ";
|
||||
|
||||
my $ret = run($cfg->{cmd},
|
||||
my $ret = run3($cfg->{cmd},
|
||||
$cfg->{input},
|
||||
\$out, \$error, 10, 0, undef);
|
||||
|
||||
@@ -203,11 +209,26 @@ sub final {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub run {
|
||||
sub run3 {
|
||||
# open3 wrapper. catch stderr, stdout, errno; add timeout and kill
|
||||
my($cmd, $input, $output, $error, $timeout, $debug, $monitorfile) = @_;
|
||||
|
||||
if ($^O =~ /win/i) {
|
||||
my ($o, $e, @c);
|
||||
if ($cmd =~ /\|/) {
|
||||
@c = ("sh", "-c", $cmd);
|
||||
}
|
||||
else {
|
||||
@c = split /\s\s*/, $cmd;
|
||||
}
|
||||
my $ret = run \@c, \$input, \$o, \$e, timeout( $timeout );
|
||||
$$output = $o;
|
||||
$$error = $e;
|
||||
return ret;
|
||||
}
|
||||
|
||||
my ($stdin, $stderr, $stdout) = ('', '', '');
|
||||
|
||||
my $child = 0;
|
||||
my $cmdline = join " ", @{$cmd};
|
||||
$timeout = $timeout ? $timeout : 10;
|
||||
@@ -320,6 +341,20 @@ sub run {
|
||||
}
|
||||
}
|
||||
|
||||
sub runipc {
|
||||
my($cmd, $input, $output, $error, $timeout, $debug, $monitorfile) = @_;
|
||||
|
||||
print STDERR Dumper(\@_);
|
||||
|
||||
if (run $cmd, $input, $output, $error, timeout( $timeout )) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub reaper {
|
||||
my $pid;
|
||||
while (1) {
|
||||
|
||||
Reference in New Issue
Block a user