Skip to content

Commit 434e7cf

Browse files
authored
feat(scep): serve SCEP so network devices can enrol a trustpoint (#288)
* feat(ca): allow a per-profile RSA subject-key floor down to 2048 Cisco IOS and IOS-XE SCEP trustpoints cannot hold an RSA key larger than 2048 bits, so the SCEP device profiles need a lower floor than the node-wide 3072. ca.Profile gains MinRSAKeyBits, validated by ValidateSubjectKeyMin: zero keeps 3072, 2048 is the lowest accepted, and a CA certificate can never take a lower floor. CASigner gains IssueLeafForNamesMinRSA for the one caller that passes one; every other path keeps the node-wide floor. Refs #185 Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com> * feat(scep): serve SCEP (RFC 8894) so network devices can enrol Adds internal/scep, the node side of SCEP on the internal/cms primitives: GetCACaps, GetCACert (the CA and an RA certificate), and PKIOperation with PKCSReq, RenewalReq, CertPoll, GetCert and GetCRL. - Initial enrolment is authorized by a one-time challenge minted with MintScepChallenge: stored as a SHA-256, single-use, with a TTL, naming its profile and optionally bound to names inside the mandatory allowlist. Renewal is authorized by the device's current certificate and keeps its names and profile; a PKCSReq signed by such a certificate is treated as a renewal, which is how sscep and Cisco IOS rollover send it. - Each profile has its own RSA floor (2048 at the lowest) and an optional PENDING queue, approved or rejected through the six admin RPCs, which replace their Unimplemented stubs. - Every transactionID is recorded, so a retransmit or CertPoll returns the same certificate. - The RA is RSA 3072 (digitalSignature, keyEncipherment), minted by the node's CA, valid a year, held on the encrypted state partition and rotated with an overlap during which both RAs decrypt. - pki.scep is carried in the machine config under the same protocol-block rules as ACME and EST (an absent block in an apply keeps the stored one), refused on a Root, and read only at boot; the listener shares the CRL/OCSP port by default. NodeStatus.protocols reports it next to ACME and EST. - cryptosctl gains scep challenge mint|list|revoke and scep enrollments list|approve|reject. - Every decision is audited with the challenge id, never the challenge. Refs #185 Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com> * test(scep): cover the clock gate on SCEP issuance SCEP issues through the same clock-gated CA signer as ACME and EST, so a node whose time source has not synced refuses the enrolment. Pin that with a test, and pin that the RA certificate is minted without the gate, like the OCSP responder and EST server certificates, so SCEP can offer an RA from the first boot. List SCEP beside ACME and EST in the signing-gate docs, note the service certificates the gate leaves alone, and add the gate to the SCEP limits. Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com> --------- Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com> Co-authored-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com>
1 parent 6b602bc commit 434e7cf

42 files changed

Lines changed: 6693 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci-go.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ jobs:
6868
sudo apt-get update
6969
sudo apt-get install -y --no-install-recommends swtpm
7070
71+
- name: Build sscep for the SCEP interoperability tests
72+
# internal/scep runs a real SCEP client against the server and fails
73+
# under CI when it has none. Built from the pinned release tarball,
74+
# checksum-checked, since no prebuilt binary is published.
75+
env:
76+
SSCEP_VERSION: 0.10.0
77+
SSCEP_SHA256: 489cc8e093986776eb3f15082bf766778f707176f3cd604bf0ef1008da06b8e5
78+
run: |
79+
cd "$RUNNER_TEMP"
80+
curl -fsSL -o sscep.tar.gz "https://github.com/certnanny/sscep/archive/refs/tags/v${SSCEP_VERSION}.tar.gz"
81+
echo "${SSCEP_SHA256} sscep.tar.gz" | sha256sum -c -
82+
tar xzf sscep.tar.gz
83+
cmake -S "sscep-${SSCEP_VERSION}" -B sscep-build -DCMAKE_BUILD_TYPE=Release
84+
cmake --build sscep-build
85+
echo "CRYPTOS_TEST_SSCEP=$RUNNER_TEMP/sscep-build/sscep" >> "$GITHUB_ENV"
86+
7187
- name: Run task ci
7288
run: task ci
7389

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ A node keeps its clock in sync over SNTP with the servers in `network.ntp_server
124124

125125
Issuing LDAPS and KDC certificates to Active Directory domain controllers, including `certreq` on Server Core, is covered in [`docs/active-directory.md`](docs/active-directory.md).
126126

127+
Network devices that cannot run ACME, such as Cisco IOS and IOS-XE trustpoints, enrol over SCEP (RFC 8894): each initial enrolment is authorized by a one-time challenge from `cryptosctl scep challenge mint`, and renewal by the device's current certificate. [`docs/scep.md`](docs/scep.md) covers switching it on, the per-profile key floor, the RA certificate and the approval queue.
128+
127129
### Rebooting or powering off a node
128130

129131
Most `config apply` changes report `requires_reboot=true`. Restart the node through its orderly shutdown rather than a hypervisor hard reset:

‎cmd/cryptosctl/root.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func newRootCmd() *cobra.Command {
8181
newResetCmd(opts),
8282
newVersionCmd(opts),
8383
newTrustCmd(opts),
84+
newSCEPCmd(opts),
8485
)
8586
addDebugCommands(root, opts)
8687
return root

‎cmd/cryptosctl/scep.go‎

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
package main
2+
3+
/*
4+
Apache License 2.0
5+
6+
Copyright 2026 Shane
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
import (
22+
"errors"
23+
"fmt"
24+
"io"
25+
"strings"
26+
"text/tabwriter"
27+
"time"
28+
29+
"github.com/spf13/cobra"
30+
31+
cryptosv1 "github.com/CryptOS-PKI/api/go/cryptos/v1"
32+
)
33+
34+
// newSCEPCmd groups the SCEP administration verbs: the one-time challenges
35+
// that authorize an initial enrolment, and the queue of enrolments held for
36+
// approval on profiles with require_approval.
37+
func newSCEPCmd(opts *globalOpts) *cobra.Command {
38+
cmd := &cobra.Command{
39+
Use: "scep",
40+
Short: "Manage SCEP enrolment: one-time challenges and the approval queue",
41+
}
42+
challenge := &cobra.Command{Use: "challenge", Short: "Mint, list and revoke one-time SCEP challenges"}
43+
challenge.AddCommand(newSCEPMintCmd(opts), newSCEPListChallengesCmd(opts), newSCEPRevokeChallengeCmd(opts))
44+
enrollments := &cobra.Command{Use: "enrollments", Short: "List, approve and reject SCEP enrolments waiting for approval"}
45+
enrollments.AddCommand(newSCEPListEnrollmentsCmd(opts), newSCEPApproveCmd(opts), newSCEPRejectCmd(opts))
46+
cmd.AddCommand(challenge, enrollments)
47+
return cmd
48+
}
49+
50+
func newSCEPMintCmd(opts *globalOpts) *cobra.Command {
51+
var (
52+
profile string
53+
ttl time.Duration
54+
names []string
55+
)
56+
cmd := &cobra.Command{
57+
Use: "mint",
58+
Short: "Mint a single-use challenge for one device's initial enrolment",
59+
Long: "Mint a single-use challenge for one device's initial enrolment. The challenge is shown\n" +
60+
"once: the node keeps only its digest. Give it to the device as its enrolment password,\n" +
61+
"for example a Cisco trustpoint's `password`, before it expires.",
62+
Args: cobra.NoArgs,
63+
RunE: func(cmd *cobra.Command, _ []string) error {
64+
if ttl < 0 || ttl%time.Second != 0 {
65+
return errors.New("--ttl must be a whole number of seconds, for example 1h or 30m")
66+
}
67+
client, closeConn, err := dial(opts)
68+
if err != nil {
69+
return err
70+
}
71+
defer func() { _ = closeConn() }()
72+
resp, err := client.MintScepChallenge(cmd.Context(), &cryptosv1.MintScepChallengeRequest{
73+
Profile: profile, TtlSeconds: uint32(ttl / time.Second), BoundNames: names,
74+
})
75+
if err != nil {
76+
return err
77+
}
78+
if opts.output != formatHuman {
79+
return renderProto(cmd.OutOrStdout(), resp, opts.output)
80+
}
81+
ch := resp.GetChallenge()
82+
w := cmd.OutOrStdout()
83+
_, _ = fmt.Fprintf(w, "Challenge: %s\n", resp.GetChallengePassword())
84+
_, _ = fmt.Fprintf(w, "ID: %s\n", ch.GetId())
85+
_, _ = fmt.Fprintf(w, "Profile: %s\n", ch.GetProfile())
86+
_, _ = fmt.Fprintf(w, "Expires: %s\n", ch.GetExpiresAt().AsTime().UTC().Format(time.RFC3339))
87+
if len(ch.GetBoundNames()) > 0 {
88+
_, _ = fmt.Fprintf(w, "Bound names: %s\n", strings.Join(ch.GetBoundNames(), ", "))
89+
}
90+
_, err = fmt.Fprintln(cmd.ErrOrStderr(), "The challenge is shown once and works for one enrolment. The node cannot show it again.")
91+
return err
92+
},
93+
}
94+
cmd.Flags().StringVar(&profile, "profile", "", "SCEP profile the enrolment issues from (required when several are configured)")
95+
cmd.Flags().DurationVar(&ttl, "ttl", 0, "how long the challenge stays usable (default 1h, at most 168h)")
96+
cmd.Flags().StringSliceVar(&names, "name", nil, "bind the challenge to this DNS name (repeatable); the request may then carry only these names")
97+
return cmd
98+
}
99+
100+
func newSCEPListChallengesCmd(opts *globalOpts) *cobra.Command {
101+
return &cobra.Command{
102+
Use: "list",
103+
Short: "List the challenges that are still usable",
104+
Args: cobra.NoArgs,
105+
RunE: func(cmd *cobra.Command, _ []string) error {
106+
client, closeConn, err := dial(opts)
107+
if err != nil {
108+
return err
109+
}
110+
defer func() { _ = closeConn() }()
111+
resp, err := client.ListScepChallenges(cmd.Context(), &cryptosv1.ListScepChallengesRequest{})
112+
if err != nil {
113+
return err
114+
}
115+
return writeSCEPChallenges(cmd.OutOrStdout(), resp, opts.output)
116+
},
117+
}
118+
}
119+
120+
func newSCEPRevokeChallengeCmd(opts *globalOpts) *cobra.Command {
121+
var id string
122+
cmd := &cobra.Command{
123+
Use: "revoke",
124+
Short: "Withdraw an unused challenge",
125+
Args: cobra.NoArgs,
126+
RunE: func(cmd *cobra.Command, _ []string) error {
127+
if id == "" {
128+
return errors.New("--id is required")
129+
}
130+
client, closeConn, err := dial(opts)
131+
if err != nil {
132+
return err
133+
}
134+
defer func() { _ = closeConn() }()
135+
resp, err := client.RevokeScepChallenge(cmd.Context(), &cryptosv1.RevokeScepChallengeRequest{Id: id})
136+
if err != nil {
137+
return err
138+
}
139+
if opts.output != formatHuman {
140+
return renderProto(cmd.OutOrStdout(), resp, opts.output)
141+
}
142+
_, err = fmt.Fprintf(cmd.OutOrStdout(), "Revoked challenge %s (profile %s)\n", resp.GetChallenge().GetId(), resp.GetChallenge().GetProfile())
143+
return err
144+
},
145+
}
146+
cmd.Flags().StringVar(&id, "id", "", "id of the challenge to revoke (required)")
147+
return cmd
148+
}
149+
150+
func newSCEPListEnrollmentsCmd(opts *globalOpts) *cobra.Command {
151+
var profile string
152+
cmd := &cobra.Command{
153+
Use: "list",
154+
Short: "List the enrolments waiting for approval",
155+
Args: cobra.NoArgs,
156+
RunE: func(cmd *cobra.Command, _ []string) error {
157+
client, closeConn, err := dial(opts)
158+
if err != nil {
159+
return err
160+
}
161+
defer func() { _ = closeConn() }()
162+
resp, err := client.ListScepEnrollments(cmd.Context(), &cryptosv1.ListScepEnrollmentsRequest{Profile: profile})
163+
if err != nil {
164+
return err
165+
}
166+
return writeSCEPEnrollments(cmd.OutOrStdout(), resp, opts.output)
167+
},
168+
}
169+
cmd.Flags().StringVar(&profile, "profile", "", "only list enrolments for this SCEP profile")
170+
return cmd
171+
}
172+
173+
func newSCEPApproveCmd(opts *globalOpts) *cobra.Command {
174+
var id string
175+
cmd := &cobra.Command{
176+
Use: "approve",
177+
Short: "Issue the certificate for a waiting enrolment",
178+
Args: cobra.NoArgs,
179+
RunE: func(cmd *cobra.Command, _ []string) error {
180+
if id == "" {
181+
return errors.New("--id is required")
182+
}
183+
client, closeConn, err := dial(opts)
184+
if err != nil {
185+
return err
186+
}
187+
defer func() { _ = closeConn() }()
188+
resp, err := client.ApproveScepEnrollment(cmd.Context(), &cryptosv1.ApproveScepEnrollmentRequest{Id: id})
189+
if err != nil {
190+
return err
191+
}
192+
if opts.output != formatHuman {
193+
return renderProto(cmd.OutOrStdout(), resp, opts.output)
194+
}
195+
_, err = fmt.Fprintf(cmd.OutOrStdout(), "Approved enrolment %s: issued serial %s. The device collects it at its next poll.\n",
196+
resp.GetEnrollment().GetId(), resp.GetSerialHex())
197+
return err
198+
},
199+
}
200+
cmd.Flags().StringVar(&id, "id", "", "id of the enrolment to approve (required)")
201+
return cmd
202+
}
203+
204+
func newSCEPRejectCmd(opts *globalOpts) *cobra.Command {
205+
var id, reason string
206+
cmd := &cobra.Command{
207+
Use: "reject",
208+
Short: "Refuse a waiting enrolment",
209+
Args: cobra.NoArgs,
210+
RunE: func(cmd *cobra.Command, _ []string) error {
211+
if id == "" {
212+
return errors.New("--id is required")
213+
}
214+
client, closeConn, err := dial(opts)
215+
if err != nil {
216+
return err
217+
}
218+
defer func() { _ = closeConn() }()
219+
resp, err := client.RejectScepEnrollment(cmd.Context(), &cryptosv1.RejectScepEnrollmentRequest{Id: id, Reason: reason})
220+
if err != nil {
221+
return err
222+
}
223+
if opts.output != formatHuman {
224+
return renderProto(cmd.OutOrStdout(), resp, opts.output)
225+
}
226+
_, err = fmt.Fprintf(cmd.OutOrStdout(), "Rejected enrolment %s. The device's next poll is refused.\n", resp.GetEnrollment().GetId())
227+
return err
228+
},
229+
}
230+
cmd.Flags().StringVar(&id, "id", "", "id of the enrolment to reject (required)")
231+
cmd.Flags().StringVar(&reason, "reason", "", "why, for the audit log (the device is not told)")
232+
return cmd
233+
}
234+
235+
func writeSCEPChallenges(w io.Writer, resp *cryptosv1.ListScepChallengesResponse, format string) error {
236+
if format != formatHuman {
237+
return renderProto(w, resp, format)
238+
}
239+
if len(resp.GetChallenges()) == 0 {
240+
_, err := io.WriteString(w, "(no usable challenges)\n")
241+
return err
242+
}
243+
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
244+
_, _ = fmt.Fprintln(tw, "ID\tPROFILE\tEXPIRES\tBOUND_NAMES\tCREATED_BY")
245+
for _, c := range resp.GetChallenges() {
246+
_, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", c.GetId(), c.GetProfile(),
247+
c.GetExpiresAt().AsTime().UTC().Format(time.RFC3339), orDash(strings.Join(c.GetBoundNames(), ",")), orDash(c.GetCreatedByCn()))
248+
}
249+
return tw.Flush()
250+
}
251+
252+
func writeSCEPEnrollments(w io.Writer, resp *cryptosv1.ListScepEnrollmentsResponse, format string) error {
253+
if format != formatHuman {
254+
return renderProto(w, resp, format)
255+
}
256+
if len(resp.GetEnrollments()) == 0 {
257+
_, err := io.WriteString(w, "(no enrolments waiting)\n")
258+
return err
259+
}
260+
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
261+
_, _ = fmt.Fprintln(tw, "ID\tPROFILE\tSUBJECT\tDNS_NAMES\tKEY\tRECEIVED")
262+
for _, e := range resp.GetEnrollments() {
263+
_, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\t%s\n", e.GetId(), e.GetProfile(), e.GetSubjectDn(),
264+
orDash(strings.Join(e.GetDnsNames(), ",")), e.GetKeyAlg(), e.GetReceivedAt().AsTime().UTC().Format(time.RFC3339))
265+
}
266+
return tw.Flush()
267+
}
268+
269+
func orDash(s string) string {
270+
if s == "" {
271+
return "-"
272+
}
273+
return s
274+
}

0 commit comments

Comments
 (0)