├── .gitignore ├── LICENSE ├── README.md ├── main.py └── screenshot └── ss1.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ali İlteriş Keskin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ssl-check-api 2 | 3 | This api returns the ssl expiration date of the hostname. Default port 443. 4 | 5 | Request Url: [https://79w38kh2pa.execute-api.eu-central-1.amazonaws.com/](https://79w38kh2pa.execute-api.eu-central-1.amazonaws.com/) 6 | 7 | --- 8 | 9 | ## Postman Screenshot 10 | 11 | ![Postman Screenshot](/screenshot/ss1.png "Postman Screenshot") 12 | 13 | --- 14 | 15 | ## How to send request? 16 | 17 | Bash: 18 | ```Bash 19 | curl --location --request POST 'https://79w38kh2pa.execute-api.eu-central-1.amazonaws.com/' \ 20 | --header 'Content-Type: application/json' \ 21 | --data-raw '{ 22 | "hostname": "stackoverflow.com", 23 | "port": "443" 24 | }' 25 | ``` 26 | 27 | --- 28 | 29 | Python: 30 | ```Python 31 | import requests 32 | import json 33 | 34 | url = "https://79w38kh2pa.execute-api.eu-central-1.amazonaws.com/" 35 | 36 | payload = json.dumps({ 37 | "hostname": "stackoverflow.com", 38 | "port": "443" 39 | }) 40 | headers = { 41 | 'Content-Type': 'application/json' 42 | } 43 | 44 | response = requests.request("POST", url, headers=headers, data=payload) 45 | 46 | print(response.text) 47 | ``` 48 | 49 | --- 50 | 51 | Go: 52 | ```Go 53 | package main 54 | 55 | import ( 56 | "fmt" 57 | "strings" 58 | "net/http" 59 | "io/ioutil" 60 | ) 61 | 62 | func main() { 63 | 64 | url := "https://79w38kh2pa.execute-api.eu-central-1.amazonaws.com/" 65 | method := "POST" 66 | 67 | payload := strings.NewReader(`{ 68 | "hostname": "stackoverflow.com", 69 | "port": "443" 70 | }`) 71 | 72 | client := &http.Client { 73 | } 74 | req, err := http.NewRequest(method, url, payload) 75 | 76 | if err != nil { 77 | fmt.Println(err) 78 | return 79 | } 80 | req.Header.Add("Content-Type", "application/json") 81 | 82 | res, err := client.Do(req) 83 | if err != nil { 84 | fmt.Println(err) 85 | return 86 | } 87 | defer res.Body.Close() 88 | 89 | body, err := ioutil.ReadAll(res.Body) 90 | if err != nil { 91 | fmt.Println(err) 92 | return 93 | } 94 | fmt.Println(string(body)) 95 | } 96 | ``` -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import logging 3 | import json 4 | 5 | from urllib.request import ssl, socket 6 | 7 | 8 | logger = logging.getLogger(__name__) 9 | 10 | 11 | def check_ssl(hostname: str, port: str) -> dict: 12 | """ 13 | This function is check ssl certificate 14 | :param hostname: 15 | :param port: 16 | :return: 17 | """ 18 | context = ssl.create_default_context() 19 | 20 | try: 21 | with socket.create_connection(address=(hostname, port), timeout=3) as sock: 22 | with context.wrap_socket(sock, server_hostname=hostname) as ssock: 23 | certificate = ssock.getpeercert() 24 | 25 | certExpires = datetime.datetime.strptime( 26 | certificate['notAfter'], '%b %d %H:%M:%S %Y %Z') 27 | 28 | data = { 29 | 'status': 200, 30 | 'expiration_day': f"{certExpires.year}-{certExpires.month}-{certExpires.day}", 31 | 'remaining_day': (certExpires - datetime.datetime.now()).days 32 | } 33 | except Exception as e: 34 | logger.error(e) 35 | data = { 36 | 'status': 500, 37 | 'message': 'Server Error! Try again or contact admin.' 38 | } 39 | 40 | return data 41 | 42 | 43 | def run(event, context) -> list: 44 | """ 45 | Check SSL Service 46 | :param event: 47 | :param context: 48 | :return: 49 | """ 50 | request_body = json.loads(event['body']) 51 | hostname = request_body.get('hostname') 52 | port = request_body.get('port', 443) 53 | 54 | if not hostname: 55 | return {'ok': False, 'message': 'Wrong request parameters.'} 56 | 57 | return check_ssl(hostname=hostname, port=str(port)) 58 | -------------------------------------------------------------------------------- /screenshot/ss1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilteriskeskin/ssl-check-api/ada7bd54e89bfea537241fd0a80e70b24fbf7eaf/screenshot/ss1.png --------------------------------------------------------------------------------