mirror of
https://codeberg.org/scip/diceware.git
synced 2025-12-17 19:00:57 +01:00
Compare commits
3 Commits
origin/mas
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 641aaa94fd | |||
|
|
6221e7ae74 | ||
|
|
1ef2e34511 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
dicepwgen
|
||||||
29
.woodpecker/build.yaml
Normal file
29
.woodpecker/build.yaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- linux/amd64
|
||||||
|
|
||||||
|
labels:
|
||||||
|
platform: ${platform}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
build-n-test:
|
||||||
|
when:
|
||||||
|
event: [push]
|
||||||
|
image: alpine:latest
|
||||||
|
commands:
|
||||||
|
- apk update
|
||||||
|
- apk add --no-cache bash build-base words-en gdb valgrind
|
||||||
|
# build
|
||||||
|
- make
|
||||||
|
# look for memory leaks etc
|
||||||
|
- valgrind --leak-check=full --show-reachable=yes ./dicepwgen 2>&1 | tee log | grep "All heap blocks were freed"
|
||||||
|
- cat log
|
||||||
|
# enable in case of a crash
|
||||||
|
#- gdb -batch -ex "run" -ex "bt" --args dicepwgen
|
||||||
|
# check if we really get a password
|
||||||
|
- ./dicepwgen -y | grep -E '[a-z]*%'
|
||||||
|
# check a custom dict file and if we get 6 words when requested
|
||||||
|
- test 6 -eq $(./dicepwgen -f contrib/american-english-insane -c 6 | tee log | sed 's/[a-zA-Z]//g' | wc -c)
|
||||||
|
- cat log
|
||||||
|
|
||||||
|
|
||||||
54
.woodpecker/release.sh
Executable file
54
.woodpecker/release.sh
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This is my own simple codeberg generic releaser. It takes to
|
||||||
|
# binaries to be uploaded as arguments and takes every other args from
|
||||||
|
# env. Works on tags or normal commits (push), tags must start with v.
|
||||||
|
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo $*
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if test -z "$DEPLOY_TOKEN"; then
|
||||||
|
die "token DEPLOY_TOKEN not set"
|
||||||
|
fi
|
||||||
|
|
||||||
|
git fetch --all
|
||||||
|
|
||||||
|
# determine current tag or commit hash
|
||||||
|
version="$CI_COMMIT_TAG"
|
||||||
|
previous=""
|
||||||
|
log=""
|
||||||
|
if test -z "$version"; then
|
||||||
|
version="${CI_COMMIT_SHA:0:6}"
|
||||||
|
log=$(git log -1 --oneline)
|
||||||
|
else
|
||||||
|
previous=$(git tag -l | grep -E "^v" | tac | grep -A1 "$version" | tail -1)
|
||||||
|
log=$(git log -1 --oneline "${previous}..${version}" | sed 's|^|- |g')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# release body
|
||||||
|
printf "# Changes\n\n %s\n" "$log" > body.txt
|
||||||
|
|
||||||
|
# create the release
|
||||||
|
https --ignore-stdin --check-status -b -A bearer -a "$DEPLOY_TOKEN" POST \
|
||||||
|
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases" \
|
||||||
|
tag_name="$version" name="Release $version" body=@body.txt > release.json
|
||||||
|
|
||||||
|
# we need the id to upload files
|
||||||
|
ID=$(jq -r .id < release.json)
|
||||||
|
|
||||||
|
if test -z "$ID"; then
|
||||||
|
cat release.json
|
||||||
|
die "failed to create release"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# actually upload
|
||||||
|
for file in "$@"; do
|
||||||
|
https --ignore-stdin --check-status -A bearer -a "$DEPLOY_TOKEN" -f POST \
|
||||||
|
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases/$ID/assets" \
|
||||||
|
"name=${file}-${version}" "attachment@${file}"
|
||||||
|
done
|
||||||
28
.woodpecker/release.yaml
Normal file
28
.woodpecker/release.yaml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# build release
|
||||||
|
|
||||||
|
labels:
|
||||||
|
platform: linux/amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
compile:
|
||||||
|
when:
|
||||||
|
event: [tag,manual]
|
||||||
|
image: alpine:latest
|
||||||
|
commands:
|
||||||
|
- apk update
|
||||||
|
- apk add --no-cache bash build-base
|
||||||
|
- make static
|
||||||
|
- file dicepwgen_static
|
||||||
|
- mv dicepwgen_static dicepwgen-linux-amd64
|
||||||
|
|
||||||
|
release:
|
||||||
|
image: alpine:latest
|
||||||
|
when:
|
||||||
|
event: [tag,manual]
|
||||||
|
environment:
|
||||||
|
DEPLOY_TOKEN:
|
||||||
|
from_secret: DEPLOY_TOKEN
|
||||||
|
commands:
|
||||||
|
- apk update
|
||||||
|
- apk add --no-cache bash httpie jq git
|
||||||
|
- .woodpecker/release.sh dicepwgen-linux-amd64
|
||||||
8
Makefile
8
Makefile
@@ -22,6 +22,7 @@ CFLAGS = -Wall -Wextra -Werror -O1 -g
|
|||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
OBJS = dicepwgen.o dictfile.o tossing.o debug.o
|
OBJS = dicepwgen.o dictfile.o tossing.o debug.o
|
||||||
DST = dicepwgen
|
DST = dicepwgen
|
||||||
|
STATIC = dicepwgen_static
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
UID = root
|
UID = root
|
||||||
GID = 0
|
GID = 0
|
||||||
@@ -35,6 +36,13 @@ all: $(DST)
|
|||||||
$(DST): $(OBJS)
|
$(DST): $(OBJS)
|
||||||
gcc -DDICTFILE=$(DICTFILE) $(OBJS) -o $(DST)
|
gcc -DDICTFILE=$(DICTFILE) $(OBJS) -o $(DST)
|
||||||
|
|
||||||
|
static: $(STATIC)
|
||||||
|
|
||||||
|
$(STATIC): $(OBJS)
|
||||||
|
gcc -DDICTFILE=$(DICTFILE) -static $(OBJS) -o $(STATIC)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
gcc -c $(CFLAGS) -DDICTFILE=$(DICTFILE) $*.c -o $*.o
|
gcc -c $(CFLAGS) -DDICTFILE=$(DICTFILE) $*.c -o $*.o
|
||||||
|
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -1,6 +1,14 @@
|
|||||||
|
[](https://ci.codeberg.org/repos/15537)
|
||||||
|
[](https://codeberg.org/scip/diceware/raw/branch/master/LICENSE)
|
||||||
|
[](https://codeberg.org/scip/diceware/raw/branch/main/dicepwgen.pod)
|
||||||
|
|
||||||
## dicepwgen - A diceware password generator
|
## dicepwgen - A diceware password generator
|
||||||
|
|
||||||
This is the README file for the password generator dicepwgen.
|
`dicepwgen` generates a [diceware password](https://de.wikipedia.org/wiki/Diceware)
|
||||||
|
using a dictionary file. By default it uses pseudo random dice tosses,
|
||||||
|
but it is also possible to use real dices and enter the numbers by using
|
||||||
|
the option `-t`, which is the most secure way to generate diceware passwords.
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|||||||
@@ -37,14 +37,12 @@ int usage() {
|
|||||||
"-y --symbols Replace space with -, add non-letters\n"
|
"-y --symbols Replace space with -, add non-letters\n"
|
||||||
"-d --debug Enable debug output\n"
|
"-d --debug Enable debug output\n"
|
||||||
"-v --version Print program version\n"
|
"-v --version Print program version\n"
|
||||||
"-h -? --help Print this help screen\n"
|
"-h -? --help Print this help screen\n");
|
||||||
);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WMIN, WMAX, humantoss, verbose, dontjump, symbols;
|
int WMIN, WMAX, humantoss, verbose, dontjump, symbols;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int count = 4;
|
int count = 4;
|
||||||
char *dictfile = NULL;
|
char *dictfile = NULL;
|
||||||
@@ -67,7 +65,8 @@ int main (int argc, char **argv) {
|
|||||||
{"debug", no_argument, NULL, 'd'},
|
{"debug", no_argument, NULL, 'd'},
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "l:m:tf:c:vh?dny", longopts, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, "l:m:tf:c:vh?dny", longopts, NULL)) !=
|
||||||
|
-1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
fprintf(stderr, "This is %s version %s\n", argv[0], VERSION);
|
fprintf(stderr, "This is %s version %s\n", argv[0], VERSION);
|
||||||
@@ -176,7 +175,7 @@ void getwords(char *dictfile, int count) {
|
|||||||
|
|
||||||
free(tossed);
|
free(tossed);
|
||||||
|
|
||||||
for(i=0; i<6666; i++)
|
for (i = 0; i < 66667; i++)
|
||||||
if (words[i] != NULL)
|
if (words[i] != NULL)
|
||||||
free(words[i]);
|
free(words[i]);
|
||||||
|
|
||||||
|
|||||||
17
dicepwgen.h
17
dicepwgen.h
@@ -22,23 +22,24 @@
|
|||||||
#ifndef HAVE_DICE_H
|
#ifndef HAVE_DICE_H
|
||||||
#define HAVE_DICE_H
|
#define HAVE_DICE_H
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
#include "dictfile.h"
|
#include "dictfile.h"
|
||||||
#include "tossing.h"
|
#include "tossing.h"
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#define STRINGIZE(x) #x
|
#define STRINGIZE(x) #x
|
||||||
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
||||||
|
|
||||||
#define VERSION "1.2.0"
|
// #define VERSION "1.3.0"
|
||||||
#define RLEN 1024
|
#define RLEN 1024
|
||||||
|
static const char VERSION[] = "1.3.0";
|
||||||
|
|
||||||
extern int humantoss;
|
extern int humantoss;
|
||||||
extern int verbose;
|
extern int verbose;
|
||||||
|
|||||||
27
dictfile.c
27
dictfile.c
@@ -35,24 +35,20 @@ int *incr_dicedigit(int *digits) {
|
|||||||
digits[2] = 100;
|
digits[2] = 100;
|
||||||
if (digits[1] == 6000) {
|
if (digits[1] == 6000) {
|
||||||
digits[1] = 1000;
|
digits[1] = 1000;
|
||||||
digits[0] += 10000; /* may overflow to 71111, must be catched by caller */
|
digits[0] +=
|
||||||
}
|
10000; /* may overflow to 71111, must be catched by caller */
|
||||||
else
|
} else
|
||||||
digits[1] += 1000;
|
digits[1] += 1000;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
digits[2] += 100;
|
digits[2] += 100;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
digits[3] += 10;
|
digits[3] += 10;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
digits[4]++;
|
digits[4]++;
|
||||||
|
|
||||||
return digits;
|
return digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int get_dicenum(int *digits) {
|
int get_dicenum(int *digits) {
|
||||||
/*
|
/*
|
||||||
get the actual number of an array of dice digits
|
get the actual number of an array of dice digits
|
||||||
@@ -87,7 +83,7 @@ char **fetch_dict(char *dictfile) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
words = malloc(66666 * sizeof(char *));
|
words = malloc(66667 * sizeof(char *));
|
||||||
digits = malloc(5 * sizeof(int));
|
digits = malloc(5 * sizeof(int));
|
||||||
jump = rand_lim(32);
|
jump = rand_lim(32);
|
||||||
|
|
||||||
@@ -100,18 +96,16 @@ char **fetch_dict(char *dictfile) {
|
|||||||
pos = 11111;
|
pos = 11111;
|
||||||
next = 0;
|
next = 0;
|
||||||
|
|
||||||
for(i=0; i<6666; i++)
|
for (i = 0; i < 66667; i++)
|
||||||
words[i] = NULL;
|
words[i] = NULL;
|
||||||
|
|
||||||
|
|
||||||
LOOP:
|
LOOP:
|
||||||
while ((linelen = getline(&line, &len, DICT)) != -1) {
|
while ((linelen = getline(&line, &len, DICT)) != -1) {
|
||||||
if (!dontjump) {
|
if (!dontjump) {
|
||||||
if (jump > 0) {
|
if (jump > 0) {
|
||||||
jump--;
|
jump--;
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
jump = rand_lim(32);
|
jump = rand_lim(32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +132,8 @@ char **fetch_dict(char *dictfile) {
|
|||||||
digits = incr_dicedigit(digits);
|
digits = incr_dicedigit(digits);
|
||||||
pos = get_dicenum(digits);
|
pos = get_dicenum(digits);
|
||||||
|
|
||||||
/* this is what pos gets next after 66666, which is max reachable with 5 dices */
|
/* this is what pos gets next after 66666, which is max reachable with 5
|
||||||
|
* dices */
|
||||||
if (pos == 71111)
|
if (pos == 71111)
|
||||||
break;
|
break;
|
||||||
} /* endif word 4<=>10 */
|
} /* endif word 4<=>10 */
|
||||||
|
|||||||
Reference in New Issue
Block a user