library/src/network/BP-NetworkSSL.cc
//! generates a ssl CSR
// 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 CSR
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 CSR 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_SSLGenCertificateSignRequest(char * password, char * inKey, char * outCsr)
{
	if(!BP_StringIsReasonablePrintableString(password, bpstrlen(password), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(inKey, bpstrlen(inKey), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(outCsr, bpstrlen(outCsr), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(inKey,     bpstrlen(inKey),     BP_TRUE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(outCsr,   bpstrlen(outCsr),   BP_FALSE))
		return ERR_FAILURE;
	char keyArgs[MAX_CMD_LENGTH+1];
	int charCount = 0;
	char * openSslReqPassin = "openssl req -passin pass:";
	char * newKey = " -new -key ";
	char * out = " -out ";
	char * batch = " -batch";
	if(strstr(password, "`") || strstr(password, ";") || strstr(password, "|") || strstr(password, ".."))
		return ERR_FAILURE;
	if(strstr(inKey, "`") || strstr(inKey, ";") || strstr(inKey, "|") || strstr(inKey, ".."))
		return ERR_FAILURE;
	if(strstr(outCsr, "`") || strstr(outCsr, ";") || strstr(outCsr, "|") || strstr(outCsr, ".."))
		return ERR_FAILURE;
	memset(keyArgs, 0x00, MAX_CMD_LENGTH+1);
	strcat(keyArgs, openSslReqPassin);
	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(newKey) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strcat(keyArgs, newKey);
	charCount += bpstrlen(newKey);
	if( (bpstrlen(inKey) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strncat(keyArgs, inKey, MAX_CMD_LENGTH - charCount);
	charCount += bpstrlen(inKey);
	if( (bpstrlen(out) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strcat(keyArgs, out);
	charCount += bpstrlen(out);
	if( (bpstrlen(outCsr) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strcat(keyArgs, outCsr);
	charCount += bpstrlen(outCsr);
	if( (bpstrlen(batch) + charCount) > MAX_CMD_LENGTH)
		return ERR_FAILURE;
	strcat(keyArgs, batch);
	charCount += bpstrlen(outCsr);
	system(keyArgs);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SSLGenCertificateSignRequest ( char * password , char * inKey , char * outCsr ) { if ( ! BP_StringIsReasonablePrintableString ( password , bpstrlen ( password ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( inKey , bpstrlen ( inKey ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( outCsr , bpstrlen ( outCsr ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( inKey , bpstrlen ( inKey ) , BP_TRUE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( outCsr , bpstrlen ( outCsr ) , BP_FALSE ) ) return ERR_FAILURE ; char keyArgs [ MAX_CMD_LENGTH + 1 ] ; int charCount = 0 ; char * openSslReqPassin = " " ; char * newKey = " " ; char * out = " " ; char * batch = " " ; if ( strstr ( password , " " ) || strstr ( password , " " ) || strstr ( password , " " ) || strstr ( password , " " ) ) return ERR_FAILURE ; if ( strstr ( inKey , " " ) || strstr ( inKey , " " ) || strstr ( inKey , " " ) || strstr ( inKey , " " ) ) return ERR_FAILURE ; if ( strstr ( outCsr , " " ) || strstr ( outCsr , " " ) || strstr ( outCsr , " " ) || strstr ( outCsr , " " ) ) return ERR_FAILURE ; memset ( keyArgs , 0x00 , MAX_CMD_LENGTH + 1 ) ; strcat ( keyArgs , openSslReqPassin ) ; 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 ( newKey ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strcat ( keyArgs , newKey ) ; charCount += bpstrlen ( newKey ) ; if ( ( bpstrlen ( inKey ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strncat ( keyArgs , inKey , MAX_CMD_LENGTH - charCount ) ; charCount += bpstrlen ( inKey ) ; if ( ( bpstrlen ( out ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strcat ( keyArgs , out ) ; charCount += bpstrlen ( out ) ; if ( ( bpstrlen ( outCsr ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strcat ( keyArgs , outCsr ) ; charCount += bpstrlen ( outCsr ) ; if ( ( bpstrlen ( batch ) + charCount ) > MAX_CMD_LENGTH ) return ERR_FAILURE ; strcat ( keyArgs , batch ) ; charCount += bpstrlen ( outCsr ) ; system ( keyArgs ) ; return ERR_SUCCESS ; }
generates a ssl CSR
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 CSR 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; // actual request building strings // pass var here // key var here // cert var here // set first element // set password // set second element // set key // set third element // set out cert here // set batch