rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

commit 98be34bb28d4b0598ad42f7ae07abb80cdd2984c
parent 3f7d589e713dd681813f0fe61211c9600d71e383
Author: parazyd <parazyd@dyne.org>
Date:   Sat,  3 Mar 2018 01:05:54 +0100

Generate a semi-random MIME boundary using rputil.

Diffstat:
Mbin/rpgenc | 11+++++------
Mbin/rpgsign | 2+-
Mutil.c | 43+++++++++++++++++++++++++++++++++++++++----
Mutil.h | 3+++
4 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/bin/rpgenc b/bin/rpgenc @@ -1,7 +1,6 @@ #!/bin/sh -boundary="FuNkAdEliC" -encboundary="enc$boundary" +boundary="$(rputil genmimebound)" email="$(cat)" @@ -28,18 +27,18 @@ encr="$(echo "$emabody" | sed 's/$/\r/' | gpg -eaq --batch $to)" cat <<EOF $headers Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; - boundary="$encboundary" + boundary="$boundary" ---$encboundary +--$boundary Content-Type: application/pgp-encrypted Version: 1 ---$encboundary +--$boundary Content-Type: application/octet-stream $encr ---$encboundary-- +--$boundary-- EOF diff --git a/bin/rpgsign b/bin/rpgsign @@ -1,6 +1,6 @@ #!/bin/sh -boundary="FuNkAdEliC" +boundary="$(rputil genmimebound)" email="$(cat)" diff --git a/util.c b/util.c @@ -3,29 +3,61 @@ * by parazyd */ +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> +#include <unistd.h> #include "arg.h" #include "ind.h" #include "util.h" +char be[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + void utilusage(void) { die("usage: %s [cmd]\n" " available commands:\n" "\tgenmsgid: generates a Message-ID header\n", "rputil"); } +int randint(int max) { + unsigned int ret; + FILE *f; + + f = fopen("/dev/urandom", "r"); + fread(&ret, sizeof(ret), 1, f); + fclose(f); + + return ret % max; +} + +char *randstring(char *str, size_t size) { + if (size) { + size--; + for (size_t n = 0; n < size; n++) { + int key = randint(sizeof(be-1)); + str[n] = be[key]; + } + str[size] = '\0'; + } + return str; +} + int genmsgid(void) { - int n; char buf[15]; time_t now = time(0); strftime(buf, 15, "%Y%m%d%H%M%S", localtime(&now)); - srand(now); /* not secure ;) */ - n = rand() % 9999; - printf("<%s.GA%d@fq>\n", buf, n); + printf("<%s.GA%d@fq>\n", buf, randint(9999)); + return 0; +} + +int genmimebound(void) { + char buf[5]; + randstring(buf, sizeof(buf)); + printf("%s-FuNkADeLiC\n", buf); return 0; } @@ -37,6 +69,9 @@ int utilmain(int argc, char *argv[]) { if (!strncmp("genmsgid", argv[1], 8)) return genmsgid(); + if (!strncmp("genmimebound", argv[1], 12)) + return genmimebound(); + utilusage(); return 1; } diff --git a/util.h b/util.h @@ -7,6 +7,9 @@ #define __RPUTIL_H__ int utilmain(int argc, char *argv[]); +int randint(int max); +char *randstring(char *str, size_t size); int genmsgid(void); +int genmimebound(void); #endif