diff --git a/pkg/certs/certificateAuthority.go b/pkg/certs/certificateAuthority.go index 9c12c872..6229aa2b 100644 --- a/pkg/certs/certificateAuthority.go +++ b/pkg/certs/certificateAuthority.go @@ -162,6 +162,10 @@ func (ca *CertificateAuthority) SignRequest(csrPem []byte, oldCertPem []byte, co extKeyUsage = append(extKeyUsage, x509.ExtKeyUsageServerAuth) } + if conf != nil && conf.IsCA { + keyUsage |= x509.KeyUsageCertSign + } + csr, err := DecodeCertRequestPEM(csrPem) if err != nil { return @@ -185,9 +189,11 @@ func (ca *CertificateAuthority) SignRequest(csrPem []byte, oldCertPem []byte, co offset := (time.Hour * 24 * 365) accessIdentity := []byte{} + isCA := false if conf != nil { offset = conf.Offset accessIdentity = []byte(conf.Identity) + isCA = conf.IsCA } now := time.Now().UTC() @@ -201,6 +207,8 @@ func (ca *CertificateAuthority) SignRequest(csrPem []byte, oldCertPem []byte, co BasicConstraintsValid: true, DNSNames: csr.DNSNames, IPAddresses: csr.IPAddresses, + IsCA: isCA, + MaxPathLenZero: isCA, // Enable MaxPathLenZero only when is CA } csrRenewCertsPEM := []byte{} diff --git a/pkg/certs/util.go b/pkg/certs/util.go index 010230b1..d5749c2c 100644 --- a/pkg/certs/util.go +++ b/pkg/certs/util.go @@ -37,6 +37,7 @@ type SignConfig struct { Offset time.Duration Identity string ServerAuth bool + IsCA bool } // AltNames contains the domain names and IP addresses for a cert diff --git a/rpc/cloudagent/security/certificate/moc_cloudagent_certificate.proto b/rpc/cloudagent/security/certificate/moc_cloudagent_certificate.proto index cd2622a2..1a22afac 100644 --- a/rpc/cloudagent/security/certificate/moc_cloudagent_certificate.proto +++ b/rpc/cloudagent/security/certificate/moc_cloudagent_certificate.proto @@ -37,6 +37,7 @@ message CertificateSigningRequest { string locationName = 8; string identity = 9; int64 validity = 10; + google.protobuf.BoolValue isCA = 11; } message Certificate { diff --git a/rpc/cloudagent/security/moc_cloudagent_certificate.pb.go b/rpc/cloudagent/security/moc_cloudagent_certificate.pb.go index c3510b24..660325ee 100644 --- a/rpc/cloudagent/security/moc_cloudagent_certificate.pb.go +++ b/rpc/cloudagent/security/moc_cloudagent_certificate.pb.go @@ -185,19 +185,20 @@ func (m *CertificateResponse) GetError() string { } type CertificateSigningRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Csr string `protobuf:"bytes,2,opt,name=csr,proto3" json:"csr,omitempty"` - OldCertificate string `protobuf:"bytes,3,opt,name=oldCertificate,proto3" json:"oldCertificate,omitempty"` - Status *common.Status `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` - CaName string `protobuf:"bytes,5,opt,name=caName,proto3" json:"caName,omitempty"` - GroupName string `protobuf:"bytes,6,opt,name=groupName,proto3" json:"groupName,omitempty"` - VaultName string `protobuf:"bytes,7,opt,name=vaultName,proto3" json:"vaultName,omitempty"` - LocationName string `protobuf:"bytes,8,opt,name=locationName,proto3" json:"locationName,omitempty"` - Identity string `protobuf:"bytes,9,opt,name=identity,proto3" json:"identity,omitempty"` - Validity int64 `protobuf:"varint,10,opt,name=validity,proto3" json:"validity,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Csr string `protobuf:"bytes,2,opt,name=csr,proto3" json:"csr,omitempty"` + OldCertificate string `protobuf:"bytes,3,opt,name=oldCertificate,proto3" json:"oldCertificate,omitempty"` + Status *common.Status `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` + CaName string `protobuf:"bytes,5,opt,name=caName,proto3" json:"caName,omitempty"` + GroupName string `protobuf:"bytes,6,opt,name=groupName,proto3" json:"groupName,omitempty"` + VaultName string `protobuf:"bytes,7,opt,name=vaultName,proto3" json:"vaultName,omitempty"` + LocationName string `protobuf:"bytes,8,opt,name=locationName,proto3" json:"locationName,omitempty"` + Identity string `protobuf:"bytes,9,opt,name=identity,proto3" json:"identity,omitempty"` + Validity int64 `protobuf:"varint,10,opt,name=validity,proto3" json:"validity,omitempty"` + IsCA *wrappers.BoolValue `protobuf:"bytes,11,opt,name=isCA,proto3" json:"isCA,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *CertificateSigningRequest) Reset() { *m = CertificateSigningRequest{} } @@ -295,6 +296,13 @@ func (m *CertificateSigningRequest) GetValidity() int64 { return 0 } +func (m *CertificateSigningRequest) GetIsCA() *wrappers.BoolValue { + if m != nil { + return m.IsCA + } + return nil +} + type Certificate struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` @@ -426,48 +434,49 @@ func init() { func init() { proto.RegisterFile("moc_cloudagent_certificate.proto", fileDescriptor_373194e28b9c267a) } var fileDescriptor_373194e28b9c267a = []byte{ - // 650 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xae, 0x63, 0xd7, 0x34, 0x93, 0x2a, 0x54, 0x0b, 0x6a, 0x4d, 0x04, 0x28, 0x72, 0x11, 0x0a, - 0x50, 0xd9, 0xc8, 0x5c, 0xb9, 0x34, 0xe1, 0xef, 0x04, 0xd2, 0xa6, 0x70, 0x00, 0x44, 0xe5, 0xd8, - 0x13, 0xb3, 0x92, 0xed, 0x35, 0xeb, 0x75, 0xab, 0x3c, 0x01, 0xbc, 0x0a, 0x0f, 0xc0, 0x4b, 0xf0, - 0x3e, 0xdc, 0x91, 0xd7, 0x4e, 0xe2, 0x54, 0x0d, 0x04, 0x89, 0x9e, 0xe2, 0x99, 0xef, 0x9b, 0x6f, - 0x66, 0xbe, 0xcd, 0x2e, 0xf4, 0x13, 0x1e, 0x9c, 0x06, 0x31, 0x2f, 0x42, 0x3f, 0xc2, 0x54, 0x9e, - 0x06, 0x28, 0x24, 0x9b, 0xb2, 0xc0, 0x97, 0xe8, 0x64, 0x82, 0x4b, 0x4e, 0x0e, 0x12, 0x1e, 0x38, - 0x4b, 0x86, 0x93, 0x63, 0x50, 0x08, 0x26, 0x67, 0xbd, 0xbb, 0x11, 0xe7, 0x51, 0x8c, 0xae, 0xa2, - 0x4d, 0x8a, 0xa9, 0x7b, 0x2e, 0xfc, 0x2c, 0x43, 0x91, 0x57, 0x85, 0xbd, 0x03, 0x25, 0xcd, 0x93, - 0x84, 0xa7, 0xf5, 0x4f, 0x05, 0xd8, 0x9f, 0x80, 0x8c, 0x96, 0x6d, 0x28, 0x7e, 0x29, 0x30, 0x97, - 0xe4, 0x15, 0xec, 0x36, 0xb2, 0xb9, 0xa5, 0xf5, 0xf5, 0x41, 0xc7, 0xbb, 0xe7, 0xac, 0x69, 0xef, - 0x34, 0x25, 0x56, 0x2a, 0xed, 0x13, 0x80, 0xd1, 0x98, 0xce, 0x75, 0x5f, 0x80, 0x31, 0x1a, 0xd3, - 0xb9, 0x9e, 0xb7, 0x89, 0xde, 0x98, 0x45, 0x29, 0x4b, 0xa3, 0x5a, 0x81, 0xaa, 0x7a, 0xfb, 0xbb, - 0x06, 0x37, 0x56, 0xc6, 0xce, 0x33, 0x9e, 0xe6, 0xf8, 0xff, 0xe6, 0x26, 0x1e, 0x98, 0x14, 0xf3, - 0x22, 0x96, 0x56, 0xab, 0xaf, 0x0d, 0x3a, 0x5e, 0xcf, 0xa9, 0x1c, 0x76, 0xe6, 0x0e, 0x3b, 0x43, - 0xce, 0xe3, 0x77, 0x7e, 0x5c, 0x20, 0xad, 0x99, 0xe4, 0x26, 0x6c, 0x3f, 0x17, 0x82, 0x0b, 0x4b, - 0xef, 0x6b, 0x83, 0x36, 0xad, 0x02, 0xfb, 0x67, 0x0b, 0x6e, 0xad, 0xdd, 0x87, 0x10, 0x30, 0x52, - 0x3f, 0x41, 0x4b, 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xff, 0x39, 0xe6, 0x9d, 0x71, 0x0c, 0x07, 0x00, 0x00, + // 662 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xae, 0x13, 0xd7, 0xbf, 0x66, 0x52, 0xe5, 0x57, 0x2d, 0xa8, 0x35, 0x11, 0xa0, 0x28, 0x45, + 0x28, 0x40, 0x65, 0x23, 0x73, 0xe5, 0xd2, 0x84, 0x7f, 0x27, 0x90, 0x36, 0x85, 0x03, 0x20, 0x2a, + 0xc7, 0x9e, 0x98, 0x95, 0x6c, 0xaf, 0xd9, 0x5d, 0xb7, 0xca, 0x13, 0xc0, 0xab, 0xf0, 0x00, 0x3c, + 0x1a, 0x17, 0x4e, 0xc8, 0x6b, 0x27, 0x71, 0xaa, 0x86, 0x06, 0x89, 0x9e, 0xe2, 0x9d, 0x6f, 0xe6, + 0x9b, 0x99, 0xef, 0xcb, 0x2e, 0xf4, 0x12, 0x1e, 0x9c, 0x06, 0x31, 0xcf, 0x43, 0x3f, 0xc2, 0x54, + 0x9d, 0x06, 0x28, 0x14, 0x9b, 0xb2, 0xc0, 0x57, 0xe8, 0x64, 0x82, 0x2b, 0x4e, 0x0e, 0x12, 0x1e, + 0x38, 0xcb, 0x0c, 0x47, 0x62, 0x90, 0x0b, 0xa6, 0x66, 0xdd, 0xbb, 0x11, 0xe7, 0x51, 0x8c, 0xae, + 0x4e, 0x9b, 0xe4, 0x53, 0xf7, 0x5c, 0xf8, 0x59, 0x86, 0x42, 0x96, 0x85, 0xdd, 0x03, 0x4d, 0xcd, + 0x93, 0x84, 0xa7, 0xd5, 0x4f, 0x09, 0xf4, 0x3f, 0x01, 0x19, 0x2d, 0xdb, 0x50, 0xfc, 0x92, 0xa3, + 0x54, 0xe4, 0x15, 0xec, 0xd6, 0xa2, 0xd2, 0x36, 0x7a, 0xcd, 0x41, 0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, 0xd1, 0xff, 0x4a, 0x74, 0x11, 0x20, 0x7d, 0xd8, 0x8d, 0x79, 0xe0, 0x2b, 0xc6, + 0x53, 0x9d, 0xb0, 0xa3, 0x13, 0x56, 0x62, 0xa4, 0x0b, 0x3b, 0x2c, 0xc4, 0x54, 0x31, 0x35, 0xb3, + 0x5b, 0x1a, 0x5f, 0x9c, 0x0b, 0xec, 0xcc, 0x8f, 0x59, 0x58, 0x60, 0xd0, 0x33, 0x06, 0x4d, 0xba, + 0x38, 0x13, 0x07, 0x4c, 0x26, 0x47, 0xc7, 0x76, 0xfb, 0x4a, 0x53, 0x74, 0x5e, 0xff, 0x67, 0x03, + 0xda, 0x75, 0x51, 0x2e, 0x93, 0xbb, 0x03, 0x0d, 0x16, 0x96, 0x6a, 0xd3, 0x06, 0x0b, 0x8b, 0xed, + 0x52, 0xae, 0x86, 0x38, 0xe5, 0xa2, 0x54, 0xb8, 0x49, 0x97, 0x81, 0x62, 0xba, 0x94, 0xab, 0xe3, + 0xa9, 0x42, 0xa1, 0x85, 0x6d, 0xd2, 0xc5, 0x99, 0xdc, 0x87, 0x76, 0xed, 0xce, 0x96, 0x92, 0x56, + 0xee, 0xd4, 0x81, 0x9a, 0x35, 0xd6, 0x7a, 0x6b, 0x9e, 0x82, 0xa9, 0x66, 0x59, 0xa9, 0x6f, 0xc7, + 0x1b, 0x6c, 0xf2, 0x1f, 0x3e, 0x99, 0x65, 0x48, 0x75, 0xd5, 0xaa, 0x81, 0x3b, 0x7f, 0x34, 0xb0, + 0x75, 0x95, 0x81, 0x70, 0x89, 0x81, 0x77, 0xc0, 0x54, 0x7e, 0x24, 0x2b, 0x23, 0x5a, 0x7a, 0xba, + 0x13, 0x3f, 0x92, 0x54, 0x87, 0x1f, 0x3e, 0x80, 0xff, 0x2f, 0xcc, 0x45, 0x00, 0xac, 0x51, 0xcc, + 0x30, 0x55, 0x7b, 0x5b, 0xc5, 0xf7, 0x18, 0xc5, 0x19, 0x8a, 0x3d, 0xc3, 0xfb, 0x6a, 0xc2, 0x5e, + 0x2d, 0xf7, 0xb8, 0xd8, 0x8e, 0x24, 0xd0, 0x19, 0x09, 0xf4, 0x15, 0xbe, 0x11, 0x6f, 0xb3, 0xb0, + 0xd0, 0xec, 0xd1, 0x46, 0x97, 0xb8, 0xbc, 0x55, 0xdd, 0xa3, 0xcd, 0x92, 0xcb, 0x57, 0xa3, 0xbf, + 0x45, 0x26, 0xd0, 0x7c, 0x89, 0xea, 0x7a, 0x7b, 0x20, 0x58, 0xcf, 0x30, 0xc6, 0xeb, 0x5e, 0xe5, + 0x03, 0x98, 0xc5, 0x13, 0x43, 0x0e, 0xd7, 0xd7, 0x2d, 0xde, 0xe3, 0xbf, 0x26, 0xff, 0x08, 0xdb, + 0x14, 0x53, 0x3c, 0xbf, 0x16, 0xf6, 0xa1, 0xf7, 0xfe, 0x71, 0xc4, 0xd4, 0xe7, 0x7c, 0xe2, 0x04, + 0x3c, 0x71, 0x13, 0x16, 0x08, 0x2e, 0xf9, 0x54, 0xb9, 0x09, 0x0f, 0x5c, 0x91, 0x05, 0xee, 0x92, + 0xc9, 0x9d, 0x33, 0x4d, 0x2c, 0x7d, 0xf5, 0x9f, 0xfc, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x84, 0xa5, + 0xb9, 0x84, 0x3c, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used.