]> git.mxchange.org Git - friendica-addons.git/blobdiff - securemail/php-gpg/libs/GPG/Public_Key.php
securemail: update pgp library
[friendica-addons.git] / securemail / php-gpg / libs / GPG / Public_Key.php
diff --git a/securemail/php-gpg/libs/GPG/Public_Key.php b/securemail/php-gpg/libs/GPG/Public_Key.php
deleted file mode 100644 (file)
index b46118d..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-<?php\r
-/** @package    php-gpg::GPG */\r
-\r
-/** require supporting files */\r
-require_once("Expanded_Key.php");\r
-\r
-define("PK_TYPE_ELGAMAL", 1);\r
-define("PK_TYPE_RSA", 0);\r
-define("PK_TYPE_UNKNOWN", -1);\r
-\r
-/**\r
- * Pure PHP implementation of PHP/GPG public key\r
- *\r
- * @package php-gpg::GPG\r
- * @link http://www.verysimple.com/\r
- * @copyright  1997-2011 VerySimple, Inc.\r
- * @license    http://www.gnu.org/licenses/lgpl.html  LGPL\r
- * @todo implement decryption\r
- * @version 1.0\r
- */\r
-class GPG_Public_Key {\r
-    var $version;\r
-       var $fp;\r
-       var $key_id;\r
-       var $user;\r
-       var $public_key;\r
-       var $type;\r
-       \r
-       function IsValid()\r
-       {\r
-               return $this->version != -1 && $this->GetKeyType() != PK_TYPE_UNKNOWN;\r
-       }\r
-       \r
-       function GetKeyType()\r
-       {\r
-               if (!strcmp($this->type, "ELGAMAL")) return PK_TYPE_ELGAMAL;\r
-               if (!strcmp($this->type, "RSA")) return PK_TYPE_RSA;\r
-               return PK_TYPE_UNKNOWN;\r
-       }\r
-\r
-       function GetFingerprint()\r
-       {\r
-               return strtoupper( trim(chunk_split($this->fp, 4, ' ')) );\r
-       }\r
-       \r
-       function GetKeyId()\r
-       {\r
-               return (strlen($this->key_id) == 16) ? strtoupper($this->key_id) : '0000000000000000';\r
-       }\r
-       \r
-       function GetPublicKey()\r
-       {\r
-               return str_replace("\n", "", $this->public_key);\r
-       }\r
-       \r
-       function GPG_Public_Key($asc) {\r
-               $found = 0;\r
-               \r
-               // normalize line breaks\r
-               $asc = str_replace("\r\n", "\n", $asc);\r
-               \r
-               if (strpos($asc, "-----BEGIN PGP PUBLIC KEY BLOCK-----\n") === false)\r
-                       throw new Exception("Missing header block in Public Key");\r
-\r
-               if (strpos($asc, "\n\n") === false)\r
-                       throw new Exception("Missing body delimiter in Public Key");\r
-               \r
-               if (strpos($asc, "\n-----END PGP PUBLIC KEY BLOCK-----") === false)\r
-                       throw new Exception("Missing footer block in Public Key");\r
-               \r
-               // get rid of everything except the base64 encoded key\r
-               $headerbody = explode("\n\n", str_replace("\n-----END PGP PUBLIC KEY BLOCK-----", "", $asc), 2);\r
-               $asc = trim($headerbody[1]);\r
-               \r
-               \r
-               $len = 0;\r
-               $s =  base64_decode($asc);\r
-               $sa = str_split($s);\r
-               \r
-               for($i = 0; $i < strlen($s);) {\r
-                       $tag = ord($sa[$i++]);\r
-                       \r
-                       // echo 'TAG=' . $tag . '/';\r
-                       \r
-                       if(($tag & 128) == 0) break;\r
-                       \r
-                       if($tag & 64) {\r
-                               $tag &= 63;\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 {\r
-                               $len = $tag & 3;\r
-                               $tag = ($tag >> 2) & 15;\r
-                               if ($len == 0) $len = ord($sa[$i++]);\r
-                               else if($len == 1) $len = (ord($sa[$i++]) << 8) + ord($sa[$i++]);\r
-                                       else if($len == 2) $len = (ord($sa[$i++]) << 24) + (ord($sa[$i++]) << 16) + (ord($sa[$i++]) << 8) + ord($sa[$i++]);\r
-                                               else $len = strlen($s) - 1;\r
-                       }\r
-                       \r
-                       // echo $tag . ' ';\r
-                       \r
-                       if ($tag == 6 || $tag == 14) {\r
-                               $k = $i;\r
-                               $version = ord($sa[$i++]);\r
-                               $found = 1;\r
-                               $this->version = $version;\r
-                               \r
-                               $time = (ord($sa[$i++]) << 24) + (ord($sa[$i++]) << 16) + (ord($sa[$i++]) << 8) + ord($sa[$i++]);\r
-                               \r
-                               if($version == 2 || $version == 3) $valid = ord($sa[$i++]) << 8 + ord($sa[$i++]);\r
-                               \r
-                               $algo = ord($sa[$i++]);\r
-                               \r
-                               if($algo == 1 || $algo == 2) {\r
-                                       $m = $i;\r
-                                       $lm = floor((ord($sa[$i]) * 256 + ord($sa[$i + 1]) + 7) / 8);\r
-                                       $i += $lm + 2;\r
-                                       \r
-                                       $mod = substr($s, $m, $lm + 2);\r
-                                       $le = floor((ord($sa[$i]) * 256 + ord($sa[$i+1]) + 7) / 8);\r
-                                       $i += $le + 2;\r
-                                       \r
-                                       $this->public_key = base64_encode(substr($s, $m, $lm + $le + 4));\r
-                                       $this->type = "RSA";\r
-                                       \r
-                                       if ($version == 3) {\r
-                                               $this->fp = '';\r
-                                               $this->key_id = bin2hex(substr($mod, strlen($mod) - 8, 8));\r
-                                       } else if($version == 4) {\r
-                                               \r
-                                               // https://tools.ietf.org/html/rfc4880#section-12\r
-                                               $headerPos = strpos($s, chr(0x04));  // TODO: is this always the correct starting point for the pulic key packet 'version' field?\r
-                                               $delim = chr(0x01) . chr(0x00);  // TODO: is this the correct delimiter for the end of the public key packet? \r
-                                               $delimPos = strpos($s, $delim) + (3-$headerPos);\r
-                                               \r
-                                               // echo "POSITION: $delimPos\n";\r
-                                               \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); // use this for now\r
-                                               \r
-                                               $fp = sha1($pkt);\r
-                                               $this->fp = $fp;\r
-                                               $this->key_id = substr($fp, strlen($fp) - 16, 16);\r
-                                               \r
-                                               // uncomment to debug the start point for the signing string\r
-//                                             for ($ii = 5; $ii > -1; $ii--) {\r
-//                                                     $pkt = chr(0x99) . chr($ii >> 8) . chr($ii & 255) . substr($s, $headerPos, $ii);\r
-//                                                     $fp = sha1($pkt);\r
-//                                                     echo "LENGTH=" . $headerPos . '->' . $ii . " CHR(" . ord(substr($s,$ii, 1)) . ") = " . substr($fp, strlen($fp) - 16, 16) . "\n";\r
-//                                             }\r
-//                                             echo "\n";\r
-                                               \r
-                                               // uncomment to debug the end point for the signing string\r
-//                                             for ($ii = strlen($s); $ii > 1; $ii--) {\r
-//                                                     $pkt = chr(0x99) . chr($ii >> 8) . chr($ii & 255) . substr($s, $headerPos, $ii);\r
-//                                                     $fp = sha1($pkt);\r
-//                                                     echo "LENGTH=" . $headerPos . '->' . $ii . " CHR(" . ord(substr($s,$ii, 1)) . ") = " . substr($fp, strlen($fp) - 16, 16) . "\n";\r
-//                                             }\r
-                                       } else {\r
-                                               throw new Exception('GPG Key Version ' . $version . ' is not supported');\r
-                                       }\r
-                                       $found = 2;\r
-                               } else if(($algo == 16 || $algo == 20) && $version == 4) {\r
-                                               $m = $i;\r
-                                               \r
-                                               $lp = floor((ord($sa[$i]) * 256 + ord($sa[$i +1]) + 7) / 8);\r
-                                               $i += $lp + 2;\r
-                                               \r
-                                               $lg = floor((ord($sa[$i]) * 256 + ord($sa[$i + 1]) + 7) / 8);\r
-                                               $i += $lg + 2;\r
-                                               \r
-                                               $ly = floor((ord($sa[$i]) * 256 + ord($sa[$i + 1]) + 7)/8);\r
-                                               $i += $ly + 2;\r
-                                               \r
-                                               $this->public_key = base64_encode(substr($s, $m, $lp + $lg + $ly + 6));\r
-                                               \r
-                                               // TODO: should this be adjusted as it was for RSA (above)..?\r
-                                               \r
-                                               $pkt = chr(0x99) . chr($len >> 8) . chr($len & 255) . substr($s, $k, $len);\r
-                                               $fp = sha1($pkt);\r
-                                               $this->fp = $fp;\r
-                                               $this->key_id = substr($fp, strlen($fp) - 16, 16);\r
-                                               $this->type = "ELGAMAL";\r
-                                               $found = 3;\r
-                                       } else {\r
-                                               $i = $k + $len;\r
-                                       }\r
-                       } else if ($tag == 13) {\r
-                                       $this->user = substr($s, $i, $len);\r
-                                       $i += $len;\r
-                               } else {\r
-                                       $i += $len;\r
-                               }\r
-               }\r
-               \r
-               if($found < 2) {  \r
-                       \r
-                       throw new Exception("Unable to parse Public Key");\r
-//                     $this->version = "";\r
-//                     $this->fp = "";\r
-//                     $this->key_id = "";\r
-//                     $this->user = ""; \r
-//                     $this->public_key = "";\r
-               }\r
-       }\r
-       \r
-       function GetExpandedKey()\r
-       {\r
-               $ek = new Expanded_Key($this->public_key);\r
-       }\r
-}\r
-\r
-?>\r