• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

squinky86 / STIGQter / 41772281141

04 Nov 2026 04:16AM UTC coverage: 68.902% (-7.0%) from 75.946%
41772281141

push

github

squinky86
Refactor STIGQter and modernize build and update services

8082 of 13137 branches covered (61.52%)

Branch coverage included in aggregate %.

2404 of 2696 new or added lines in 30 files covered. (89.17%)

9 existing lines in 8 files now uncovered.

5914 of 7176 relevant lines covered (82.41%)

38491.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.04
/src/cklbparser.cpp
1
/*
2
 * STIGQter - STIG fun with Qt
3
 *
4
 * Copyright © 2018–2023 Jon Hood, http://www.hoodsecurity.com/
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "asset.h"
21
#include "cklcheck.h"
22
#include "common.h"
23
#include "contentcatalog.h"
24
#include "dbmanager.h"
25
#include "workercklimport.h"
26
#include "workerstigadd.h"
27

28
#include <QFile>
29
#include <QJsonArray>
30
#include <QJsonDocument>
31
#include <QJsonObject>
32
#include <QTemporaryFile>
33
#include <QUrlQuery>
34
#include <QXmlStreamReader>
35

36
/**
37
 * @brief WorkerCKLImport::ParseCKLB
38
 * @param fileName
39
 *
40
 * Given a CKLB (STIG Viewer 3 JSON) file, parse it and put its data
41
 * into the database.
42
 */
43
void WorkerCKLImport::ParseCKLB(const QString &fileName)
1 ✔
44
{
45
    QFile f(fileName);
1 ✔
46
    if (!f.open(QFile::ReadOnly))
1 !
47
    {
NEW
48
        Q_EMIT ThrowWarning(QStringLiteral("Unable to Open CKLB"), "The CKLB file " + fileName + " cannot be opened.");
×
NEW
49
        return;
×
50
    }
51

52
    QJsonParseError err;
1 ✔
53
    QJsonDocument doc = QJsonDocument::fromJson(f.readAll(), &err);
1 ✔
54
    if (doc.isNull())
1 !
55
    {
NEW
56
        Q_EMIT ThrowWarning(QStringLiteral("Invalid CKLB"), "The CKLB file " + fileName + " could not be parsed: " + err.errorString());
×
NEW
57
        return;
×
58
    }
59

60
    DbManager db;
1 ✔
61
    QJsonObject root = doc.object();
1 ✔
62

63
    // Parse asset/target metadata
64
    Asset a;
1 ✔
65
    QJsonObject td = root[QStringLiteral("target_data")].toObject();
1 ✔
66
    a.assetType     = td[QStringLiteral("target_type")].toString();
1 ✔
67
    a.hostName      = td[QStringLiteral("host_name")].toString();
1 ✔
68
    a.hostIP        = td[QStringLiteral("ip_address")].toString();
1 ✔
69
    a.hostMAC       = td[QStringLiteral("mac_address")].toString();
1 ✔
70
    a.hostFQDN      = td[QStringLiteral("fqdn")].toString();
1 ✔
71
    a.targetComment = td[QStringLiteral("comments")].toString();
1 ✔
72
    a.webOrDB       = td[QStringLiteral("is_web_database")].toBool();
1 ✔
73
    a.techArea      = td[QStringLiteral("technology_area")].toString();
1 ✔
74
    a.webDbSite     = td[QStringLiteral("web_db_site")].toString();
1 ✔
75
    a.webDbInstance = td[QStringLiteral("web_db_instance")].toString();
1 ✔
76
    a.marking       = td[QStringLiteral("marking")].toString();
1 ✔
77

78
    // Ensure asset exists in DB
79
    a = CheckAsset(a);
1 ✔
80

81
    for (const QJsonValue &stigVal : root[QStringLiteral("stigs")].toArray())
2 ✔
82
    {
83
        QJsonObject stigObj = stigVal.toObject();
1 ✔
84
        QString benchmarkId = stigObj[QStringLiteral("stig_id")].toString();
1 ✔
85

86
        // Look up the STIG by benchmarkId
87
        QVector<STIG> matches = db.GetSTIGs(
2 !
88
            QStringLiteral("WHERE benchmarkId = :benchmarkId"),
2 ✔
89
            {std::make_tuple<QString, QVariant>(QStringLiteral(":benchmarkId"), benchmarkId)});
3 ✔
90

91
        if (matches.isEmpty())
1 !
92
        {
NEW
93
            QString stigName = stigObj[QStringLiteral("stig_name")].toString();
×
NEW
94
            Q_EMIT ThrowWarning(QStringLiteral("STIG/SRG Not Found"),
×
NEW
95
                "The CKLB file " + fileName + " references a STIG that has not been imported (" + stigName + " / " + benchmarkId + ").");
×
NEW
96
            return;
×
NEW
97
        }
×
98

99
        STIG stig = matches.first();
1 ✔
100

101
        QVector<STIG> assetStigs = a.GetSTIGs();
1 ✔
102
        if (assetStigs.contains(stig))
1 !
103
        {
NEW
104
            Q_EMIT ThrowWarning(QStringLiteral("Asset already has STIG applied!"),
×
NEW
105
                "The asset " + PrintAsset(a) + " already has the STIG " + PrintSTIG(stig) + " applied and will not be imported.");
×
NEW
106
            continue;
×
107
        }
108

109
        Q_EMIT updateStatus("Adding " + PrintSTIG(stig) + " to " + PrintAsset(a) + "…");
1 ✔
110
        db.AddSTIGToAsset(stig, a);
1 ✔
111

112
        db.DelayCommit(true);
1 ✔
113
        for (const QJsonValue &ruleVal : stigObj[QStringLiteral("rules")].toArray())
287 ✔
114
        {
115
            QJsonObject rule = ruleVal.toObject();
286 ✔
116
            QString ruleId = rule[QStringLiteral("rule_id")].toString();
286 ✔
117

118
            STIGCheck sc = db.GetSTIGCheck(stig, ruleId);
286 ✔
119
            if (sc.id < 0)
286 !
NEW
120
                continue;
×
121

122
            CKLCheck cc;
286 ✔
123
            cc.assetId        = a.id;
286 ✔
124
            cc.stigCheckId    = sc.id;
286 ✔
125
            cc.status         = GetStatus(rule[QStringLiteral("status")].toString());
286 ✔
126
            cc.findingDetails = rule[QStringLiteral("finding_details")].toString();
286 ✔
127
            cc.comments       = rule[QStringLiteral("comments")].toString();
286 ✔
128
            cc.severityOverride     = GetSeverity(rule[QStringLiteral("severity_override")].toString());
286 ✔
129
            cc.severityJustification = rule[QStringLiteral("severity_justification")].toString();
286 ✔
130

131
            db.UpdateCKLCheck(cc);
286 ✔
132
        }
286 !
133
        db.DelayCommit(false);
1 ✔
134
    }
2 !
135
}
3 !
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc