What are the potential security risks involved in using shell_exec in PHP for certificate generation?

Using shell_exec in PHP for certificate generation can pose a security risk as it allows for the execution of arbitrary shell commands, opening up the possibility of command injection attacks. To mitigate this risk, it is recommended to use PHP's built-in functions for certificate generation instead of relying on shell_exec.

// Example of using PHP's built-in functions for certificate generation
$privateKey = openssl_pkey_new();
$csr = openssl_csr_new(['commonName' => 'example.com'], $privateKey);
$cert = openssl_csr_sign($csr, null, $privateKey, 365);

// Save the private key, CSR, and certificate to files
openssl_pkey_export_to_file($privateKey, 'private.key');
openssl_csr_export_to_file($csr, 'example.csr');
openssl_x509_export_to_file($cert, 'example.crt');