Spaces:
Sleeping
Sleeping
NimaBoscarino
commited on
Commit
·
839d8d8
1
Parent(s):
2fad31c
wrapping up for Ola
Browse files- .idea/.gitignore +8 -0
- .idea/inspectionProfiles/Project_Default.xml +30 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .idea/review-claim.iml +8 -0
- .idea/vcs.xml +6 -0
- .python-version +1 -0
- app.py +72 -0
- decrypt.py +18 -0
- encrypt.py +25 -0
- encrypted_data.bin +3 -0
- gen_keys.py +12 -0
- mykey.pem +27 -0
- private.pem +27 -0
- public_key.pem +9 -0
- receiver.pem +9 -0
- requirements.txt +5 -0
- scratch.py +48 -0
- test.py +29 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
4 |
+
# Editor-based HTTP Client requests
|
5 |
+
/httpRequests/
|
6 |
+
# Datasource local storage ignored files
|
7 |
+
/dataSources/
|
8 |
+
/dataSources.local.xml
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredPackages">
|
6 |
+
<value>
|
7 |
+
<list size="1">
|
8 |
+
<item index="0" class="java.lang.String" itemvalue="pytest-runner" />
|
9 |
+
</list>
|
10 |
+
</value>
|
11 |
+
</option>
|
12 |
+
</inspection_tool>
|
13 |
+
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
14 |
+
<option name="ignoredErrors">
|
15 |
+
<list>
|
16 |
+
<option value="N801" />
|
17 |
+
<option value="N806" />
|
18 |
+
</list>
|
19 |
+
</option>
|
20 |
+
</inspection_tool>
|
21 |
+
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
22 |
+
<option name="ignoredIdentifiers">
|
23 |
+
<list>
|
24 |
+
<option value="dict.labels" />
|
25 |
+
<option value="geograpy.places.countries" />
|
26 |
+
</list>
|
27 |
+
</option>
|
28 |
+
</inspection_tool>
|
29 |
+
</profile>
|
30 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (hackathon)" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/review-claim.iml" filepath="$PROJECT_DIR$/.idea/review-claim.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/review-claim.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="jdk" jdkName="Python 3.10 (hackathon)" jdkType="Python SDK" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
hackathon
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import get_repo_discussions, get_discussion_details
|
3 |
+
from Crypto.PublicKey import RSA
|
4 |
+
from Crypto.Cipher import AES, PKCS1_OAEP
|
5 |
+
import base64
|
6 |
+
|
7 |
+
|
8 |
+
def decrypt_claim(encrypted_claim_encoded, private_key_file):
|
9 |
+
base64_encoded = encrypted_claim_encoded.split("\n")[1]
|
10 |
+
encrypted_claim_encoded = encrypted_claim_encoded.split('\n')[1]
|
11 |
+
b64_fixed = bytes(base64_encoded[2:-1], 'utf-8')
|
12 |
+
encrypted_claim = base64.b64decode(b64_fixed)
|
13 |
+
|
14 |
+
private_key = RSA.import_key(open(private_key_file.name).read())
|
15 |
+
|
16 |
+
enc_session_key, nonce, tag, ciphertext = \
|
17 |
+
[encrypted_claim for x in (private_key.size_in_bytes(), 16, 16, -1)]
|
18 |
+
|
19 |
+
# Decrypt the session key with the private RSA key
|
20 |
+
cipher_rsa = PKCS1_OAEP.new(private_key)
|
21 |
+
session_key = cipher_rsa.decrypt(enc_session_key)
|
22 |
+
|
23 |
+
# Decrypt the data with the AES session key
|
24 |
+
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
25 |
+
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
26 |
+
decrypted_claim = data.decode("utf-8")
|
27 |
+
|
28 |
+
return decrypted_claim
|
29 |
+
|
30 |
+
|
31 |
+
def get_claim(claim_id, private_key):
|
32 |
+
claims = []
|
33 |
+
|
34 |
+
# TODO: Currently fetching ALL discussions, in case we want to build a view to see list of discussions in the claim-review space
|
35 |
+
# for discussion in get_repo_discussions(repo_id="Team8/dataset", repo_type="dataset"):
|
36 |
+
# claims = claims + [discussion]
|
37 |
+
# # print(f"{discussion.num} - {discussion.title}, pr: {discussion.is_pull_request}")
|
38 |
+
#
|
39 |
+
# claim = [c for c in claims if c.num == claim_id][0]
|
40 |
+
|
41 |
+
claim = get_discussion_details(
|
42 |
+
repo_id="Team8/dataset",
|
43 |
+
repo_type="dataset",
|
44 |
+
discussion_num=int(claim_id)
|
45 |
+
)
|
46 |
+
|
47 |
+
return gr.Textbox.update(value=claim.title), gr.Textbox.update(value=decrypt_claim(claim.events[0].content, private_key))
|
48 |
+
|
49 |
+
|
50 |
+
demo = gr.Blocks()
|
51 |
+
|
52 |
+
with demo:
|
53 |
+
gr.Markdown(
|
54 |
+
"""
|
55 |
+
# Flip Text!
|
56 |
+
Start typing below to see the output.
|
57 |
+
"""
|
58 |
+
)
|
59 |
+
button = gr.Button(value="Fetch Claim")
|
60 |
+
private_key = gr.File(label="Private Key")
|
61 |
+
|
62 |
+
claim_id = gr.Number()
|
63 |
+
claim_title = gr.Textbox(label="Claim Title", value="")
|
64 |
+
claim_text = gr.Textbox(label="Claim Text", value="")
|
65 |
+
|
66 |
+
button.click(
|
67 |
+
fn=get_claim,
|
68 |
+
inputs=[claim_id, private_key],
|
69 |
+
outputs=[claim_title, claim_text]
|
70 |
+
)
|
71 |
+
|
72 |
+
demo.launch()
|
decrypt.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from Crypto.PublicKey import RSA
|
2 |
+
from Crypto.Cipher import AES, PKCS1_OAEP
|
3 |
+
|
4 |
+
file_in = open("encrypted_data.bin", "rb")
|
5 |
+
|
6 |
+
private_key = RSA.import_key(open("private.pem").read())
|
7 |
+
|
8 |
+
enc_session_key, nonce, tag, ciphertext = \
|
9 |
+
[ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
|
10 |
+
|
11 |
+
# Decrypt the session key with the private RSA key
|
12 |
+
cipher_rsa = PKCS1_OAEP.new(private_key)
|
13 |
+
session_key = cipher_rsa.decrypt(enc_session_key)
|
14 |
+
|
15 |
+
# Decrypt the data with the AES session key
|
16 |
+
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
17 |
+
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
18 |
+
print(data.decode("utf-8"))
|
encrypt.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from Crypto.PublicKey import RSA
|
2 |
+
from Crypto.Random import get_random_bytes
|
3 |
+
from Crypto.Cipher import AES, PKCS1_OAEP
|
4 |
+
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
|
7 |
+
import yaml
|
8 |
+
import io
|
9 |
+
|
10 |
+
loc = hf_hub_download(repo_id="Team8/dataset", repo_type="dataset", filename="receiver.pem")
|
11 |
+
data = "I met aliens in UFO. Here is the map.".encode("utf-8")
|
12 |
+
file_out = open("encrypted_data.bin", "wb")
|
13 |
+
|
14 |
+
recipient_key = RSA.import_key(open(loc).read())
|
15 |
+
session_key = get_random_bytes(16)
|
16 |
+
|
17 |
+
# Encrypt the session key with the public RSA key
|
18 |
+
cipher_rsa = PKCS1_OAEP.new(recipient_key)
|
19 |
+
enc_session_key = cipher_rsa.encrypt(session_key)
|
20 |
+
|
21 |
+
# Encrypt the data with the AES session key
|
22 |
+
cipher_aes = AES.new(session_key, AES.MODE_EAX)
|
23 |
+
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
|
24 |
+
[ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
|
25 |
+
file_out.close()
|
encrypted_data.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3982bcc86b1f5ffdfc8ed12d9cef4fce794d92aad44e661a5dad9f474f0e4ddd
|
3 |
+
size 325
|
gen_keys.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from Crypto.PublicKey import RSA
|
2 |
+
|
3 |
+
key = RSA.generate(2048)
|
4 |
+
private_key = key.export_key()
|
5 |
+
file_out = open("private.pem", "wb")
|
6 |
+
file_out.write(private_key)
|
7 |
+
file_out.close()
|
8 |
+
|
9 |
+
public_key = key.publickey().export_key()
|
10 |
+
file_out = open("receiver.pem", "wb")
|
11 |
+
file_out.write(public_key)
|
12 |
+
file_out.close()
|
mykey.pem
ADDED
@@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|
+
pyyaml
|
scratch.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import get_repo_discussions, get_discussion_details
|
2 |
+
|
3 |
+
# from huggingface_hub import DatasetFilter, HfApi
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
#
|
6 |
+
# claim = get_discussion_details(
|
7 |
+
# repo_id="Team8/dataset",
|
8 |
+
# repo_type="dataset",
|
9 |
+
# discussion_num=int(1)
|
10 |
+
# )
|
11 |
+
#
|
12 |
+
# print(claim.events[0].content)
|
13 |
+
|
14 |
+
from Crypto.PublicKey import RSA
|
15 |
+
key = RSA.generate(2048)
|
16 |
+
pub = key.public_key()
|
17 |
+
|
18 |
+
f = open('mykey.pem','wb')
|
19 |
+
f.write(key.export_key('PEM'))
|
20 |
+
f.close()
|
21 |
+
|
22 |
+
f = open('public_key.pem','wb')
|
23 |
+
f.write(pub.export_key('PEM'))
|
24 |
+
f.close()
|
25 |
+
|
26 |
+
|
27 |
+
# api = HfApi()
|
28 |
+
# filt = DatasetFilter(
|
29 |
+
# author="Team8",
|
30 |
+
# dataset_name="dataset"
|
31 |
+
# )
|
32 |
+
#
|
33 |
+
# dsets = api.list_datasets(filter=filt)[0]
|
34 |
+
|
35 |
+
# print(dsets)
|
36 |
+
|
37 |
+
from huggingface_hub import hf_hub_download
|
38 |
+
|
39 |
+
loc = hf_hub_download(repo_id="Team8/dataset", repo_type="dataset", filename="README.md")
|
40 |
+
|
41 |
+
import yaml
|
42 |
+
|
43 |
+
with open(loc) as f:
|
44 |
+
front_matter = next(yaml.load_all(f, Loader=yaml.FullLoader))
|
45 |
+
print(front_matter["public_key"])
|
46 |
+
|
47 |
+
|
48 |
+
RSA
|
test.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from Crypto.PublicKey import RSA
|
2 |
+
from Crypto.Cipher import AES, PKCS1_OAEP
|
3 |
+
from huggingface_hub import get_repo_discussions, get_discussion_details
|
4 |
+
import base64
|
5 |
+
|
6 |
+
claim = get_discussion_details(
|
7 |
+
repo_id="Team8/dataset",
|
8 |
+
repo_type="dataset",
|
9 |
+
discussion_num=int(5)
|
10 |
+
)
|
11 |
+
|
12 |
+
encryptedtext_encoded = claim.events[0].content
|
13 |
+
encrypted_text = base64.b64decode(encryptedtext_encoded)
|
14 |
+
|
15 |
+
file_in = open("encrypted_data.bin", "rb")
|
16 |
+
|
17 |
+
private_key = RSA.import_key(open("private.pem").read())
|
18 |
+
|
19 |
+
enc_session_key, nonce, tag, ciphertext = \
|
20 |
+
[ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
|
21 |
+
|
22 |
+
# Decrypt the session key with the private RSA key
|
23 |
+
cipher_rsa = PKCS1_OAEP.new(private_key)
|
24 |
+
session_key = cipher_rsa.decrypt(enc_session_key)
|
25 |
+
|
26 |
+
# Decrypt the data with the AES session key
|
27 |
+
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
28 |
+
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
29 |
+
print(data.decode("utf-8"))
|