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

mendersoftware / deviceauth / 1029905495

09 Oct 2023 04:24AM UTC coverage: 83.929% (-3.9%) from 87.856%
1029905495

Pull #674

gitlab-ci

tranchitella
feat: support for ED25519 server keys for signing the JWT tokens

Ticket: MEN-6775
Changelog: Title

Signed-off-by: Fabio Tranchitella <fabio.tranchitella@northern.tech>
Pull Request #674: feat: support for ED25519 server keys for signing the JWT tokens

139 of 148 new or added lines in 4 files covered. (93.92%)

88 existing lines in 3 files now uncovered.

4721 of 5625 relevant lines covered (83.93%)

46.83 hits per line

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

94.74
/keys/key.go
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
package keys
15

16
import (
17
        "crypto/ed25519"
18
        "crypto/rsa"
19
        "os"
20

21
        "github.com/golang-jwt/jwt/v4"
22
        "github.com/pkg/errors"
23
)
24

25
const (
26
        ErrMsgPrivKeyReadFailed = "failed to read server private key file"
27
)
28

29
func LoadRSAPrivate(privKeyPath string) (*rsa.PrivateKey, error) {
8✔
30
        pemData, err := os.ReadFile(privKeyPath)
8✔
31
        if err != nil {
9✔
32
                return nil, errors.Wrap(err, ErrMsgPrivKeyReadFailed)
1✔
33
        }
1✔
34
        return jwt.ParseRSAPrivateKeyFromPEM(pemData)
7✔
35
}
36

37
func LoadEd25519Private(privKeyPath string) (*ed25519.PrivateKey, error) {
5✔
38
        pemData, err := os.ReadFile(privKeyPath)
5✔
39
        if err != nil {
6✔
40
                return nil, errors.Wrap(err, ErrMsgPrivKeyReadFailed)
1✔
41
        }
1✔
42
        private, err := jwt.ParseEdPrivateKeyFromPEM(pemData)
4✔
43
        if err != nil {
7✔
44
                return nil, err
3✔
45
        }
3✔
46
        if key, ok := private.(ed25519.PrivateKey); ok {
2✔
47
                return &key, nil
1✔
48
        }
1✔
NEW
UNCOV
49
        return nil, errors.New(ErrMsgPrivKeyReadFailed)
×
50
}
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