Some Korean banking websites still expect a handful of proprietary security programs to be running on your computer. The page doesn’t reach them over the internet. It calls them on fixed localhost ports and asks for device information, installation status, a stamp for each request and an encrypted log of the machine. That works until the programs no longer support the operating system you use.
I wanted a small, maintainable compatibility service that could answer those calls without shipping anybody else’s binaries, certificates or private keys. It ended up as one Rust program that listens only on 127.0.0.1 and gives the bank pages the requests and responses they expect. I run it on macOS and Linux. The Windows build passes the same tests in CI, but I haven’t tried it against a bank page on a real Windows machine yet.
I used two AI tools, for two different jobs. Kimi helped me work out the protocols and prove a Python implementation against the real sites. Claude helped turn that working Python into the Rust program. Neither tool stood in for the other, and neither stood in for testing. The reverse engineering produced a specification, and the rewrite had to keep to it.
The rules came first#
This was an interoperability project on my own machine, not an attempt to defeat a bank’s controls. These are the rules the program keeps:
- It contains no proprietary executables, no captured private keys and no vendor certificates.
- The device facts it reports are the current machine’s real ones, and it generates fresh values for each request.
- Every service stays on loopback, behind a local certificate authority that belongs to one user and can sign only for the loopback names.
- Anything it doesn’t implement is refused. There are no convincing placeholder successes.
- The bank’s server is the authority on what’s acceptable. A payload I can decrypt locally is a unit test, and it proves nothing about compatibility.
The rules made the project simpler as well as safer. I never needed a server to accept arbitrary data. I needed a client correct enough that the server would accept true data through the normal flow.
Mapping the protocol with Kimi#
Before writing a replacement, I needed to know what the browser really does.
Kimi read the login pages and their JavaScript, traced the localhost requests and grouped the calls by role. One program handles transaction stamps. Another collects device and network facts. Others report installation status, keyboard support or the result of an environment scan. Some calls are JSONP over HTTPS and others are WebSockets. The port numbers and response shapes can’t move, because the bank’s JavaScript already depends on them.
What came out of this stage was a protocol map, which is a lot more useful than a pile of captured traffic:
| Role | What the page expects from it |
|---|---|
| Stamp | A handshake, a stamp for each request, certificate setup and an encrypted log of the machine |
| Collector | Device and network facts, over HTTPS and WebSockets |
| Manager | Which of the required programs are installed, and their versions |
| Keyboard and keyguard | Version, health and keepalive replies |
| Scanner | Replies to an environment scan |
For each operation I wrote down the request parameters, the response envelope, the content type, the callback behaviour and what a failure looks like. Then each observation was reduced to a small pure function: a salted encoding here, a cipher layer there, an ordered list of device fields somewhere else.
Keeping protocol facts apart from implementation choices paid off later. Port numbers and field names are fixed by the protocol. The Python modules, the Rust crates and the error types were mine to choose.
Python as the executable specification#
Python was a good first language for this. Its cryptography libraries are convenient, byte manipulation is quick, and you can change a response and try the bank page again straight away. So the first working version was never a throwaway mock. It held everything I’d learned, in a form I could run.
Each protocol rule got a local test with synthetic inputs. For one bank’s encrypted device log, the tests generated a throwaway key and certificate, ran the encoder, and decrypted the result to check the field order and values. That caught plenty of encoding mistakes without going near a real account.
Then one failure showed why passing locally isn’t enough.
The request ID that was only right locally#
The log response looked right and decrypted correctly in the tests, but the bank rejected it with a security-program validation error. Rather than keep spending login attempts, Kimi compared fresh localhost responses from the bank’s own installed program with the ones my Python produced.
The outer envelope had the same shape in both, and so did the encrypted key. The request ID didn’t. The native program encrypted the ID with the session key before encoding it. Mine encrypted the device log but only encoded the ID.
With evidence that clear, the fix was small. The regression test now decrypts the request ID with the generated key, as it already did for the log. On the next real attempt the bank stopped returning the validation error and went on to check the ID and password. A later attempt completed the login.
That’s the loop I want an agent to follow when it reverse engineers something: observe, state one precise hypothesis, change one thing, test it locally, and only then make a single end-to-end check. It gets a lot further than asking for ten speculative fixes at once.
From observations to a Rust design with Claude#
Once the Python worked, the job changed, and I changed tools with it. Claude had nothing to discover. Its job was to keep the behaviour exactly as it was while the structure and the packaging improved.
The Rust code is split along the protocol’s own boundaries: a module for each role, one for the machine’s real operating-system and network facts, one for the cryptography and the local certificate authority, and one for the command line. Tokio, Hyper and Rustls do the async server and TLS work. Explicit result types mean a malformed certificate, a bad parameter or an unsupported operation fails on purpose. A lockfile pins the dependencies, and a toolchain file pins the compiler the releases are built with.
Rust also gives me one native executable for each operating system, so nobody needs a Python runtime or a PyInstaller bundle. The bundles had been the fragile part. The Intel Mac build wouldn’t start because the cryptography package no longer ships an Intel wheel: pip compiled it from source against a different OpenSSL from the one PyInstaller bundles. For people who already work in Python, a small PyO3 package exposes the same Rust program as a module and a command, and it doesn’t keep a second copy of the protocol logic.
I should be honest about what “modernised” means here. This wasn’t a benchmark-driven rewrite, and I’m not claiming a speed-up I haven’t measured. The goals were smaller artefacts, clearer ownership of concurrency and errors, reproducible native builds and less packaging to carry around. Python was the right tool for discovery. Rust is easier for me to ship and maintain.
The contract: new implementation, old behaviour#
A rewrite is only safe if you can say what mustn’t change. I checked that at three levels.
Golden bytes from Python#
A folder of test fixtures holds output from the Python version: an encoded device record, its compressed form, some cipher output, a certificate authority it minted and a few stamps. The Rust tests compare their own results with those bytes.
Fixtures like these answer questions that ordinary unit tests can quietly redefine. Does the compressed stream match what the C library behind the Python version produced, byte for byte? Is the field order intact? Does a certificate authority made by the earlier version still work when the new one renews the server certificate?
A request corpus across every role#
I ran the Python and Rust servers side by side against a corpus of 37 requests that covers every role and transport, refusals included. Similar JSON wasn’t enough to pass. Status lines, CORS headers, content types and bodies all had to be identical.
The refusals belong in that corpus. A replacement that returns success where the reference rejects a request has changed the security behaviour, and I don’t count that as compatible.
Real sockets and the built program#
On top of the unit tests there are socket tests and a smoke test of the release binary. The smoke test starts the real program, then requires its status command to find every fixed port answering with the new local certificate. CI lints and tests the Rust code on macOS, Linux and Windows, and builds the Python wheel as a separate job. The release workflow runs the tests again on each target, builds, smoke-tests what it built, and only then packages it.
Hardening is part of compatibility#
A local service that hands out device information is sensitive even though it never sees a password. Any website can name a localhost port in a script tag or a WebSocket, and CORS stops neither.
So the program checks the caller on every role and transport. It reads Origin, Referer and Sec-Fetch-Site, refuses an unexpected Host, and answers only the bank origins on its allow-list. The certificate authority can sign only for 127.0.0.1, localhost and the one hostname a stamp page calls. Its private key stays in the user’s data folder, and a throwaway container run never writes the key to disk at all.
Keyboard encryption and certificate signing aren’t implemented, so they return explicit errors. Nothing fabricates encrypted output, and nothing pretends an install or an update succeeded.
None of that was bolted on after the rewrite. It was already behaviour, so the rewrite had to carry it over.
The workflow, if you want to reuse it#
The split worked because each phase had its own definition of done.
- Map before you implement. Have the first agent read the browser code, the localhost calls and the request sequences that carry state, and keep what was observed apart from what’s still a guess.
- Build a small reference implementation. Python suited me: fast iteration, readable transforms and cryptographic round trips on synthetic data.
- Go to the real service sparingly. Compare fresh responses, isolate one mismatch, and don’t retry blind against something live.
- Freeze the behaviour as fixtures before you change languages: golden bytes, a request corpus and the failure cases, none of them secret.
- Let the second agent refactor against that contract. Ask it for module boundaries, typed errors, concurrency, packaging and CI, and don’t ask it to reinterpret the protocol.
- Test what you ship. That means the release binary on every target, which a library import or a clean compile won’t tell you about.
- Read the diff yourself. An agent can hold a lot of context, but it can’t decide your legal scope, your appetite for risk or what compatibility has to mean.
Separate git worktrees help when the exploring and the refactoring run in parallel. Without them, an exploratory edit and a structural rewrite can overwrite each other before the tests ever run. I wrote about that in Claude Code Worktrees.
What I would do again#
The prompts that worked best weren’t “reverse engineer this product” or “rewrite this in Rust”. They were a run of narrower jobs:
- Recover this request’s exact encoding and prove it with a local round trip.
- Explain the difference between the native response and the reference one, without guessing.
- Keep these bytes while replacing the implementation.
- Make the release fail if any behaviour changes.
That order also told me where a failure belonged. A protocol mismatch went back to discovery, a broken fixture to the rewrite, and a packaging failure to the release. Both tools were at their most useful when the evidence, and not their confidence, decided what happened next. Python sat between the two and gave each of them something concrete to keep to.
