|
| 1 | +from typing import Dict, Tuple |
| 2 | + |
| 3 | +import abc |
| 4 | + |
| 5 | + |
| 6 | +class CryptoCallError(ValueError): |
| 7 | + pass |
| 8 | + |
| 9 | + |
| 10 | +class CryptoCaller(abc.ABC): |
| 11 | + """Abstract base class for `CryptoCaller`s - an interface that |
| 12 | + encapsulates basic password and TLS cert related functions |
| 13 | + needed by the Ceph MGR. |
| 14 | + """ |
| 15 | + |
| 16 | + @abc.abstractmethod |
| 17 | + def create_private_key(self) -> str: |
| 18 | + """Create a new TLS private key, returning it as a string.""" |
| 19 | + |
| 20 | + @abc.abstractmethod |
| 21 | + def create_self_signed_cert( |
| 22 | + self, dname: Dict[str, str], pkey: str |
| 23 | + ) -> str: |
| 24 | + """Given TLS certificate subject parameters and a private key, |
| 25 | + create a new self signed certificate - returned as a string. |
| 26 | + """ |
| 27 | + |
| 28 | + @abc.abstractmethod |
| 29 | + def verify_tls(self, crt: str, key: str) -> None: |
| 30 | + """Given a TLS certificate and a private key raise an error |
| 31 | + if the combination is not valid. |
| 32 | + """ |
| 33 | + |
| 34 | + @abc.abstractmethod |
| 35 | + def certificate_days_to_expire(self, crt: str) -> int: |
| 36 | + """Return the number of days until the given TLS certificate expires.""" |
| 37 | + |
| 38 | + @abc.abstractmethod |
| 39 | + def get_cert_issuer_info(self, crt: str) -> Tuple[str, str]: |
| 40 | + """Basic validation of a ca cert""" |
| 41 | + |
| 42 | + @abc.abstractmethod |
| 43 | + def password_hash(self, password: str, salt_password: str) -> str: |
| 44 | + """Hash a password. Returns the hashed password as a string.""" |
| 45 | + |
| 46 | + @abc.abstractmethod |
| 47 | + def verify_password(self, password: str, hashed_password: str) -> bool: |
| 48 | + """Return true if a password and hash match.""" |
0 commit comments