Android to Mac Verification Code Relay with E2E Encryption and No Cloud
🥳 Never Have to Pick Up Your Phone to Copy a Verification Code Again! I Made an Android → Mac "Verification Relay" Tool
Preface
Maybe I'm someone who likes tinkering with small tools. Whenever I run into a problem that isn't serious but repeats every day, I always want to write something to fix it.
This time the problem is very simple: when I'm logging into a website on my Mac, the verification code is on my Android phone.
The normal flow goes like this: wake the phone → unlock → open SMS → remember the six digits → go back to the Mac → enter the code. Sometimes I remember only the first three digits, and when I switch back, I've forgotten the last three, so I have to pick up the phone again 🥲.
Once or twice is no big deal, but after it happens several times a day, "lazy spirit" kicks in: since the phone and Mac are on the same Wi-Fi, why can't the code just walk over to the Mac on its own?
So Verification Relay was born 🥳!
🎯 After the Android phone receives an SMS verification code, it only extracts the code and sender name, and sends them end-to-end encrypted over the same LAN to the Mac.
🔒 No cloud server is used, no full SMS is uploaded, and the device private keys on both phone and Mac never leave their own devices.
🍎 The Mac side is a menu bar app. Once a code arrives, you can copy it with one click, and it disappears from the interface after expiry.
- Online site: Verification Relay
- GitHub: ox4f5da2/VerificationRelay, give it a 🌟 if you find it useful
- 28-second demo video: Click to view
Quick Installation
Install the Mac App
- Open the project's Releases page.
- Download
OtpBridge-macOS.zipand unzip it. - Drag "Verification Relay.app" into the "Applications" folder.
- On first launch, allow Local Network and Notification permissions.
The Mac version only appears in the status bar, not in the Dock. Closing the main window does not quit the app; to fully quit, click "Quit" in the status bar menu.
The current automatic build uses ad-hoc signing and has not been notarized by Apple. If macOS blocks the first launch, confirm the package is from the project's Release, then right-click the app in Finder and choose "Open."
Install the Android App
- Download
VerificationRelay-Android.apkfrom the Releases page. - Allow the browser or file manager to "Install unknown apps."
- Tap the APK to complete installation.
If ADB is already configured on your computer, you can also use this command:
adb install -r -g VerificationRelay-Android.apk
Here -r means overwrite upgrade and preserves existing pairing and settings.
Getting Started
The whole setup is just four steps:
- Confirm the Android phone and Mac are on the same Wi-Fi.
- Open the Mac app and generate a QR code in the "Connect & Pair" page.
- Open the Android app and tap "Scan Mac pairing QR code."
- Grant SMS permission, then tap "Send test verification code."
If the Mac successfully displays the test code 123456, the whole relay chain is ready 🚀.
The QR code only contains a one-time pairing token that is valid for 5 minutes and becomes invalid after one use. If the code expires, tap "Generate new pairing code."
Feature Showcase
Automatic Verification Code Extraction
After Android receives a new SMS, it looks for 4-8 digit numbers locally on the phone and combines them with keywords like "验证码" (verification code), "校验码" (check code), "OTP", "code", etc. to make a judgment.
The app only sends the extracted code and sender name; it never sends the full SMS to the Mac.
To be compatible with systems that impose strict SMS permission restrictions, I also made a "Notification Read (fallback)" channel. However, this channel only processes notifications from the system's current default SMS app; notifications from WeChat, Alipay, email, and other apps are not parsed.
Secure QR Pairing
On first use, the Mac generates a one-time QR code valid for five minutes. After the Android scans it, the two devices exchange public keys and complete pairing.
An important design decision here: the QR code contains no private keys.
The Mac's private key is stored in the macOS Keychain, and the Android private key is stored in the phone's local encrypted storage. The QR code only carries the one-time pairing token, device information, and data needed to establish the connection.
Dual-Sided Online Diagnostics
The most annoying thing about cross-device tools is often not "whether they run," but not knowing where it got stuck when something goes wrong.
So the Android home screen shows at the same time:
- Whether the Mac is paired;
- Whether the Mac's receiving service is available;
- Whether SMS permission is granted;
- Whether the notification-read fallback channel is enabled;
- Whether the Android background service is running;
- The status of the last operation.
The Mac side also shows whether the phone service is "online" or "no service found." At least when the verification code doesn't appear, you don't have to guess which end is broken 😃.
One-Click Copy in Mac Status Bar
After the code arrives, the status bar menu automatically expands and shows the code and sender name. Click the copy button and you can paste it directly into a browser or other app.
System notifications serve as a supplementary reminder. After the code expires, it is automatically cleared from the interface, so old codes don't stay on the desktop.
Paired Devices and Key Management
The Mac side can view already paired Android phones, pairing time, and online status, and can remove a specific device.
In "Security Settings," you can also view the device ID, public key fingerprint, or reset the entire device key. After resetting, all phones need to re-scan the QR code to pair, but the APK installation signature is unaffected.
Extra Setup for Domestic Android Devices
Some Xiaomi, Redmi, POCO, OPPO, vivo, Honor and other models add an extra "notification SMS" or "verification SMS" permission on top of the standard Android SMS permission.
If the relay works normally in normal state but no longer receives codes after the screen is locked, check the following in order:
- Whether "Receive SMS" is allowed;
- Whether "Notification SMS / verification SMS" is allowed;
- Whether auto-start is enabled;
- Whether background activity is allowed;
- Whether the battery policy is set to "Unrestricted";
- Whether the phone and Mac are still on the same Wi-Fi.
Note that after the phone restarts, before the first unlock, Android's credential-encrypted storage is not yet available, so the relay won't forward codes at that time. It recovers after one unlock; this is different from a normal lock screen.
Why Stick with No Cloud Server?
Verification codes themselves are very sensitive information. If to avoid picking up the phone once, I had to send the full SMS to some remote server, I don't think that trade is worth it.
So from the start, this project set several principles:
- The phone and Mac only communicate directly on the same LAN;
- No account system, no login required;
- No upload of full SMS; only the code and sender name are sent;
- Each device independently generates its own private key, and private keys are never sent over the network;
- Even if LAN traffic is intercepted, the code content cannot be directly read.
The encryption combination currently used is:
P-256 ECDH
↓
HKDF-SHA256 derives a 32-byte session key
↓
AES-256-GCM authenticated encryption of the code message
Code Implementation
Extracting the Code Locally on Android
The code extractor looks for standalone 4-8 digit numbers and combines them with common keywords:
private static final Pattern DIGITS =
Pattern.compile("(?<![A-Za-z0-9])([0-9]{4,8})(?![A-Za-z0-9])");
private static final String[] KEYWORDS = {
"验证码", "校验码", "动态码", "认证码",
"一次性密码", "otp", "verification", "code", "passcode"
};
public static String extract(String text) {
if (text == null || text.isBlank()) return null;
Matcher matcher = DIGITS.matcher(text);
if (!matcher.find()) return null;
String firstMatch = matcher.group(1);
String lower = text.toLowerCase(Locale.ROOT);
for (String keyword : KEYWORDS) {
if (lower.contains(keyword)) return firstMatch;
}
return firstMatch;
}
All SMS parsing happens locally on the Android; only after extraction does it enter the encryption and sending flow.
Discovering the Mac on the LAN
The Mac uses Bonjour / DNS-SD to broadcast the receiving service, and Android uses NsdManager to automatically discover the service, so users don't have to manually enter an IP and port.
manager.discoverServices(
serviceType,
NsdManager.PROTOCOL_DNS_SD,
discoveryListener
);
After discovering the service, Android resolves the Mac's LAN address and port, then establishes a connection. If the service isn't discovered within the timeout, it prompts the user to check Wi-Fi and background running status.
Deriving the Session Key
After the two devices complete P-256 ECDH, they don't use the shared secret directly as the encryption key. Instead, they use HKDF-SHA256 to derive a fixed-length session key:
let secret = try privateKey.sharedSecretFromKeyAgreement(with: publicKey)
let deviceIDs = [localDeviceID, peerDeviceID]
.sorted()
.joined(separator: ":")
return secret.hkdfDerivedSymmetricKey(
using: SHA256.self,
salt: Data(deviceIDs.utf8),
sharedInfo: BridgeProtocol.keyInfo,
outputByteCount: 32
)
Then AES-GCM encrypts the message and includes the device ID as additional authenticated data:
let sealed = try AES.GCM.seal(
plaintext,
using: key,
authenticating: Data(authenticatedDeviceID.utf8)
)
This protects both the content of the code and verifies that the message hasn't been modified and that it comes from the expected device.
Mac Receiving Service
The Mac uses Network.framework to create a TCP listener and publishes the service to the LAN:
let listener = try NWListener(using: .tcp)
listener.service = NWListener.Service(
name: serviceName,
type: BridgeProtocol.serviceType
)
listener.newConnectionHandler = { connection in
accept(connection)
}
listener.start(queue: queue)
When a message is received, it first checks the protocol version and device pairing status, then derives the session key and decrypts. Only already paired devices can send valid codes.
Problems Encountered During Development
Background Operation Is Harder to Handle Than the Foreground Page
At the beginning of testing, everything worked fine when the Android app was open, but after the screen locked for a while, the service might be paused by the system. Different manufacturers handle background activity, auto-start, and battery optimization differently.
In the end, I had to implement a foreground service, recovery on boot, online status diagnostics, and clearly document in the README which vendor permissions users need to check.
"Notification Read" Fallback Can't Read Everything
Notification listening permission is very powerful. If you naively scan all notifications, numbers in WeChat, email, or even payment apps could be misidentified.
So the fallback channel checks the notification source and only accepts notifications from the system's current default SMS app. Better to support fewer scenarios than to broaden the read scope.
Pairing QR Codes Can't Be Valid Forever
If the QR code were valid indefinitely, a screenshot leak could be reused. So the pairing token has a five-minute validity period and becomes invalid immediately after one successful use. To add another phone, you must generate a new QR code.
Author's Words
The starting point of this project is very simple: I just don't want to pick up my phone to copy a verification code every time I log in.
But when I actually built it, I realized that a feature that looks like just "sending six digits over" actually involves LAN discovery, cross-platform communication, device identity, key management, authenticated encryption, Android background limitations, macOS menu bar interaction, and other problems.
The project is now open source, with a complete official site and demo video. If you're an Android + Mac user, feel free to try it out! If you find it useful, please give a ⭐ on GitHub, and feel free to file Issues for bugs or new ideas 🥺.
- Website: https://ox4f5da2.github.io/VerificationRelay/
- GitHub: https://github.com/ox4f5da2/VerificationRelay
- Releases: https://github.com/ox4f5da2/VerificationRelay/releases
If you're interested in Android/macOS LAN communication, end-to-end encryption, or menu bar app development, I can later write a more detailed development post 😌.
Future plans:
- Implement auto-filling verification codes into input fields.
- Any other good ideas or suggestions can be discussed in the comments. The author doesn't have a Windows computer or iOS phone, so a cross-platform adaptation isn't possible at the moment.
Top 1 of 2 from juejin.cn, machine-translated. The original thread is authoritative.
Actually, many Android vendors already have apps on the Mac side for phone–Mac syncing, but the key apps are all really large. With this app, I think the tricky part is still Android app background persistence: sometimes even after you've granted all permissions and fully allowed background activity, there can still be anomalies. Also, consider splitting the APK workflow into separate v7 and v8 builds to further reduce the package size.
What are the specific signs of this anomaly?