-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from 0x41424142/certs
Added certificate view module, sql uploads
- Loading branch information
Showing
18 changed files
with
724 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Certificate View APIs | ||
|
||
Certificate View APIs return data on certificates in the subscription. | ||
|
||
After running: | ||
```py | ||
from qualysdk.cert import * | ||
``` | ||
You can use any of the endpoints currently supported: | ||
|
||
## Certificate View Endpoints | ||
|
||
|API Call| Description | | ||
|--|--| | ||
| ```list_certs``` | Lists all certificates in the subscription that match given kwargs. | | ||
|
||
|
||
## List Certificates API | ||
|
||
```list_certs``` returns a list of certificates in the subscription that match the given kwargs. | ||
|
||
|Parameter| Possible Values |Description| Required| | ||
|--|--|--|--| | ||
|```auth```|```qualysdk.auth.TokenAuth``` | Authentication object | ✅ | | ||
| ```page_count``` | ```Union[int, 'all'] = 'all'``` | Number of pages to pull | ❌ | | ||
| ```certId``` | ```str``` | The ID of a certificate to return | ❌ | | ||
| ```certId_operator``` | ```Literal["IN", "LESSER", "IS_EMPTY", "GREATER", "GREATER_THAN_EQUAL", "IS_NOT_EMPTY", "EQUALS", "NOT_EQUALS", "LESS_THAN_EQUAL", "CONTAINS"] = "IS_NOT_EMPTY"``` | The operator to use for the certId | ❌ | | ||
| ```hash``` | ```str``` | The hash of a certificate to return | ❌ | | ||
| ```hash_operator``` | ```Literal["IN", "LESSER", "IS_EMPTY", "GREATER", "GREATER_THAN_EQUAL", "IS_NOT_EMPTY", "EQUALS", "NOT_EQUALS", "LESS_THAN_EQUAL", "CONTAINS"] = "IS_NOT_EMPTY"``` | The operator to use for the hash | ❌ | | ||
| ```validFromDate``` | ```str``` | The date the certificate is valid from | ❌ | | ||
| ```validFromDate_operator``` | ```Literal["IN", "LESSER", "IS_EMPTY", "GREATER", "GREATER_THAN_EQUAL", "IS_NOT_EMPTY", "EQUALS", "NOT_EQUALS", "LESS_THAN_EQUAL", "CONTAINS"] = "GREATER"``` | The operator to use for the validFromDate | ❌ | | ||
| ```wasUrl``` | ```str``` | The URL of the site the certificate lives on, according to the WAS module | ❌ | | ||
| ```wasUrl_operator``` | ```Literal["IN", "LESSER", "IS_EMPTY", "GREATER", "GREATER_THAN_EQUAL", "IS_NOT_EMPTY", "EQUALS", "NOT_EQUALS", "LESS_THAN_EQUAL", "CONTAINS"] = "IS_NOT_EMPTY"``` | The operator to use for the wasUrl | ❌ | | ||
| ```certificateType``` | ```Literal["Leaf", "Intermediate", "Root"]``` | The type of certificate | ❌ | | ||
| ```pageSize``` | ```int > 0 (default=10)``` | The number of certificates to return per page | ❌ | | ||
|
||
```py | ||
from qualysdk.auth import TokenAuth | ||
from qualysdk.cert import list_certs | ||
|
||
auth = TokenAuth(<username>, <password>, platform='qg1') | ||
|
||
# Get all certificates: | ||
certs = list_certs(auth) | ||
|
||
# Get all certificates that match a given piece of a hash | ||
# and are valid afer a certain date: | ||
certs = list_certs(auth, hash='1234', hash_operator='CONTAINS', validFromDate='2024-01-01') | ||
>>>[ | ||
Certificate( | ||
id=12345678, | ||
certhash='111222333444...', | ||
keySize=2048, | ||
serialNumber='12345...', | ||
validToDate=datetime.datetime(2030, 1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), | ||
... | ||
), | ||
... | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
from . import cs | ||
from . import was | ||
from . import pm | ||
from . import cert | ||
|
||
from .sql import db_connect | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
TOTALCLOUD_SCHEMA, | ||
VMDR_SCHEMA, | ||
WAS_SCHEMA, | ||
CERTVIEW_SCHEMA, | ||
] | ||
|
||
CALL_SCHEMA = dict() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
certificate view call schemas | ||
""" | ||
|
||
from frozendict import frozendict | ||
|
||
CERTVIEW_SCHEMA = frozendict( | ||
{ | ||
"cert": { | ||
"url_type": "gateway", | ||
"list_certs": { | ||
"endpoint": "/certview/v2/certificates", | ||
"method": ["POST"], | ||
"valid_params": [], | ||
"valid_POST_data": [ | ||
"certId", | ||
"pageSize", | ||
"pageNumber", | ||
"hash", | ||
"validFromDate", | ||
"wasUrl", | ||
"certificateType", | ||
], | ||
"use_requests_json_data": True, | ||
"return_type": "json", | ||
"pagination": True, | ||
"auth_type": "token", | ||
}, | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
""" | ||
Certificate View module | ||
""" | ||
|
||
from .list_certs import list_certs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
""" | ||
Asset data class | ||
""" | ||
|
||
from dataclasses import dataclass, asdict | ||
from typing import Union | ||
|
||
from ...base.base_list import BaseList | ||
|
||
""" | ||
TODO: Move BaseCls into the package's base module | ||
so it can be used universally. Things you realize | ||
months into a project... | ||
""" | ||
|
||
|
||
@dataclass | ||
class BaseCls: | ||
pass | ||
|
||
def to_dict(self): | ||
return asdict(self) | ||
|
||
def __dict__(self): | ||
return self.to_dict() | ||
|
||
def keys(self): | ||
return self.to_dict().keys() | ||
|
||
def values(self): | ||
return self.to_dict().values() | ||
|
||
def items(self): | ||
return self.to_dict().items() | ||
|
||
@classmethod | ||
def from_dict(cls, d: dict): | ||
return cls(**d) | ||
|
||
|
||
@dataclass | ||
class hostInstance(BaseCls): | ||
id: int = None | ||
port: int = None | ||
fqdn: str = None | ||
protocol: str = None | ||
service: str = None | ||
grade: str = None | ||
|
||
def __str__(self): | ||
return str(getattr(self, "id", "")) | ||
|
||
def __int__(self): | ||
return int(getattr(self, "id", 0)) | ||
|
||
|
||
@dataclass | ||
class assetInterface(BaseCls): | ||
hostname: str = None | ||
address: str = None | ||
|
||
def __str__(self): | ||
return self.hostname if self.hostname else self.address | ||
|
||
|
||
@dataclass | ||
class Tag(BaseCls): | ||
name: str = None | ||
uuid: str = None | ||
|
||
def __str__(self): | ||
return self.name if self.name else self.uuid | ||
|
||
|
||
@dataclass | ||
class Asset(BaseCls): | ||
""" | ||
Represents an asset in CERT, | ||
underneath a certificate | ||
data class. | ||
""" | ||
|
||
id: int = None | ||
uuid: str = None | ||
netbiosName: str = None | ||
name: str = None | ||
operatingSystem: str = None | ||
hostInstances: Union[list[dict], BaseList[object]] = None | ||
assetInterfaces: Union[list[dict], BaseList[object]] = None | ||
tags: Union[list[str], BaseList[str]] = None | ||
primaryIp: str = None | ||
|
||
def __post_init__(self): | ||
if self.hostInstances: | ||
setattr( | ||
self, | ||
"hostInstances", | ||
BaseList([hostInstance(**x) for x in self.hostInstances]), | ||
) | ||
|
||
if self.assetInterfaces: | ||
setattr( | ||
self, | ||
"assetInterfaces", | ||
BaseList([assetInterface(**x) for x in self.assetInterfaces]), | ||
) | ||
|
||
if self.tags: | ||
setattr(self, "tags", BaseList([Tag(**x) for x in self.tags])) | ||
|
||
def __str__(self): | ||
return getattr(self, "name", "") |
Oops, something went wrong.