From 9ca783a022ca4d796b876217c62d27af64888598 Mon Sep 17 00:00:00 2001 From: idk Date: Sun, 13 Dec 2020 00:57:13 -0500 Subject: [PATCH] fix public key out put in generateKeys --- examples/sam3/Makefile | 7 ++++++- src/libsam3/libsam3.c | 29 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/sam3/Makefile b/examples/sam3/Makefile index 15dac56..6496516 100644 --- a/examples/sam3/Makefile +++ b/examples/sam3/Makefile @@ -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 diff --git a/src/libsam3/libsam3.c b/src/libsam3/libsam3.c index 5a64580..e00e2ea 100644 --- a/src/libsam3/libsam3.c +++ b/src/libsam3/libsam3.c @@ -716,20 +716,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\n") < 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);