Skip to content

Commit

Permalink
small changes on README & add required packages
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyWyy committed Jul 31, 2023
1 parent 959c2a9 commit e9b4fb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![Python package](https://github.com/naivekun/libhustpass/workflows/Python%20package/badge.svg?branch=master)


Since the fucking `pass.hust.edu.cn` site has changed the encryption method from RSA to **SB** DES, this lib would let you fuck it again.
now the `pass.hust.edu.cn` changed the encryption method from DES to RSA again.

## Installation

Expand Down Expand Up @@ -33,22 +33,21 @@ print(ret.text)

## Implementation

`des.js` uses some spacial `__pc1` (sbDes.py:270) to generate the DES 56-bit key
`jsencryption.js` uses normal RSA to encrypt.

so I use package **pycryptodome** to implement the RSA encryption.

```python
__pc1 = [
56, 48, 40, 32, 24, 16, 8,
0, 57, 49, 41, 33, 25, 17,
9, 1, 58, 50, 42, 34, 26,
18, 10, 2, 59, 51, 43, 35,
27, 19, 11, 3, 60, 52, 44,
36, 28, 20, 12, 4, 61, 53,
45, 37, 29, 21, 13, 5, 62,
54, 46, 38, 30, 22, 14, 6
]
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Crypto.PublicKey import RSA

def encrypt(password, public_key):
rsakey = RSA.importKey(public_key)
cipher = Cipher_pksc1_v1_5.new(rsakey)
cipher_text = base64.b64encode(cipher.encrypt(password.encode()))
return cipher_text.decode()
```

So I modified pyDes.py(from the python library `pyDes`) to sbDes.py

## changelog

Expand All @@ -66,6 +65,11 @@ accuracy is 995/1000

Install Tesseract first !

#### 20230723

`pass.hust.edu.cn` use RSA to encrypt frontend input nows, libhustpass now support it.


## License

WTFPL
4 changes: 0 additions & 4 deletions libhustpass/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def login(username, password, url):
response = r.post("http://pass.hust.edu.cn/cas/rsa",headers=headers,cookies=cookies)
data = response.json()
public_key = data['publicKey']
print(public_key)
public_key = '-----BEGIN PUBLIC KEY-----\n' + public_key + '\n-----END PUBLIC KEY-----'
username_enc = encrypt(username, public_key)
password_enc = encrypt(password, public_key)
Expand All @@ -88,12 +87,9 @@ def login(username, password, url):
"execution": "e1s1",
"_eventId": "submit",
}
print("https://pass.hust.edu.cn" + action)
print(post_params)
redirect_html = r.post(
"https://pass.hust.edu.cn" + action, data=post_params, allow_redirects=False,cookies=cookies,headers=headers
)
print(redirect_html.text)
try:
return redirect_html.headers["Location"]
except:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pillow
pytesseract
requests
requests
pycryptodome
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
setup_requires=["pillow", "pytesseract", "pytest-runner"],
setup_requires=["pillow", "pytesseract", "pytest-runner", "pycryptodome"],
tests_require=["pytest"],
python_requires=">=3.6",
test_suite="tests"
Expand Down

0 comments on commit e9b4fb8

Please sign in to comment.