示例#1
0
dc_pass *__get_pass_keyfiles(
		HWND h_pass,
		BOOL use_keyfiles,
		int  key_list
	)
{
	dc_pass *pass;
	wchar_t *s_pass;
	size_t   plen;
	int      rlt;

	if ( (pass = secure_alloc(sizeof(dc_pass))) == NULL )
	{
		return NULL;
	}
	if ( (s_pass = secure_alloc((MAX_PASSWORD + 1) * sizeof(wchar_t))) == NULL) 
	{
		return NULL;
	}
	GetWindowText( h_pass, s_pass, MAX_PASSWORD + 1 );
	if ( wcslen(s_pass) > 0 )
	{
		plen       = wcslen(s_pass) * sizeof(wchar_t);
		pass->size = d32( min( plen, MAX_PASSWORD * sizeof(wchar_t) ) );

		mincpy( &pass->pass, s_pass, pass->size );
		secure_free( s_pass );
	}
	if ( use_keyfiles )
	{
		_list_key_files *key_file;

		if ( key_file = _first_keyfile(key_list) )
		{
			do {
				rlt = dc_add_keyfiles( pass, key_file->path );
				if ( rlt != ST_OK )
				{
					__error_s( GetParent(h_pass), L"Keyfiles not loaded", rlt );

					secure_free( pass );
					pass = NULL;

					break;
				}
				key_file = _next_keyfile( key_file, key_list );

			} while ( key_file != NULL );
		} 
	}

	return pass;
}
示例#2
0
int dc_start_format(wchar_t *device, dc_pass *password, crypt_info *crypt)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(dctl->device, device);
		autocpy(&dctl->passw1, password, sizeof(dc_pass));

		dctl->crypt = crypt[0];

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_FORMAT_START,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
示例#3
0
int dc_restore_header(wchar_t *device, dc_pass *password, void *in)
{
	dc_backup_ctl *back;
	u32            bytes;
	int            succs;
	int            resl;

	do
	{
		if ( (back = secure_alloc(sizeof(dc_backup_ctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(back->device, device);
		autocpy(&back->pass, password, sizeof(dc_pass));
		autocpy(back->backup, in, DC_AREA_SIZE);

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_RESTORE_HEADER,
			back, sizeof(dc_backup_ctl), back, sizeof(dc_backup_ctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}
		
		resl = back->status;
	} while (0);

	if (back != NULL) {
		secure_free(back);
	}

	return resl;
}
示例#4
0
int dc_add_password(dc_pass *password)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		autocpy(&dctl->passw1, password, sizeof(dc_pass));

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_ADD_PASS,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL
			);

		if (succs == 0) {
			resl = ST_ERROR;
		} else {
			resl = dctl->status;
		}
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}
	return resl;
}
示例#5
0
文件: wallet.c 项目: Methimpact/bitc
static char *
wallet_encrypt_string(struct wallet    *wallet,
                      const char       *plaintext,
                      struct crypt_key *ckey)
{
   struct secure_area *sec;
   char cipherStr[1024];
   uint8 *cipher;
   char *hmac;
   char *res;
   size_t clen;
   size_t len;
   bool s;

   ASSERT(plaintext);

   len = strlen(plaintext) + 1;
   sec = secure_alloc(len);
   memcpy(sec->buf, plaintext, len);

   s = crypt_encrypt(ckey, sec, &cipher, &clen);
   ASSERT(s);

   str_snprintf_bytes(cipherStr, sizeof cipherStr, NULL, cipher, clen);
   hmac = wallet_hmac_string(cipher, clen, wallet->pass);
   res = safe_asprintf("%s-%s", cipherStr, hmac);
   free(hmac);

   free(cipher);
   secure_free(sec);

   return res;
}
示例#6
0
文件: main.c 项目: mdugot/Lem-in
int	main(void)
{
	t_anthill	*anthill;

	anthill = secure_alloc(sizeof(t_anthill));
	read_anthill(0, anthill);
	print_overview(anthill->list_line);
	overview(anthill);
	ft_putendl("");
	while (anthill->finish_ants < anthill->number_ants)
	{
		one_turn(anthill);
	}
	return (0);
}
示例#7
0
文件: wallet.c 项目: Methimpact/bitc
static struct wallet *
wallet_open_file(struct config      *config,
                 struct secure_area *pass,
                 char              **errStr,
                 enum wallet_state  *wallet_state)
{
   struct wallet *wallet;
   struct config *wcfg;
   int res;

   *wallet_state = WALLET_UNKNOWN;

   wallet = safe_calloc(1, sizeof *wallet);
   wallet->filename   = wallet_get_filename();
   wallet->hash_keys  = hashtable_create();
   wallet->pass       = pass;
   wallet->ckey_store = secure_alloc(sizeof *wallet->ckey);
   wallet->ckey       = (struct crypt_key *)wallet->ckey_store->buf;

   if (!file_exists(wallet->filename)) {
      wcfg = config_create();
   } else {
      res = config_load(wallet->filename, &wcfg);
      if (res) {
         *errStr = "failed to read wallet file";
         NOT_TESTED();
         goto exit;
      }
   }

   res = wallet_load_keys(wallet, errStr, wcfg, wallet_state);
   config_free(wcfg);
   if (res) {
      goto exit;
   }

   ASSERT(wallet);

   return wallet;
exit:

   wallet_close(wallet);

   return NULL;
}
示例#8
0
int dc_mount_all(dc_pass *password, int *mounted, int flags)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		if (password != NULL) {
			autocpy(&dctl->passw1, password, sizeof(dc_pass));			
		}

		dctl->flags = flags;

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_MOUNT_ALL,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status; 
		mounted[0] = dctl->n_mount;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
示例#9
0
int dc_change_password(
	  wchar_t *device, dc_pass *old_pass, dc_pass *new_pass
	  )
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(dctl->device, device);
		autocpy(&dctl->passw1, old_pass, sizeof(dc_pass));
		autocpy(&dctl->passw2, new_pass, sizeof(dc_pass));

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_CHANGE_PASS,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
示例#10
0
int dc_mount_volume(wchar_t *device, dc_pass *password, int flags)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(dctl->device, device); dctl->flags = flags;

		if (password != NULL) {
			autocpy(&dctl->passw1, password, sizeof(dc_pass));
		}

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_MOUNT,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
示例#11
0
static
int dc_add_single_kf(dc_pass *pass, wchar_t *path)
{
	kf_ctx *k_ctx;
	HANDLE  h_file;
	int     resl, i;
	int     succs;
	u32     bytes;

	h_file = NULL; k_ctx = NULL;
	do
	{
		if ( (k_ctx = secure_alloc(sizeof(kf_ctx))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		h_file = CreateFile(
			path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

		if (h_file == INVALID_HANDLE_VALUE) {
			h_file = NULL; resl = ST_ACCESS_DENIED; break;
		}

		/* initialize sha512 for hashing keyfile */
		sha512_init(&k_ctx->sha);

		do
		{
			succs = ReadFile(h_file, k_ctx->kf_block, KF_BLOCK_SIZE, &bytes, NULL);

			if ( (succs == 0) || (bytes == 0) ) {
				break;
			}
			sha512_hash(&k_ctx->sha, k_ctx->kf_block, bytes);
		} while (1);		
	
		/* done hasing */
		sha512_done(&k_ctx->sha, k_ctx->hash);

		/* zero unused password buffer bytes */
		zeromem(
			p8(pass->pass) + pass->size, (MAX_PASSWORD*2) - pass->size);

		/* mix the keyfile hash and password */
		for (i = 0; i < (SHA512_DIGEST_SIZE / sizeof(u32)); i++) {
			p32(pass->pass)[i] += p32(k_ctx->hash)[i];
		}
		pass->size = max(pass->size, SHA512_DIGEST_SIZE); 
		resl = ST_OK;		
	} while (0);

	if (h_file != NULL) {
		CloseHandle(h_file);
	}

	if (k_ctx != NULL) {
		secure_free(k_ctx);
	}

	return resl;
}
示例#12
0
static
INT_PTR CALLBACK
_keyfiles_dlg_proc(
		HWND	hwnd,
		UINT	message,
		WPARAM	wparam,
		LPARAM	lparam
	)
{
	static int			key_list;
	static list_entry  *head;

	switch ( message )
	{
		case WM_CLOSE : 
		{
			EndDialog( hwnd, 0 );
			return 0L;
		}
		break;		

		case WM_NOTIFY : 
		{
			if( wparam == IDC_LIST_KEYFILES )
			{
				if ( ((NMHDR *)lparam)->code == LVN_ITEMCHANGED &&
					 (((NMLISTVIEW *)lparam)->uNewState & LVIS_FOCUSED ) )
				{
					HWND h_list = GetDlgItem( hwnd, IDC_LIST_KEYFILES );

					EnableWindow(GetDlgItem( hwnd, IDB_REMOVE_ITEM), ListView_GetSelectedCount( h_list ) );

					return 1L;
				}
				if ( ((NM_LISTVIEW *)lparam)->hdr.code == NM_CLICK )
				{
					HWND h_list = GetDlgItem( hwnd, IDC_LIST_KEYFILES );

					EnableWindow( GetDlgItem( hwnd, IDB_REMOVE_ITEM), ListView_GetSelectedCount( h_list ) );
				}
			}
		}
		case WM_COMMAND :
		{
			HWND h_list = GetDlgItem( hwnd, IDC_LIST_KEYFILES );

			int code = HIWORD(wparam);
			int id   = LOWORD(wparam);

			switch ( id )
			{
				case IDB_GENERATE_KEYFILE :
				{
					wchar_t s_file[MAX_PATH] = { L"keyfile" };

					byte keyfile[64];
					int rlt;					

					if ( _save_file_dialog(
							hwnd, s_file, countof(s_file), L"Save 64 bytes random keyfile as.."
						) )
					{
						if ( (rlt = dc_get_random(keyfile, sizeof(keyfile))) == ST_OK ) 
						{
							rlt = save_file(s_file, keyfile, sizeof(keyfile));
							burn(keyfile, sizeof(keyfile));
						}
						if ( rlt == ST_OK )
						{							
							if ( __msg_q(hwnd, 
								L"Keyfile \"%s\" successfully created\n\n"
								L"Add this file to the keyfiles list?", 
								s_file
								)	)
							{
								_ui_keys_list_refresh(hwnd);

								if ( key_list == KEYLIST_EMBEDDED ) 
								{
									ListView_DeleteAllItems( h_list );
								}
								_add_item( h_list, s_file );

								_ui_embedded( hwnd, key_list );
							}							
						} else {
							__error_s( hwnd, L"Error creating Keyfile", rlt );
						}
					}
				}
				break;
				case IDB_REMOVE_ITEM :
				{					
					ListView_DeleteItem( h_list, ListView_GetSelectionMark(h_list) );

					_ui_keys_list_refresh( hwnd );
					_ui_embedded( hwnd, key_list );
				}
				break;
				case IDB_REMOVE_ITEMS :
				{
					ListView_DeleteAllItems( h_list );

					_ui_keys_list_refresh( hwnd );
					_ui_embedded( hwnd, key_list );
				}
				break;
				case IDB_ADD_FOLDER :
				{
					wchar_t path[MAX_PATH];
					if ( _folder_choice(hwnd, path, L"Choice folder..") )
					{
						_ui_keys_list_refresh( hwnd );

						_set_trailing_slash( path );
						_add_item( h_list, path );
					}
				}
				break;
				case IDB_ADD_FILE :
				{
					wchar_t s_path[MAX_PATH] = { 0 };
					if ( _open_file_dialog(hwnd, s_path, countof(s_path), L"Select File..") )
					{					
						if ( key_list == KEYLIST_EMBEDDED )
						{
							HWND h_file = 
								CreateFile(
									s_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
									);

							if ( h_file != INVALID_HANDLE_VALUE )
							{
								if ( GetFileSize( h_file, NULL ) != 64 )
								{
									__error_s( hwnd, L"Embedded keyfile must be 64 byte size", ST_ERROR );
								} else 
								{
									_ui_keys_list_refresh( hwnd );
									_add_item( h_list, s_path );
								}
								CloseHandle( h_file );
							}
							_ui_embedded( hwnd, key_list );
						} else 
						{
							_ui_keys_list_refresh( hwnd );
							_add_item( h_list, s_path );
						}
					}
				}
				break;
			}
			if ( id == IDCANCEL )
			{
				EndDialog(hwnd, 0);
			}
			if ( id == IDOK )
			{
				int k = 0;

				_keyfiles_wipe(key_list);

				for ( ; k < ListView_GetItemCount( h_list ); k ++ )
				{
					wchar_t item[MAX_PATH];
					_get_item_text( h_list, k, 0, item, countof(item) );

					if ( wcscmp(item, IDS_EMPTY_LIST) != 0 )
					{
						_list_key_files *new_node;

						if ( (new_node = secure_alloc(sizeof(_list_key_files))) == NULL )
						{
							__error_s( hwnd, L"Can't allocate memory", ST_NOMEM );
							_keyfiles_wipe(key_list);
							break;
						}
						wcsncpy(new_node->path, item, countof(new_node->path));
						_insert_tail_list(head, &new_node->next);
					}
				}
				EndDialog(hwnd, 0);

			}
		}
		break;
		case WM_INITDIALOG : 
		{
			HWND h_list = GetDlgItem(hwnd, IDC_LIST_KEYFILES);
			
			_list_key_files *key_file;

			key_list = (int)lparam;
			head     = _KEYFILES_HEAD_( key_list );

			_init_list_headers( h_list, _keyfiles_headers );

			if ( key_file = _first_keyfile( key_list ) )
			{
				EnableWindow( GetDlgItem(hwnd, IDB_REMOVE_ITEMS), TRUE );
				do 
				{
					_list_insert_item( h_list, ListView_GetItemCount(h_list), 0, key_file->path, 0 );
					key_file = _next_keyfile( key_file, key_list );

				} while ( key_file != NULL );
			} 

			_ui_keys_list_refresh( hwnd );
			_ui_embedded( hwnd, key_list );

			ListView_SetBkColor( h_list, GetSysColor(COLOR_BTNFACE) );
			ListView_SetTextBkColor( h_list, GetSysColor(COLOR_BTNFACE) );
			ListView_SetExtendedListViewStyle( h_list, LVS_EX_FLATSB | LVS_EX_FULLROWSELECT );

			SetForegroundWindow(hwnd);
			return 1L;
		}
		break;
		case WM_CTLCOLOREDIT :
		{
			return _ctl_color(wparam, _cl(COLOR_BTNFACE, LGHT_CLR));
		}
		break;
		default:
		{
			int rlt = _draw_proc(message, lparam);
			if (rlt != -1) return rlt;
		}
	}
	return 0L;

}