Exemplo n.º 1
0
int decrypt_dir(const char *dirName, unsigned char *key) {
    char buffer[PATH_SIZE];

    DIR *dir;
    struct dirent *entry;

    dir = opendir(dirName);
    if (!dir) {
        perror("diropen");
        exit(1);
    };

    while ( (entry = readdir(dir)) != NULL) {
        if(entry->d_type != DT_DIR && strcmp(entry->d_name,".DS_Store")) {
        	cnct(dirName,entry->d_name,buffer);
        	decrypt_file(dirName,buffer,key);
        }
        if(entry->d_type == DT_DIR && strcmp(entry->d_name,"..") && strcmp(entry->d_name,".")) {
        	cnct(dirName,entry->d_name,buffer);
        	decrypt_dir(buffer, key);
        }
    }

    closedir(dir);
    return 0;
}
Exemplo n.º 2
0
//********************************************************************************************
//**-------------------------------------FILE CRYPTION--------------------------------------**
//********************************************************************************************
int crypt_file(const char *path, const char *fileName, unsigned char *key) {

	int outlen, inlen;
	
	FILE *file, *temp;
	file = fopen(fileName,"r+b");
	if(file == NULL) {
		return -2;
	}
	
	char tempName[PATH_SIZE];
	cnct(path,"TemP.TemP",tempName);
	temp = fopen(tempName,"wb");

	unsigned char iv[8] = "DAJ-7l2"; /* вектор инициализации */ 
	unsigned char inbuf[BUF_SIZE], outbuf[BUF_SIZE]; 
	
	EVP_CIPHER_CTX ctx;
	const EVP_CIPHER * cipher;

	EVP_CIPHER_CTX_init(&ctx);
	cipher = EVP_bf_cbc();

	EVP_EncryptInit(&ctx, cipher, key, iv);

	while(1) {
		inlen = fread(inbuf, 1, BUF_SIZE, file);
		if(inlen <= 0) break;
		if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, inbuf, inlen))
			return 1;
		fwrite(outbuf, 1, outlen, temp);
	}

	if(!EVP_EncryptFinal(&ctx, outbuf, &outlen)) 
		return 1; 
	fwrite(outbuf, 1, outlen, temp); 
	EVP_CIPHER_CTX_cleanup(&ctx);

	fclose(file);
	fclose(temp);

	remove(fileName);
	rename(tempName,fileName);

	return 0;
}
Exemplo n.º 3
0
 /* ip_addr is now in network byte order 
  *
  * first we have to get hold of the portnumber to
  *  the node through epmd at that host 
  *
*/
int ei_xconnect_tmo(ei_cnode* ec, Erl_IpAddr adr, char *alivename, unsigned ms)
{
    struct in_addr *ip_addr=(struct in_addr *) adr;
    int rport = 0; /*uint16 rport = 0;*/
    int sockd;
    int one = 1;
    int dist = 0;
    ErlConnect her_name;
    unsigned her_flags, her_version;

    erl_errno = EIO;		/* Default error code */
    
    EI_TRACE_CONN1("ei_xconnect","-> CONNECT attempt to connect to %s",
		   alivename);
    
    if ((rport = ei_epmd_port_tmo(ip_addr,alivename,&dist, ms)) < 0) {
	EI_TRACE_ERR0("ei_xconnect","-> CONNECT can't get remote port");
	/* ei_epmd_port_tmo() has set erl_errno */
	return ERL_NO_PORT;
    }
    
    /* we now have port number to enode, try to connect */
    if((sockd = cnct((uint16)rport, ip_addr, sizeof(struct in_addr),ms)) < 0) {
	EI_TRACE_ERR0("ei_xconnect","-> CONNECT socket connect failed");
	/* cnct() has set erl_errno */
	return ERL_CONNECT_FAIL;
    }
    
    EI_TRACE_CONN0("ei_xconnect","-> CONNECT connected to remote");

    /* FIXME why connect before checking 'dist' output from ei_epmd_port() ?! */
    if (dist <= 4) {
	EI_TRACE_ERR0("ei_xconnect","-> CONNECT remote version not compatible");
	goto error;
    }
    else {
	unsigned our_challenge, her_challenge;
	unsigned char our_digest[16];
	
	if (send_name(sockd, ec->thisnodename, (unsigned) dist, ms))
	    goto error;
	if (recv_status(sockd, ms))
	    goto error;
	if (recv_challenge(sockd, &her_challenge, &her_version,
	    &her_flags, &her_name, ms))
	    goto error;
	our_challenge = gen_challenge();
	gen_digest(her_challenge, ec->ei_connect_cookie, our_digest);
	if (send_challenge_reply(sockd, our_digest, our_challenge, ms))
	    goto error;
	if (recv_challenge_ack(sockd, our_challenge, 
	    ec->ei_connect_cookie, ms))
	    goto error;
	put_ei_socket_info(sockd, dist, null_cookie, ec); /* FIXME check == 0 */
    }
    
    setsockopt(sockd, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one));
    setsockopt(sockd, SOL_SOCKET, SO_KEEPALIVE, (char *)&one, sizeof(one));

    EI_TRACE_CONN1("ei_xconnect","-> CONNECT (ok) remote = %s",alivename);
    
    erl_errno = 0;
    return sockd;
    
error:
    EI_TRACE_ERR0("ei_xconnect","-> CONNECT failed");
    closesocket(sockd);
    return ERL_ERROR;
} /* ei_xconnect */