library/src/network/BP-NetworkSSL.cc
//! Generates a ssl server key
// TODO: This code is some of the oldest in blockparty and must be updated with value checks and filtering
//       to prevent code injection scenarios.
Generates a ssl server key
TODO: This code is some of the oldest in blockparty and must be updated with value checks and filtering
to prevent code injection scenarios.
Generates a ssl server key TODO : This code is some of the oldest in blockparty and must be updated with value checks and filtering to prevent code injection scenarios .
BP_ERROR_T BP_SSLGenrsaServerKey(char *password, char * randomSeedFile, char * outKeyFile)
{
	if(!BP_StringIsReasonablePrintableString(password, bpstrlen(password), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(randomSeedFile, bpstrlen(randomSeedFile), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(outKeyFile, bpstrlen(outKeyFile), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(randomSeedFile,     bpstrlen(randomSeedFile),     BP_TRUE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(outKeyFile,   bpstrlen(outKeyFile),   BP_FALSE))
		return ERR_FAILURE;
	char keyArgs[MAX_CMD_LENGTH+1];
	int charCount = 0;
	if(strstr(password, "`") || strstr(password, ";") || strstr(password, "|") || strstr(password, ".."))
		return ERR_FAILURE;
	if(strstr(randomSeedFile, "`") || strstr(randomSeedFile, ";") || strstr(randomSeedFile, "|") || strstr(randomSeedFile, ".."))
		return ERR_FAILURE;
	if(strstr(outKeyFile, "`") || strstr(outKeyFile, ";") || strstr(outKeyFile, "|") || strstr(outKeyFile, ".."))
		return ERR_FAILURE;
	memset(keyArgs, 0x00, MAX_CMD_LENGTH);
	strcat(keyArgs, "openssl genrsa -passout pass:");
	charCount += bpstrlen("openssl genrsa -passout pass:");
	if((bpstrlen(password) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, password, MAX_CMD_LENGTH-charCount);
	charCount += bpstrlen(password);
	strcat(keyArgs, " -des3");
	charCount += bpstrlen(" -des3");
	strcat(keyArgs, " -rand ");
	charCount += bpstrlen(" -rand ");
	if( (bpstrlen(randomSeedFile) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, randomSeedFile, MAX_CMD_LENGTH-charCount);
	charCount += bpstrlen(randomSeedFile);
	strcat(keyArgs, " -out ");
	charCount += bpstrlen(" -out ");
	if((bpstrlen(outKeyFile) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, outKeyFile, MAX_CMD_LENGTH-charCount);
	charCount += bpstrlen(outKeyFile);
	system(keyArgs);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SSLGenrsaServerKey ( char * password , char * randomSeedFile , char * outKeyFile ) { if ( ! BP_StringIsReasonablePrintableString ( password , bpstrlen ( password ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( randomSeedFile , bpstrlen ( randomSeedFile ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( outKeyFile , bpstrlen ( outKeyFile ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( randomSeedFile , bpstrlen ( randomSeedFile ) , BP_TRUE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( outKeyFile , bpstrlen ( outKeyFile ) , BP_FALSE ) ) return ERR_FAILURE ; char keyArgs [ MAX_CMD_LENGTH + 1 ] ; int charCount = 0 ; if ( strstr ( password , " " ) || strstr ( password , " " ) || strstr ( password , " " ) || strstr ( password , " " ) ) return ERR_FAILURE ; if ( strstr ( randomSeedFile , " " ) || strstr ( randomSeedFile , " " ) || strstr ( randomSeedFile , " " ) || strstr ( randomSeedFile , " " ) ) return ERR_FAILURE ; if ( strstr ( outKeyFile , " " ) || strstr ( outKeyFile , " " ) || strstr ( outKeyFile , " " ) || strstr ( outKeyFile , " " ) ) return ERR_FAILURE ; memset ( keyArgs , 0x00 , MAX_CMD_LENGTH ) ; strcat ( keyArgs , " " ) ; charCount += bpstrlen ( " " ) ; if ( ( bpstrlen ( password ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , password , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( password ) ; strcat ( keyArgs , " " ) ; charCount += bpstrlen ( " " ) ; strcat ( keyArgs , " " ) ; charCount += bpstrlen ( " " ) ; if ( ( bpstrlen ( randomSeedFile ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , randomSeedFile , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( randomSeedFile ) ; strcat ( keyArgs , " " ) ; charCount += bpstrlen ( " " ) ; if ( ( bpstrlen ( outKeyFile ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , outKeyFile , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( outKeyFile ) ; system ( keyArgs ) ; return ERR_SUCCESS ; }
Generates a ssl server key
TODO: This code is some of the oldest in blockparty and must be updated with value checks and filtering
to prevent code injection scenarios.
Generates a ssl server key TODO : This code is some of the oldest in blockparty and must be updated with value checks and filtering to prevent code injection scenarios .
// run basic string hecks // ensure the inCsr exists //struct stat fileStats; // check parameters for escapes