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

mendersoftware / mender / 1056184062

31 Oct 2023 12:41PM UTC coverage: 80.182% (+0.3%) from 79.877%
1056184062

push

gitlab-ci

kacf
chore: Do not try to resume requests that were cancelled by callers.

This requires us to move the destruction of the inner reader until
after the body handler has been called, otherwise it will trigger
another `operation_canceled` error which we don't want.

Ticket: MEN-6807

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

5 of 5 new or added lines in 1 file covered. (100.0%)

6890 of 8593 relevant lines covered (80.18%)

9363.89 hits per line

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

68.97
/src/mender-auth/cli/keystore.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <mender-auth/cli/keystore.hpp>
16

17
#include <string>
18
#include <utility>
19

20
#include <common/log.hpp>
21
#include <common/crypto.hpp>
22

23

24
namespace mender {
25
namespace auth {
26
namespace cli {
27

28
using namespace std;
29

30
namespace log = mender::common::log;
31

32
namespace crypto = mender::common::crypto;
33

34
const KeyStoreErrorCategoryClass KeyStoreErrorCategory;
35

36
const char *KeyStoreErrorCategoryClass::name() const noexcept {
×
37
        return "KeyStoreErrorCategory";
×
38
}
39

40
string KeyStoreErrorCategoryClass::message(int code) const {
×
41
        switch (code) {
×
42
        case NoError:
43
                return "Success";
×
44
        case NoKeysError:
45
                return "No key in memory";
×
46
        case StaticKeyError:
47
                return "Cannot replace static key";
×
48
        }
49
        // Don't use "default" case. This should generate a warning if we ever add any enums. But
50
        // still assert here for safety.
51
        assert(false);
52
        return "Unknown";
×
53
}
54

55
error::Error MakeError(KeyStoreErrorCode code, const string &msg) {
9✔
56
        return error::Error(error_condition(code, KeyStoreErrorCategory), msg);
14✔
57
}
58

59
error::Error MenderKeyStore::Load() {
6✔
60
        auto exp_key = crypto::PrivateKey::LoadFromPEM(key_name_, passphrase_);
6✔
61
        if (!exp_key) {
6✔
62
                return MakeError(
63
                        NoKeysError,
64
                        "Error loading private key from " + key_name_ + ": " + exp_key.error().message);
6✔
65
        }
66
        log::Debug("Successfully loaded private key from " + key_name_);
3✔
67
        key_ = move(exp_key.value());
3✔
68

69
        return error::NoError;
3✔
70
}
71

72
error::Error MenderKeyStore::Save() {
6✔
73
        if (!key_) {
6✔
74
                return MakeError(NoKeysError, "Need to load or generate a key before save");
2✔
75
        }
76

77
        return key_.get()->SaveToPEM(key_name_);
5✔
78
}
79

80
error::Error MenderKeyStore::Generate() {
7✔
81
        if (static_key_ == StaticKey::Yes) {
7✔
82
                return MakeError(StaticKeyError, "A static key cannot be re-generated");
2✔
83
        }
84

85
        auto exp_key = crypto::PrivateKey::Generate(MENDER_DEFAULT_KEY_LENGTH);
6✔
86
        if (!exp_key) {
6✔
87
                return exp_key.error();
×
88
        }
89
        key_ = std::move(exp_key.value());
6✔
90

91
        return error::NoError;
6✔
92
}
93

94
} // namespace cli
95
} // namespace auth
96
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc