diff --git a/codecept.phar b/codecept.phar new file mode 100644 index 0000000000..d4212c8b33 Binary files /dev/null and b/codecept.phar differ diff --git a/lib/util/dkim.php b/lib/util/dkim.php new file mode 100644 index 0000000000..5e673dcef2 --- /dev/null +++ b/lib/util/dkim.php @@ -0,0 +1,23 @@ + 1024)); + + $keys = array('public' => '', 'private' => ''); + + // get private key + openssl_pkey_export($certificate, $keys['private']); + + // get public key + $details = openssl_pkey_get_details($certificate); + $keys['public'] = $details['key']; + + return $keys; + } catch(Exception $e) { + return false; + } + } +} \ No newline at end of file diff --git a/tests/unit/DKIMCest.php b/tests/unit/DKIMCest.php new file mode 100644 index 0000000000..097609d8ed --- /dev/null +++ b/tests/unit/DKIMCest.php @@ -0,0 +1,44 @@ +wantTo('generate public and private keys'); + + $keys = \MailPoet\Util\DKIM::generate_keys(); + + $I->expect('public key is not empty'); + $I->assertNotEmpty($keys['public']); + + $I->expect('private key is not empty'); + $I->assertNotEmpty($keys['private']); + + $I->expect('public key starts with proper header'); + $I->assertTrue( + strpos( + $keys['public'], + '-----BEGIN PUBLIC KEY-----' + ) === 0 + ); + + $I->expect('private key starts with proper header'); + $I->assertTrue( + strpos( + $keys['private'], + '-----BEGIN RSA PRIVATE KEY-----' + ) === 0 + ); + } +}