#include #include #include #include int create_keyfile(const char *filename) { int fd = open(filename, O_WRONLY|O_CREAT|O_EXCL, 0600); int rand = open("/dev/urandom", O_RDONLY); char matrix[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; unsigned char n; int i; assert(sizeof(matrix) == 65); if ( fd == -1 ) { fprintf(stderr, "Can't create key file: %d\n", strerror(errno)); return 1; } if ( rand == -1 ) { fprintf(stderr, "Can't open /dev/urandom: %d\n", strerror(errno)); return 1; } for (i=0; i<64; i++) { read(rand, &n, 1); write(fd, matrix+(n&63), 1); //write(fd, matrix+(n%64), 1); } write(fd, "\n", 1); close(rand); close(fd); return 0; } int main(int argc, char ** argv) { //create_keyfile("test"); if (argc!=2) { printf("[!] USAGE:\t\tcsync2-key FILENAME\n"); } else { create_keyfile(argv[1]); } return 0; }