static void buffer_get_attributes(FILE * fp, int *next_offset) { guint list_size; guint type; guint val; int i; int ret; get_uint32(fp, next_offset, &list_size); for (i = 0; i < list_size; i++) { ret = get_utf8_string(fp, next_offset); assert(ret == 1); get_uint32(fp, next_offset, &type); switch (type) { case 0: /* A string */ get_utf8_string(fp, next_offset); break; case 1: /* A uint32 */ get_uint32(fp, next_offset, &val); break; } } }
static void process_file(const char *fname) { FILE *fp; unsigned char buf[1024]; int i, offset; uint32_t flags; uint32_t lock_timeout; unsigned char major, minor, crypto, hash; uint32_t tmp; uint32_t num_items; uint32_t crypto_size; uint32_t hash_iterations; unsigned char salt[8]; unsigned char *to_decrypt; if (!(fp = fopen(fname, "rb"))) { fprintf(stderr, "%s : %s\n", fname, strerror(errno)); return; } count = fread(buf, KEYRING_FILE_HEADER_LEN, 1, fp); assert(count == 1); if (memcmp(buf, KEYRING_FILE_HEADER, KEYRING_FILE_HEADER_LEN) != 0) { fprintf(stderr, "%s : Not a GNOME Keyring file!\n", fname); return; } offset = KEYRING_FILE_HEADER_LEN; major = fgetc(fp); minor = fgetc(fp); crypto = fgetc(fp); hash = fgetc(fp); offset += 4; if (major != 0 || minor != 0 || crypto != 0 || hash != 0) { fprintf(stderr, "%s : Un-supported GNOME Keyring file!\n", fname); return; } // Keyring name if (!get_utf8_string(fp, &offset)) goto bail; // ctime count = fread(buf, 8, 1, fp); if (count != 1) goto bail; offset += 8; // mtime count = fread(buf, 8, 1, fp); if (count != 1) goto bail; offset += 8; // flags get_uint32(fp, &offset, &flags); // lock timeout get_uint32(fp, &offset, &lock_timeout); // hash_iterations get_uint32(fp, &offset, &hash_iterations); // salt count = fread(salt, 8, 1, fp); if (count != 1) goto bail; offset += 8; // reserved for (i = 0; i < 4; i++) { get_uint32(fp, &offset, &tmp); } // num_items get_uint32(fp, &offset, &num_items); if (!read_hashed_item_info(fp, &offset, num_items)) goto bail; // crypto_size get_uint32(fp, &offset, &crypto_size); fprintf(stderr, "%s: crypto size: %u offset : %d\n", fname, crypto_size, offset); /* Make the crypted part is the right size */ if (crypto_size % 16 != 0) goto bail; to_decrypt = (unsigned char *) mem_alloc(crypto_size); count = fread(to_decrypt, crypto_size, 1, fp); assert(count == 1); printf("%s:$keyring$", basename(fname)); print_hex(salt, 8); printf("*%d*%d*%d*", hash_iterations, crypto_size, 0); print_hex(to_decrypt, crypto_size); printf("\n"); if(to_decrypt) MEM_FREE(to_decrypt); return; bail: fprintf(stderr, "%s: parsing failed, please report this on john-users if input was a valid keyring!\n", fname); return; }
hash_stat load_keyring(char *filename) { FILE *fp; unsigned char buf[1024]; int i, offset; uint32_t flags; uint32_t lock_timeout; unsigned char major, minor, crypto, hash; uint32_t tmp; uint32_t num_items; unsigned char salt[8]; unsigned char *to_decrypt; int count; if (!(fp = fopen(filename, "rb"))) { return hash_err; } count = fread(buf, KEYRING_FILE_HEADER_LEN, 1, fp); if (count!=1) return hash_err; if (memcmp(buf, KEYRING_FILE_HEADER, KEYRING_FILE_HEADER_LEN) != 0) { return hash_err; } offset = KEYRING_FILE_HEADER_LEN; major = fgetc(fp); minor = fgetc(fp); crypto = fgetc(fp); hash = fgetc(fp); offset += 4; if (major != 0 || minor != 0 || crypto != 0 || hash != 0) { fclose(fp); return hash_err; } // Keyring name if (!get_utf8_string(fp, &offset)) goto bail; // ctime count = fread(buf, 8, 1, fp); if (count!=1) { fclose(fp); return hash_err; } offset += 8; // mtime count = fread(buf, 8, 1, fp); offset += 8; // flags get_uint32(fp, &offset, &flags); // lock timeout get_uint32(fp, &offset, &lock_timeout); // iterations get_uint32(fp, &offset, &cs.iterations); // salt count = fread(salt, 8, 1, fp); offset += 8; // reserved for (i = 0; i < 4; i++) { get_uint32(fp, &offset, &tmp); } // num_items get_uint32(fp, &offset, &num_items); if (!read_hashed_item_info(fp, &offset, num_items)) goto bail; // crypto_size get_uint32(fp, &offset, &cs.crypto_size); /* Make the crypted part is the right size */ if (cs.crypto_size % 16 != 0) goto bail; to_decrypt = (unsigned char *) malloc(cs.crypto_size); count = fread(to_decrypt, cs.crypto_size, 1, fp); memcpy(cs.salt, salt, SALTLEN); memcpy(cs.ct, to_decrypt, cs.crypto_size); if(to_decrypt) free(to_decrypt); memcpy(cs.hash,"\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e",16); return hash_ok; bail: fclose(fp); return hash_err; }