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

mendersoftware / iot-manager / 1445709825

09 Sep 2024 11:23AM UTC coverage: 86.917% (-0.3%) from 87.172%
1445709825

Pull #303

gitlab-ci

alfrunes
ci: update gitlab runner

Moving to deprecated docker gitlab public runner, to a self-hosted runner

Ticket: SEC-1133
Changelog: none

Signed-off-by: Roberto Giovanardi <roberto.giovanardi@northern.tech>
(cherry picked from commit bb026f77c)
Pull Request #303: Cherry-pick MEN-7478 to 1.3.x (3.7.x)

42 of 54 new or added lines in 2 files covered. (77.78%)

128 existing lines in 10 files now uncovered.

3169 of 3646 relevant lines covered (86.92%)

9.75 hits per line

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

82.35
/crypto/csr.go
1
// Copyright 2022 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
package crypto
16

17
import (
18
        "crypto/ecdsa"
19
        "crypto/elliptic"
20
        "crypto/rand"
21
        "crypto/x509"
22
        "crypto/x509/pkix"
23
        "encoding/pem"
24
        "flag"
25
        "fmt"
26
)
27

28
func NewPrivateKey() (*ecdsa.PrivateKey, error) {
2✔
29
        privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
2✔
30
        if err != nil {
2✔
UNCOV
31
                return nil, err
×
32
        }
×
33
        return privateKey, nil
2✔
34
}
35

36
func PrivateKeyToPem(privateKey *ecdsa.PrivateKey) ([]byte, error) {
1✔
37
        x509Encoded, err := x509.MarshalPKCS8PrivateKey(privateKey)
1✔
38
        if err != nil {
1✔
NEW
39
                return nil, fmt.Errorf("failed to serialize private key: %w", err)
×
NEW
40
        }
×
41
        pemEncoded := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: x509Encoded})
1✔
42
        return pemEncoded, nil
1✔
43
}
44

45
func NewCertificateSigningRequest(commonName string, key *ecdsa.PrivateKey) ([]byte, error) {
1✔
46
        subject := pkix.Name{
1✔
47
                Country:            []string{""},
1✔
48
                Province:           []string{""},
1✔
49
                Locality:           []string{""},
1✔
50
                Organization:       []string{""},
1✔
51
                OrganizationalUnit: []string{""},
1✔
52
                CommonName:         commonName,
1✔
53
        }
1✔
54

1✔
55
        template := x509.CertificateRequest{Subject: subject, DNSNames: flag.Args()}
1✔
56
        csr, err := x509.CreateCertificateRequest(rand.Reader, &template, key)
1✔
57
        if err != nil {
1✔
UNCOV
58
                return nil, err
×
UNCOV
59
        }
×
60
        csrPemBlock := &pem.Block{
1✔
61
                Type:  "CERTIFICATE REQUEST",
1✔
62
                Bytes: csr,
1✔
63
        }
1✔
64

1✔
65
        return pem.EncodeToMemory(csrPemBlock), nil
1✔
66
}
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