-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__pycache__ | ||
.*.swp | ||
venv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import secure_server | ||
import bad_server | ||
import api | ||
import secrets | ||
from typing import Optional | ||
|
||
class Client: | ||
def __init__(self, remote: secure_server.VerySecureServer): | ||
def __init__(self, remote: bad_server.BadServer): | ||
self._remote = remote | ||
|
||
def steal_secret_token(self, l: int) -> Optional[str]: | ||
secret_token = secrets.token_hex(l) | ||
req = api.VerifyTokenRequest(secret_token) | ||
if self._remote.verify_token(req).ret: | ||
return secret_token | ||
def steal_password (self, l: int) -> Optional[str]: | ||
password = secrets.token_hex(l) | ||
req = api.VerifyRequest(password) | ||
if self._remote.verify_password(req).ret: | ||
return password | ||
else: | ||
return None | ||
|
||
if __name__ == "__main__": | ||
token = '37a4e5bf847630173da7e6d19991bb8d' | ||
nbytes = len(token) // 2 | ||
server = secure_server.VerySecureServer(token) | ||
passwd = '37a4e5bf847630173da7e6d19991bb8d' | ||
nbytes = len(passwd) // 2 | ||
server = bad_server.BadServer(passwd) | ||
alice = Client(server) | ||
print(alice.steal_secret_token(nbytes)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import secrets | ||
import api | ||
from typing import Optional | ||
|
||
class BadServer: | ||
def __init__(self, password: Optional[str] = None): | ||
if password is None: | ||
self._password = secrets.token_hex(256) | ||
else: | ||
self._password = password | ||
|
||
def send_money(self): | ||
# This is where the protected code would run. | ||
pass | ||
|
||
def verify_password(self, request: api.VerifyRequest) -> api.VerifyResponse: | ||
try: | ||
s = request.password | ||
for i in range(len(self._password)): | ||
if len(s) <= i: | ||
return api.VerifyResponse(False) | ||
elif s[i] != self._password[i]: | ||
return api.VerifyResponse(False) | ||
|
||
# At this point, the user is authenticated. | ||
self.send_money() | ||
|
||
return api.VerifyResponse(True) | ||
except: | ||
return api.VerifyResponse(False) | ||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.