Skip to content

Instantly share code, notes, and snippets.

View paragonie-scott's full-sized avatar

Scott paragonie-scott

View GitHub Profile
@paragonie-scott
paragonie-scott / rsa-mult.php
Created May 24, 2017 18:11
RSA Encryption Homomorphism
<?php
/* Key generation */
$keypair = openssl_pkey_new([
"digest_alg" => "sha512",
"private_key_type" => OPENSSL_KEYTYPE_RSA,
'private_key_bits' => 1024
]);
$secret = null;
if (!openssl_pkey_export($keypair, $secret)) {
@paragonie-scott
paragonie-scott / Trololol.php
Last active May 4, 2017 11:38
The Trolololol Design Pattern
<?php
declare(strict_types=1);
class Foo
{
/**
* Even if the code that calls isn't using strict_types, it will still TypeError
* if the wrong type is passed.
*/
public function bar($param, $secondParam)
@paragonie-scott
paragonie-scott / 32bitadd.php
Last active March 26, 2017 14:06
Add two integers modulo 2^32 on a 32-bit system
<?php
/**
* Since integers in 32-bit PHP 5.x are signed, exclusively, this only goes up to 2147483647
*/
function add_32bit($intA, $intB)
{
if (!is_int($intA) || !is_int($intB)) {
return false;
}
@paragonie-scott
paragonie-scott / crypto-fails.md
Last active March 26, 2017 14:04
Don't use the OWASP PHP Crypto Library
DCF93A0B883972EC0E19989AC5A2CE310E1D37717E8D9571BB7623731866E61EF75A2E27898B057F9891C2E27A639C3F29B60814581CD3B2CA3986D2683705577D45C2E7E52DC81C7A171876E5CEA74B1448BFDFAF18828EFD2519F14E45E3826634AF1949E5B535CC829A483B8A76223E5D490A257F05BDFF16F2FB22C583AB
@paragonie-scott
paragonie-scott / auto-update.md
Last active March 7, 2017 22:32
PHP Auto Update Quick Start

This is a more "how" to the "what": https://paragonie.com/blog/2016/10/guide-automatic-security-updates-for-php-developers

HTTPS + Digital Signatures

This is a minimalistic secure auto update approach.

  1. Make an API call to a server to get the latest version information. This should be delivered over HTTPS, possibly with HPKP.
  2. If an update is available, the client software should download the update file.
  3. An Ed25519 signature should be available, either as a separate API call or as an HTTP header with the downloaded file.
  4. Verify that the signature is valid for one of the hard-coded Ed25519 public keys.
@paragonie-scott
paragonie-scott / GOALS and OVERVIEW.md
Created October 28, 2016 19:53
Android App Design Notes

I want to build an app that stops harassment and other forms of unsolicited bullshit.

  • I don't want any money for it.
  • I don't want to serve ads.
  • I just want it to perform one simple task and get out of the user's way.

Goal

A mobile app (Android and/or iOS) that only allows trusted callers to go through.

@paragonie-scott
paragonie-scott / sodium-compat-aes-gcm.php
Created February 11, 2017 22:58
Is libsodium's AES-256-GCM compatible with OpenSSL?
<?php
$message = random_bytes(1024);
$key = random_bytes(32);
$nonce = random_bytes(12);
$tag = '';
$aad = random_bytes(random_int(1, 127));
$cipher = openssl_encrypt($message, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $nonce, $tag, $aad, 16);
@paragonie-scott
paragonie-scott / spotilocal.priv.pem
Created January 23, 2017 18:28 — forked from venoms/spotilocal.priv.pem
spotilocal.com private key
Private-Key: (4096 bit)
modulus:
00:f0:71:c0:a3:bb:5f:cc:63:f9:55:33:ed:a3:d0:
78:ae:fc:ce:2e:f2:36:d1:e5:cb:64:d7:55:37:8b:
7b:a0:60:5e:31:c3:2a:b3:6e:1f:33:89:0a:ba:f5:
ab:48:0e:0d:f7:39:31:06:18:3d:66:d8:b9:0e:ba:
bb:08:46:78:3a:51:4b:61:d7:0a:9d:46:54:72:94:
71:b6:a7:82:58:5b:6d:96:11:ae:f7:d2:19:f2:b1:
20:e7:00:72:df:15:ac:1f:1e:1e:34:04:fc:0b:63:
b5:03:ff:47:34:27:c7:54:4e:ee:d7:c7:77:cd:1d:

Via Twitter

Authors consider SQLi as main attack vector. Hashed token mitigate r/o SQLi, encrypted mitigate r/w SQLi

That actually doesn't buy you anything. Consider the following table schema:

CREATE TABLE reset_tokens (
    tokenid BIGSERIAL PRIMARY KEY,
 selector TEXT,