5.3 KiB
pbconv
import "github.com/effective-security/trustyca/internal/ca/pbconv"
Package pbconv converts between the CA API messages and the xpki authority configuration: a profile definition (pb.CertProfile) and the authority.CertProfile that signs with it, the runtime settings of an issuer (pb.IssuerConfig) and the authority.IssuerConfig the registry builds, and the X.509 extensions of requests and profiles.
The package is a leaf: the CA core, the CA and CIS services and the administrative CLI share it, so a profile written in the YAML shape of a ca-config file is registered through the API with the same conversion the bootstrap uses:
var p authority.CertProfile
if err := yaml.Unmarshal(data, &p); err != nil {
return err
}
def := pbconv.ProfileToPb("server", &p)
_, err := caClient.RegisterProfile(ctx, &pb.RegisterProfileRequest{
OrgID: orgID,
Profile: def,
})
ExpandIssuerURL replaces the issuer placeholders of the AIA, CRL and OCSP URL templates (`${ISSUER_ID}` of the API, `:ISSUER_ID` of a ca-config file) with the key identifier of an issuer.
Index
- Constants
- func ExpandIssuerURL(template, skid string) string
- func ExtensionsFromPb(list []*pb.X509Extension) ([]csr.X509Extension, error)
- func ExtensionsToPb(list []csr.X509Extension) []*pb.X509Extension
- func IssuerConfigFromPb(label string, c *pb.IssuerConfig) (*authority.IssuerConfig, error)
- func IssuerConfigToPb(c *authority.IssuerConfig) *pb.IssuerConfig
- func ProfileFromPb(p *pb.CertProfile) (*authority.CertProfile, error)
- func ProfileToPb(label string, p *authority.CertProfile) *pb.CertProfile
Constants
The placeholders of the issuer in the AIA, CRL and OCSP URL templates of an issuer configuration: `${ISSUER_ID}` of the API and `:ISSUER_ID`, which the config loader does not expand as an environment variable. Both are replaced with the Subject Key Identifier of the issuer.
const (
IssuerIDVariable = "${ISSUER_ID}"
IssuerIDPlaceholder = ":ISSUER_ID"
)
func ExpandIssuerURL
func ExpandIssuerURL(template, skid string) string
ExpandIssuerURL returns the URL of an AIA, CRL or OCSP template of an issuer with its Subject Key Identifier in place of the placeholders, as the authority puts it in the certificates it issues
func ExtensionsFromPb
func ExtensionsFromPb(list []*pb.X509Extension) ([]csr.X509Extension, error)
ExtensionsFromPb converts the extensions of a request or a profile; the value stays encoded, as csr.X509Extension expects it
func ExtensionsToPb
func ExtensionsToPb(list []csr.X509Extension) []*pb.X509Extension
ExtensionsToPb converts the extensions of an authority profile
func IssuerConfigFromPb
func IssuerConfigFromPb(label string, c *pb.IssuerConfig) (*authority.IssuerConfig, error)
IssuerConfigFromPb converts the runtime settings of an issuer row to the configuration of the authority issuer with the label. The AIA section is always present, so that the CRL and OCSP timings fall back to the authority defaults when the row does not set them; the profiles are empty and are registered by the Registry.
func IssuerConfigToPb
func IssuerConfigToPb(c *authority.IssuerConfig) *pb.IssuerConfig
IssuerConfigToPb converts the configuration of a ca-config issuer to the runtime settings stored on its row: the AIA section, the allowed profiles and the extension policy. File locations and the loaded profiles are not settings of the row.
func ProfileFromPb
func ProfileFromPb(p *pb.CertProfile) (*authority.CertProfile, error)
ProfileFromPb converts a profile definition to the authority profile that signs with it and validates it with authority.CertProfile.Validate, which also compiles the allowed name patterns. The identity fields of the definition (ID, scope, status and timestamps) are not part of the result.
func ProfileToPb
func ProfileToPb(label string, p *authority.CertProfile) *pb.CertProfile
ProfileToPb converts an authority profile, such as one loaded from a ca-config file, to the profile definition stored for the label
Generated by gomarkdoc