Documentation
¶
Overview ¶
Package db provides a simplistic ORM to communicate with an SQL database for storage
Example ¶
database, err := db.NewDatabase("./certs.db") if err != nil { log.Fatalln(err) } err = database.CreateCertificateRequest(BananaCSR) if err != nil { log.Fatalln(err) } err = database.AddCertificateChainToCertificateRequest(db.ByCSRPEM(BananaCSR), BananaCert) if err != nil { log.Fatalln(err) } err = database.Close() if err != nil { log.Fatalln(err) }
Output:
Index ¶
- func CertificateMatchesCSR(cert string, csr string) error
- func HashPassword(password string) (string, error)
- func ValidateCertificate(cert string) error
- func ValidateCertificateRequest(csr string) error
- type CSRFilter
- type Certificate
- type CertificateFilter
- type CertificateRequest
- type CertificateRequestWithChain
- type Database
- func (db *Database) AddCertificateChainToCertificateRequest(csrFilter CSRFilter, certPEM string) error
- func (db *Database) Close() error
- func (db *Database) CreateCertificateRequest(csr string) error
- func (db *Database) CreateUser(username string, password string, permission int) error
- func (db *Database) DeleteCertificate(filter CertificateFilter) error
- func (db *Database) DeleteCertificateRequest(filter CSRFilter) error
- func (db *Database) DeleteUser(filter UserFilter) error
- func (db *Database) GetCertificate(filter CertificateFilter) (*Certificate, error)
- func (db *Database) GetCertificateChain(filter CertificateFilter) ([]Certificate, error)
- func (db *Database) GetCertificateRequest(filter CSRFilter) (*CertificateRequest, error)
- func (db *Database) GetCertificateRequestAndChain(filter CSRFilter) (*CertificateRequestWithChain, error)
- func (db *Database) GetUser(filter UserFilter) (*User, error)
- func (db *Database) ListCertificateRequestWithCertificates() ([]CertificateRequestWithChain, error)
- func (db *Database) ListCertificateRequests() ([]CertificateRequest, error)
- func (db *Database) ListCertificates() ([]Certificate, error)
- func (db *Database) ListUsers() ([]User, error)
- func (db *Database) NumUsers() (int, error)
- func (db *Database) RejectCertificateRequest(filter CSRFilter) error
- func (db *Database) RevokeCertificate(filter CSRFilter) error
- func (db *Database) UpdateUserPassword(filter UserFilter, password string) error
- type NumUsers
- type PrivateKey
- type User
- type UserFilter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CertificateMatchesCSR ¶
CertificateMatchesCSR makes sure that the given certificate and CSR match. The given CSR and Cert must pass their respective validation functions The given CSR and Cert must share the same public key
func HashPassword ¶
Takes the password string, makes sure it's not empty, and hashes it using bcrypt
func ValidateCertificate ¶
ValidateCertificate validates the given Cert string to the following:
The string must include 2 or more PEM formatted certificate strings. Each cert must be a valid PEM string, and should be capable of being parsed into type x509 CERTIFICATE Each subsequent certificate in the string should be the issuer of the previous string, which means:
All except the first certificate should have the "is a CA" Basic Constraint. The public key of the certificate should match the public key of the following certificate. The issuer field of the certificate should match the subject field of the following certificate.
func ValidateCertificateRequest ¶
ValidateCertificateRequest validates the given CSR string to the following: The string must be a valid PEM string, and should be of type CERTIFICATE REQUEST The PEM string should be able to be parsed into a x509 Certificate Request
Types ¶
type Certificate ¶
type Certificate struct { CertificateID int `db:"certificate_id"` Issuer int `db:"issuer_id"` // if the issuer id == certificate_id, then this is a self-signed certificate PrivateKeyID int `db:"private_key_id"` // if there is no private key, then this certificate cannot sign CSR's CertificatePEM string `db:"certificate"` }
type CertificateFilter ¶
func ByCertificateID ¶
func ByCertificateID(id int) CertificateFilter
func ByCertificatePEM ¶
func ByCertificatePEM(pem string) CertificateFilter
type CertificateRequest ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is the object used to communicate with the established repository.
func NewDatabase ¶
NewDatabase connects to a given table in a given database, stores the connection information and returns an object containing the information. The database path must be a valid file path or ":memory:". The table will be created if it doesn't exist in the format expected by the package.
func (*Database) AddCertificateChainToCertificateRequest ¶
func (db *Database) AddCertificateChainToCertificateRequest(csrFilter CSRFilter, certPEM string) error
AddCertificateChainToCertificateRequestByCSR adds a new certificate chain to a row for a given CSR string.
func (*Database) CreateCertificateRequest ¶
CreateCertificateRequest creates a new CSR entry in the repository. The string must be a valid CSR and unique.
func (*Database) CreateUser ¶
CreateUser creates a new user from a given username, password and permission level. The permission level 1 represents an admin, and a 0 represents a regular user. The password passed in should be in plaintext. This function handles hashing and salting the password before storing it in the database.
func (*Database) DeleteCertificate ¶
func (db *Database) DeleteCertificate(filter CertificateFilter) error
DeleteCertificate removes a certificate from the database.
func (*Database) DeleteCertificateRequest ¶
DeleteCertificateRequest removes a CSR from the database.
func (*Database) DeleteUser ¶
func (db *Database) DeleteUser(filter UserFilter) error
DeleteUserByID removes a user from the table.
func (*Database) GetCertificate ¶
func (db *Database) GetCertificate(filter CertificateFilter) (*Certificate, error)
GetCertificateByID gets a certificate row from the repository from a given ID.
func (*Database) GetCertificateChain ¶
func (db *Database) GetCertificateChain(filter CertificateFilter) ([]Certificate, error)
GetCertificateChainByID gets a certificate chain row from the repository from a given ID.
func (*Database) GetCertificateRequest ¶
func (db *Database) GetCertificateRequest(filter CSRFilter) (*CertificateRequest, error)
GetCertificateRequestByID gets a CSR row from the repository from a given ID.
func (*Database) GetCertificateRequestAndChain ¶
func (db *Database) GetCertificateRequestAndChain(filter CSRFilter) (*CertificateRequestWithChain, error)
GetCertificateRequestAndChain gets a CSR row from the repository from a given ID.
func (*Database) GetUser ¶
func (db *Database) GetUser(filter UserFilter) (*User, error)
GetUserByID retrieves the name, password and the permission level of a user.
func (*Database) ListCertificateRequestWithCertificates ¶
func (db *Database) ListCertificateRequestWithCertificates() ([]CertificateRequestWithChain, error)
ListCertificateRequestWithCertificates gets every CertificateRequest entry in the table.
func (*Database) ListCertificateRequests ¶
func (db *Database) ListCertificateRequests() ([]CertificateRequest, error)
ListCertificateRequests gets every CertificateRequest entry in the table.
func (*Database) ListCertificates ¶
func (db *Database) ListCertificates() ([]Certificate, error)
ListCertificateRequests gets every CertificateRequest entry in the table.
func (*Database) ListUsers ¶
ListUsers returns all of the users and their fields available in the database.
func (*Database) RejectCertificateRequest ¶
RejectCertificateRequest updates input CSR's row by setting the certificate bundle to "" and moving the row status to "Rejected".
func (*Database) RevokeCertificate ¶
RevokeCertificate updates the input CSR's row by setting the certificate bundle to "" and sets the row status to "Revoked".
func (*Database) UpdateUserPassword ¶
func (db *Database) UpdateUserPassword(filter UserFilter, password string) error
UpdateUser updates the password of the given user. Just like with CreateUser, this function handles hashing and salting the password before storage.
type PrivateKey ¶
type UserFilter ¶
func ByUserID ¶
func ByUserID(id int) UserFilter
func ByUsername ¶
func ByUsername(username string) UserFilter