This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flows for manipulating TUF metadata
- Loading branch information
Shaun Taheri
committed
Nov 14, 2017
1 parent
d3f50d4
commit 654709e
Showing
15 changed files
with
236 additions
and
47 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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
|
||
from api.datatypes.metadata import Metadata | ||
from api.utils import is_metadata | ||
|
||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.info(f"Deleting a signature...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") | ||
return | ||
|
||
try: | ||
meta = Metadata.from_flow(flow) | ||
del_sig = meta.signatures.random() | ||
ctx.log.debug(f"deleting sig with keyid: {del_sig.keyid}") | ||
meta.signatures = meta.signatures.remove_key(del_sig.keyid) | ||
|
||
flow.response.headers["x-mitm-flow"] = "delete_signature" | ||
flow.response.content = meta.to_json().encode("UTF-8") | ||
except Exception as e: | ||
ctx.log.error(f"Processing error: {e}") | ||
ctx.log.debug(e.__traceback__) |
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,25 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
|
||
from api.datatypes.metadata import Metadata | ||
from api.utils import is_metadata | ||
|
||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.info(f"Duplicating a signature...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") | ||
return | ||
|
||
try: | ||
meta = Metadata.from_flow(flow) | ||
dup_sig = meta.signatures.random() | ||
ctx.log.debug(f"duplicating sig with keyid: {dup_sig.keyid}") | ||
meta.signatures = meta.signatures.duplicate_key(dup_sig.keyid) | ||
|
||
flow.response.headers["x-mitm-flow"] = "duplicate_signature" | ||
flow.response.content = meta.to_json().encode("UTF-8") | ||
except Exception as e: | ||
ctx.log.error(f"Processing error: {e}") | ||
ctx.log.debug(e.__traceback__) |
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 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
|
||
from api.datatypes.metadata import Metadata | ||
from api.datatypes.signing import Rsa | ||
from api.utils import is_metadata | ||
|
||
|
||
PUB_KEY = "/unsafe_keys/rsa_4096.pub" | ||
PRIV_KEY = "/unsafe_keys/rsa_4096.key" | ||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.info(f"Replacing a signature with one from another key...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") | ||
return | ||
|
||
try: | ||
meta = Metadata.from_flow(flow) | ||
rsa = Rsa.from_files(PUB_KEY, PRIV_KEY) | ||
|
||
sigs = meta.signatures | ||
old_sig = sigs.random() | ||
ctx.log.debug(f"deleting sig with keyid: {old_sig.keyid}") | ||
new_sig = rsa.sign(meta.canonical_signed().encode("UTF-8")) | ||
ctx.log.debug(f"adding sig with keyid: {new_sig.keyid}") | ||
meta.signatures = sigs.replace_key(old_sig.keyid, new_sig) | ||
|
||
flow.response.headers["x-mitm-flow"] = "new_signature" | ||
flow.response.content = meta.to_json().encode("UTF-8") | ||
except Exception as e: | ||
ctx.log.error(f"Processing error: {e}") | ||
ctx.log.debug(e.__traceback__) |
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,11 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
|
||
from api.utils import is_metadata | ||
|
||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.debug("skipping metadata response...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") |
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
|
||
from api.datatypes.metadata import Metadata | ||
from api.utils import is_metadata | ||
|
||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.info(f"Randomizing a key-id...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") | ||
return | ||
|
||
try: | ||
meta = Metadata.from_flow(flow) | ||
old_sig = meta.signatures.random() | ||
new_sig = old_sig.randomize_key() | ||
ctx.log.debug(f"changing key-id from {old_sig.keyid} to {new_sig.keyid}...") | ||
meta.signatures = meta.signatures.replace_key(old_sig.keyid, new_sig) | ||
|
||
flow.response.headers["x-mitm-flow"] = "randomize_keyid" | ||
flow.response.content = meta.to_json().encode("UTF-8") | ||
except Exception as e: | ||
ctx.log.error(f"Processing error: {e}") | ||
ctx.log.debug(e.__traceback__) |
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,26 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
|
||
from api.datatypes.metadata import Metadata | ||
from api.utils import is_metadata | ||
|
||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.info(f"Randomizing a signature...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") | ||
return | ||
|
||
try: | ||
meta = Metadata.from_flow(flow) | ||
old_sig = meta.signatures.random() | ||
new_sig = old_sig.randomize_sig() | ||
ctx.log.debug(f"replacing keyid {old_sig.keyid} with {new_sig}.keyid") | ||
meta.signatures = meta.signatures.replace_key(old_sig.keyid, new_sig) | ||
|
||
flow.response.headers["x-mitm-flow"] = "randomize_signature" | ||
flow.response.content = meta.to_json().encode("UTF-8") | ||
except Exception as e: | ||
ctx.log.error(f"Processing error: {e}") | ||
ctx.log.debug(e.__traceback__) |
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,28 @@ | ||
import sys | ||
|
||
from mitmproxy import ctx | ||
from mitmproxy.http import HTTPFlow | ||
from random import randrange | ||
|
||
from api.datatypes.metadata import Metadata | ||
from api.utils import is_metadata | ||
|
||
|
||
def response(flow: HTTPFlow) -> None: | ||
if is_metadata(flow): | ||
ctx.log.info(f"Randomize the signed version...") | ||
else: | ||
ctx.log.debug("skipping non-metadata response...") | ||
return | ||
|
||
try: | ||
meta = Metadata.from_flow(flow) | ||
new_version = randrange(sys.maxsize) | ||
ctx.log.debug(f"replacing metadata version {meta.version} with {new_version}") | ||
meta.version = new_version | ||
|
||
flow.response.headers["x-mitm-flow"] = "randomize_version" | ||
flow.response.content = meta.to_json().encode("UTF-8") | ||
except Exception as e: | ||
ctx.log.error(f"Processing error: {e}") | ||
ctx.log.debug(e.__traceback__) |
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