Files
teleport/lib/auth/testauthority/testauthority.go
T
Brian Joerger 488af75797 Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00

117 lines
4.4 KiB
Go

/*
Copyright 2015 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package testauthority implements a wrapper around native.Keygen that uses
// pre-computed keys.
package testauthority
import (
"context"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/gravitational/teleport/api/utils/keys"
"github.com/gravitational/teleport/lib/auth/keygen"
"github.com/gravitational/teleport/lib/auth/native"
"github.com/gravitational/teleport/lib/services"
)
type Keygen struct {
*keygen.Keygen
}
// New creates a new key generator with defaults
func New() *Keygen {
return NewWithClock(clockwork.NewRealClock())
}
// NewWithClock creates a new key generator with the specified configuration
func NewWithClock(clock clockwork.Clock) *Keygen {
inner := keygen.New(context.Background(), keygen.SetClock(clock))
return &Keygen{Keygen: inner}
}
// GeneratePrivateKey generates a new PrivateKey.
func (n *Keygen) GeneratePrivateKey() (*keys.PrivateKey, error) {
priv, _, err := n.GenerateKeyPair()
if err != nil {
return nil, trace.Wrap(err)
}
return keys.ParsePrivateKey(priv)
}
func (n *Keygen) GetNewKeyPairFromPool() (priv []byte, pub []byte, err error) {
return n.GenerateKeyPair()
}
// GenerateKeyPair returns a new private key in PEM format and an ssh
// public key in authorized_key format.
func (n *Keygen) GenerateKeyPair() (priv []byte, pub []byte, err error) {
return native.GenerateKeyPair()
}
func (n *Keygen) GenerateHostCert(c services.HostCertParams) ([]byte, error) {
return n.GenerateHostCertWithoutValidation(c)
}
func (n *Keygen) GenerateUserCert(c services.UserCertParams) ([]byte, error) {
return n.GenerateUserCertWithoutValidation(c)
}
func (n *Keygen) GenerateJWT() (pub []byte, priv []byte, err error) {
return []byte(`-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA+Igxw1i29PtAgaXOdJnkpPRaKANbIYvXpXZ3+UZ0MGYEnS01nqVE
gSic9sDPKtPcw0Bj35u6/2TTJpB1BJqYrcMB1ahP2aRzBgomUSV1BPVLI7F7EH6U
TIdk41ZT0qBtpPlUWJEAjmkPEcC8e+4oBpwW+mvdvupVcrTgFFLqzsvx2ger2S89
/IrVPWPoW513Dml5zJMgiWEf5cKyyXtQAtieftQmX5bJ9t4PEmH3+mMCu4WKKNt9
rLkmqva/gU21PHsop4nbjl5Sd8wITJkfvf/okxLIv1YXkg9z7RpbzSfvQSUUp9RR
9n4Y1beA+k6YyMGjUHeRw3PfbKfiDFaRvQIDAQAB
-----END RSA PUBLIC KEY-----`), []byte(`-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA+Igxw1i29PtAgaXOdJnkpPRaKANbIYvXpXZ3+UZ0MGYEnS01
nqVEgSic9sDPKtPcw0Bj35u6/2TTJpB1BJqYrcMB1ahP2aRzBgomUSV1BPVLI7F7
EH6UTIdk41ZT0qBtpPlUWJEAjmkPEcC8e+4oBpwW+mvdvupVcrTgFFLqzsvx2ger
2S89/IrVPWPoW513Dml5zJMgiWEf5cKyyXtQAtieftQmX5bJ9t4PEmH3+mMCu4WK
KNt9rLkmqva/gU21PHsop4nbjl5Sd8wITJkfvf/okxLIv1YXkg9z7RpbzSfvQSUU
p9RR9n4Y1beA+k6YyMGjUHeRw3PfbKfiDFaRvQIDAQABAoIBAQCFdN0EAQd91c11
0QtkIZ9d1Lj085hkEyvhdhRGj0alFqMzo6s/XY/Dq4NeHXshjFLnphP7ZyyrKAEa
nEe6CSojZKv/hzoZrOz3OUwKFwsXdoC60fs7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