forked from marcan2020/shc-decoder-poc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shc-decoder-poc.py
executable file
·31 lines (22 loc) · 2.16 KB
/
shc-decoder-poc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import base64
import re
import zlib
qr_data = "shc:/567629095243206034602924374044603122295953265460346029254077280433602870286471674522280928613331456437653141590640220306450459085643550341424541364037063665417137241236380304375622046737407532323925433443326057360104413333527570752435036945652955560456532134341275386403316824406473453857292204440900303559452952006826505600550339666359775936093042093843697708700410035935662630262131684000336442677526685945265961385654232160612010575336603372416830094368087268583034220858653868405566737300676125522604302403684570446967365009635270603428764571693256573264396370103435043129720355532071362041710338407377455561123629414403691039073772267629582653595341365920676509072704756762393223665909237432547227110341752758564033075344643024205259213433223275231145112344442077504133374423657738732465036268045333500372292428680305752055066161205908590727574039273565100365453467620676070466562374456011640503052612603433352534627643734526297670536641110369320974692670435941656559530672526365744144392929372455403655296826416910330331702770525959062807257522393924313335716156446225321038684203745070327705435227392923353242241273761130335734312154002724683467287609315543752975265426124341547269386510063170735444033524323109036562255462334100753044505239593704336853601144044303067643563009455908314400052367685333606845283543332368052172450304695777120961747623331028343573401038623404535367200023435327675723580300766876627154233043006804230025103369507231500670446306070903575832014453337756590712383705676069074064360005643067283632385063256409252323366162400606120354527428123073066511712009226844663207632755572431336840456368371037205910610777322474"
parts = re.findall("..", qr_data[5:])
jws = ""
for p in parts:
jws += chr(int(p)+ 45)
print("JWS:", jws)
def decode(data):
missing_padding = len(data) % 4
if missing_padding:
data += "="* (4 - missing_padding)
return base64.urlsafe_b64decode(data)
jws_parts = list(map(decode, jws.split(".")))
print("JWS Header:")
print(jws_parts[0])
# https://bugs.python.org/issue5784
shc_data = zlib.decompress(jws_parts[1], wbits=-15)
print("SHC Data:")
print(shc_data)