summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'app.py')
-rw-r--r--app.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/app.py b/app.py
index 4029b7f..bdb43f6 100644
--- a/app.py
+++ b/app.py
@@ -8,7 +8,7 @@ from wtforms import StringField, RadioField
from wtforms.validators import DataRequired, Length, ValidationError, InputRequired
from Crypto.Cipher import AES
-from aesgcmanalysis import xor, gmac, gcm_encrypt, nonce_reuse_recover_secrets, gf128_to_bytes, mac_truncation_recover_secrets, att_merge_jpg_bmp
+from aesgcmanalysis import xor, gmac, gcm_encrypt, nonce_reuse_recover_secrets, gf128_to_bytes, mac_truncation_recover_secrets, att_merge_jpg_bmp, att_merge_pdf_pdf
app = Flask(__name__)
@@ -144,11 +144,16 @@ def FileSizeLimit(max_bytes, magic_start=None, magic_end=None):
return file_length_check
class KeyCommitmentForm(FlaskForm):
- mode = RadioField('mode', choices=[('sample', 'sample'), ('custom', 'custom')], validators=[DataRequired()])
+ mode = RadioField('mode', choices=[('sample', 'sample'), ('custom', 'custom'),
+ ('sample-pdf', 'sample-pdf'), ('custom-pdf', 'custom-pdf')], validators=[DataRequired()])
jpeg = FileField('jpeg_file', validators=[FileAllowed(['jpg', 'jpeg']),
- RequiredIf('mode', 'custom'), FileSizeLimit(150000, b'\xff\xd8', b'\xff\xd9')])
+ RequiredIf('mode', 'custom'), FileSizeLimit(200000, b'\xff\xd8', b'\xff\xd9')])
bmp = FileField('bmp_file', validators=[FileAllowed(['bmp']),
RequiredIf('mode', 'custom'), FileSizeLimit(50000, b'\x42\x4d')])
+ pdf1 = FileField('pdf1_file', validators=[FileAllowed(['pdf']),
+ RequiredIf('mode', 'custom-pdf'), FileSizeLimit(200000)])
+ pdf2 = FileField('pdf2_file', validators=[FileAllowed(['pdf']),
+ RequiredIf('mode', 'custom-pdf'), FileSizeLimit(200000)])
@app.route('/key-commitment', methods=['GET', 'POST'])
def key_commitment():
@@ -160,17 +165,29 @@ def key_commitment():
if form.is_submitted():
if form.validate():
+ merge = None
if form.mode.data == 'sample':
+ # merge = att_merge_jpg_bmp
# jpeg_bytes = open('static/axolotl.jpg', 'rb').read()
# bmp_bytes = open('static/kitten.bmp', 'rb').read()
- return send_file('static/sample-polyglot.enc',
+ return send_file('static/jpg-bmp-polyglot.enc',
+ mimetype='application/octet-stream', as_attachment=True, download_name="polyglot.enc")
+ elif form.mode.data == 'custom':
+ merge = att_merge_jpg_bmp
+ first = form.jpeg.data.read()
+ second = form.bmp.data.read()
+ elif form.mode.data == 'sample-pdf':
+ # merge = att_merge_pdf_pdf
+ # first = open('static/bishop-sestina.pdf', 'rb').read()
+ # second = open('static/ashbery-sestina.pdf', 'rb').read()
+ return send_file('static/pdf-pdf-polyglot.enc',
mimetype='application/octet-stream', as_attachment=True, download_name="polyglot.enc")
else:
- jpeg_bytes = form.jpeg.data.read()
- bmp_bytes = form.bmp.data.read()
- c, mac = att_merge_jpg_bmp(jpeg_bytes, bmp_bytes, aad=b"")
- ct = c + mac
- f = io.BytesIO(ct)
+ merge = att_merge_pdf_pdf
+ first = form.pdf1.data.read()
+ second = form.pdf2.data.read()
+ c, mac = merge(first, second, aad=b"")
+ f = io.BytesIO(c + mac)
return send_file(f, mimetype='application/octet-stream', as_attachment=True, download_name="polyglot.enc")
return render_template('key-commitment.html', form=form, k1=k1, k2=k2, nonce=nonce, c=c)