48 Commits

Author SHA1 Message Date
Oliver Falk
44a6b9a099 Merge branch 'devel' into cipher_test 2022-02-18 14:19:02 +01:00
Oliver Falk
2163c60f5b Merge branch 'master' into cipher_test 2022-02-18 14:14:20 +01:00
Oliver Falk
0c68843849 Add test for the stats 2022-02-18 14:09:38 +01:00
Oliver Falk
92f495ebe0 Add stats about unconfirmed mail/openid + avatar count 2022-02-18 14:09:38 +01:00
Oliver Falk
39ff27984c Remove redundant all() before count() 2022-02-18 14:09:38 +01:00
Oliver Falk
f0a2d5aae4 Add a few more trusted URLs that we gathered from the logs 2022-02-18 14:09:10 +01:00
Oliver Falk
cc761467f5 Update gravatar check to be easier and less error prone 2022-02-18 14:09:10 +01:00
Oliver Falk
44e85365bc First preparations for Django >= 4.x 2022-02-18 14:09:09 +01:00
Oliver Falk
8c9b14ec0e Fix building of master, do not use Django >4 yet 2022-02-18 14:09:09 +01:00
Oliver Falk
88e6e5a80f Add Daniel Aleksandersen to the security page 2022-02-18 14:09:09 +01:00
Oliver Falk
aa3a7a2497 A few more sites known to use default param 2022-02-18 14:09:09 +01:00
Oliver Falk
9a5bdf9364 Enhance and fix tests to accomodate the changes related to CWE-601 2022-02-18 14:09:09 +01:00
Oliver Falk
01f0f29859 String search returns > 0 if found... 2022-02-18 14:09:09 +01:00
Oliver Falk
a80d704a59 Enhance the list. It's possible some non-ssl sites still use gravatar without https and some sites use secure.gravatar.com 2022-02-18 14:09:09 +01:00
Oliver Falk
63a4737717 Increase version 2022-02-18 14:09:09 +01:00
Oliver Falk
5ec186e039 Fix CWE-601 - Open URL redirection
- Only a few URLs are allowed now and this _will_ break some implementations
- Print information in the log about which URL was kicked
2022-02-18 14:09:08 +01:00
Oliver Falk
358b3cec8c Redesigned profile page 2022-02-18 14:09:08 +01:00
Oliver Falk
bc3ce39a19 Do not use 404 in case no default is set - we need to redir to the default Gravatar 2022-02-18 14:09:08 +01:00
Oliver Falk
70ffb10d51 Additional logging of gravatar fetches and ensure we don't send d=None, if default hasn't been set; Reformat with black 2022-02-18 14:08:47 +01:00
Oliver Falk
3797018139 We're aware there are some complext functions, it's a complex topic. 2022-02-18 14:08:47 +01:00
Oliver Falk
c6601b60c0 Update ignored files (for coverage report) 2022-02-18 14:08:47 +01:00
Oliver Falk
26ae405899 v1.5 - massive code update 2022-02-18 14:08:47 +01:00
Oliver Falk
a40f262ceb More testing of the export 2022-02-18 14:08:47 +01:00
Oliver Falk
817984a43b Use SCHEMAROOT from config and reformat with black 2022-02-18 14:08:46 +01:00
Oliver Falk
84a265eca5 Central place for the schema root 2022-02-18 14:08:46 +01:00
Oliver Falk
f53ad22524 Wire up the export functionality in the menu 2022-02-18 14:08:46 +01:00
Oliver Falk
abd9ccff7c Add export functionality and reformat with black 2022-02-18 14:08:46 +01:00
Oliver Falk
1b70908f58 Test export page - without any functionality and reformat with black 2022-02-18 14:08:46 +01:00
Oliver Falk
0fe50c6317 Need to ignore E402 - we check this with pylint 2022-02-18 14:08:46 +01:00
Oliver Falk
af98487c1d Some safety measures to avoid breaking old/new export and reformat with black 2022-02-18 14:08:46 +01:00
Oliver Falk
ccd72d5422 Fix trailing whitespace and reformat with black 2022-02-18 14:08:46 +01:00
Oliver Falk
86bb77eb9d Ingore W503 2022-02-18 14:08:45 +01:00
Oliver Falk
0f84845ca9 Make sure we list the email instead of the dict and 2022-02-18 14:08:45 +01:00
Oliver Falk
d9c33f7ee3 Ignore this module, as it's hardly used and very difficult to test 2022-02-18 14:08:45 +01:00
Oliver Falk
c04e5ad266 Clean up with black 2022-02-18 14:08:45 +01:00
Oliver Falk
4cdb61724f Clean up with black 2022-02-18 14:08:45 +01:00
Oliver Falk
507e623962 Clean up with black 2022-02-18 14:08:45 +01:00
Oliver Falk
85ccf0f7be Clean up with black 2022-02-18 14:08:45 +01:00
Oliver Falk
d2e28fe809 Add flake and pre commit config 2022-02-18 14:08:45 +01:00
Oliver Falk
6c6afd5152 Clean up with black 2022-02-18 14:08:44 +01:00
Oliver Falk
4db099156b Reuse username as email if it looks like a valid email address
* Automatically add it as UnconfirmedEmail and trigger confirmation mail
* Clean up views with black
2022-02-18 14:08:44 +01:00
Oliver Falk
870a2a2365 Add some padding at the end, so the logo is fully visible 2022-02-18 14:08:44 +01:00
Oliver Falk
3f01e0c3e1 Add Gandi logo - since sponsoring 2022-02-18 14:08:44 +01:00
Oliver Falk
03bf496117 Merge branch 'master' into cipher_test 2021-09-10 12:46:49 +02:00
Oliver Falk
a573985248 Merge branch 'devel' into cipher_test 2020-02-25 16:41:09 +01:00
Oliver Falk
c3214a9a2b Merge branch 'master' into cipher_test 2020-02-25 13:48:20 +01:00
Oliver Falk
29c8f17e06 Merge branch 'devel' into cipher_test 2020-02-25 13:45:01 +01:00
Oliver Falk
c864c2f115 Provide examples how to encode mail address with PHP, decrypt in python, using standard AES for use as local proxy for libravatar image requests 2019-10-01 14:28:16 +02:00
6 changed files with 220 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
The code in here should be able to help to build up some encrypting proxy.
If your app uses a lot of libravatar and therefore has to do a lot of DNS
lookups, change your app in such a way, that it encodes the mail address,
sends it over to the proxy, which will decrypt it, do the DNS lookup and
return the image binary.
No guarantee for this code. It's untested and just provided as example.

View File

@@ -0,0 +1,90 @@
<?php
/**
* Valid encryption methods AES-256-CFB
* Code kindly borrowed from:
* https://github.com/arajapandi/php-python-encrypt-decrypt
*
* $cypher = new MyCypher($iv);
* $php_encrypted = $cypher->encrypt('test');
* $php_decrypted = $cypher->decrypt($php_encrypted);
*/
class MyCypher {
private $key = 'asdfa923aksadsYahoasdw998sdsads';
private $iv = null;
private $method = "AES-256-CFB";
private $blocksize = 32;
private $padwith = '`';
/*
* construct for cypher class - get, set key and iv
*/
function __construct($iv, $key = null) {
if (is_string($key)) {
$this->key = $key;
}
$this->iv = $iv;
}
/*
* get hased key - if key is not set on init, then default key wil be used
*/
private function getKEY() {
if (empty($this->key)) {
die('Key not set!');
}
return substr(hash('sha256', $this->key), 0, 32);
}
/*
* get hashed IV value - if no IV values then it throw error
*/
private function getIV() {
if (empty($this->iv)) {
die('IV not set!');
}
return substr(hash('sha256', $this->iv), 0, 16);
}
/*
* Encrypt given string using AES encryption standard
*/
public function encrypt($secret) {
try {
$padded_secret = $secret . str_repeat($this->padwith, ($this->blocksize - strlen($secret) % $this->blocksize));
$encrypted_string = openssl_encrypt($padded_secret, $this->method, $this->getKEY(), OPENSSL_RAW_DATA, $this->getIV());
$encrypted_secret = base64_encode($encrypted_string);
return $encrypted_secret;
} catch (Exception $e) {
die('Error : ' . $e->getMessage());
}
}
/*
* Decrypt given string using AES standard
*/
public function decrypt($secret) {
try {
$decoded_secret = base64_decode($secret);
$decrypted_secret = openssl_decrypt($decoded_secret, $this->method, $this->getKEY(), OPENSSL_RAW_DATA, $this->getIV());
return rtrim($decrypted_secret, $this->padwith);
} catch (Exception $e) {
die('Error : ' . $e->getMessage());
}
}
}

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env python2
#encoding: UTF-8
# Code kindly borrowed from:
# https://github.com/arajapandi/php-python-encrypt-decrypt
# Python Class for AES encryption
"""
Example Usage
enc_str = cipher.encrypt('secret')
enc_str = cipher.decrypt(enc_str)
print(enc_str); #secret
"""
from Crypto.Cipher import AES
import base64
import hashlib
import sys
class MyCypher:
# Default Key for encryption
rawkey = 'asdfa923aksadsYahoasdw998sdsads'
method = AES.MODE_CFB
blocksize = 32 # 16, 32..etc
padwith = '`'.encode('utf-8') # padding value for string
#lambda function for padding
pad = lambda self, s: s + (self.blocksize - len(s) % self.blocksize) * self.padwith
"""
construct for cypher class - get, set key and iv
"""
def __init__(self, iv, key=''):
if(not key):
key = self.rawkey
self.key = key.encode('utf-8')
self.iv = iv.encode('utf-8')
"""
get hased key - if key is not set on init, then default key wil be used
"""
def getKEY(self):
if(not self.key):
sys.exit()
return hashlib.sha256(self.key).hexdigest()[:32]
"""
get hashed IV value - if no IV values then it throw error
"""
def getIV(self):
if(not self.iv):
sys.exit()
self.iv = self.iv
return hashlib.sha256(self.iv).hexdigest()[:16]
"""
Encrypt given string using AES encryption standard
"""
def encrypt(self, raw):
cipher = AES.new(self.getKEY(), self.method, self.getIV(), segment_size=128)
return base64.b64encode(cipher.encrypt(self.pad(raw)))
"""
Decrypt given string using AES standard
"""
def decrypt(self, encrypted):
encrypted = base64.b64decode(encrypted)
cipher = AES.new(self.getKEY(), self.method, self.getIV(), segment_size=128)
return cipher.decrypt(encrypted).rstrip(self.padwith)

32
encrypted_proxy/proxy.py Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import urllib.request
import sys
import os
from lib.MyCypher import MyCypher
import libravatar
# Both need to be the same as in your client code that encrypts the
# mail address
iv = 'asdf'
key = 'Hallo123'
#sys.stderr.buffer.write(b'%s' % bytes(os.environ.get("QUERY_STRING", "No Query String in url"), 'utf-8'))
cypher = MyCypher(iv = iv, key = key)
mail = cypher.decrypt(os.environ.get('QUERY_STRING').encode('utf-8')).decode('utf-8')
link = libravatar.libravatar_url(mail)
sys.stderr.buffer.write(b'%s' % bytes(link, 'utf-8'))
data = None
with urllib.request.urlopen(link) as f:
data = f.read()
for header in f.headers._headers:
if header[0] == 'Content-Type':
sys.stdout.buffer.write(b"%s: %s\n\n" % (bytes(header[0], 'utf-8'), bytes(header[1], 'utf-8')))
sys.stdout.flush()
break
sys.stdout.buffer.write(data)

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env python
from MyCypher import MyCypher
encstr = bytes('drEN/LqPBu1wJYHpN5eCjZXqVgvDEP3rZnXJt85Ma0k=', 'utf-8')
cypher = MyCypher(iv = str('asdf'))
print(cypher.decrypt(encstr))

View File

@@ -0,0 +1,8 @@
<?php
include 'lib/MyCypher.php';
$iv = 'asdf';
$key = 'Hallo123';
$cypher = new MyCypher($iv=$iv, $key=$key);
$php_encrypted = $cypher->encrypt('oliver@linux-kernel.at');
print($php_encrypted);