File: list-credentials.gmp.py

package info (click to toggle)
gvm-tools 25.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,480 kB
  • sloc: python: 10,611; xml: 445; makefile: 27
file content (59 lines) | stat: -rwxr-xr-x 1,848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
# SPDX-FileCopyrightText: 2024 Martin Boller
#
# SPDX-License-Identifier: GPL-3.0-or-later

from argparse import Namespace

from gvm.protocols.gmp import Gmp
from gvmtools.helper import Table


def main(gmp: Gmp, args: Namespace) -> None:
    # pylint: disable=unused-argument

    response_xml = gmp.get_credentials(filter_string="rows=-1")
    credentials_xml = response_xml.xpath("credential")

    heading = ["#", "Id", "Name", "Type", "Insecure use"]

    rows = []
    numberRows = 0

    print("Listing credentials.\n")

    for credential in credentials_xml:
        # Count number of reports
        numberRows = numberRows + 1
        # Cast/convert to text to show in list
        rowNumber = str(numberRows)

        name = "".join(credential.xpath("name/text()"))
        credential_id = credential.get("id")
        cred_type = "".join(credential.xpath("type/text()"))
        if cred_type.upper() == "UP":
            cred_type = "Username + Password (up)"
        elif cred_type.upper() == "USK":
            cred_type = "Username + SSH Key (usk)"
        elif cred_type.upper() == "SMIME":
            cred_type = "S/MIME Certificate (smime)"
        elif cred_type.upper() == "PGP":
            cred_type = "PGP Encryption Key (pgp)"
        elif cred_type.upper() == "SNMP":
            cred_type = "Simple Network Management Protocol (snmp)"
        elif cred_type.upper() == "PW":
            cred_type = "Password only (pw)"
        cred_insecureuse = "".join(credential.xpath("allow_insecure/text()"))
        if cred_insecureuse == "1":
            cred_insecureuse = "Yes"
        else:
            cred_insecureuse = "No"

        rows.append(
            [rowNumber, credential_id, name, cred_type, cred_insecureuse]
        )

    print(Table(heading=heading, rows=rows))


if __name__ == "__gmp__":
    main(gmp, args)