Get the list of current certificates from zgrab scans for the specified zones. Append any new entries to the provided array of current_certs. This currently does not check
(
mongo_connector, zgrab_collection, zone, current_certs
)
| 295 | |
| 296 | |
| 297 | def add_initial_zgrab_certificates( |
| 298 | mongo_connector, zgrab_collection, zone, current_certs |
| 299 | ): |
| 300 | """ |
| 301 | Get the list of current certificates from zgrab scans for the specified zones. |
| 302 | Append any new entries to the provided array of current_certs. |
| 303 | This currently does not check |
| 304 | """ |
| 305 | |
| 306 | results = mongo_connector.perform_find( |
| 307 | zgrab_collection, |
| 308 | { |
| 309 | "$or": [ |
| 310 | { |
| 311 | "data.http.redirect_response_chain.0.request.tls_handshake.server_certificates.certificate.parsed.subject.common_name": { |
| 312 | "$regex": r"^(.+\.)*" + zone + "$" |
| 313 | } |
| 314 | }, |
| 315 | { |
| 316 | "data.http.redirect_response_chain.0.request.tls_handshake.server_certificates.certificate.parsed.extensions.subject_alt_name.dns_names": { |
| 317 | "$regex": r"^(.+\.)*" + zone + "$" |
| 318 | } |
| 319 | }, |
| 320 | ] |
| 321 | }, |
| 322 | filter={"data.http.redirect_response_chain": 1}, |
| 323 | ) |
| 324 | |
| 325 | for result in results: |
| 326 | i = next( |
| 327 | ( |
| 328 | index |
| 329 | for (index, item) in enumerate(current_certs) |
| 330 | if item["id"] |
| 331 | == result["data"]["http"]["redirect_response_chain"][0]["request"][ |
| 332 | "tls_handshake" |
| 333 | ]["server_certificates"]["certificate"]["parsed"]["fingerprint_sha256"] |
| 334 | ), |
| 335 | None, |
| 336 | ) |
| 337 | if i is None: |
| 338 | item = { |
| 339 | "id": result["data"]["http"]["redirect_response_chain"][0]["request"][ |
| 340 | "tls_handshake" |
| 341 | ]["server_certificates"]["certificate"]["parsed"]["fingerprint_sha256"] |
| 342 | } |
| 343 | dns_list = [] |
| 344 | try: |
| 345 | for dns_name in result["data"]["http"]["redirect_response_chain"][0][ |
| 346 | "request" |
| 347 | ]["tls_handshake"]["server_certificates"]["certificate"]["parsed"][ |
| 348 | "subject" |
| 349 | ][ |
| 350 | "common_name" |
| 351 | ]: |
| 352 | if dns_name not in dns_list: |
| 353 | dns_list.append(dns_name) |
| 354 | except KeyError: |
no test coverage detected