WordPress.org

Plugin Directory

Changeset 1355290


Ignore:
Timestamp:
02/21/16 19:08:22 (19 months ago)
Author:
meitar
Message:

Closes #4: Refactor to expose library methods via WordPress plugin API.

Location:
wp-pgp-encrypted-emails/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-pgp-encrypted-emails/trunk/readme.txt

    r1354772 r1355290  
    55Requires at least: 4.4 
    66Tested up to: 4.4.2 
    7 Stable tag: 0.1.2 
     7Stable tag: 0.2.0 
    88License: GPLv3 
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html 
    1010 
    11 Encrypts emails WordPress sends using PGP public keys. 
     11Encrypts emails WordPress sends using PGP public keys. Provides OpenPGP functions via WordPress plugin API. 
    1212 
    1313== Description == 
     
    2525* [The Electronic Frontier Foundation's Surveillance Self-Defense guide to PGP](https://ssd.eff.org/en/module/introduction-public-key-cryptography-and-pgp) 
    2626* [RiseUp.net's OpenPGP best practices guide](https://help.riseup.net/en/gpg-best-practices) 
     27 
     28Additionally, WP PGP Encrypted Emails provides an easy to use API to OpenPGP operations through the familiar [WordPress plugin API](https://codex.wordpress.org/Plugin_API). See the [Other Notes](https://wordpress.org/plugins/wp-pgp-encrypted-emails/other_notes/) page for details. 
    2729 
    2830**Security Disclaimer** 
     
    109111 
    110112If you like this plugin, **please consider [making a donation](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=TJLPJYXHSRBEE&lc=US&item_name=WP%20PGP%20Encrypted%20Emails&item_number=wp-pgp-encrypted-emails&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted) for your use of the plugin**, [purchasing one of Meitar's web development books](http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2Fs%3Fie%3DUTF8%26redirect%3Dtrue%26sort%3Drelevancerank%26search-type%3Dss%26index%3Dbooks%26ref%3Dntt%255Fathr%255Fdp%255Fsr%255F2%26field-author%3DMeitar%2520Moscovitz&tag=maymaydotnet-20&linkCode=ur2&camp=1789&creative=390957) or, better yet, contributing directly to [Meitar's Cyberbusking fund](http://Cyberbusking.org/). (Publishing royalties ain't exactly the lucrative income it used to be, y'know?) Your support is appreciated! 
     113 
     114= Plugin hooks = 
     115 
     116This plugin offers additional functionality intended for other plugin developers or theme authors to make use of. This functionality is documented here. 
     117 
     118== Filters == 
     119 
     120* `openpgp_key` - Gets a binary OpenPGP public key for use in later PGP operations from an ASCII-armored representation of that key. 
     121    * Required parameters: 
     122        * `string` `$key` - The ASCII-armored PGP public key block. 
     123 
     124Example: Get a key saved as an ASCII string in the WordPress database option `my_plugin_pgp_public_key`. 
     125 
     126    $key = apply_filters('openpgp_key', get_option('my_plugin_pgp_public_key')); 
     127 
     128* `openpgp_encrypt` - Encrypts data to one or more PGP public keys or passphrases. 
     129    * Required arguments: 
     130        * `string` `$data` - Data to encrypt. 
     131        * `array|string` `$keys` - Passphrases or keys to use to encrypt the data. 
     132 
     133Examples: Encrypt the content of a blog post. 
     134 
     135    // First, get the PGP public key(s) of the recipient(s) 
     136    $ascii_key = '-----BEGIN PGP PUBLIC KEY BLOCK----- 
     137    [...snipped for length...] 
     138    -----END PGP PUBLIC KEY BLOCK-----'; 
     139    $encryption_key = apply_filters('openpgp_key', $ascii_key); 
     140    $encrypted_post = apply_filters('openpgp_encrypt', $post->post_content, $encryption_key); 
     141    // Now you can safely send or display $encrypted_post anywhere you like and only 
     142    // those who control the corresponding private key(s) can decrypt it. 
  • wp-pgp-encrypted-emails/trunk/wp-pgp-encrypted-emails.php

    r1354772 r1355290  
    88 * * Plugin URI: https://github.com/meitar/wp-pgp-encrypted-emails 
    99 * * Description: Encrypts all emails sent to a given user if that user adds a PGP public key to their profile. <strong>Like this plugin? Please <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=TJLPJYXHSRBEE&amp;lc=US&amp;item_name=WP%20PGP%20Encrypted%20Emails&amp;item_number=wp-pgp-encrypted-emails&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted" title="Send a donation to the developer of WP PGP Encrypted Emails">donate</a>. &hearts; Thank you!</strong> 
    10  * * Version: 0.1.2 
     10 * * Version: 0.2.0 
    1111 * * Author: Maymay <bitetheappleback@gmail.com> 
    1212 * * Author URI: https://maymay.net/ 
     
    9494     */ 
    9595    public static function initialize () { 
    96         if (!class_exists('OpenPGP')) { 
    97             require_once plugin_dir_path(__FILE__).'vendor/openpgp-php/vendor/autoload.php'; 
    98             require_once plugin_dir_path(__FILE__).'vendor/openpgp-php/openpgp.php'; 
    99             require_once plugin_dir_path(__FILE__).'vendor/openpgp-php/openpgp_crypt_rsa.php'; 
    100             require_once plugin_dir_path(__FILE__).'vendor/openpgp-php/openpgp_crypt_symmetric.php'; 
    101         } 
     96        require_once plugin_dir_path(__FILE__).'class-wp-openpgp.php'; 
     97        WP_OpenPGP::register(); 
    10298    } 
    10399 
     
    183179        } 
    184180 
    185         $openpgp_msg = OpenPGP_Message::parse(OpenPGP::unarmor($ascii_key, 'PGP PUBLIC KEY BLOCK')); 
    186         return (is_null($openpgp_msg)) ? false : $openpgp_msg; 
     181        return apply_filters('openpgp_key', $ascii_key); 
    187182    } 
    188183 
     
    193188     */ 
    194189    public static function getAdminKey () { 
    195         $ascii_key = get_option(self::$meta_key); 
    196         $openpgp_msg = OpenPGP_Message::parse(OpenPGP::unarmor($ascii_key, 'PGP PUBLIC KEY BLOCK')); 
    197         return (is_null($openpgp_msg)) ? false : $openpgp_msg; 
     190        return apply_filters('openpgp_key', get_option(self::$meta_key)); 
    198191    } 
    199192 
     
    368361<?php 
    369362    } 
     363 
    370364    /** 
    371365     * Saves profile field values to the database on profile update. 
     
    419413        if ($pub_key instanceof OpenPGP_Message) { 
    420414            try { 
    421                 $plain_data  = new OpenPGP_LiteralDataPacket( 
    422                     $args['message'], 
    423                     array('format' => 'u', 'filename' => 'encrypted.gpg') 
    424                 ); 
    425                 $encrypted = OpenPGP_Crypt_Symmetric::encrypt( 
    426                     $pub_key, 
    427                     new OpenPGP_Message(array($plain_data)) 
    428                 ); 
    429                 $args['message'] = wordwrap(OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'), 75, "\n", true); 
     415                $args['message'] = apply_filters('openpgp_encrypt', $args['message'], $pub_key); 
    430416            } catch (Exception $e) { 
    431417                error_log(sprintf( 
Note: See TracChangeset for help on using the changeset viewer.