diff --git a/.circleci/config.yml b/.circleci/config.yml index e8f14d92..006c3cc3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ jobs: steps: - checkout - run: sudo apt-get update - - run: sudo apt-get install -y ffmpeg texlive-latex-base texlive-latex-extra + - run: sudo apt-get install -y ffmpeg - run: name: Install Requirements command: | @@ -36,7 +36,7 @@ jobs: steps: - checkout - run: sudo apt-get update - - run: sudo apt-get install -y ffmpeg texlive-latex-base texlive-latex-extra + - run: sudo apt-get install -y ffmpeg - run: name: Install Requirements command: | @@ -56,7 +56,7 @@ jobs: steps: - checkout - run: sudo apt-get update - - run: sudo apt-get install -y ffmpeg texlive-latex-base texlive-latex-extra + - run: sudo apt-get install -y ffmpeg - run: name: Install Requirements command: | diff --git a/app/src/components/Apps.js b/app/src/components/Apps.js index 7b8b0f8d..adb9c280 100644 --- a/app/src/components/Apps.js +++ b/app/src/components/Apps.js @@ -129,7 +129,7 @@ class Decrypt extends React.Component { class OTP extends React.Component { render() { - let newPadURL = `http://${window.location.host}/api/otp/pdf`; + let newPadURL = `http://${window.location.host}/api/otp/html`; let cheatSheetURL = `${process.env.PUBLIC_URL}/one-time-pad-cheat-sheet.pdf`; return ( diff --git a/docker/api/Dockerfile b/docker/api/Dockerfile index 939b89ac..e1e4dd21 100644 --- a/docker/api/Dockerfile +++ b/docker/api/Dockerfile @@ -4,9 +4,8 @@ WORKDIR /opt/wrolpi # Update dependencies for the services install. RUN apt update -# ffmpeg for Videos and Latex for OTP PDF. osm2pgsql to import map files. -RUN apt-get install -y ffmpeg texlive-latex-base texlive-latex-extra -RUN pdflatex --version +# ffmpeg for Videos +RUN apt-get install -y ffmpeg RUN ffmpeg -version # Install WROLPi diff --git a/modules/otp/api.py b/modules/otp/api.py index 47cd4220..552e195c 100644 --- a/modules/otp/api.py +++ b/modules/otp/api.py @@ -1,7 +1,3 @@ -import random -from http import HTTPStatus -from string import ascii_letters - from sanic import response from sanic.request import Request from sanic_ext import validate @@ -35,13 +31,7 @@ async def post_decrypt_otp(_: Request, body: schema.DecryptOTPRequest): return response.json(data) -@bp.get('/pdf') -async def get_new_otp_pdf(_: Request): - random_name = ''.join(random.choice(ascii_letters) for _ in range(8)) - filename = f'one-time-pad-{random_name}.pdf' - headers = { - 'Content-type': 'application/pdf', - 'Content-Disposition': f'attachment;filename={filename}' - } - contents = lib.generate_pdf() - return response.raw(contents, HTTPStatus.OK, headers) +@bp.get('/html') +async def get_new_otp_html(_: Request): + body = lib.generate_html() + return response.html(body) diff --git a/modules/otp/lib.py b/modules/otp/lib.py index fc1ce393..7155af70 100644 --- a/modules/otp/lib.py +++ b/modules/otp/lib.py @@ -1,9 +1,8 @@ import secrets -import subprocess from functools import partial from typing import Dict -from wrolpi.common import chunks, remove_whitespace, logger, temporary_directory_path +from wrolpi.common import chunks, remove_whitespace, logger from wrolpi.errors import InvalidOTP, InvalidPlaintext, InvalidCiphertext # These are the only characters we support. @@ -41,54 +40,40 @@ def generate_message(): return format_message(''.join(generate_char() for _ in range(400)), 16) -ONE_TIME_PAD_TEX = r''' -\documentclass{article} -\usepackage{hyperref} -\usepackage[margin=0.3in]{geometry} -\usepackage{mathptmx} +PAGE_HTML = ''' + +One Time Pad - Unique, just for you + + +{messages} -\title{One Time Pad} -\begin{document} - -\begin{verbatim} -%s -\end{verbatim} - -Print this page and distribute the copies (along with the \href{https://lrnsr.co/aY6m}{One Time Pad Cheat Sheet -https://lrnsr.co/aY6m}) to all members of your group that you trust to receive your encrypted messages. Every person -must have their OWN copy of this “One Time Pad” to encrypt and decrypt messages. -\\ - -\textbf{Use each message ONLY ONCE}. Cut off and burn each message from this paper as it is used. -\\ - -To learn how to use this page, please visit: \href{https://lrnsr.co/H7Za}{https://lrnsr.co/H7Za} - -\end{document} +Print this page and distribute the copies (along with the One Time Pad Cheat Sheet +https://lrnsr.co/aY6m) to all members of your group that you trust to receive your encrypted messages. Every +person must have their OWN copy of this "One Time Pad" to encrypt and decrypt messages. +
+Use each message ONLY ONCE. Cut off and burn each message from this paper as it is used. +
+If you want more One Time Pads, simply go here to refresh the page: +https://learningselfreliance.com/one_time_pad. The server will generate a unique page just for you. This page +is not stored on the server, and cannot be retrieved once you close this window! +
+To learn how to use this page, please visit: https://lrnsr.co/H7Za + + ''' -def generate_pdf() -> bytes: +def generate_html() -> str: """ - Create a PDF One Time Pad. + Create an HTML One-Time Pad page. This page will have instructions on how to use the OTP. """ - messages = '\n\n'.join(f'MESSAGE {i}\n{generate_message()}' for i in range(1, 8)) - with temporary_directory_path() as d: - tex_path = d / 'otp.tex' - tex_path.write_text(ONE_TIME_PAD_TEX % messages) - cmd = ('pdflatex', tex_path) - try: - subprocess.check_output(cmd, cwd=d) - # Output path is chosen by `pdflatex`. - pdf_path = tex_path.with_suffix('.pdf') - contents = pdf_path.read_bytes() - except Exception as e: - logger.fatal(f'Failed to generate One Time Pad PDF!', exc_info=e) - raise - # Files are cleaned up. - assert not d.is_dir() - return contents + messages = [generate_message() for _ in range(9)] + messages = '\n\n'.join(f'
MESSAGE {i}
{j}
' for i, j in enumerate(messages, 1)) + return PAGE_HTML.format(messages=messages) def validate_message(otp, error_class): diff --git a/modules/otp/test/test_api.py b/modules/otp/test/test_api.py index 23f6bd6f..e00225be 100644 --- a/modules/otp/test/test_api.py +++ b/modules/otp/test/test_api.py @@ -24,6 +24,6 @@ def test_decrypt(test_client): ) -def test_get_pdf(test_client): - request, response = test_client.get('/api/otp/pdf') +def test_get_html(test_client): + request, response = test_client.get('/api/otp/html') assert response.status_code == HTTPStatus.OK diff --git a/modules/otp/test/test_otp.py b/modules/otp/test/test_otp.py index f533c95e..15c0b879 100644 --- a/modules/otp/test/test_otp.py +++ b/modules/otp/test/test_otp.py @@ -96,8 +96,6 @@ def test_format_message(message, expected): assert result == expected -def test_latex_pdf(): - """ - Generate a OTP PDF. - """ - assert lib.generate_pdf() +def test_get_new_otp_html(): + """Generate a OTP HTML page.""" + assert lib.generate_html() diff --git a/scripts/install_debian_11.sh b/scripts/install_debian_11.sh index a7c3933f..63046de0 100755 --- a/scripts/install_debian_11.sh +++ b/scripts/install_debian_11.sh @@ -8,7 +8,7 @@ set -e # Install dependencies apt install -y apt-transport-https ca-certificates curl gnupg-agent gcc libpq-dev software-properties-common \ postgresql-13 nginx-full nginx-doc python3-full python3-dev python3-doc python3-venv htop vim ffmpeg hostapd \ - texlive-latex-base texlive-latex-extra chromium chromium-driver cpufrequtils network-manager npm + chromium chromium-driver cpufrequtils network-manager npm # Install Archiving tools. npm install -g 'git+https://github.com/gildas-lormeau/SingleFile' diff --git a/scripts/install_ubuntu_20.04.sh b/scripts/install_ubuntu_20.04.sh index c2e1cf67..d685a143 100755 --- a/scripts/install_ubuntu_20.04.sh +++ b/scripts/install_ubuntu_20.04.sh @@ -11,8 +11,7 @@ curl -fsSL https://deb.nodesource.com/setup_14.x | bash - # Install dependencies apt install -y apt-transport-https ca-certificates curl gnupg-agent gcc libpq-dev software-properties-common \ postgresql-12 nginx-full nginx-doc python3.8-minimal python3.8-dev python3.8-doc python3.8-venv \ - ffmpeg hostapd nodejs texlive-latex-base texlive-latex-extra chromium-browser chromium-chromedriver \ - cpufrequtils network-manager + ffmpeg hostapd nodejs chromium-browser chromium-chromedriver cpufrequtils network-manager # Install Archiving tools. npm install -g 'git+https://github.com/gildas-lormeau/SingleFile'