Onionprobe package¶
Onionprobe: test and monitoring for Onion Services.
app
¶
Onionprobe
¶
Bases: OnionprobeInit
, OnionprobeConfig
, OnionprobeLogger
, OnionprobeTime
, OnionprobeTor
, OnionprobeDescriptor
, OnionprobeMetrics
, OnionprobeProber
, OnionprobeHTTP
, OnionprobeTLS
, OnionprobeCertificate
, OnionprobeTeardown
, OnionprobeMain
Onionprobe class to test and monitor Tor Onion Services
Source code in packages/onionprobe/app.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
finish(status=0)
¶
Stops Onionprobe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status |
Exit status code. |
0
|
Source code in packages/onionprobe/app.py
60 61 62 63 64 65 66 67 68 69 70 71 |
|
finish_handler(signal, frame)
¶
Wrapper around finish() for handling system signals
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal |
Signal number. |
required | |
frame |
Current stack frame. |
required |
Source code in packages/onionprobe/app.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
run(args)
¶
Run Onionprobe from arguments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Instance arguments. |
required |
Source code in packages/onionprobe/app.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
run_from_cmdline()
¶
Run Onionprobe getting arguments from the command line.
Source code in packages/onionprobe/app.py
135 136 137 138 139 140 141 142 |
|
certificate
¶
OnionprobeCertificate
¶
Onionprobe class with X.509 Certificate methods.
Source code in packages/onionprobe/certificate.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
get_cert_info(cert, format='tree')
¶
Get basic information from a X.509 certificate.
This method is compatible with SSLSocket.geetpeercert, with the advantage that it does not require a valid certificate in order to process it's data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cert |
The X.509 Certificate object. |
required | |
format |
The output format, either 'tree' or 'flat'. The 'tree' format is the same as returned returned by SSLSocket.getpeercert and accepted by ssl.match_hostname. The 'flat' format uses just one level of key-value pairs, and all values are strings, and is accepted by Prometheus info metrics. |
'tree'
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary with basic certificate information in the same format returned by SSLSocket.getpeercert and accepted by ssl.match_hostname, additionally with certificate fingerprints. |
Source code in packages/onionprobe/certificate.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
get_cert_rdns(cert, field='issuer', format='tuple')
¶
Get the Relative Distinguished Names (RDNs) from a given X.509 certificate field like issuer or subject.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
The name of the X.509 certificate field ('issuer' or 'subject'). |
'issuer'
|
format |
The output format, either 'list' or 'tuple' in the same format returned by SSLSocket.getpeercert and accepted by ssl.match_hostname. |
'tuple'
|
|
cert |
The X.509 Certificate object. |
required |
Returns:
Type | Description |
---|---|
dict | tuple
|
The dict or tuple with the certificate's DNS Subject Alternative Names. |
Source code in packages/onionprobe/certificate.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
get_certificate(endpoint, config, tls)
¶
Get the certificate information from a TLS connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
The endpoint name from the 'endpoints' instance config. |
required | |
config |
Endpoint configuration |
required | |
tls |
The TLS socket connection to the endpoint. |
required |
Returns:
Type | Description |
---|---|
cryptography.x509.Certificate | False
|
The X.509 certificate object on success. False on error. |
Source code in packages/onionprobe/certificate.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
get_certificate_expiration(cert)
¶
Get the number of seconds remaining before a X.509 certificate expires, or the number of seconds passed since it's expiration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cert |
The X.509 Certificate object. |
required |
Returns:
Type | Description |
---|---|
int
|
Number of seconding remaining before the certificate expiration (if positive) or the number of seconds passed since the expiration (if negative). |
Source code in packages/onionprobe/certificate.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
get_dns_alt_names_from_cert(cert, format='tuple')
¶
Get the DNS names from a X.509 certificate's SubjectAltName extension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cert |
The X.509 Certificate object. |
required | |
format |
The output format, either 'list' or 'tuple' in the same format returned by SSLSocket.getpeercert and accepted by ssl.match_hostname. |
'tuple'
|
Returns:
Type | Description |
---|---|
list | tuple
|
The list or tuple with the certificate's DNS Subject Alternative Names. |
Source code in packages/onionprobe/certificate.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
config
¶
OnionprobeConfig
¶
Onionprobe class with configuration-related methods.
Source code in packages/onionprobe/config.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
get_config(item, default=None)
¶
Helper to get instance configuration
Retrieve a config parameter from the self.config object or use a default value as fallback
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
Configuration item name |
required | |
default |
Default config value to be used as a fallback if there's no self.config[item] available. Defaults to None |
None
|
Returns:
Type | Description |
---|---|
The configuration parameter value or the default fallback value. |
Source code in packages/onionprobe/config.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
OnionprobeConfigCompiler
¶
Base class to build Onionprobe configs from external sources of Onion Services
Source code in packages/onionprobe/config.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
|
__init__(databases, config_template, output_folder, wait=0, config_overrides=None, loop=False)
¶
Constructor for the OnionprobeConfigCompiler class.
Loads the default Onionprobe configuration to be used as a template.
Keeps the dictionary of Onion Services databases as a class attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
databases |
Dictionary of data sources to fetch .onion sites. Format is { 'database_name': 'database_url' } |
required | |
config_template |
Configuration file path to be used as template |
required | |
output_folder |
Output folder where configs are written |
required |
Source code in packages/onionprobe/config.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
build_and_wait()
¶
Build Onionprobe configs, then wait.
Source code in packages/onionprobe/config.py
483 484 485 486 487 488 489 490 491 492 493 494 |
|
build_endpoints_config(database)
¶
Build the Onion Service endpoints dictionary.
This method is only a placeholder.
By default this method returns an empty dictionary as it's meant to be overriden by specific implementations inheriting from the OnionprobeConfigCompiler base class and where custom logic for extracting .onion endpoints from external databases should be located.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database |
A database name from the databases dictionary. This parameter allows accesing the URL of the external database from the self.databases class attribute. |
required |
Returns:
Type | Description |
---|---|
dict
|
Onion Service endpoints in the format accepted by Onionprobe. |
Source code in packages/onionprobe/config.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
build_onionprobe_config()
¶
Build an Onionprobe config.
Writes an Onionprobe-compatible configuration file for each database listed in self.databases attribute.
The Onion Service endpoints are generated from the build_endpoints_config() methods. To be effective, it's required that classes inheriting from this base class to implement the build_endpoints_configs() method.
The filenames ared derived from the database names (each key from the self.databases attribute).
Source code in packages/onionprobe/config.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
compile()
¶
Main compilation procedure.
Source code in packages/onionprobe/config.py
496 497 498 499 500 501 502 503 504 505 506 |
|
cmdline()
¶
Evalutate the command line.
Returns:
Type | Description |
---|---|
argparse.Namespace
|
Command line arguments. |
Source code in packages/onionprobe/config.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
cmdline_compiler(default_source=None)
¶
Evalutate the command line for the configuration compiler.
Returns:
Type | Description |
---|---|
argparse.Namespace
|
Command line arguments. |
Source code in packages/onionprobe/config.py
578 579 580 581 582 583 584 585 586 587 588 589 |
|
cmdline_parser()
¶
Generate command line arguments
Returns:
Type | Description |
---|---|
argparse.ArgumentParser
|
The parser object |
Source code in packages/onionprobe/config.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
cmdline_parser_compiler(default_source=None)
¶
Generate command line arguments for the configuration compiler
Returns:
Type | Description |
---|---|
argparse.ArgumentParser
|
The parser object |
Source code in packages/onionprobe/config.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
|
descriptor
¶
OnionprobeDescriptor
¶
Onionprobe class with Tor descriptor-related methods.
Source code in packages/onionprobe/descriptor.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
get_descriptor(endpoint, config, attempt=1)
¶
Get Onion Service descriptor from a given endpoint
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
The endpoint name from the 'endpoints' instance config. |
required | |
config |
Endpoint configuration |
required |
Returns:
Type | Description |
---|---|
stem.descriptor.hidden_service.InnerLayer | False
|
The Onion Service descriptor inner layer on success. False on error. |
Source code in packages/onionprobe/descriptor.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
get_endpoint_by_pubkey(pubkey)
¶
Get an endpoint configuration given an Onion Service pubkey.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pubkey |
Onion Service pubkey |
required |
Returns:
Type | Description |
---|---|
tuple | False
|
Endpoint name and configuration if a match is found. False otherwise. |
Source code in packages/onionprobe/descriptor.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
get_pubkey_from_address(address)
¶
Extract .onion pubkey from the address
Leaves out the .onion domain suffix and any existing subdomains.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
Onion Service address |
required |
Returns:
Type | Description |
---|---|
str
|
Onion Service public key |
Source code in packages/onionprobe/descriptor.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
hsdesc_event(event)
¶
Process HS_DESC events.
Sets the onion_service_descriptor_reachable metric.
See https://spec.torproject.org/control-spec/replies.html#HS_DESC https://spec.torproject.org/control-spec/replies.html#HS_DESC_CONTENT
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream |
HS_DESC event |
required |
Source code in packages/onionprobe/descriptor.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
parse_pow_params(inner_text, labels)
¶
Parse the Proof of Work (PoW) parameters from a descriptor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inner_text |
The decrypted raw inner descriptor layer plaintext for the endpoint. |
required | |
labels |
Metrics labels |
required |
Returns:
Type | Description |
---|---|
None
|
This method does not return any special value. |
Source code in packages/onionprobe/descriptor.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
http
¶
OnionprobeHTTP
¶
Onionprobe class with HTTP methods.
Source code in packages/onionprobe/http.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
build_url(config, path=None)
¶
Build an Onion Service URL to be probed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Endpoint configuration |
required | |
path |
The path to be chosen in the endpoint configuration. |
None
|
Returns:
Type | Description |
---|---|
str
|
The Onion Service URL for the given config and path |
Source code in packages/onionprobe/http.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
query_http(endpoint, config, path, attempt=1)
¶
Fetches endpoint from URL
Tries an HTTP connection to the URL and update metrics when needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
The endpoint name from the 'endpoints' instance config. |
required | |
config |
Endpoint configuration |
required | |
path |
A path dictionary from the endpoint configuration. |
required | |
attempt |
The current attempt used to determine the maximum number of retries. |
1
|
Returns:
Type | Description |
---|---|
requests.Response | False
|
The query result on success. False on error. |
Source code in packages/onionprobe/http.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
init
¶
OnionprobeInit
¶
Source code in packages/onionprobe/init.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
__init__(args)
¶
Onionprobe class constructor.
Setup instance configuration.
Handles command-line parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Instance arguments. |
required |
Source code in packages/onionprobe/init.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
initialize()
¶
Onionprobe initialization procedures
Initializes all Onionprobe subsystems, like the random number generator, logging, metrics and a Tor daemon instance.
Returns:
Type | Description |
---|---|
bol
|
True if initialization is successful, False on error |
Source code in packages/onionprobe/init.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
logger
¶
OnionprobeLogger
¶
Onionprobe class with logging methods.
Source code in packages/onionprobe/logger.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
initialize_logging()
¶
Initialize Onionprobe's logging subsystem
Returns:
Type | Description |
---|---|
bol
|
True if initialization is successful, False on error |
Source code in packages/onionprobe/logger.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
log(message, level='info')
¶
Helper log function
Appends a message into the logging subsystem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
The message to be logged. |
required | |
level |
The log level. Defaults to 'info'. For the available log levels, check https://docs.python.org/3/howto/logging.html#logging-levels |
'info'
|
Source code in packages/onionprobe/logger.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
main
¶
OnionprobeMain
¶
Onionprobe class with main application logic.
Source code in packages/onionprobe/main.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
round()
¶
Process a round of probes
Each round is composed of the entire set of the endpoints which is optionally shuffled.
Each endpoint is then probed.
Returns:
Type | Description |
---|---|
bol
|
True on success, false if at least one of the probes fails. |
Source code in packages/onionprobe/main.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
run()
¶
Main application loop
Checks if should be run indefinitely. Then dispatch to a round of probes.
If runs continuously, waits before starting the next round.
If not, just returns.
Returns:
Type | Description |
---|---|
bol
|
True on success, false if at least one of the probes fails. |
Source code in packages/onionprobe/main.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
metrics
¶
OnionprobeMetrics
¶
Onionprobe class with metrics methods.
Source code in packages/onionprobe/metrics.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
inc_metric(metric, value=1, labels={})
¶
Increment a metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
Metric name |
required | |
value |
Increment value. Defaults to 1. |
1
|
|
labels |
Metric labels dictionary. Defaults to an empty dictionary. |
{}
|
Source code in packages/onionprobe/metrics.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
|
info_metric(metric, value, labels={})
¶
Set an info metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
Metric name |
required | |
value |
Increment value. |
required | |
labels |
Metric labels dictionary. Defaults to an empty dictionary. |
{}
|
Source code in packages/onionprobe/metrics.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
initialize_metrics()
¶
Initialize the metrics subsystem
It uses Prometheus metrics even if the Prometheus exporter is not in use.
This means that the Prometheus metrics are always used, even if only for internal purposes, saving resources from preventing us to build additional metric logic.
Source code in packages/onionprobe/metrics.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
|
initialize_prometheus_exporter()
¶
Initialize the Prometheus Exporter
Source code in packages/onionprobe/metrics.py
496 497 498 499 500 501 502 503 504 505 506 |
|
set_metric(metric, value, labels={})
¶
Set a metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
Metric name |
required | |
value |
Metric value |
required | |
labels |
Metric labels dictionary. Defaults to an empty dictionary. |
{}
|
Source code in packages/onionprobe/metrics.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
state_metric(metric, value, labels={})
¶
Set a metric state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
Metric name |
required | |
value |
Increment value. |
required | |
labels |
Metric labels dictionary. Defaults to an empty dictionary. |
{}
|
Source code in packages/onionprobe/metrics.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
prober
¶
OnionprobeProber
¶
Onionprobe class with probing methods.
Source code in packages/onionprobe/prober.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
probe(endpoint)
¶
Probe an unique endpoint
Checks for a valid and published Onion Service descriptor for the endpoint.
Then probes each path configured for the endpoint, storing the results in a dictionary.
Ensure that each probe starts with a cleared Stem Controller cache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
The endpoint name from the 'endpoints' instance config. |
required |
Returns:
Type | Description |
---|---|
dict | False
|
A dictionary of results for each path configured for the endpoint. False in case of Onion Service descriptor error. |
Source code in packages/onionprobe/prober.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
teardown
¶
OnionprobeTeardown
¶
Onionprobe class with methods related to... stop running!
Source code in packages/onionprobe/teardown.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
close()
¶
Onionprobe teardown procedure.
Change the internal metrics state to running.
Stops the built-in Tor daemon.
Source code in packages/onionprobe/teardown.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
time
¶
OnionprobeTime
¶
Onionprobe class with timing-related methods.
Source code in packages/onionprobe/time.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
elapsed(init_time, verbose=False, label='')
¶
Calculate the time elapsed since an initial time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init_time |
Initial time. |
required | |
verbose |
If verbose is True, logs the elapsed time. Defaults to False. |
False
|
|
label |
A label to add in the elapsed time log message. Only used if verbose is set to true. Defaults to an empty string. |
''
|
Returns:
Type | Description |
---|---|
int
|
Number of elapsed time in seconds |
Source code in packages/onionprobe/time.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
now()
¶
Wrapper around datetime.now()
Returns:
Type | Description |
---|---|
datetime.datetime
|
Current time. |
Source code in packages/onionprobe/time.py
32 33 34 35 36 37 38 39 40 |
|
timestamp()
¶
Wrapper around datetime.now().timestamp()
Returns:
Type | Description |
---|---|
datetime.datetime
|
Current time. |
Source code in packages/onionprobe/time.py
92 93 94 95 96 97 98 99 100 |
|
wait(value)
¶
Helper to wait some time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Number of seconds to wait. |
required |
Source code in packages/onionprobe/time.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
tls
¶
OnionprobeTLS
¶
Onionprobe class with TLS methods.
Source code in packages/onionprobe/tls.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
query_tls(endpoint, config, attempt=1)
¶
Tries a TLS connection to the endpoint and update metrics when needed.
This method does not make any certificate verification upfront when connecting to the remote endpoint. This is on purpose, since this is just a test procedure to get TLS and certificate information.
Certificate validity check is already done at OnionprobeHTTP.query_http().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
The endpoint name from the 'endpoints' instance config. |
required | |
config |
Endpoint configuration |
required | |
attempt |
The current attempt used to determine the maximum number of retries. |
1
|
Returns:
Type | Description |
---|---|
bool
|
True if the connection succeeded. False on error. |
Source code in packages/onionprobe/tls.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
tor
¶
OnionprobeTor
¶
Onionprobe class with Tor-related methods.
Source code in packages/onionprobe/tor.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
gen_control_password()
¶
Generates a random password
Returns:
Type | Description |
---|---|
str
|
A random password between 22 and 32 bytes |
Source code in packages/onionprobe/tor.py
143 144 145 146 147 148 149 150 151 152 153 |
|
hash_password(password)
¶
Produce a hashed password in the format used by HashedControlPassword
It currently relies on spawning a "tor --hash-password" process so it suffering from the security issue of temporarily exposing the unhashed password in the operating system's list of running processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password |
A password to be hashed |
required |
Returns:
Type | Description |
---|---|
str
|
The hashed password |
Source code in packages/onionprobe/tor.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
initialize_listeners()
¶
Initialize Tor event listeners
Source code in packages/onionprobe/tor.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
initialize_tor()
¶
Initialize Tor control connection
Returns:
Type | Description |
---|---|
bol
|
True if initialization is successful, False on error |
Source code in packages/onionprobe/tor.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
initialize_tor_auth()
¶
Initialize an authenticated Tor control connection
Returns:
Type | Description |
---|---|
bol
|
True if initialization is successful, False on error |
Source code in packages/onionprobe/tor.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
launch_tor()
¶
Launch a built-in Tor process
See https://stem.torproject.org/tutorials/to_russia_with_love.html https://stem.torproject.org/api/process.html
Source code in packages/onionprobe/tor.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
new_circuit(stream)
¶
Setup a fresh Tor circuit for new streams
See https://stem.torproject.org/tutorials/to_russia_with_love.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream |
Stream event |
required |
Source code in packages/onionprobe/tor.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|