Debian Codegraph @

src/modules/auth_arnacon/README

raw
1 The Arnacon Authentication Module
2
3 Jonathan Kandel
4
5 Cellact B.V.
6 <[email protected]>
7
8 Copyright © 2025 Cellact B.V.
9 __________________________________________________________________
10
11 Table of Contents
12
13 1. Admin Guide
14
15 1. Overview
16 2. Technical Details
17
18 2.1. ENS Resolution
19 2.2. Signature Verification
20 2.3. Multi-Network Support
21 2.4. Security Features
22
23 3. Dependencies
24 4. Parameters
25
26 4.1. ens_registry_address (string)
27 4.2. rpc_url (string)
28 4.3. signature_timeout (integer)
29 4.4. debug_mode (integer)
30
31 5. Functions
32
33 5.1. arnacon_authenticate(ens, x_data, x_sign)
34 5.2. arnacon_user_exists(ens)
35
36 List of Examples
37
38 1.1. Setting the ens_registry_address parameter
39 1.2. Setting the rpc_url parameter
40 1.3. Setting the signature_timeout parameter
41 1.4. Setting the debug_mode parameter
42 1.5. arnacon_authenticate usage
43 1.6. arnacon_user_exists usage
44
45 Chapter 1. Admin Guide
46
47 Table of Contents
48
49 1. Overview
50 2. Technical Details
51
52 2.1. ENS Resolution
53 2.2. Signature Verification
54 2.3. Multi-Network Support
55 2.4. Security Features
56
57 3. Dependencies
58 4. Parameters
59
60 4.1. ens_registry_address (string)
61 4.2. rpc_url (string)
62 4.3. signature_timeout (integer)
63 4.4. debug_mode (integer)
64
65 5. Functions
66
67 5.1. arnacon_authenticate(ens, x_data, x_sign)
68 5.2. arnacon_user_exists(ens)
69
70 1. Overview
71
72 The Arnacon Authentication module provides ENS-based authentication for
73 Kamailio by verifying ENS domain ownership through cryptographic
74 signature validation. This module enables users to authenticate using
75 their ENS domains (e.g., user.cellact.global) instead of traditional
76 username/password combinations.
77
78 The module implements a secure authentication flow where clients sign a
79 message containing a UUID and timestamp, and the module verifies that
80 the signature comes from the current owner of the specified ENS domain.
81 This provides strong cryptographic authentication while maintaining
82 compatibility with existing SIP infrastructure.
83
84 Key features:
85 * ENS domain-based authentication
86 * ECDSA signature verification using secp256k1
87 * Support for both traditional and wrapped ENS domains
88 * Automatic ENS Name Wrapper detection and handling
89 * Configurable signature timeout for replay attack prevention
90 * Multi-network support (Polygon, Ethereum, custom networks)
91
92 2. Technical Details
93
94 2.1. ENS Resolution
95 2.2. Signature Verification
96 2.3. Multi-Network Support
97 2.4. Security Features
98
99 The module implements a comprehensive ENS-based authentication system
100 with the following technical features:
101
102 2.1. ENS Resolution
103
104 The module supports both traditional ENS ownership and wrapped domain
105 ownership:
106 * Direct ownership via ENS Registry contract
107 * Wrapped domain ownership via ENS Name Wrapper contract
108 * Automatic detection of wrapped vs traditional domains
109 * Zero address detection for unregistered domains
110
111 2.2. Signature Verification
112
113 Implements Ethereum-style message signing and verification:
114 * Ethereum message prefix handling (\x19Ethereum Signed Message:\n)
115 * ECDSA signature recovery using secp256k1
116 * Address recovery from signature for ownership verification
117 * Timestamp validation to prevent replay attacks
118
119 2.3. Multi-Network Support
120
121 * Primary support for Polygon network
122 * Configurable for Ethereum mainnet, testnets, or custom networks
123 * Custom RPC endpoint configuration
124 * Flexible contract address configuration for different networks
125
126 2.4. Security Features
127
128 Comprehensive security measures to ensure authentication integrity:
129 * Replay attack protection via timestamp validation
130 * Cryptographic signature verification
131 * ENS ownership verification against blockchain state
132 * Configurable signature timeout (default 30 seconds)
133
134 3. Dependencies
135
136 The following modules must be loaded before this module:
137 * none
138
139 External dependencies:
140 * libcurl - HTTP client library for blockchain RPC calls
141 * libsecp256k1 - cryptographic library for ECDSA signature operations
142
143 4. Parameters
144
145 4.1. ens_registry_address (string)
146 4.2. rpc_url (string)
147 4.3. signature_timeout (integer)
148 4.4. debug_mode (integer)
149
150 4.1. ens_registry_address (string)
151
152 ENS Registry contract address for the target blockchain network. This
153 contract is used to resolve ENS domain ownership and handle the initial
154 ownership lookup.
155
156 Common Addresses:
157 * Polygon: 0x16742E546bF92118F7dfdbEF5170E44C47ae254b
158 * Ethereum Mainnet: 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
159 * Ethereum Sepolia: 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
160
161 Default: "0x16742E546bF92118F7dfdbEF5170E44C47ae254b" (Polygon)
162
163 Example 1.1. Setting the ens_registry_address parameter
164 ...
165 modparam("auth_arnacon", "ens_registry_address", "0x16742E546bF92118F7dfdbEF5170
166 E44C47ae254b")
167 ...
168
169 4.2. rpc_url (string)
170
171 RPC endpoint URL for blockchain network communication. Used for all ENS
172 registry and contract calls via JSON-RPC eth_call method. The module
173 automatically detects and interacts with Name Wrapper contracts when
174 needed.
175
176 Common Endpoints:
177 * Polygon Mainnet: https://polygon-rpc.com
178 * Ethereum Mainnet: https://eth.drpc.org
179 * Ethereum Sepolia: https://ethereum-sepolia-rpc.publicnode.com
180
181 Default: "https://polygon-rpc.com"
182
183 Example 1.2. Setting the rpc_url parameter
184 ...
185 modparam("auth_arnacon", "rpc_url", "https://polygon-rpc.com")
186 ...
187
188 4.3. signature_timeout (integer)
189
190 Timeout in seconds for signature validation. Signatures older than this
191 timeout will be rejected to prevent replay attacks. The timestamp is
192 extracted from the X-Data header and compared against the current
193 system time.
194
195 Recommended Values:
196 * 30s - Default, balanced security and usability
197 * 60s - More lenient for slower networks
198 * 15s - Stricter security for high-security environments
199
200 Default: 30
201
202 Example 1.3. Setting the signature_timeout parameter
203 ...
204 modparam("auth_arnacon", "signature_timeout", 30)
205 ...
206
207 4.4. debug_mode (integer)
208
209 Enable debug logging for authentication operations. When enabled,
210 detailed information about ENS resolution, signature verification, and
211 authentication steps will be logged. Warning: May log sensitive
212 authentication data.
213
214 Values:
215 * 0 - Debug disabled
216 * 1 - Debug enabled
217
218 Default: 0
219
220 Example 1.4. Setting the debug_mode parameter
221 ...
222 modparam("auth_arnacon", "debug_mode", 1)
223 ...
224
225 5. Functions
226
227 5.1. arnacon_authenticate(ens, x_data, x_sign)
228 5.2. arnacon_user_exists(ens)
229
230 5.1. arnacon_authenticate(ens, x_data, x_sign)
231
232 Authenticates a user by verifying ENS domain ownership through
233 cryptographic signature validation. This function implements the core
234 authentication logic by resolving ENS ownership, recovering the
235 signer's address from the provided signature, and validating that the
236 signer owns the specified ENS domain.
237
238 Authentication Flow:
239 1. Resolve ENS domain ownership (handling both traditional and wrapped
240 domains)
241 2. Extract and validate timestamp from X-Data header
242 3. Recover Ethereum address from ECDSA signature
243 4. Compare recovered address with ENS domain owner
244
245 Parameters:
246 * ens (string) - ENS domain name (e.g., "user.cellact.global")
247 * x_data (string) - X-Data header value in format "UUID:TIMESTAMP"
248 (can be empty to extract from headers)
249 * x_sign (string) - X-Sign header value containing Ethereum signature
250 (can be empty to extract from headers)
251
252 Return Type: integer
253
254 Return codes:
255 * 1 - Authentication successful
256 * -1 - Authentication failed (invalid signature, ENS ownership
257 mismatch, timeout, or error)
258
259 This function can be used from REQUEST_ROUTE.
260
261 Example 1.5. arnacon_authenticate usage
262 ...
263 # Basic authentication with explicit parameters
264 if (arnacon_authenticate("$fU", "$hdr(X-Data)", "$hdr(X-Sign)")) {
265 xlog("L_INFO", "User $fU authenticated successfully\n");
266 # Allow registration/call
267 } else {
268 xlog("L_ERR", "Authentication failed for $fU\n");
269 sl_send_reply("403", "Forbidden");
270 exit;
271 }
272 ...
273
274 ...
275 # Automatic header extraction (pass empty strings)
276 if (arnacon_authenticate("$fU", "", "")) {
277 xlog("L_INFO", "ENS domain $fU authenticated\n");
278 # Proceed with request processing
279 } else {
280 sl_send_reply("403", "Forbidden");
281 exit;
282 }
283 ...
284
285 ...
286 # Complete authentication flow with error handling
287 route[AUTH] {
288 # Check if user exists first
289 if (!arnacon_user_exists("$fU")) {
290 xlog("L_ERR", "User $fU does not exist\n");
291 sl_send_reply("404", "User Not Found");
292 exit;
293 }
294
295 # Authenticate with headers
296 if (arnacon_authenticate("$fU", "$hdr(X-Data)", "$hdr(X-Sign)")) {
297 xlog("L_INFO", "User $fU authenticated successfully\n");
298 return;
299 } else {
300 xlog("L_ERR", "Authentication failed for $fU\n");
301 sl_send_reply("403", "Forbidden");
302 exit;
303 }
304 }
305 ...
306
307 5.2. arnacon_user_exists(ens)
308
309 Checks if an ENS domain has an owner, effectively verifying if the user
310 exists in the ENS system. This function performs ENS resolution to
311 determine if the domain is registered and has a valid owner address
312 (not the zero address).
313
314 Use Case: This function is useful for pre-authentication checks to
315 provide better error messages to clients and avoid unnecessary
316 authentication attempts for non-existent ENS domains.
317
318 ENS Resolution: The function handles both traditional ENS ownership
319 through the ENS Registry and wrapped domain ownership through the ENS
320 Name Wrapper contract, automatically detecting the appropriate
321 resolution method.
322
323 Parameters:
324 * ens (string) - ENS domain name to check
325
326 Return Type: integer
327
328 Return codes:
329 * 1 - User exists (ENS has a valid owner)
330 * -1 - User does not exist (ENS unregistered, zero owner, or error)
331
332 This function can be used from REQUEST_ROUTE.
333
334 Example 1.6. arnacon_user_exists usage
335 ...
336 # Basic user existence check
337 if (arnacon_user_exists("$fU")) {
338 xlog("L_INFO", "User $fU exists\n");
339 # Proceed with authentication
340 } else {
341 xlog("L_ERR", "User $fU does not exist\n");
342 sl_send_reply("404", "User Not Found");
343 exit;
344 }
345 ...
346
347 ...
348 # Pre-authentication validation
349 route[PREAUTH] {
350 if (!arnacon_user_exists("$fU")) {
351 xlog("L_WARN", "Authentication attempt for non-existent user: $fU\n");
352 sl_send_reply("404", "User Not Found");
353 exit;
354 }
355 xlog("L_INFO", "User $fU exists, proceeding with authentication\n");
356 }
357 ...
358
359 ...
360 # Registration flow with user existence check
361 if (is_method("REGISTER")) {
362 if (!arnacon_user_exists("$fU")) {
363 sl_send_reply("404", "ENS domain not registered");
364 exit;
365 }
366 # Continue with authentication
367 route(AUTH);
368 }
369 ...
370
371 Chapter 2. Frequently Asked Questions
372
373 2.1. How does ENS-based authentication work?
374 2.2. What networks are supported?
375 2.3. What are the X-Data and X-Sign headers?
376 2.4. How does the module handle wrapped ENS domains?
377 2.5. What happens if the blockchain network is unavailable?
378 2.6. Do SIP clients need special modifications?
379 2.7. How do I troubleshoot authentication failures?
380 2.8. What are the signature timeout considerations?
381 2.9. Is this suitable for production use?
382 2.10. What are the performance implications?
383 2.11. Can I use free RPC providers?
384
385 2.1.
386
387 How does ENS-based authentication work?
388
389 The module uses cryptographic signatures to verify ENS domain
390 ownership. Clients sign a message containing a UUID and timestamp with
391 their private key, then the module recovers the signer's address and
392 verifies it matches the current owner of the specified ENS domain.
393
394 2.2.
395
396 What networks are supported?
397
398 Primary Network: Polygon mainnet (default configuration)
399
400 Other Supported Networks: Ethereum mainnet, Ethereum Sepolia testnet,
401 or any EVM-compatible network with ENS contracts deployed.
402
403 Configuration: Set the appropriate RPC URL and contract addresses for
404 your target network in the module parameters.
405
406 2.3.
407
408 What are the X-Data and X-Sign headers?
409
410 X-Data: Contains authentication data in format "UUID:TIMESTAMP" where
411 UUID is a unique identifier and TIMESTAMP is Unix timestamp when the
412 signature was created.
413
414 X-Sign: Contains the Ethereum ECDSA signature of the X-Data value,
415 signed with the private key corresponding to the ENS domain owner's
416 address.
417
418 Example: X-Data: "550e8400-e29b-41d4-a716-446655440000:1640995200",
419 X-Sign: "0x1b2c3d4e5f6789abcdef..."
420
421 2.4.
422
423 How does the module handle wrapped ENS domains?
424
425 The module automatically detects wrapped ENS domains by first querying
426 the ENS Registry. If the owner is the Name Wrapper contract address, it
427 then queries the Name Wrapper contract to find the actual NFT owner.
428 This ensures compatibility with both traditional and wrapped ENS
429 domains.
430
431 2.5.
432
433 What happens if the blockchain network is unavailable?
434
435 Authentication will fail if the RPC endpoint is unreachable or returns
436 errors. For production deployments, use reliable RPC providers and
437 consider implementing fallback authentication mechanisms. The module
438 logs detailed error information when debug mode is enabled.
439
440 2.6.
441
442 Do SIP clients need special modifications?
443
444 Yes, clients need to be modified to generate the required X-Data and
445 X-Sign headers. Clients must implement Ethereum message signing
446 functionality and include the cryptographic signature in SIP requests.
447 Standard SIP digest authentication is not used.
448
449 2.7.
450
451 How do I troubleshoot authentication failures?
452
453 1. Enable debug mode: modparam("auth_arnacon", "debug_mode", 1)
454 2. Check Kamailio logs for detailed error information
455 3. Verify ENS domain ownership on blockchain explorer
456 4. Test RPC endpoint connectivity and response times
457 5. Verify contract addresses are correct for your network
458 6. Check signature format and timestamp validity
459
460 2.8.
461
462 What are the signature timeout considerations?
463
464 The signature timeout prevents replay attacks by rejecting signatures
465 older than the configured timeout (default 30 seconds). Consider
466 network latency and client clock synchronization when setting this
467 value. Shorter timeouts provide better security but may cause issues
468 with slow networks or unsynchronized clocks.
469
470 2.9.
471
472 Is this suitable for production use?
473
474 Yes, but consider these factors: blockchain network reliability (use
475 enterprise RPC providers), latency (blockchain calls add 100-500ms),
476 client implementation complexity (requires cryptographic capabilities),
477 and monitoring (implement comprehensive health checks).
478
479 Security Considerations: Ensure clients securely manage private keys,
480 use HTTPS for all RPC endpoints, implement proper timestamp validation,
481 and consider backup authentication for critical services.
482
483 2.10.
484
485 What are the performance implications?
486
487 Each authentication requires 1-2 blockchain RPC calls (ENS Registry +
488 potentially Name Wrapper), adding 100-500ms latency compared to
489 database authentication. The module performs cryptographic operations
490 locally (signature verification) which adds minimal overhead. Use
491 connection pooling and reliable RPC providers to minimize network
492 impact.
493
494 2.11.
495
496 Can I use free RPC providers?
497
498 Free providers work for development and testing but have rate limits
499 and no SLA guarantees. For production, use paid providers (Infura,
500 Alchemy, QuickNode) for better reliability, higher rate limits, and
501 support. Polygon mainnet has several reliable free options for
502 low-volume production use.
503
504 Recommended Providers:
505
506 Polygon Mainnet: https://polygon-rpc.com (free),
507 https://rpc.ankr.com/polygon (free)
508
509 Ethereum Mainnet: https://mainnet.infura.io/v3/YOUR_KEY (paid),
510 https://eth.drpc.org (free tier)