mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-05-16 20:26:58 +00:00
issue #25: still WIP
This commit is contained in:
parent
3e4fa309ef
commit
fb09b21684
3 changed files with 167 additions and 18 deletions
BIN
SimpleX/__pycache__/utils.cpython-313.pyc
Normal file
BIN
SimpleX/__pycache__/utils.cpython-313.pyc
Normal file
Binary file not shown.
|
@ -1,34 +1,128 @@
|
|||
import re
|
||||
def IsSimpleXChatroomValid(url: str) -> bool:
|
||||
#simplex:/ contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40 b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion %2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D
|
||||
#simplex:/ contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40 smp5.simplex.im %2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D
|
||||
print("isSimplexChatroomValid", url)
|
||||
from utils import IsUrlValid
|
||||
import urllib.parse
|
||||
|
||||
#simplex:/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40 b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion %2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D
|
||||
#simplex:/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40 smp5.simplex.im %2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D
|
||||
#TODO: 1) check if it starts with http:// or https:// OR simplex:/
|
||||
#TODO: 1.5) if http:// or https:// check if it has a valid clearnet or onion domain (else if simplex:/ then no need for the domain check)
|
||||
#TODO: 2) check if AFTER it has the "contact#/?v=2-7&smp=smp%3A%2F%2F[...]%3D%40" string in it
|
||||
#TODO: 3) check if AFTER it has a valid hostname (can be an ip, a clearnet domain or an onion domain)
|
||||
#TODO: 3) check if AFTER it has a valid hostname (can be an ip, a clearnet domain or an onion domain)
|
||||
#TODO: 4) check if AFTER it has the %2F[...]%3D%3D%22%7D
|
||||
#TODO: only if all is OK up until 4 (or 5) return True, else False
|
||||
#TODO: only if all is OK up until 4 (or 5) return True, else False
|
||||
# Regular expression pattern for a valid hostname (can be an IP, domain, or onion)
|
||||
|
||||
pattern = re.compile('[0-9A-Za-z-_]*')
|
||||
|
||||
# Regular expression pattern for a valid hostname (can be an IP, domain, or onion)
|
||||
hostname_pattern = re.compile(r'^(?:[a-zA-Z0-9.-]+|[0-9]{1,3}(?:\.[0-9]{1,3}){3}|[a-zA-Z0-9-]+\.onion)$')
|
||||
|
||||
|
||||
|
||||
def IsSimpleXChatroomValid(url: str) -> bool:
|
||||
# Step 1: Check if it starts with http://, https://, or simplex:/
|
||||
if url.startswith(('http://', 'https://', 'simplex:/')):
|
||||
# Step 1.5: If http:// or https://, check for valid clearnet or onion domain
|
||||
if url.startswith(('http://', 'https://')):
|
||||
parsed_url = urllib.parse.urlparse(url)
|
||||
print(parsed_url.hostname)
|
||||
if not IsUrlValid(parsed_url.hostname):
|
||||
return False # Invalid domain
|
||||
elif not url.startswith('simplex:/'):
|
||||
return False # Must start with one of the valid protocols
|
||||
|
||||
|
||||
# Step 2: Check for the presence of "contact#/?v=2-7&smp=smp%3A%2F"
|
||||
if "contact#/?v=2-7&smp=smp%3A%2F" not in url:
|
||||
return False # Required substring not found
|
||||
|
||||
|
||||
# Step 3: Extract the part after "smp=smp%3A%2F" and before the next "&" or end of string
|
||||
smp_start = url.find("smp=smp%3A%2F")
|
||||
if smp_start == -1:
|
||||
return False # Required substring not found
|
||||
|
||||
|
||||
smp_start += len("smp=smp%3A%2F")
|
||||
smp_end = url.find("&", smp_start)
|
||||
if smp_end == -1:
|
||||
smp_end = len(url) # Take until the end if no "&" is found
|
||||
|
||||
|
||||
smp_value = urllib.parse.unquote(url[smp_start:smp_end]) # Decode the URL-encoded string
|
||||
|
||||
|
||||
# Step 3.5: Check if the smp_value contains a valid hostname
|
||||
if '@' not in smp_value:
|
||||
return False # Must contain '@' to separate fingerprint and hostname
|
||||
|
||||
|
||||
fingerprint, hostname = smp_value.split('@', 1)
|
||||
if not IsUrlValid(hostname):
|
||||
return False # Invalid hostname
|
||||
|
||||
|
||||
# Step 4: Check for the presence of "%2F" in the original URL
|
||||
if "%2F" not in url:
|
||||
return False # Required substring not found
|
||||
|
||||
|
||||
# If all checks pass, return True
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
def IsSimpleXServerValid(url: str) -> bool:
|
||||
|
||||
#xftp://fingerprint:password@host1,host2
|
||||
# format 1 : smp://[:]@<public_hostname>[,<onion_hostname>]
|
||||
# format 2 : xftp://[:]@<public_hostname>[,<onion_hostname>]
|
||||
#xftp://Rh19D5e4Eez37DEE9hAlXDB3gZa1BdFYJTPgJWPO9OI=@xftp5.simplexonflux.com
|
||||
|
||||
#TODO: 1) check if it starts with smp:// OR xftp://
|
||||
#TODO: 2) check if AFTER it has the 44 char fingerprint (with the following chars a-zA-Z0-9-_ (base64 format?))
|
||||
#TODO: 3) check if AFTER it has the @ string in it
|
||||
#TODO: 4) check if AFTER it has a valid domain (can be an ip, a clearnet domain or an onion domain)
|
||||
#TODO: 5) ONLY IF THERE IS A COMMA AFTER, check if it has a valid onion domain
|
||||
#TODO: 2) check if AFTER it has the 44 char fingerprint (with the following chars a-zA-Z0-9-_ (base64 format?))
|
||||
#TODO: 3) check if AFTER it has the @ string in it
|
||||
# the try block checks for that
|
||||
#TODO: 4) check if AFTER it has a valid domain (can be an ip, a clearnet domain or an onion domain)
|
||||
#TODO: 5) ONLY IF THERE IS A COMMA AFTER, check if it has a valid onion domain
|
||||
#TODO: only if all is OK up until 4 (or 5) return True, else False
|
||||
print("IsSimplexServerValid", url)
|
||||
|
||||
|
||||
|
||||
|
||||
def IsSimpleXServerValid(url: str) -> bool:
|
||||
url = url.strip()
|
||||
try:
|
||||
if url.startswith(('smp://', 'xftp://')):
|
||||
# Remove the protocol part
|
||||
proless = url.split('//', 1)[-1]
|
||||
# Split the fingerprint and hostname
|
||||
parts = proless.split('@')
|
||||
if len(parts) != 2:
|
||||
return False # Must have exactly one '@' character
|
||||
|
||||
fingerprint = parts[0]
|
||||
hostname = parts[1].split(',')[0] # Get the hostname before any comma
|
||||
|
||||
# Check fingerprint length and pattern
|
||||
if len(fingerprint) == 44 and pattern.match(fingerprint):
|
||||
# Validate the hostname
|
||||
result = IsUrlValid(hostname)
|
||||
if result:
|
||||
# Check for an optional comma and a valid onion domain
|
||||
if ',' in proless:
|
||||
onion_part = proless.split(',')[1].strip()
|
||||
if not hostname_pattern.match(onion_part):
|
||||
return False
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
# Any error will be a false
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
### SHOULD RETURN TRUE: ###
|
||||
link = 'smp://BD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI=@b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion'
|
||||
#link = 'smp://BD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI=@b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion'
|
||||
#link = 'smp://KO7hwMqeal3RmpOmt_1xGRwWh723vbDMmuyYxC6tfKM=@smp1.taurix.net'
|
||||
#link = 'smp://PN7-uqLBToqlf1NxHEaiL35lV2vBpXq8Nj8BW11bU48=@smp6.simplexonflux.com'
|
||||
#link = 'smp://OQuEA1D0jtlUDVALyVGWMr8LcMDan6g1CN_d23y2cTI=@65.109.174.146'
|
||||
|
@ -37,13 +131,14 @@ if __name__ == '__main__':
|
|||
#link = 'xftp://Rh19D5e4Eez37DEE9hAlXDB3gZa1BdFYJTPgJWPO9OI=@xftp5.simplexonflux.com'
|
||||
#link = 'xftp://__t00f17zicHnk2E8n5-AI-YYxQB5sWCY2oYw2m9ZUg=@xftp2.adminforge.de:4433'
|
||||
#link = 'xftp://9bkubN5akZbxDn48tXed-DoZd_fiSQEiIfn0u3M81LQ=@xftp2.asriyan.me:15510'
|
||||
IsSimpleXServerValid(link)
|
||||
### ALL TESTS PASSED ###
|
||||
#print(IsSimpleXServerValid(link))
|
||||
|
||||
|
||||
### SHOULD RETURN TRUE: ###
|
||||
link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
||||
#link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
||||
#link = 'simplex:/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
||||
#link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||
#link = 'https://simplex.hackliberty.org/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||
link = 'https://simplex.hackliberty.org/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||
#link = 'http://b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||
IsSimpleXChatroomValid(link)
|
||||
print(IsSimpleXChatroomValid(link))
|
||||
|
|
54
SimpleX/utils.py
Normal file
54
SimpleX/utils.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import re
|
||||
|
||||
def IsOnionValid(url: str)-> bool:
|
||||
"""
|
||||
Checks if the domain(param) is a valid onion domain and return True else False.
|
||||
"""
|
||||
try:
|
||||
pattern = re.compile("^[A-Za-z0-9.]+(.onion)?$")
|
||||
url = url.strip().removesuffix('/')
|
||||
if url.startswith('http://'):
|
||||
domain = url.split('/')[2]
|
||||
if pattern.fullmatch(domain) is not None:
|
||||
if len(domain.split('.')) > 3:
|
||||
return False
|
||||
else:
|
||||
if len(domain) < 62:
|
||||
return False
|
||||
return True
|
||||
elif pattern.fullmatch(domain) is None:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
#TODO : edit the url to make sure it has http:// at the beginning, in case if it's missing? (problem is that it only returns true or false)
|
||||
if pattern.fullmatch(url) is not None:
|
||||
if len(url.split('.')) > 3:
|
||||
return False
|
||||
else:
|
||||
if len(url) < 62:
|
||||
return False
|
||||
return True
|
||||
elif pattern.fullmatch(url) is None:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
def IsUrlValid(url:str)->bool:
|
||||
"""
|
||||
Check if url is valid both dark net end clearnet.
|
||||
"""
|
||||
pattern = re.compile("^[A-Za-z0-9:/.-]+$")
|
||||
url = str(url)
|
||||
if len(url) < 4:
|
||||
return False
|
||||
if url.endswith('.onion'):
|
||||
return IsOnionValid(url)
|
||||
else:
|
||||
if not url.__contains__('.'):
|
||||
return False
|
||||
if pattern.fullmatch(url) is None:
|
||||
return False
|
||||
return True
|
Loading…
Add table
Add a link
Reference in a new issue