cvs: presentations / sensitive.xml /slides/sensitive advantages.xml broad_vulnerabilities.xml credits.xml crypto_hashes.xml
data_poisoning_and_decoys.xml drawbacks.xml example_code.xml example_code_2.xml example_code_3.xml followup.xml identity_crisis.xml introduction.xml
key_exchange_distro.xml lossy_storage.xml mysql.xml php.xml private_key_cryptosystems.xml private_key_encryption.xml public_key_cryptosystems.xml
public_key_encryption.xml quantization.xml questions.xml reputation_poisoning.xml risks.xml sensitive_data.xml setup.xml solutions.xml
specific_focus.xml thank_you.xml titlepage.xml tools.xml welcome.xml you_get_the_idea.xml /slides/sensitive/code Cipher.php MyConnect.php
SharedKeys.php shared_keys.php show.php

From: Date: Sun, 04 May 2003 05:48:17 +0000
Subject: cvs: presentations / sensitive.xml /slides/sensitive advantages.xml broad_vulnerabilities.xml credits.xml crypto_hashes.xml
data_poisoning_and_decoys.xml drawbacks.xml example_code.xml example_code_2.xml example_code_3.xml followup.xml identity_crisis.xml introduction.xml
key_exchange_distro.xml lossy_storage.xml mysql.xml php.xml private_key_cryptosystems.xml private_key_encryption.xml public_key_cryptosystems.xml
public_key_encryption.xml quantization.xml questions.xml reputation_poisoning.xml risks.xml sensitive_data.xml setup.xml solutions.xml
specific_focus.xml thank_you.xml titlepage.xml tools.xml welcome.xml you_get_the_idea.xml /slides/sensitive/code Cipher.php MyConnect.php
SharedKeys.php shared_keys.php show.php
Groups: php.pres 
Request: Send a blank email to pres+get-685@lists.php.net to get a copy of this message
zak Sun May 4 01:48:17 2003 EDT Added files: /presentations sensitive.xml /presentations/slides/sensitive advantages.xml broad_vulnerabilities.xml credits.xml crypto_hashes.xml data_poisoning_and_decoys.xml drawbacks.xml example_code.xml example_code_2.xml example_code_3.xml followup.xml identity_crisis.xml introduction.xml key_exchange_distro.xml lossy_storage.xml mysql.xml php.xml private_key_cryptosystems.xml private_key_encryption.xml public_key_cryptosystems.xml public_key_encryption.xml quantization.xml questions.xml reputation_poisoning.xml risks.xml sensitive_data.xml setup.xml solutions.xml specific_focus.xml thank_you.xml titlepage.xml tools.xml welcome.xml you_get_the_idea.xml /presentations/slides/sensitive/code Cipher.php MyConnect.php SharedKeys.php shared_keys.php show.php Log: Protecting sensitive data presentation from PQ PHP Conference

Index: presentations/sensitive.xml +++ presentations/sensitive.xml <presentation template="php" navmode="html" backgroundimage="slides/intro/background.png" backgroundrepeat="1" backgroundfixed="1" > <topic>PHP</topic> <title>Protecting Sensitive Data</title> <subtitle>with MySQL and PHP</subtitle> <event>Conférence PHP Québec</event> <location>Montréal</location> <date>March 20, 2003</date> <speaker>Zak Greant</speaker> <email>zak@mysql.com</email> <slide>slides/sensitive/titlepage.xml</slide> <slide>slides/sensitive/setup.xml</slide> <slide>slides/sensitive/followup.xml</slide> <slide>slides/sensitive/credits.xml</slide> <slide>slides/sensitive/thank_you.xml</slide> <slide>slides/sensitive/introduction.xml</slide> <slide>slides/sensitive/sensitive_data.xml</slide> <slide>slides/sensitive/identity_crisis.xml</slide> <slide>slides/sensitive/reputation_poisoning.xml</slide> <slide>slides/sensitive/you_get_the_idea.xml</slide> <slide>slides/sensitive/risks.xml</slide> <slide>slides/sensitive/broad_vulnerabilities.xml</slide> <slide>slides/sensitive/solutions.xml</slide> <slide>slides/sensitive/specific_focus.xml</slide> <slide>slides/sensitive/drawbacks.xml</slide> <slide>slides/sensitive/advantages.xml</slide> <slide>slides/sensitive/tools.xml</slide> <slide>slides/sensitive/quantization.xml</slide> <slide>slides/sensitive/data_poisoning_and_decoys.xml</slide> <slide>slides/sensitive/crypto_hashes.xml</slide> <slide>slides/sensitive/public_key_encryption.xml</slide> <slide>slides/sensitive/private_key_encryption.xml</slide> <slide>slides/sensitive/key_exchange_distro.xml</slide> <!-- ECB: Electronic Codebook - crypt blocks separately - easiest to crack CBC: Cipher Block Chaining - each block XOR'd with previous clear block before being crypted CFB: Cipher Feedback - block XOR'd with previous crypted block OFB: Output Feedback - block XOR'd with other data (not clear or crypted block) --> <slide>slides/sensitive/mysql.xml</slide> <slide>slides/sensitive/php.xml</slide> <slide>slides/sensitive/example_code.xml</slide> <slide>slides/sensitive/example_code_2.xml</slide> <slide>slides/sensitive/example_code_3.xml</slide> <slide>slides/sensitive/questions.xml</slide> </presentation> Index: presentations/slides/sensitive/advantages.xml +++ presentations/slides/sensitive/advantages.xml <slide title="Advantages"> <list title="Advantages"> <bullet>Data is much less vulnerable even if leaked</bullet> <bullet>Reduced likelihood of problems with failures in policy</bullet> <bullet>Moderate combinations of AC restrictions and data encryption/manipulation require much less effort than extensive access control schemes and offer much greater security</bullet> <bullet>Reduced risk</bullet> </list> </slide> Index: presentations/slides/sensitive/broad_vulnerabilities.xml +++ presentations/slides/sensitive/broad_vulnerabilities.xml <slide title="Broad Vulnerabilities"> <list title="Broad Vulnerabilities"> <bullet>Human - trusted user abuse, lack of vigilance, uneducated users (joe, PHB syndrome)</bullet> <bullet>Network - virtual/physical compromise</bullet> <bullet>Server - virtual/physical access</bullet> <bullet>Software - permissions escalation, software interactions, side effects</bullet> <bullet>Storage - disk, hardcopy</bullet> <bullet>Consumption - data consumer disclosure, transfer to insecure area, poor data management...</bullet> </list> </slide> Index: presentations/slides/sensitive/credits.xml +++ presentations/slides/sensitive/credits.xml <slide title="Credits"> <list title="Credits"> <bullet>*Peter Wayner*</bullet> <bullet>Translucent Databases</bullet> <bullet>*A. Menezes, P. van Oorschot, S. Vanstone*</bullet> <bullet>CRC Press</bullet> <bullet>Handbook of Applied Cryptography</bullet> <bullet>*PHP Development Team*</bullet> </list> </slide> Index: presentations/slides/sensitive/crypto_hashes.xml +++ presentations/slides/sensitive/crypto_hashes.xml <slide title="Crypto Hashes"> <list title="Crypto Hashes"> <bullet>Algorithms that output a unique 'fingerprint' for a given input of data (MDx, SHA1)</bullet> <bullet>Input data may be of almost any length</bullet> <bullet>No key is required - only data is needed as input (Though an IV can be used in some cases (! PHP))</bullet> <bullet>Generated "fingerprint" is of a fixed length</bullet> <bullet>Deterministic</bullet> <bullet>Considered nigh-impossible to reconstruct the input data given the output data</bullet> <bullet>Also called one-way functions, message digests, signatures and hashes</bullet> </list> <list title="Examples"> <bullet>Unix, MySQL, htpasswd, ... password systems</bullet> <bullet>Hash user credentials together with preference information</bullet> <bullet>i.e. md5($user_name, $password, $mark_on_test)</bullet> <bullet>Data is not reversible - just comparable</bullet> </list> </slide> Index: presentations/slides/sensitive/data_poisoning_and_decoys.xml +++ presentations/slides/sensitive/data_poisoning_and_decoys.xml <slide title="Data Poisoning, Bait and Decoys"> <list title="Data Poisoning, Bait and Decoys"> <bullet>Poisoned data makes compromise of the real data more expensive.</bullet> <bullet>Bait is false data whose usage can be tracked, allowing administrators to detect and "watch" abusers.</bullet> <bullet>Decoy data disguises real information</bullet> </list> <list title="Examples"> <bullet>Artificial user data that includes genuine contact information that is monitored. (good for employee and paper leaks)</bullet> <bullet>Artificial user data that triggers warning systems if accessed.</bullet> <bullet>Disguise the data entry requested by a user by mixing it with non-requested data.</bullet> <bullet>Generate additional entries in systems where the cost of compromise is relatively low. (Same data, modify keys)</bullet> </list> </slide> Index: presentations/slides/sensitive/drawbacks.xml +++ presentations/slides/sensitive/drawbacks.xml <slide title="Drawbacks"> <list title="Drawbacks" effect="slide"> <bullet>Not everything is wonderful about these techniques</bullet> <bullet>The data is more difficult to manipulate and process</bullet> <bullet>Data can be lost forever</bullet> <bullet>Users may find that the application is less convenient to use</bullet> <bullet>Additional resources may be required to support the application</bullet> <bullet>The application may be harder to debug</bullet> </list> </slide> Index: presentations/slides/sensitive/example_code.xml +++ presentations/slides/sensitive/example_code.xml <slide title="Example Code"> <list title="Example Code"> <bullet>Ensure that all users are made aware of a message with roughly equal opportunity</bullet> <bullet>User enters a message intended for n people to read</bullet> <bullet>User enters a list of receipts and a message</bullet> <bullet>Application generates passphrase and a list of shared keys</bullet> <bullet>Message is encrypted with the passphrase</bullet> <bullet>Keys are distributed to users</bullet> <bullet>Passphrase and keys are destroyed</bullet> </list> <example title="Code" filename="code/shared_keys.php" result="0" fontsize="1em" /> </slide> Index: presentations/slides/sensitive/example_code_2.xml +++ presentations/slides/sensitive/example_code_2.xml <slide title="More Example Code"> <example title="More Example Code" filename="code/SharedKeys.php" fontsize="1em" /> <example title="Output" filename="code/show.php" fontsize="1em" hide="1" result="0" /> </slide> Index: presentations/slides/sensitive/example_code_3.xml +++ presentations/slides/sensitive/example_code_3.xml <slide title="Yet More Example Code"> <example title="Yet More Example Code" filename="code/Cipher.php" fontsize="1em" /> </slide> Index: presentations/slides/sensitive/followup.xml +++ presentations/slides/sensitive/followup.xml <slide title="Feeling Nervous?"> <list title="Feeling Nervous Now?" effect="slide"> <bullet>Good!</bullet> <bullet>Sensitive data is *never* safe!</bullet> </list> <list title="The CSI 2002 Computer Crime and Security Survey" effect="slide"> <bullet>Surveyed ~500 large companies (generally million to billion dollar income range)</bullet> <bullet>90% reported security breaches</bullet> <bullet>80% acknowledged financial losses</bullet> <bullet>Most frequent point of attack: 74%%% Internet / 33%%% Intranet</bullet> <bullet>34% reported the intrusion to law enforcement</bullet> <bullet>12% reported theft of transaction information</bullet> </list> </slide> Index: presentations/slides/sensitive/identity_crisis.xml +++ presentations/slides/sensitive/identity_crisis.xml <slide title="Identity Crisis"> <list title="Identity Crisis" effect="slide"> <bullet>Personal data is used daily to facilitate many activities.</bullet> <bullet>Monetary exchanges</bullet> <bullet>Junk mail delivery</bullet> <bullet>Background and credit checks</bullet> </list> <list title="Credentials" effect="slide"> <bullet>Credentials derived from personal data are often used as the primary proof of identity.</bullet> <bullet>Identity information is used to automate consent.</bullet> <bullet>Theft of identity information becomes theft of identity and consent.</bullet> <bullet>This ties to many, many issues. Competitive advantage, safety, privacy, ...</bullet> </list> </slide> Index: presentations/slides/sensitive/introduction.xml +++ presentations/slides/sensitive/introduction.xml <slide title="Overview"> <list title="Overview/Topics" effect="slide"> <bullet>One hour rapid overview</bullet> <bullet>What sensitive data is</bullet> <bullet>The risks associated with managing sensitive data</bullet> <bullet>Common methods to protect sensitive data</bullet> <bullet>Methods to protect sensitive data that integrate the protections with the data itself</bullet> <bullet>Basic tools for implementing the embedded protections</bullet> <bullet>Usage notes for each of the tools</bullet> <bullet>Sample code</bullet> </list> </slide> Index: presentations/slides/sensitive/key_exchange_distro.xml +++ presentations/slides/sensitive/key_exchange_distro.xml <slide title="Key Exchange Schemes"> <list title="Key Exchange Schemes"> <bullet>Allow keys to be shared in ways that reduce the possibility of compromise.</bullet> <bullet>Public/Private key exchanges that allow users to exchange public keys that are used to generate a shared private key (Diffie/Hellman)</bullet> <bullet>Distributed private key exchanges (see code)</bullet> </list> </slide> Index: presentations/slides/sensitive/lossy_storage.xml +++ presentations/slides/sensitive/lossy_storage.xml <slide title="Lossy Storage"> <list title="Lossy Storage"> <bullet></bullet> </list> </slide> Index: presentations/slides/sensitive/mysql.xml +++ presentations/slides/sensitive/mysql.xml <slide title="MySQL"> <list title="MySQL"> <bullet>SHA1</bullet> <bullet>MD5</bullet> <bullet>PASSWORD (caveat)</bullet> <bullet>ENCRYPT (UNIX crypt)</bullet> <bullet>ENCODE/DECODE (trivial secrets only)</bullet> <bullet>AES_ENCRYPT/DECRYPT (coming soon)</bullet> <bullet>DES_ENCRYPT/DECRYPT (coming soon)</bullet> <bullet>SSL Support (coming soon)</bullet> <bullet>UDFs</bullet> <bullet>Watch out for logging!</bullet> </list> </slide> Index: presentations/slides/sensitive/php.xml +++ presentations/slides/sensitive/php.xml <slide title="PHP"> <list title="PHP"> <bullet>MCRYPT (Access to private/symmetric ciphers)</bullet> <bullet>MHASH (Access to crypto hash algorithms)</bullet> <bullet>OpenSSL (public/asymmetric ciphers (RSA/DSA))</bullet> <bullet>BCMath and GMP (Large integer math)</bullet> <bullet>Crack (Brute force password challenges)</bullet> <bullet>General (String (md5, sha1), Regex, Array, Pack/Unpack, ...)</bullet> </list> </slide> Index: presentations/slides/sensitive/private_key_cryptosystems.xml +++ presentations/slides/sensitive/private_key_cryptosystems.xml <slide title="Private Key Cryptosystems"> <list title="Private Key Cryptosystems"> <bullet></bullet> </list> </slide> Index: presentations/slides/sensitive/private_key_encryption.xml +++ presentations/slides/sensitive/private_key_encryption.xml <slide title="Private Key Encryption"> <list title="Private Key Encryption"> <bullet>AES, 3DES and Blowfish are some of the most common symmetric ciphers</bullet> <bullet>Uses a single private key for encryption and decryption</bullet> <bullet>Slower than crypto hashes</bullet> <bullet>Most private key ciphers are much faster than most public key ciphers</bullet> <bullet>Also tremendously useful for protecting data and </bullet> <bullet>Relatively easy to use</bullet> </list> <list title="Examples"> <bullet>Examples in the code up ahead</bullet> </list> </slide> Index: presentations/slides/sensitive/public_key_cryptosystems.xml +++ presentations/slides/sensitive/public_key_cryptosystems.xml <slide title="Public Key Cryptosystems"> <list title="Public Key Cryptosystems"> <bullet></bullet> </list> </slide> Index: presentations/slides/sensitive/public_key_encryption.xml +++ presentations/slides/sensitive/public_key_encryption.xml <slide title="Public Key Encryption"> <list title="Public Key Encryption"> <bullet>RSA/DSA are the most common asmmetric ciphers (used in SSH and OpenSSL)</bullet> <bullet>Uses a pair of keys for encryption and decryption</bullet> <bullet>Encryption is accomplished with a public key</bullet> <bullet>Decryption can only be done with a private key</bullet> <bullet>Much slower than crypto hashes</bullet> <bullet>Still slower than most private (symmetric) key ciphers</bullet> <bullet>Tremendously useful for protecting data and </bullet> <bullet>Relatively easy to use</bullet> </list> <list title="Examples"> <bullet>Encrypting a message digest of a clear-text document</bullet> <bullet>Securing data entered into a database on an insecure server</bullet> </list> </slide> Index: presentations/slides/sensitive/quantization.xml +++ presentations/slides/sensitive/quantization.xml <slide title="Quantization"> <list title="Quantization"> <bullet>Mapping a data set onto a smaller data set</bullet> <bullet>Reducing the amount of sensitive data disclosed</bullet> <bullet>...while still retaining useful information.</bullet> </list> <list title="Examples" effect="slide"> <bullet>Lossy compression or scaling of images or signals to allow for broader distribution</bullet> <bullet>Discarding postal code or IP address information to prevent easy identification of individuals</bullet> <bullet>Aggregating feedback from all school districts to reduce politicking</bullet> </list> </slide> Index: presentations/slides/sensitive/questions.xml +++ presentations/slides/sensitive/questions.xml <slide title="Questions?"> <list title="Questions?"> <bullet>...</bullet> </list> </slide> Index: presentations/slides/sensitive/reputation_poisoning.xml +++ presentations/slides/sensitive/reputation_poisoning.xml <slide title="Reputation Poisoning"> <list title="Reputation Poisoning" effect="slide"> <bullet>Someone pretends to be you</bullet> <bullet>Financial losses (press release fraud)</bullet> <bullet>Personal danger (cyber stalking)</bullet> <bullet>Damage to implicit credentials</bullet> <bullet>...or someone abuses embarrassing or compromising information about you</bullet> <bullet>Medical records</bullet> <bullet>Extra-curricular activities</bullet> <bullet>Schedules/locations</bullet> </list> </slide> Index: presentations/slides/sensitive/risks.xml +++ presentations/slides/sensitive/risks.xml <slide title="Risks/Costs"> <list title="Risks/Costs of Managing Secure Data" effect="slide"> <bullet>Legal liability (responsiblity for data, governing bodies, health boards, etc.)</bullet> <bullet>Maintenance hassle (storage, policies, audits)</bullet> <bullet>Sensitive data is attractive to thieves</bullet> <bullet>Sensitive data storage compromises the freedom of others</bullet> </list> </slide> Index: presentations/slides/sensitive/sensitive_data.xml +++ presentations/slides/sensitive/sensitive_data.xml <slide title="What is Sensitive Data?"> <list title="What is Sensitive Data?" effect="slide"> <bullet>A broad definition is: "Data that requires constraints on how it is consumed."</bullet> <bullet>- with mustard ("Do you have any Grey Poupon?")</bullet> <bullet>- by whom</bullet> <bullet>- when</bullet> <bullet>- how</bullet> <bullet>This is probably too general!</bullet> <bullet>Here are some major sensitive data issues</bullet> </list> </slide> Index: presentations/slides/sensitive/setup.xml +++ presentations/slides/sensitive/setup.xml <slide title="Setup"> <list title="Setup" effect="slide"> <bullet>[Dazzling Introduction]</bullet> <bullet>[Cue Laugh Track at Intervals]</bullet> <bullet>[Insert Footage of Screaming Crowd]</bullet> <bullet>[Proceed Calmly to Next Slide :) ]</bullet> </list> </slide> Index: presentations/slides/sensitive/solutions.xml +++ presentations/slides/sensitive/solutions.xml <slide title="Solutions"> <list title="Solutions"> <bullet>Combine methods!</bullet> <bullet>Restrict access</bullet> <bullet>Encrypt communications</bullet> <bullet>Maintenance (audits, security patches, training, incremental application improvements)</bullet> <bullet>Implement data management/consumption protocols</bullet> <bullet>Educate data consumers</bullet> <bullet>Encrypt the data</bullet> <bullet>Render data unreadable (but still useable)</bullet> <bullet>Discard data when not needed</bullet> <bullet>Distribute information</bullet> </list> </slide> Index: presentations/slides/sensitive/specific_focus.xml +++ presentations/slides/sensitive/specific_focus.xml <slide title="Specific Focus"> <list title="Specific Focus" effect="slide"> <bullet>This session focuses on protecting the data with cryptographic methods rather than access controls</bullet> <bullet>Restricting application and data access is critical, but...</bullet> <bullet>many developers and software tools already deal with access control issues fairly well (Apache, Linux, MySQL, PHP, ...)</bullet> <bullet>Data is vulnerable at so many points that it takes massive effort to create a very low risk environment for it if only relying on access control and policies</bullet> </list> </slide> Index: presentations/slides/sensitive/thank_you.xml +++ presentations/slides/sensitive/thank_you.xml <slide title="Thank You"> <list title="Thank You"> <bullet>Conference Organizers and Sponsors</bullet> <bullet>Damien Seguy</bullet> <bullet>Calgary PHP User Group</bullet> <bullet>Derick Rethans</bullet> <bullet>... and thanks for attending!</bullet> </list> </slide> Index: presentations/slides/sensitive/titlepage.xml +++ presentations/slides/sensitive/titlepage.xml <slide template="titlepage" fontsize="6em"> <title>Welcome!</title> </slide> Index: presentations/slides/sensitive/tools.xml +++ presentations/slides/sensitive/tools.xml <slide title="Tools"> <list title="Tools" effect="slide"> <bullet>Quantization</bullet> <bullet>Data Poisoning / Decoys</bullet> <bullet>Crypto Hashes</bullet> <bullet>Public/Private Key Encryption (RSA, DSA / AES Rijndael, Blowfish. 3DES)</bullet> <bullet>Public/Private Key Crypto Schemes (Diffie/Hellman / Shared Key Segments)</bullet> </list> </slide> Index: presentations/slides/sensitive/welcome.xml +++ presentations/slides/sensitive/welcome.xml <slide title="Welcome"> <list title="Welcome"> <bullet></bullet> </list> </slide> Index: presentations/slides/sensitive/you_get_the_idea.xml +++ presentations/slides/sensitive/you_get_the_idea.xml <slide title="You Get The Idea"> <list title="You Get The Idea" effect="slide"> <bullet>Disclosure of sensitive information is bad...</bullet> <bullet>don't disclose sensitive data.</bullet> </list> </slide> Index: presentations/slides/sensitive/code/Cipher.php +++ presentations/slides/sensitive/code/Cipher.php <?php class Cipher{ var $cipher, $data, $iv, $key, $mode, $td; function Cipher( $key, $cipher=MCRYPT_RIJNDAEL_256, $mode=MCRYPT_MODE_CFB, $cipher_dir='', $mode_dir='' ){ $this->key = $key; $this->cipher = $cipher; $this->mode = $mode; $this->cipher_dir = $cipher_dir; $this->mode_dir = $mode_dir; # Open the modules to support the chosen cipher and mode $this->td = mcrypt_module_open( $this->cipher, $this->cipher_dir, $this->mode, $this->mode_dir ); # Create an initialization vector for the open modules from a random source $this->iv = mcrypt_create_iv( mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM ); } function init(){ # Initialize the buffers required for encryption/decryption mcrypt_generic_init ($this->td, $this->key, $this->iv); } function Encrypt( $data ){ $this->init(); return mcrypt_generic( $this->td, $data ); } function Decrypt( $encrypted_data ){ $this->init(); return mdecrypt_generic( $this->td, $encrypted_data ); } function Cleanup(){ mcrypt_generic_deinit( $this->td ); mcrypt_module_close( $this->td ); } } /* Cipher Test $cipher = new Cipher('boo'); $enc_data = $cipher->Encrypt("J. Random Data"); echo "Encrypted data: ", $enc_data, "\n"; $dec_data = $cipher->Decrypt($enc_data); echo "Decrypted data: ", $dec_data, "\n"; $cipher->Cleanup(); */ ?> Index: presentations/slides/sensitive/code/MyConnect.php +++ presentations/slides/sensitive/code/MyConnect.php <?php $mysql = mysql_connect( 'localhost', 'MrSensitive', '' ); mysql_select_db( 'scratch' ); ?> Index: presentations/slides/sensitive/code/SharedKeys.php +++ presentations/slides/sensitive/code/SharedKeys.php <?php class SharedKeys{ function Create($secret, $people, $show = false){ $step = 1; # Truncate/Pad $secret to 16 characters $secret = sprintf( "%-' 16s", substr($secret, 0, 16) ); $keys = array(); # Generate an array of random keys if( $show ){ echo "\nGenerating Random Keys\n"; } for( $n = 1; $n < $people; ++$n ){ # Create the binary string from an md5 hash # Use mt_rand() to seed the hash $keys[] = pack("H*", md5(mt_rand())); if( $show ){ echo "Generating Random Key: ", $keys[count($keys) - 1],"\n"; } } # Generate the final key by XORing the # previous keys together with the secret if( $show ){ echo "\nDeconstructing Original Key\n", "Deconstructing Original Key (Step 1): ", $secret, "\n"; } $out = $secret; foreach( $keys as $key ){ $out ^= $key; if( $show ){ echo "Deconstructing Original Key (Step ", ++$step, "): " , $out,"\n"; } } array_push($keys, $out); # Don't always allow $out to come last in the array sort($keys); return $keys; } function Assemble($keys, $show = false){ $step = 0; $out = array_pop($keys); if( $show ){ echo "\nReconstructing Original Key\n", "Reconstructing Original Key (Step ", ++$step, "): " , $out,"\n"; } foreach($keys as $key){ $out ^= $key; if( $show ){ echo "Reconstructing Original Key (Step ", ++$step, "): ", $out,"\n"; } } return $out; } } ?> Index: presentations/slides/sensitive/code/shared_keys.php +++ presentations/slides/sensitive/code/shared_keys.php <?php include 'MyConnect.php'; include 'Cipher.php'; include 'SharedKeys.php'; ob_start(); mysql_query( "DROP TABLE IF EXISTS equal_opps" ); $query = <<<EOS CREATE TABLE equal_opps ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, sender VARCHAR(64) NOT NULL, recipients TEXT NOT NULL, message BLOB NOT NULL, PRIMARY KEY (id) ) EOS; mysql_query($query) or die("Could not execute query '$query' : " . mysql_error()); $message = <<<EOS Sam Poblano from NetTech books is looking for an author for a book titled 'MySQL and PHP for Southern Germans'. The job details are ... EOS; $key = "Usually Random!"; $cipher = new Cipher($key); $recipients = array( 'georg@php.net', 'hartmut@php.net', 'sandro@zzoss.com' ); $query = sprintf( "INSERT equal_opps (sender, recipients, message) VALUES ('%s', '%s', '%s')", 'zak@mysql.com', join( ',', $recipients ), mysql_escape_string( $cipher->Encrypt($message) ) ); mysql_query( $query ) or die("Could not execute query '$query'"); $query = "SELECT * FROM equal_opps"; echo $query, "\n", str_repeat('-', strlen($query)), "\n"; $qh = mysql_query( $query ) or die("Could not execute query '$query'"); foreach( mysql_fetch_assoc( $qh ) as $k => $v ){ printf( "%-12s: %s\n", $k, $v ); } echo "\n\n", $msg = "Keys Generated for Recipients", "\n", str_repeat('-', strlen($msg)), "\n"; $keys = SharedKeys::Create( $key, count($recipients) ); foreach($keys as $index => $key){ printf( "%-18s: %s\n", $recipients[$index], $key ); } $msg = "Re-assembling Keys using 'SharedKeys::Assemble( array(\"". join("\",\n \"", $keys) ."\") );'"; echo "\n\n", $msg, "\n"; echo "Reassembled Key is: ", SharedKeys::Assemble( $keys ); $qh = mysql_query( "DROP TABLE equal_opps"); $cipher->Cleanup(); $out = ob_get_contents(); ob_end_clean(); echo nl2br($out); ?> Index: presentations/slides/sensitive/code/show.php +++ presentations/slides/sensitive/code/show.php <?php include 'Cipher.php'; include 'SharedKeys.php'; ob_start(); $keys = SharedKeys::Create('Conférence PHP Québec', 3, true); SharedKeys::Assemble($keys, true); $out = ob_get_contents(); ob_end_clean(); echo nl2br($out); ?>
« previous php.pres (#685) next »