tacruc / gpgmailer

Send encryped emails to registered users
GNU Affero General Public License v3.0
17 stars 4 forks source link

App not working #20

Open Spitfireap opened 3 years ago

Spitfireap commented 3 years ago

Hey ! This app seems really great, unfortunately I can't find a way to make it works on NC21. I've installed gnupg and php -i | grep -i gnupg do returns : /usr/local/etc/php/ext-20-gnupg.ini, gnupg gnupg support => enabled Unfortunately upon clicking on "Download server Key" I get redirected to mycloud.com/index.php/apps/gpgmailer/key/download/server but I get a file not found warning Screenshot_20210516_140148. And on the server there is no key folder under apps/gpgmailer/ GpgMailer do send a warning in the log [gpgmailer] Error: Creating server GPG key pair failed. Emails are not going to be signed, expect keys are server keys imported manually POST /index.php/settings/apps/enable from XX.XX.XX.XX by adrien at 2021-05-16T12:11:55+00:00 I also get two log entries : `[PHP] Error: Error: sizeof(): Parameter must be an array or an object that implements Countable at /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php#231 at <>

  1. <> OC\Log\ErrorHandler::onError(2, "sizeof(): Param ... e", "/usr/local/www/ ... p", 231, {email: "/////})
  2. /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php line 231 sizeof(false)
  3. /usr/local/www/nextcloud/apps/gpgmailer/lib/Settings/Personal.php line 84 OCA\GpgMailer\Service\Gpg->getPublicKeyFromEmail("/////")
  4. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/CommonSettingsTrait.php line 138 OCA\GpgMailer\Settings\Personal->getForm()
  5. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/PersonalSettingsController.php line 77 OCA\Settings\Controller\PersonalSettingsController->formatSettings({10: [OCA\Settin ... ]})
  6. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/CommonSettingsTrait.php line 149 OCA\Settings\Controller\PersonalSettingsController->getSettings("security")
  7. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/PersonalSettingsController.php line 68 OCA\Settings\Controller\PersonalSettingsController->getIndexResponse("personal", "security")
  8. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 218 OCA\Settings\Controller\PersonalSettingsController->index("security")
  9. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 127 OC\AppFramework\Http\Dispatcher->executeController(OCA\Settings\Con ... {}, "index")
  10. /usr/local/www/nextcloud/lib/private/AppFramework/App.php line 157 OC\AppFramework\Http\Dispatcher->dispatch(OCA\Settings\Con ... {}, "index")
    1. /usr/local/www/nextcloud/lib/private/Route/Router.php line 302 OC\AppFramework\App::main("OCA\Settings\ ... r", "index", OC\AppFramework\ ... {}, {section: "secur ... "})
    2. /usr/local/www/nextcloud/lib/base.php line 993 OC\Route\Router->match("/settings/user/security")
    3. /usr/local/www/nextcloud/index.php line 37 OC::handleRequest()

GET /index.php/settings/user/security from XX.XX.XX.XX by adrien at 2021-05-16T09:45:25+00:00`

as well as `[PHP] Error: Error: Invalid argument supplied for foreach() at /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php#232 at <>

  1. /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php line 232 OC\Log\ErrorHandler::onError(2, "Invalid argument supplied for foreach()", "/usr/local/www/ ... p", 232, {email: "/////})
  2. /usr/local/www/nextcloud/apps/gpgmailer/lib/Settings/Personal.php line 84 OCA\GpgMailer\Service\Gpg->getPublicKeyFromEmail("/////")
  3. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/CommonSettingsTrait.php line 138 OCA\GpgMailer\Settings\Personal->getForm()
  4. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/PersonalSettingsController.php line 77 OCA\Settings\Controller\PersonalSettingsController->formatSettings({10: [OCA\Settin ... ]})
  5. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/CommonSettingsTrait.php line 149 OCA\Settings\Controller\PersonalSettingsController->getSettings("security")
  6. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/PersonalSettingsController.php line 68 OCA\Settings\Controller\PersonalSettingsController->getIndexResponse("personal", "security")
  7. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 218 OCA\Settings\Controller\PersonalSettingsController->index("security")
  8. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 127 OC\AppFramework\Http\Dispatcher->executeController(OCA\Settings\Con ... {}, "index")
  9. /usr/local/www/nextcloud/lib/private/AppFramework/App.php line 157 OC\AppFramework\Http\Dispatcher->dispatch(OCA\Settings\Con ... {}, "index")
  10. /usr/local/www/nextcloud/lib/private/Route/Router.php line 302 OC\AppFramework\App::main("OCA\Settings\ ... r", "index", OC\AppFramework\ ... {}, {section: "secur ... "})
    1. /usr/local/www/nextcloud/lib/base.php line 993 OC\Route\Router->match("/settings/user/security")
    2. /usr/local/www/nextcloud/index.php line 37 OC::handleRequest()

GET /index.php/settings/user/security from XX.XX.XX.XX by adrien at 2021-05-16T09:45:25+00:00`

Also regarding importing my own public key, I try to copy it from thunderbird and pasting, but I get an "Error importing public key"...

`

Spitfireap commented 3 years ago

Okay here is why I don't have any key generated : `[gpgmailer] Warning: gpg --batch --gen-key foo: Array ( [0] => gpg: Warning: using insecure memory! [1] => gpg: foo:4: missing argument )

This took 0seconds.`

Seems to be due to Name-Comment. By deleting it I get a new error (yess) key generation failed: Unknown elliptic curve. After looking at here https://askubuntu.com/questions/861978/unattended-gnupg-key-generation-for-ecc/861985 I've just added Key-Curve: nistp256 and Subkey-Curve: nistp256 in foo. And then key generation seems to work : `[gpgmailer] Warning: gpg --batch --gen-key foo: Array ( [0] => gpg: Warning: using insecure memory! [1] => gpg: key 91AB6DB08A49BFDF marked as ultimately trusted [2] => gpg: revocation certificate stored as '/mnt/data/.gnupg/openpgp-revocs.d/C7FFDEA2B732DD6E4E6C1B0891AB6DB08A49BFDF.rev' )

This took 0seconds.

POST /index.php/settings/apps/enable`

but again : `[PHP] Error: Error: Invalid argument supplied for foreach() at /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php#320 at <>

  1. /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php line 320 OC\Log\ErrorHandler::onError(2, "Invalid argument supplied for foreach()", "/usr/local/www/ ... p", 320, {0: "And 11 more ... }})
  2. /usr/local/www/nextcloud/apps/gpgmailer/lib/Migration/CreateGpgServerKeys.php line 67 OCA\GpgMailer\Service\Gpg->generateKey()
  3. /usr/local/www/nextcloud/lib/private/Repair.php line 117 OCA\GpgMailer\Migration\CreateGpgServerKeys->run(OC\Repair {})
  4. /usr/local/www/nextcloud/lib/private/legacy/OC_App.php line 1054 OC\Repair->run()
  5. /usr/local/www/nextcloud/lib/private/Installer.php line 175 OC_App::executeRepairSteps("gpgmailer", {step: "OCA\Gpg ... "})
  6. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/AppSettingsController.php line 448 OC\Installer->installApp("gpgmailer")
  7. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 218 OCA\Settings\Controller\AppSettingsController->enableApps(["gpgmailer"], [])
  8. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 127 OC\AppFramework\Http\Dispatcher->executeController(OCA\Settings\Con ... {}, "enableApps")
  9. /usr/local/www/nextcloud/lib/private/AppFramework/App.php line 157 OC\AppFramework\Http\Dispatcher->dispatch(OCA\Settings\Con ... {}, "enableApps")
  10. /usr/local/www/nextcloud/lib/private/Route/Router.php line 302 OC\AppFramework\App::main("OCA\Settings\ ... r", "enableApps", OC\AppFramework\ ... {}, {_route: "settin ... "})
    1. /usr/local/www/nextcloud/lib/base.php line 993 OC\Route\Router->match("/settings/apps/enable")
    2. /usr/local/www/nextcloud/index.php line 37 OC::handleRequest()

POST /index.php/settings/apps/enable' and [gpgmailer] Warning: No server GPG key found so no signed emails are possible.

It seems that every foreach and sizeof raises an error...

tacruc commented 3 years ago

Something is going wrong while gpg->keyinfo eg. in https://github.com/tacruc/gpgmailer/blob/7c3cbaea2d8722b84be9969478d4a6bc1893e7ef/lib/Service/Gpg.php#L230

You could use echo $gpg -> geterror(); afterwards to get the error message of php_gnupg. The foreach fails because keyinfo returns for some reason false.

Spitfireap commented 3 years ago

Okay, well only thing the geterror() returns is [gpgmailer] Warning: could not init keylist`

And here is a more in-depth view of the debug of keyinfo(). I tried to activate the debug on nextcloud but I get so many RuntimeException that log for the PHP app is not saved... Tell me if you need these 9 more entries and I'll try to see if I can get them.

[PHP] Error: Error: gnupg::keyinfo(): could not init keylist at /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php#329 at <>

  1. <> OC\Log\ErrorHandler::onError(2, "gnupg::keyinfo( ... t", "/usr/local/www/ ... p", 329, {0: "And 9 more entries, set log level to debug to see all entries","email":"foo@bar.com","name":"foo","commend":"testing //if [""] key is not generated for me","uid":null,"gpg":{"class":"gnupg"}})
  2. /usr/local/www/nextcloud/apps/gpgmailer/lib/Service/Gpg.php line 329 gnupg->keyinfo("foo@bar.com//changed for privacy")
  3. /usr/local/www/nextcloud/apps/gpgmailer/lib/Migration/CreateGpgServerKeys.php line 67 OCA\GpgMailer\Service\Gpg->generateKey()
  4. /usr/local/www/nextcloud/lib/private/Repair.php line 117 OCA\GpgMailer\Migration\CreateGpgServerKeys->run(OC\Repair {})
  5. /usr/local/www/nextcloud/lib/private/legacy/OC_App.php line 1054 OC\Repair->run()
  6. /usr/local/www/nextcloud/lib/private/Installer.php line 175 OC_App::executeRepairSteps("gpgmailer", {step: "OCA\Gpg ... "})
  7. /usr/local/www/nextcloud/apps-pkg/settings/lib/Controller/AppSettingsController.php line 448 OC\Installer->installApp("gpgmailer")
  8. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 218 OCA\Settings\Controller\AppSettingsController->enableApps(["gpgmailer"], [])
  9. /usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 127 OC\AppFramework\Http\Dispatcher->executeController(OCA\Settings\Con ... {}, "enableApps")
  10. /usr/local/www/nextcloud/lib/private/AppFramework/App.php line 157 OC\AppFramework\Http\Dispatcher->dispatch(OCA\Settings\Con ... {}, "enableApps")
    1. /usr/local/www/nextcloud/lib/private/Route/Router.php line 302 OC\AppFramework\App::main("OCA\Settings\ ... r", "enableApps", OC\AppFramework\ ... {}, {_route: "settin ... "})
    2. /usr/local/www/nextcloud/lib/base.php line 993 OC\Route\Router->match("/settings/apps/enable")
    3. /usr/local/www/nextcloud/index.php line 37 OC::handleRequest()

POST /index.php/settings/apps/enable

tacruc commented 3 years ago

Could you try to get this small example running? It seems to be some problem with gnupg.

<?php

// make sure that this folder is NOT accesible as an URL

error_reporting(E_ALL);
$res = gnupg_init();
gnupg_seterrormode($res,GNUPG_ERROR_WARNING);

$info = gnupg_keyinfo($res, '');
echo geterror($res); 
Spitfireap commented 3 years ago

Sadly I only get AH01071: Got error 'PHP message: PHP Warning: gnupg_keyinfo(): could not init keylist in /usr/local/www/apache24/data/test.php on line 9' no matter if I set the GNUPGHOME or not :(. It's on a fresh new jail on freebsd but it does the exact same on my nextcloud jail.

And no error output from the gnupg_geterror($res);

tacruc commented 3 years ago

Could you check the permissions of the .gnupg folder?

http://superuser.com/questions/954509/ddg#954536

Spitfireap commented 3 years ago

On data/.gnupg and data/user/.gnupg I've got drwx------ 2 www www 5 May 17 17:04 .gnupg so 700 by default. Changing them to 777 doesn't change anything.

tacruc commented 3 years ago

and apache/php is running as www, www-data, wwwrun or php-fpm?

http://php.adamharvey.name/manual/en/function.gnupg-init.php#121851

Spitfireap commented 3 years ago

apache and php-fm run both under www user.

Spitfireap commented 3 years ago

It's driving me crazy. I tried all day yesterday and still can't at least introduce a new bug :p. I even changed php version to 8.0 but didn't improve anything. Do you think I should open an issue at https://github.com/php-gnupg/php-gnupg ? Thanks for your help !

tacruc commented 3 years ago

If the basic example of php-gnupg is not working. They might know whats going wrong. I'm sorry but I have no idea left right now.