selfprivacy-rest-api/selfprivacy_api/resources/common.py

57 lines
1.6 KiB
Python
Raw Normal View History

2021-11-11 18:31:28 +00:00
#!/usr/bin/env python3
2021-11-16 16:14:01 +00:00
"""Unassigned views"""
2021-11-11 18:31:28 +00:00
import subprocess
2021-11-16 16:14:01 +00:00
from flask_restful import Resource, reqparse
2021-11-11 18:31:28 +00:00
class DecryptDisk(Resource):
2021-11-16 16:14:01 +00:00
"""Decrypt disk"""
2021-11-11 18:31:28 +00:00
def post(self):
2021-11-16 16:14:01 +00:00
"""
Decrypt /dev/sdb using cryptsetup luksOpen
---
consumes:
- application/json
tags:
- System
security:
- bearerAuth: []
parameters:
- in: body
name: body
required: true
description: Provide a password for decryption
schema:
type: object
required:
- password
properties:
password:
type: string
description: Decryption password.
responses:
201:
description: OK
400:
description: Bad request
401:
description: Unauthorized
"""
parser = reqparse.RequestParser(bundle_errors=True)
parser.add_argument("password", type=str, required=True)
args = parser.parse_args()
decryption_command = ["cryptsetup", "luksOpen", "/dev/sdb", "decryptedVar"]
# TODO: Check if this works at all
2021-11-11 18:31:28 +00:00
2021-11-16 16:14:01 +00:00
decryption_service = subprocess.Popen(
decryption_command,
shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
2021-11-11 18:31:28 +00:00
)
2021-11-16 16:14:01 +00:00
decryption_service.communicate(input=args["password"])
return {"status": decryption_service.returncode}, 201