/* Encrypt the encoded SPA data. */ int fko_encrypt_spa_data(fko_ctx_t ctx, const char * const enc_key, const int enc_key_len) { int res = 0; /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) return(FKO_ERROR_CTX_NOT_INITIALIZED); if(enc_key_len < 0) return(FKO_ERROR_INVALID_KEY_LEN); /* If there is no encoded data or the SPA data has been modified, * go ahead and re-encode here. */ if(ctx->encoded_msg == NULL || FKO_IS_SPA_DATA_MODIFIED(ctx)) res = fko_encode_spa_data(ctx); if(res != FKO_SUCCESS) return(res); /* Croak on invalid encoded message as well. At present this is a * check for a somewhat arbitrary minimum length for the encoded * data. */ if (! is_valid_encoded_msg_len(ctx->encoded_msg_len)) return(FKO_ERROR_MISSING_ENCODED_DATA); /* Encrypt according to type and return... */ if(ctx->encryption_type == FKO_ENCRYPTION_RIJNDAEL) { if(enc_key == NULL) return(FKO_ERROR_INVALID_KEY_LEN); res = _rijndael_encrypt(ctx, enc_key, enc_key_len); } else if(ctx->encryption_type == FKO_ENCRYPTION_GPG) #if HAVE_LIBGPGME res = gpg_encrypt(ctx, enc_key); #else res = FKO_ERROR_UNSUPPORTED_FEATURE; #endif else
/* * Edit the passwords. * * This function dumps all the plain-text passwords ("results") in a temporary * file in your * ~/.mdp/ folder, fires your editor and save the output back * to your password file. */ void edit_results() { int i, tmp_fd = -1; struct result *result; uint32_t sum = 0, size = 0; char line[MAX_LINE_SIZE]; if (atexit(atexit_cleanup) != 0) err(1, "get_results atexit"); signal(SIGINT, sig_cleanup); signal(SIGKILL, sig_cleanup); /* Create the temporary file for edit mode. */ snprintf(tmp_path, MAXPATHLEN, "%ls/.mdp/tmp_edit.XXXXXXXX", home); tmp_fd = mkstemp(tmp_path); if (tmp_fd == -1) { err(1, "edit_results mkstemp()"); } /* Iterate over the results and dump them in this file. */ for (i = 0; i < ARRAY_LENGTH(&results); i++) { result = ARRAY_ITEM(&results, i); wcstombs(line, result->value, sizeof(line)); if (write(tmp_fd, line, strlen(line)) == -1) err(1, "edit_results write"); } if (close(tmp_fd) != 0) { err(1, "edit_results close(tmp_fd)"); } spawn_editor(tmp_path); if (has_changed(tmp_path, sum, size)) { gpg_encrypt(tmp_path); } else { fprintf(stderr, "No changes, exiting...\n"); } }