-----------
Send notification mails to user encrypted with GPG.
-Each user can enable it and submit his public key under Settings-> Addon
+Each user can enable it and submit his public key under Settings-> Addon
-> "Secure Mail" Settings.
-Use 'php-gpg' library, a pure PHP implementation of GPG/PGP, released
+Use 'php-gpg' library, a pure PHP implementation of GPG/PGP, released
under GPL. See [project repo](https://github.com/jasonhinkle/php-gpg).
-This plugin need Friendica version > 3.3.2 to work.
+This plugin could have some problems with keys larger than 2048 ([see issue](https://github.com/jasonhinkle/php-gpg/issues/7))
+
+Need Friendica version > 3.3.2 to work.
+++ /dev/null
-/.buildpath
-/.settings
-.DS_Store
\ No newline at end of file
private function gpg_encrypt($key, $text) {\r
\r
$i = 0;\r
- $i = 0;\r
- $len = strlen($text);\r
$len = strlen($text);\r
$iblock = array_fill(0, $this->width, 0);\r
$rblock = array_fill(0, $this->width, 0);\r
\r
private function gpg_header($tag, $len)\r
{\r
- if ($len > 0xff) $tag += 1;\r
- $h = chr($tag);\r
- if ($len > 0xff) $h .= chr($len / 0x100);\r
- $h .= chr($len % 0x100);\r
-\r
+ $h = "";\r
+ if ($len < 0x100) {\r
+ $h .= chr($tag);\r
+ $h .= chr($len);\r
+ } else if ($len < 0x10000) {\r
+ $tag+=1;\r
+ $h .= chr($tag);\r
+ $h .= $this->writeNumber($len, 2);\r
+ } else {\r
+ $tag+=2;\r
+ $h .= chr($tag);\r
+ $h .= $this->writeNumber($len, 4);\r
+ }\r
return $h;\r
}\r
\r
+ private function writeNumber($n, $bytes)\r
+ {\r
+ // credits for this function go to OpenPGP.js\r
+ $b = '';\r
+ for ($i = 0; $i < $bytes; $i++) {\r
+ $b .= chr(($n >> (8 * ($bytes - $i - 1))) & 0xff);\r
+ }\r
+ return $b;\r
+ }\r
+\r
private function gpg_session($key_id, $key_type, $session_key, $public_key)\r
{ \r
\r
$this->gpg_data($session_key, $plaintext);\r
\r
$code = base64_encode($cp);\r
- $code = wordwrap($code, 60, "\n", 1);\r
+ $code = wordwrap($code, 64, "\n", 1);\r
\r
return\r
"-----BEGIN PGP MESSAGE-----\nVersion: VerySimple PHP-GPG v".$this->version."\n\n" .\r
}\r
}\r
\r
-?>
\ No newline at end of file
+?>\r
$len = ord($sa[$i++]);\r
if ($len > 191 && $len < 224) $len = (($len - 192) << 8) + ord($sa[$i++]);\r
else if ($len == 255) $len = (ord($sa[$i++]) << 24) + (ord($sa[$i++]) << 16) + (ord($sa[$i++]) << 8) + ord($sa[$i++]);\r
- else if ($len > 223 && len < 255) $len = (1 << ($len & 0x1f));\r
+ else if ($len > 223 && $len < 255) $len = (1 << ($len & 0x1f));\r
} else {\r
$len = $tag & 3;\r
$tag = ($tag >> 2) & 15;\r
\r
// echo "POSITION: $delimPos\n";\r
\r
- $pkt = chr(0x99) . chr($delimPos >> 8) . chr($delimPos & 255) . substr($s, $headerPos, $delimPos);\r
+ // this does not work, tried it with RSA 1024 and RSA 4096 keys generated by GnuPG v2 (2.0.29) on Windows running Apache and PHP 5.6.3\r
+ // $pkt = chr(0x99) . chr($delimPos >> 8) . chr($delimPos & 255) . substr($s, $headerPos, $delimPos);\r
\r
// this is the original signing string which seems to have only worked for key lengths of 1024 or less\r
- //$pkt = chr(0x99) . chr($len >> 8) . chr($len & 255) . substr($s, $k, $len);\r
+ $pkt = chr(0x99) . chr($len >> 8) . chr($len & 255) . substr($s, $k, $len); // use this for now\r
\r
$fp = sha1($pkt);\r
$this->fp = $fp;\r
}\r
}\r
\r
-?>
\ No newline at end of file
+?>\r