Documentation ¶
Overview ¶
Package db provides a simplistic ORM to communicate with an SQL database for storage
Example ¶
db, err := db.NewDatabase("./certs.db") if err != nil { log.Fatalln(err) } err = db.CreateCertificateRequest(BananaCSR) if err != nil { log.Fatalln(err) } err = db.AddCertificateChainToCertificateRequestByCSR(BananaCSR, BananaCert) if err != nil { log.Fatalln(err) } entry, err := db.GetCertificateRequestByCSR(BananaCSR) if err != nil { log.Fatalln(err) } if entry.CertificateChain != BananaCert { log.Fatalln("Retrieved Certificate doesn't match Stored Certificate") } err = db.Close() if err != nil { log.Fatalln(err) }
Output:
Index ¶
- func CertificateMatchesCSR(cert string, csr string) error
- func ValidateCertificate(cert string) error
- func ValidateCertificateRequest(csr string) error
- type CertificateRequest
- type Database
- func (db *Database) AddCertificateChainToCertificateRequestByCSR(csr string, cert string) error
- func (db *Database) AddCertificateChainToCertificateRequestByID(id int, cert 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) DeleteCertificateRequestByCSR(csr string) error
- func (db *Database) DeleteCertificateRequestByID(id int) error
- func (db *Database) DeleteUserByID(id int) error
- func (db *Database) GetCertificateRequestByCSR(csr string) (*CertificateRequest, error)
- func (db *Database) GetCertificateRequestByID(id int) (*CertificateRequest, error)
- func (db *Database) GetUserByID(id int) (*User, error)
- func (db *Database) GetUserByUsername(name string) (*User, error)
- func (db *Database) ListCertificateRequests() ([]CertificateRequest, error)
- func (db *Database) ListUsers() ([]User, error)
- func (db *Database) NumUsers() (int, error)
- func (db *Database) RejectCertificateRequestByCSR(csr string) error
- func (db *Database) RejectCertificateRequestByID(id int) error
- func (db *Database) RevokeCertificateByCSR(csr string) error
- func (db *Database) UpdateUserPassword(id int, password string) error
- type NumUsers
- type User
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 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 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) AddCertificateChainToCertificateRequestByCSR ¶
AddCertificateChainToCertificateRequestByCSR adds a new certificate chain to a row for a given CSR string.
func (*Database) AddCertificateChainToCertificateRequestByID ¶
AddCertificateChainToCSRbyID adds a new certificate chain to a row for a given row ID.
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) DeleteCertificateRequestByCSR ¶
DeleteCertificateRequestByCSR removes a CSR from the database alongside the certificate that may have been generated for it.
func (*Database) DeleteCertificateRequestByID ¶
DeleteCSRByID removes a CSR from the database alongside the certificate that may have been generated for it.
func (*Database) DeleteUserByID ¶
DeleteUserByID removes a user from the table.
func (*Database) GetCertificateRequestByCSR ¶
func (db *Database) GetCertificateRequestByCSR(csr string) (*CertificateRequest, error)
GetCertificateRequestByCSR gets a given CSR row from the repository using the CSR text.
func (*Database) GetCertificateRequestByID ¶
func (db *Database) GetCertificateRequestByID(id int) (*CertificateRequest, error)
GetCertificateRequestByID gets a CSR row from the repository from a given ID.
func (*Database) GetUserByID ¶
GetUserByID retrieves the name, password and the permission level of a user.
func (*Database) GetUserByUsername ¶
GetUserByUsername retrieves the id, password and the permission level of a user.
func (*Database) ListCertificateRequests ¶
func (db *Database) ListCertificateRequests() ([]CertificateRequest, 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) RejectCertificateRequestByCSR ¶
RejectCertificateRequestByCSR updates input CSR's row by setting the certificate bundle to "" and moving the row status to "Rejected".
func (*Database) RejectCertificateRequestByID ¶
RejectCSRbyCSR updates input ID's row by setting the certificate bundle to "" and sets the row status to "Rejected".
func (*Database) RevokeCertificateByCSR ¶
RevokeCertificateByCSR updates the input CSR's row by setting the certificate bundle to "" and sets the row status to "Revoked".