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

mendersoftware / iot-manager / 1401702106

05 Aug 2024 08:32PM UTC coverage: 87.577%. Remained the same
1401702106

push

gitlab-ci

web-flow
Merge pull request #295 from mendersoftware/dependabot/docker/docker-dependencies-03b04ac819

chore: bump golang from 1.22.4-alpine3.19 to 1.22.5-alpine3.19 in the docker-dependencies group

3264 of 3727 relevant lines covered (87.58%)

11.44 hits per line

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

87.5
/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
)
26

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

35
func PrivateKeyToPem(privateKey *ecdsa.PrivateKey) []byte {
1✔
36
        x509Encoded, _ := x509.MarshalECPrivateKey(privateKey)
1✔
37
        pemEncoded := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: x509Encoded})
1✔
38
        return pemEncoded
1✔
39
}
1✔
40

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

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

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