Skip to content

Commit

Permalink
feat: add cert validation code
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoPlain committed Nov 12, 2023
1 parent 2a94d98 commit 4738cd3
Showing 1 changed file with 81 additions and 13 deletions.
94 changes: 81 additions & 13 deletions hashes/src/Hashes_salt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {
"id": "0Wg0gBwY-2Eo"
},
Expand All @@ -14,14 +14,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 11,
"metadata": {
"id": "v7fM-yxH-2Er"
},
"outputs": [],
"source": [
"password = '12345Qwert'\n",
"salt = 'dotnet2023'"
"salt = 'whatAnAmazingCon'"
]
},
{
Expand All @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 12,
"metadata": {
"id": "KZW8caXA-2Es"
},
Expand All @@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 13,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -71,7 +71,7 @@
"output_type": "stream",
"text": [
"The md5 hash is: 18a49c364ba10330d894b11652e65bc2\n",
"The salted md5 hash is: 66e99cc5306f5fc13d5ae882119affc6\n"
"The salted md5 hash is: ec31aadc6a06fe53ca079564c48596a6\n"
]
}
],
Expand All @@ -94,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 14,
"metadata": {
"id": "ZeGVBMMv-2Et"
},
Expand All @@ -110,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 15,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -124,7 +124,7 @@
"output_type": "stream",
"text": [
"The sha256 hash is: c90142696762be2f4632c18382315ab39e20a41e997cd8a41502aeafcfae49fe\n",
"The salted sha256 hash is: 4c08e5ccb92fcb5ef84ebac9636a099121a1609a564d8cf91e87509cc123f64e\n"
"The salted sha256 hash is: b60c0049182cc396182f62cf598c39a4cfe73ce889f31c840014c09cdc1b3bb6\n"
]
}
],
Expand All @@ -136,6 +136,67 @@
"print(f'The salted sha256 hash is: {salted_hash}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Certificates Checker\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: certvalidator in /opt/conda/lib/python3.11/site-packages (0.11.1)\n",
"Requirement already satisfied: asn1crypto>=0.18.1 in /opt/conda/lib/python3.11/site-packages (from certvalidator) (1.5.1)\n",
"Requirement already satisfied: oscrypto>=0.16.1 in /opt/conda/lib/python3.11/site-packages (from certvalidator) (1.3.0)\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install certvalidator\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unexpected The path could not be validated because the end-entity certificate expired 2015-04-12 23:59:59Z\n",
" type: <class 'certvalidator.errors.PathValidationError'>\n"
]
}
],
"source": [
"from oscrypto import tls\n",
"from certvalidator import CertificateValidator\n",
"\n",
"\n",
"expired_cert = 'expired.badssl.com'\n",
"self_signed = 'self-signed.badssl.com'\n",
"bad_dh = 'dh480.badssl.com'\n",
"\n",
"try:\n",
" session = tls.TLSSession(manual_validation=True)\n",
" connection = tls.TLSSocket(expired_cert, 443, session=session)\n",
"\n",
" validator = CertificateValidator(connection.certificate, connection.intermediates)\n",
" validator.validate_tls(connection.hostname)\n",
"except Exception as err:\n",
" print(f\"Unexpected {err}\")\n",
" print(f\" type: {type(err)}\")"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -147,7 +208,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -156,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 20,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -169,7 +230,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"This password has been seen 1954 times before...\n"
"This password has been seen 1473205 times before...\n"
]
}
],
Expand Down Expand Up @@ -202,6 +263,13 @@
"1. [Salt OWASP](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#salting)\n",
"1. [Pepper OWASP](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#peppering)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -223,7 +291,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 4738cd3

Please sign in to comment.