Commit 7c4ac58
authored
sign_request previously stripped the query string but left any '#fragment'
intact. httpx drops fragments from the request-target before transmission
(RFC 3986 §3.5), so the SDK was signing /path#frag while httpx sent /path —
a guaranteed signature mismatch surfacing as a 401 KalshiAuthError with no
hint that a stray '#' was the cause. The canonicalization now applies the
same shape as the existing '?' strip.
The RSA-PSS / MGF1 / SHA256 configuration objects are pure immutable
algorithm descriptors. They were being reallocated on every signature; for
a high-RPS client the per-call Python-object churn is wasted work. They
are now bound once at module import as _SHA256 / _PSS_PADDING and reused.
The cryptography library explicitly supports reuse of these instances.
Regression tests verify (a) signatures for fragment-bearing paths verify
against the fragment-stripped canonical message — the right oracle since
PSS uses a random salt and is non-deterministic — and (b) the cached
config objects retain identity across sign_request calls.
Closes #317, #345
1 parent b0861eb commit 7c4ac58
2 files changed
Lines changed: 72 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
| |||
262 | 271 | | |
263 | 272 | | |
264 | 273 | | |
265 | | - | |
| 274 | + | |
| 275 | + | |
266 | 276 | | |
267 | 277 | | |
268 | 278 | | |
| |||
271 | 281 | | |
272 | 282 | | |
273 | 283 | | |
274 | | - | |
275 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
276 | 288 | | |
277 | 289 | | |
278 | 290 | | |
| |||
287 | 299 | | |
288 | 300 | | |
289 | 301 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 302 | + | |
| 303 | + | |
295 | 304 | | |
296 | 305 | | |
297 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
795 | 795 | | |
796 | 796 | | |
797 | 797 | | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
0 commit comments