certificates/db/simple.go

165 lines
4.3 KiB
Go
Raw Normal View History

2019-05-07 18:38:27 +00:00
package db
import (
"crypto/x509"
"sync"
"time"
"github.com/pkg/errors"
2019-05-27 00:41:10 +00:00
"github.com/smallstep/nosql/database"
"golang.org/x/crypto/ssh"
2019-05-07 18:38:27 +00:00
)
// ErrNotImplemented is an error returned when an operation is Not Implemented.
var ErrNotImplemented = errors.Errorf("not implemented")
// SimpleDB is a barebones implementation of the DB interface. It is NOT an
// in memory implementation of the DB, but rather the bare minimum of
// functionality that the CA requires to operate securely.
type SimpleDB struct {
usedTokens *sync.Map
}
2023-05-10 06:47:28 +00:00
func newSimpleDB(*Config) (*SimpleDB, error) {
2019-05-07 18:38:27 +00:00
db := &SimpleDB{}
db.usedTokens = new(sync.Map)
return db, nil
}
// IsRevoked noop
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) IsRevoked(string) (bool, error) {
2019-05-07 18:38:27 +00:00
return false, nil
}
// IsSSHRevoked noop
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) IsSSHRevoked(string) (bool, error) {
return false, nil
}
2019-05-07 18:38:27 +00:00
// Revoke returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) Revoke(*RevokedCertificateInfo) error {
2019-05-07 18:38:27 +00:00
return ErrNotImplemented
}
2021-10-30 07:52:50 +00:00
// GetRevokedCertificates returns a "NotImplemented" error.
func (s *SimpleDB) GetRevokedCertificates() (*[]RevokedCertificateInfo, error) {
return nil, ErrNotImplemented
}
// GetCRL returns a "NotImplemented" error.
func (s *SimpleDB) GetCRL() (*CertificateRevocationListInfo, error) {
return nil, ErrNotImplemented
}
// StoreCRL returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) StoreCRL(*CertificateRevocationListInfo) error {
2021-10-30 07:52:50 +00:00
return ErrNotImplemented
}
// RevokeSSH returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) RevokeSSH(*RevokedCertificateInfo) error {
return ErrNotImplemented
}
2020-09-16 01:14:03 +00:00
// GetCertificate returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) GetCertificate(string) (*x509.Certificate, error) {
2020-09-16 01:14:03 +00:00
return nil, ErrNotImplemented
}
2019-05-07 18:38:27 +00:00
// StoreCertificate returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) StoreCertificate(*x509.Certificate) error {
2019-05-07 18:38:27 +00:00
return ErrNotImplemented
}
type usedToken struct {
UsedAt int64 `json:"ua,omitempty"`
Token string `json:"tok,omitempty"`
}
// UseToken returns a "NotImplemented" error.
func (s *SimpleDB) UseToken(id, tok string) (bool, error) {
if _, ok := s.usedTokens.LoadOrStore(id, &usedToken{
UsedAt: time.Now().Unix(),
Token: tok,
}); ok {
// Token already exists in DB.
return false, nil
}
// Successfully stored token.
return true, nil
}
// IsSSHHost returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) IsSSHHost(string) (bool, error) {
return false, ErrNotImplemented
}
// StoreSSHCertificate returns a "NotImplemented" error.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) StoreSSHCertificate(*ssh.Certificate) error {
return ErrNotImplemented
}
2019-10-25 20:47:49 +00:00
// GetSSHHostPrincipals returns a "NotImplemented" error.
func (s *SimpleDB) GetSSHHostPrincipals() ([]string, error) {
return nil, ErrNotImplemented
}
2019-05-07 18:38:27 +00:00
// Shutdown returns nil
func (s *SimpleDB) Shutdown() error {
return nil
}
2019-05-27 00:41:10 +00:00
// nosql.DB interface implementation //
// Open opens the database available with the given options.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) Open(string, ...database.Option) error {
2019-05-27 00:41:10 +00:00
return ErrNotImplemented
}
// Close closes the current database.
func (s *SimpleDB) Close() error {
return ErrNotImplemented
}
// Get returns the value stored in the given table/bucket and key.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) Get([]byte, []byte) ([]byte, error) {
2019-05-27 00:41:10 +00:00
return nil, ErrNotImplemented
}
// Set sets the given value in the given table/bucket and key.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) Set([]byte, []byte, []byte) error {
2019-05-27 00:41:10 +00:00
return ErrNotImplemented
}
// CmpAndSwap swaps the value at the given bucket and key if the current
// value is equivalent to the oldValue input. Returns 'true' if the
// swap was successful and 'false' otherwise.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) CmpAndSwap([]byte, []byte, []byte, []byte) ([]byte, bool, error) {
2019-05-27 00:41:10 +00:00
return nil, false, ErrNotImplemented
}
// Del deletes the data in the given table/bucket and key.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) Del([]byte, []byte) error {
2019-05-27 00:41:10 +00:00
return ErrNotImplemented
}
// List returns a list of all the entries in a given table/bucket.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) List([]byte) ([]*database.Entry, error) {
2019-05-27 00:41:10 +00:00
return nil, ErrNotImplemented
}
// Update performs a transaction with multiple read-write commands.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) Update(*database.Tx) error {
2019-05-27 00:41:10 +00:00
return ErrNotImplemented
}
// CreateTable creates a table or a bucket in the database.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) CreateTable([]byte) error {
2019-05-27 00:41:10 +00:00
return ErrNotImplemented
}
// DeleteTable deletes a table or a bucket in the database.
2023-05-10 06:47:28 +00:00
func (s *SimpleDB) DeleteTable([]byte) error {
2019-05-27 00:41:10 +00:00
return ErrNotImplemented
}