library/src/network/BP-NetworkSSL.cc
//! Generates a certificate
// 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 certificate
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 certificate 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_SSLGenCertificate
(
		char *password,
		char *daysValid,
		char *inCsr,
		char *signKey,
		char *serverCrt
)
{
	if(!BP_StringIsReasonablePrintableString(password, bpstrlen(password), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(daysValid, bpstrlen(daysValid), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(signKey, bpstrlen(signKey), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(serverCrt, bpstrlen(serverCrt), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(inCsr,     bpstrlen(inCsr),     BP_TRUE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(signKey,   bpstrlen(signKey),   BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(serverCrt, bpstrlen(serverCrt), BP_FALSE))
		return ERR_FAILURE;
	char keyArgs[MAX_CMD_LENGTH+1];
	int charCount = 0;
	char * opensslx509Passin = "openssl x509 -passin pass:";
	char * reqDays = " -req -days ";
	char * in = " -in ";
	char * signkey = " -signkey ";
	char * out = " -out ";
	if(strstr(password, "`") || strstr(password, ";") || strstr(password, "|") || strstr(password, ".."))
		return ERR_FAILURE;
	if(strstr(daysValid, "`") || strstr(daysValid, ";") || strstr(daysValid, "|") || strstr(daysValid, ".."))
		return ERR_FAILURE;
	if(strstr(inCsr, "`") || strstr(inCsr, ";") || strstr(inCsr, "|") || strstr(inCsr, ".."))
		return ERR_FAILURE;
	if(strstr(signKey, "`") || strstr(signKey, ";") || strstr(signKey, "|") || strstr(signKey, ".."))
		return ERR_FAILURE;
	if(strstr(serverCrt, "`") || strstr(serverCrt, ";") || strstr(serverCrt, "|") || strstr(serverCrt, ".."))
		return ERR_FAILURE;
	memset(keyArgs, 0x00, MAX_CMD_LENGTH+1);
	strncat(keyArgs, opensslx509Passin, MAX_CMD_LENGTH);
	charCount = bpstrlen(keyArgs);
	if( (bpstrlen(password) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, password, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(password);
	if( (bpstrlen(reqDays) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, reqDays, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(reqDays);
	Valid
	if( (bpstrlen(daysValid) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, daysValid, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(daysValid);
	if( (bpstrlen(in) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, in, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(in);
	if( (bpstrlen(inCsr) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, inCsr, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(inCsr);
	 (lowercase)
	if( (bpstrlen(signkey) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, signkey, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(signkey);
	if( (bpstrlen(signKey) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, signKey, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(signKey);
	if( (bpstrlen(out) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, out, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(out);
	if( (bpstrlen(serverCrt) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, serverCrt, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(serverCrt);
	system(keyArgs);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SSLGenCertificate ( char * password , char * daysValid , char * inCsr , char * signKey , char * serverCrt ) { if ( ! BP_StringIsReasonablePrintableString ( password , bpstrlen ( password ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( daysValid , bpstrlen ( daysValid ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( signKey , bpstrlen ( signKey ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( serverCrt , bpstrlen ( serverCrt ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( inCsr , bpstrlen ( inCsr ) , BP_TRUE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( signKey , bpstrlen ( signKey ) , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( serverCrt , bpstrlen ( serverCrt ) , BP_FALSE ) ) return ERR_FAILURE ; char keyArgs [ MAX_CMD_LENGTH + 1 ] ; int charCount = 0 ; char * opensslx509Passin = " " ; char * reqDays = " " ; char * in = " " ; char * signkey = " " ; char * out = " " ; if ( strstr ( password , " " ) || strstr ( password , " " ) || strstr ( password , " " ) || strstr ( password , " " ) ) return ERR_FAILURE ; if ( strstr ( daysValid , " " ) || strstr ( daysValid , " " ) || strstr ( daysValid , " " ) || strstr ( daysValid , " " ) ) return ERR_FAILURE ; if ( strstr ( inCsr , " " ) || strstr ( inCsr , " " ) || strstr ( inCsr , " " ) || strstr ( inCsr , " " ) ) return ERR_FAILURE ; if ( strstr ( signKey , " " ) || strstr ( signKey , " " ) || strstr ( signKey , " " ) || strstr ( signKey , " " ) ) return ERR_FAILURE ; if ( strstr ( serverCrt , " " ) || strstr ( serverCrt , " " ) || strstr ( serverCrt , " " ) || strstr ( serverCrt , " " ) ) return ERR_FAILURE ; memset ( keyArgs , 0x00 , MAX_CMD_LENGTH + 1 ) ; strncat ( keyArgs , opensslx509Passin , MAX_CMD_LENGTH ) ; charCount = bpstrlen ( keyArgs ) ; if ( ( bpstrlen ( password ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , password , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( password ) ; if ( ( bpstrlen ( reqDays ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , reqDays , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( reqDays ) ; if ( ( bpstrlen ( daysValid ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , daysValid , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( daysValid ) ; if ( ( bpstrlen ( in ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , in , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( in ) ; if ( ( bpstrlen ( inCsr ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , inCsr , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( inCsr ) ; if ( ( bpstrlen ( signkey ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , signkey , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( signkey ) ; if ( ( bpstrlen ( signKey ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , signKey , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( signKey ) ; if ( ( bpstrlen ( out ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , out , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( out ) ; if ( ( bpstrlen ( serverCrt ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , serverCrt , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( serverCrt ) ; system ( keyArgs ) ; return ERR_SUCCESS ; }
Generates a certificate
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 certificate 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; // set password // set days // set inCsr // set signkey // set cert // Check for invalids // zero out buff // set first element // set password // set reqDays // set daysValid // set in // set inCsr // set signkey (lowercase) // set signKey (user value) // set out // set serverCrt // generate CSR // return indicating success