order.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. package api
  2. import (
  3. "context"
  4. "crypto/rand"
  5. "crypto/x509"
  6. "encoding/base64"
  7. "encoding/json"
  8. "fmt"
  9. "net"
  10. "net/http"
  11. "strings"
  12. "time"
  13. "github.com/go-chi/chi/v5"
  14. "go.step.sm/crypto/randutil"
  15. "go.step.sm/crypto/x509util"
  16. "github.com/smallstep/certificates/acme"
  17. "github.com/smallstep/certificates/acme/wire"
  18. "github.com/smallstep/certificates/api/render"
  19. "github.com/smallstep/certificates/authority/policy"
  20. "github.com/smallstep/certificates/authority/provisioner"
  21. )
  22. // maxRemoteAttestationHint is the maximum length of the value of a
  23. // remote-attestation identifier.
  24. const maxRemoteAttestationHint = 128
  25. // NewOrderRequest represents the body for a NewOrder request.
  26. type NewOrderRequest struct {
  27. Identifiers []acme.Identifier `json:"identifiers"`
  28. NotBefore time.Time `json:"notBefore,omitzero"`
  29. NotAfter time.Time `json:"notAfter,omitzero"`
  30. }
  31. // Validate validates a new-order request body.
  32. func (n *NewOrderRequest) Validate() error {
  33. if len(n.Identifiers) == 0 {
  34. return acme.NewError(acme.ErrorMalformedType, "identifiers list cannot be empty")
  35. }
  36. var remoteAttestations int
  37. for _, id := range n.Identifiers {
  38. switch id.Type {
  39. case acme.IP:
  40. if net.ParseIP(id.Value) == nil {
  41. return acme.NewError(acme.ErrorMalformedType, "invalid IP address: %s", id.Value)
  42. }
  43. case acme.DNS:
  44. value, _ := trimIfWildcard(id.Value)
  45. if _, err := x509util.SanitizeName(value); err != nil {
  46. return acme.NewError(acme.ErrorMalformedType, "invalid DNS name: %s", id.Value)
  47. }
  48. case acme.PermanentIdentifier:
  49. if id.Value == "" {
  50. return acme.NewError(acme.ErrorMalformedType, "permanent identifier cannot be empty")
  51. }
  52. case acme.WireUser, acme.WireDevice:
  53. // validation of Wire identifiers is performed in `validateWireIdentifiers`, but
  54. // marked here as known and supported types.
  55. continue
  56. case acme.RemoteAttestation:
  57. // The value is a hint, which may be empty.
  58. if len(id.Value) > maxRemoteAttestationHint {
  59. return acme.NewError(acme.ErrorMalformedType, "remote-attestation identifier value cannot be longer than %d bytes", maxRemoteAttestationHint)
  60. }
  61. // One attestation per order, so that finalize, the webhooks
  62. // and the templates each see a single one.
  63. remoteAttestations++
  64. if remoteAttestations > 1 {
  65. return acme.NewError(acme.ErrorMalformedType, "an order cannot have more than one remote-attestation identifier")
  66. }
  67. default:
  68. return acme.NewError(acme.ErrorMalformedType, "identifier type unsupported: %s", id.Type)
  69. }
  70. }
  71. if err := n.validateWireIdentifiers(); err != nil {
  72. return acme.WrapError(acme.ErrorMalformedType, err, "failed validating Wire identifiers")
  73. }
  74. // TODO(hs): add some validations for DNS domains?
  75. // TODO(hs): combine the errors from this with allow/deny policy, like example error in https://datatracker.ietf.org/doc/html/rfc8555#section-6.7.1
  76. return nil
  77. }
  78. func (n *NewOrderRequest) validateWireIdentifiers() error {
  79. if !n.hasWireIdentifiers() {
  80. return nil
  81. }
  82. userIdentifiers := identifiersOfType(acme.WireUser, n.Identifiers)
  83. deviceIdentifiers := identifiersOfType(acme.WireDevice, n.Identifiers)
  84. if len(userIdentifiers) != 1 {
  85. return fmt.Errorf("expected exactly one Wire UserID identifier; got %d", len(userIdentifiers))
  86. }
  87. if len(deviceIdentifiers) != 1 {
  88. return fmt.Errorf("expected exactly one Wire DeviceID identifier, got %d", len(deviceIdentifiers))
  89. }
  90. wireUserID, err := wire.ParseUserID(userIdentifiers[0].Value)
  91. if err != nil {
  92. return fmt.Errorf("failed parsing Wire UserID: %w", err)
  93. }
  94. wireDeviceID, err := wire.ParseDeviceID(deviceIdentifiers[0].Value)
  95. if err != nil {
  96. return fmt.Errorf("failed parsing Wire DeviceID: %w", err)
  97. }
  98. if _, err := wire.ParseClientID(wireDeviceID.ClientID); err != nil {
  99. return fmt.Errorf("invalid Wire client ID %q: %w", wireDeviceID.ClientID, err)
  100. }
  101. switch {
  102. case wireUserID.Domain != wireDeviceID.Domain:
  103. return fmt.Errorf("UserID domain %q does not match DeviceID domain %q", wireUserID.Domain, wireDeviceID.Domain)
  104. case wireUserID.Name != wireDeviceID.Name:
  105. return fmt.Errorf("UserID name %q does not match DeviceID name %q", wireUserID.Name, wireDeviceID.Name)
  106. case wireUserID.Handle != wireDeviceID.Handle:
  107. return fmt.Errorf("UserID handle %q does not match DeviceID handle %q", wireUserID.Handle, wireDeviceID.Handle)
  108. }
  109. return nil
  110. }
  111. // hasWireIdentifiers returns whether the [NewOrderRequest] contains
  112. // Wire identifiers.
  113. func (n *NewOrderRequest) hasWireIdentifiers() bool {
  114. for _, i := range n.Identifiers {
  115. if i.Type == acme.WireUser || i.Type == acme.WireDevice {
  116. return true
  117. }
  118. }
  119. return false
  120. }
  121. // identifiersOfType returns the Identifiers that are of type typ.
  122. func identifiersOfType(typ acme.IdentifierType, ids []acme.Identifier) (result []acme.Identifier) {
  123. for _, id := range ids {
  124. if id.Type == typ {
  125. result = append(result, id)
  126. }
  127. }
  128. return
  129. }
  130. // FinalizeRequest captures the body for a Finalize order request.
  131. type FinalizeRequest struct {
  132. CSR string `json:"csr"`
  133. csr *x509.CertificateRequest
  134. }
  135. // Validate validates a finalize request body.
  136. func (f *FinalizeRequest) Validate() error {
  137. var err error
  138. // RFC 8555 isn't 100% conclusive about using raw base64-url encoding for the
  139. // CSR specifically, instead of "normal" base64-url encoding (incl. padding).
  140. // By trimming the padding from CSRs submitted by ACME clients that use
  141. // base64-url encoding instead of raw base64-url encoding, these are also
  142. // supported. This was reported in https://github.com/smallstep/certificates/issues/939
  143. // to be the case for a Synology DSM NAS system.
  144. csrBytes, err := base64.RawURLEncoding.DecodeString(strings.TrimRight(f.CSR, "="))
  145. if err != nil {
  146. return acme.WrapError(acme.ErrorMalformedType, err, "error base64url decoding csr")
  147. }
  148. f.csr, err = x509.ParseCertificateRequest(csrBytes)
  149. if err != nil {
  150. return acme.WrapError(acme.ErrorMalformedType, err, "unable to parse csr")
  151. }
  152. if err = f.csr.CheckSignature(); err != nil {
  153. return acme.WrapError(acme.ErrorMalformedType, err, "csr failed signature check")
  154. }
  155. return nil
  156. }
  157. var defaultOrderExpiry = time.Hour * 24
  158. var defaultOrderBackdate = time.Minute
  159. // NewOrder ACME api for creating a new order.
  160. func NewOrder(w http.ResponseWriter, r *http.Request) {
  161. ctx := r.Context()
  162. ca := mustAuthority(ctx)
  163. db := acme.MustDatabaseFromContext(ctx)
  164. linker := acme.MustLinkerFromContext(ctx)
  165. acc, err := accountFromContext(ctx)
  166. if err != nil {
  167. render.Error(w, r, err)
  168. return
  169. }
  170. prov, err := provisionerFromContext(ctx)
  171. if err != nil {
  172. render.Error(w, r, err)
  173. return
  174. }
  175. payload, err := payloadFromContext(ctx)
  176. if err != nil {
  177. render.Error(w, r, err)
  178. return
  179. }
  180. var nor NewOrderRequest
  181. if err := json.Unmarshal(payload.value, &nor); err != nil {
  182. render.Error(w, r, acme.WrapError(acme.ErrorMalformedType, err,
  183. "failed to unmarshal new-order request payload"))
  184. return
  185. }
  186. if err := nor.Validate(); err != nil {
  187. render.Error(w, r, err)
  188. return
  189. }
  190. // TODO(hs): gather all errors, so that we can build one response with ACME subproblems
  191. // include the nor.Validate() error here too, like in the example in the ACME RFC?
  192. acmeProv, err := acmeProvisionerFromContext(ctx)
  193. if err != nil {
  194. render.Error(w, r, err)
  195. return
  196. }
  197. if err := addRemoteAttestationIdentifier(ctx, acmeProv, &nor); err != nil {
  198. render.Error(w, r, err)
  199. return
  200. }
  201. var eak *acme.ExternalAccountKey
  202. if acmeProv.RequireEAB {
  203. if eak, err = db.GetExternalAccountKeyByAccountID(ctx, prov.GetID(), acc.ID); err != nil {
  204. render.Error(w, r, acme.WrapErrorISE(err, "error retrieving external account binding key"))
  205. return
  206. }
  207. }
  208. acmePolicy, err := newACMEPolicyEngine(eak)
  209. if err != nil {
  210. render.Error(w, r, acme.WrapErrorISE(err, "error creating ACME policy engine"))
  211. return
  212. }
  213. for _, identifier := range nor.Identifiers {
  214. // A remote-attestation identifier names nothing in the certificate,
  215. // so the name policies do not apply to it.
  216. if identifier.Type == acme.RemoteAttestation {
  217. continue
  218. }
  219. // evaluate the ACME account level policy
  220. if err = isIdentifierAllowed(acmePolicy, identifier); err != nil {
  221. render.Error(w, r, acme.WrapError(acme.ErrorRejectedIdentifierType, err, "not authorized"))
  222. return
  223. }
  224. // evaluate the provisioner level policy
  225. orderIdentifier := provisioner.ACMEIdentifier{Type: provisioner.ACMEIdentifierType(identifier.Type), Value: identifier.Value}
  226. if err = prov.AuthorizeOrderIdentifier(ctx, orderIdentifier); err != nil {
  227. render.Error(w, r, acme.WrapError(acme.ErrorRejectedIdentifierType, err, "not authorized"))
  228. return
  229. }
  230. // evaluate the authority level policy
  231. if err = ca.AreSANsAllowed(ctx, []string{identifier.Value}); err != nil {
  232. render.Error(w, r, acme.WrapError(acme.ErrorRejectedIdentifierType, err, "not authorized"))
  233. return
  234. }
  235. }
  236. now := clock.Now()
  237. // New order.
  238. o := &acme.Order{
  239. AccountID: acc.ID,
  240. ProvisionerID: prov.GetID(),
  241. Status: acme.StatusPending,
  242. Identifiers: nor.Identifiers,
  243. ExpiresAt: now.Add(defaultOrderExpiry),
  244. AuthorizationIDs: make([]string, len(nor.Identifiers)),
  245. NotBefore: nor.NotBefore,
  246. NotAfter: nor.NotAfter,
  247. }
  248. for i, identifier := range o.Identifiers {
  249. az := &acme.Authorization{
  250. AccountID: acc.ID,
  251. Identifier: identifier,
  252. ExpiresAt: o.ExpiresAt,
  253. Status: acme.StatusPending,
  254. }
  255. if err := newAuthorization(ctx, az); err != nil {
  256. render.Error(w, r, err)
  257. return
  258. }
  259. o.AuthorizationIDs[i] = az.ID
  260. }
  261. if o.NotBefore.IsZero() {
  262. o.NotBefore = now
  263. }
  264. if o.NotAfter.IsZero() {
  265. o.NotAfter = o.NotBefore.Add(prov.DefaultTLSCertDuration())
  266. }
  267. // if request NotBefore was empty, then backdate the order.NotBefore (now)
  268. // to avoid timing issues.
  269. if nor.NotBefore.IsZero() {
  270. backdate := defaultOrderBackdate
  271. if bd := ca.GetBackdate(); bd != nil {
  272. backdate = *bd
  273. }
  274. o.NotBefore = o.NotBefore.Add(-backdate)
  275. }
  276. if err := db.CreateOrder(ctx, o); err != nil {
  277. render.Error(w, r, acme.WrapErrorISE(err, "error creating order"))
  278. return
  279. }
  280. linker.LinkOrder(ctx, o)
  281. w.Header().Set("Location", linker.GetLink(ctx, acme.OrderLinkType, o.ID))
  282. render.JSONStatus(w, r, o, http.StatusCreated)
  283. }
  284. // addRemoteAttestationIdentifier refuses a remote-attestation identifier if the
  285. // provisioner does not enable remote-attest-01, and adds one with an empty hint
  286. // if the provisioner requires remote attestation and the order has none, as
  287. // draft-ietf-acme-rats-03 section 3.2 allows.
  288. func addRemoteAttestationIdentifier(ctx context.Context, prov *provisioner.ACME, nor *NewOrderRequest) error {
  289. enabled := prov.IsChallengeEnabled(ctx, provisioner.REMOTE_ATTEST_01)
  290. for _, id := range nor.Identifiers {
  291. if id.Type == acme.RemoteAttestation {
  292. if !enabled {
  293. return acme.NewError(acme.ErrorUnsupportedIdentifierType, "remote-attestation identifiers are not supported by this provisioner")
  294. }
  295. return nil
  296. }
  297. }
  298. if enabled && prov.GetRemoteAttestation().IsRequired() {
  299. nor.Identifiers = append(nor.Identifiers, acme.Identifier{Type: acme.RemoteAttestation})
  300. }
  301. return nil
  302. }
  303. func isIdentifierAllowed(acmePolicy policy.X509Policy, identifier acme.Identifier) error {
  304. if acmePolicy == nil {
  305. return nil
  306. }
  307. return acmePolicy.AreSANsAllowed([]string{identifier.Value})
  308. }
  309. func newACMEPolicyEngine(eak *acme.ExternalAccountKey) (policy.X509Policy, error) {
  310. if eak == nil {
  311. //nolint:nilnil,nolintlint // expected values
  312. return nil, nil
  313. }
  314. return policy.NewX509PolicyEngine(eak.Policy)
  315. }
  316. func trimIfWildcard(value string) (string, bool) {
  317. if after, ok := strings.CutPrefix(value, "*."); ok {
  318. return after, true
  319. }
  320. return value, false
  321. }
  322. func newAuthorization(ctx context.Context, az *acme.Authorization) error {
  323. value, isWildcard := trimIfWildcard(az.Identifier.Value)
  324. az.Wildcard = isWildcard
  325. az.Identifier = acme.Identifier{
  326. Value: value,
  327. Type: az.Identifier.Type,
  328. }
  329. chTypes := challengeTypes(az)
  330. var err error
  331. az.Token, err = randutil.Alphanumeric(32)
  332. if err != nil {
  333. return acme.WrapErrorISE(err, "error generating random alphanumeric ID")
  334. }
  335. db := acme.MustDatabaseFromContext(ctx)
  336. prov := acme.MustProvisionerFromContext(ctx)
  337. az.Challenges = make([]*acme.Challenge, 0, len(chTypes))
  338. for _, typ := range chTypes {
  339. if !prov.IsChallengeEnabled(ctx, provisioner.ACMEChallenge(typ)) {
  340. continue
  341. }
  342. var target string
  343. switch az.Identifier.Type {
  344. case acme.WireUser:
  345. wireOptions, err := prov.GetOptions().GetWireOptions()
  346. if err != nil {
  347. return acme.WrapErrorISE(err, "failed getting Wire options")
  348. }
  349. target, err = wireOptions.GetOIDCOptions().EvaluateTarget("") // TODO(hs): determine if required by Wire
  350. if err != nil {
  351. return acme.WrapError(acme.ErrorMalformedType, err, "invalid Go template registered for 'target'")
  352. }
  353. case acme.WireDevice:
  354. wireID, err := wire.ParseDeviceID(az.Identifier.Value)
  355. if err != nil {
  356. return acme.WrapError(acme.ErrorMalformedType, err, "failed parsing WireDevice")
  357. }
  358. clientID, err := wire.ParseClientID(wireID.ClientID)
  359. if err != nil {
  360. return acme.WrapError(acme.ErrorMalformedType, err, "failed parsing ClientID")
  361. }
  362. wireOptions, err := prov.GetOptions().GetWireOptions()
  363. if err != nil {
  364. return acme.WrapErrorISE(err, "failed getting Wire options")
  365. }
  366. target, err = wireOptions.GetDPOPOptions().EvaluateTarget(clientID.DeviceID)
  367. if err != nil {
  368. return acme.WrapError(acme.ErrorMalformedType, err, "invalid Go template registered for 'target'")
  369. }
  370. }
  371. ch := &acme.Challenge{
  372. AccountID: az.AccountID,
  373. Value: az.Identifier.Value,
  374. Type: typ,
  375. Token: az.Token,
  376. Status: acme.StatusPending,
  377. Target: target,
  378. }
  379. if typ == acme.REMOTEATTEST01 {
  380. ch.FreshnessNonce = newFreshnessNonce()
  381. ch.AttestClaimsHint = prov.GetRemoteAttestation().GetClaimsHint()
  382. }
  383. if err := db.CreateChallenge(ctx, ch); err != nil {
  384. return acme.WrapErrorISE(err, "error creating challenge")
  385. }
  386. az.Challenges = append(az.Challenges, ch)
  387. }
  388. if err = db.CreateAuthorization(ctx, az); err != nil {
  389. return acme.WrapErrorISE(err, "error creating authorization")
  390. }
  391. return nil
  392. }
  393. // newFreshnessNonce returns the freshness nonce of a remote-attest-01
  394. // challenge: 32 random bytes, base64url encoded without padding.
  395. func newFreshnessNonce() string {
  396. b := make([]byte, 32)
  397. _, _ = rand.Read(b) // never fails
  398. return base64.RawURLEncoding.EncodeToString(b)
  399. }
  400. // GetOrder ACME api for retrieving an order.
  401. func GetOrder(w http.ResponseWriter, r *http.Request) {
  402. ctx := r.Context()
  403. db := acme.MustDatabaseFromContext(ctx)
  404. linker := acme.MustLinkerFromContext(ctx)
  405. acc, err := accountFromContext(ctx)
  406. if err != nil {
  407. render.Error(w, r, err)
  408. return
  409. }
  410. prov, err := provisionerFromContext(ctx)
  411. if err != nil {
  412. render.Error(w, r, err)
  413. return
  414. }
  415. o, err := db.GetOrder(ctx, chi.URLParam(r, "ordID"))
  416. if err != nil {
  417. render.Error(w, r, acme.WrapErrorISE(err, "error retrieving order"))
  418. return
  419. }
  420. if acc.ID != o.AccountID {
  421. render.Error(w, r, acme.NewError(acme.ErrorUnauthorizedType,
  422. "account '%s' does not own order '%s'", acc.ID, o.ID))
  423. return
  424. }
  425. if prov.GetID() != o.ProvisionerID {
  426. render.Error(w, r, acme.NewError(acme.ErrorUnauthorizedType,
  427. "provisioner '%s' does not own order '%s'", prov.GetID(), o.ID))
  428. return
  429. }
  430. if err = o.UpdateStatus(ctx, db); err != nil {
  431. render.Error(w, r, acme.WrapErrorISE(err, "error updating order status"))
  432. return
  433. }
  434. linker.LinkOrder(ctx, o)
  435. w.Header().Set("Location", linker.GetLink(ctx, acme.OrderLinkType, o.ID))
  436. render.JSON(w, r, o)
  437. }
  438. // FinalizeOrder attempts to finalize an order and create a certificate.
  439. func FinalizeOrder(w http.ResponseWriter, r *http.Request) {
  440. ctx := r.Context()
  441. db := acme.MustDatabaseFromContext(ctx)
  442. linker := acme.MustLinkerFromContext(ctx)
  443. acc, err := accountFromContext(ctx)
  444. if err != nil {
  445. render.Error(w, r, err)
  446. return
  447. }
  448. prov, err := provisionerFromContext(ctx)
  449. if err != nil {
  450. render.Error(w, r, err)
  451. return
  452. }
  453. payload, err := payloadFromContext(ctx)
  454. if err != nil {
  455. render.Error(w, r, err)
  456. return
  457. }
  458. var fr FinalizeRequest
  459. if err := json.Unmarshal(payload.value, &fr); err != nil {
  460. render.Error(w, r, acme.WrapError(acme.ErrorMalformedType, err,
  461. "failed to unmarshal finalize-order request payload"))
  462. return
  463. }
  464. if err := fr.Validate(); err != nil {
  465. render.Error(w, r, err)
  466. return
  467. }
  468. o, err := db.GetOrder(ctx, chi.URLParam(r, "ordID"))
  469. if err != nil {
  470. render.Error(w, r, acme.WrapErrorISE(err, "error retrieving order"))
  471. return
  472. }
  473. if acc.ID != o.AccountID {
  474. render.Error(w, r, acme.NewError(acme.ErrorUnauthorizedType,
  475. "account '%s' does not own order '%s'", acc.ID, o.ID))
  476. return
  477. }
  478. if prov.GetID() != o.ProvisionerID {
  479. render.Error(w, r, acme.NewError(acme.ErrorUnauthorizedType,
  480. "provisioner '%s' does not own order '%s'", prov.GetID(), o.ID))
  481. return
  482. }
  483. ca := mustAuthority(ctx)
  484. if err = o.Finalize(ctx, db, fr.csr, ca, prov); err != nil {
  485. render.Error(w, r, acme.WrapErrorISE(err, "error finalizing order"))
  486. return
  487. }
  488. linker.LinkOrder(ctx, o)
  489. w.Header().Set("Location", linker.GetLink(ctx, acme.OrderLinkType, o.ID))
  490. render.JSON(w, r, o)
  491. }
  492. // challengeTypes determines the types of challenges that should be used
  493. // for the ACME authorization request.
  494. func challengeTypes(az *acme.Authorization) []acme.ChallengeType {
  495. var chTypes []acme.ChallengeType
  496. switch az.Identifier.Type {
  497. case acme.IP:
  498. chTypes = []acme.ChallengeType{acme.HTTP01, acme.TLSALPN01}
  499. case acme.DNS:
  500. chTypes = []acme.ChallengeType{acme.DNS01}
  501. // HTTP and TLS challenges can only be used for identifiers without wildcards.
  502. if !az.Wildcard {
  503. chTypes = append(chTypes, []acme.ChallengeType{acme.HTTP01, acme.TLSALPN01}...)
  504. }
  505. case acme.PermanentIdentifier:
  506. chTypes = []acme.ChallengeType{acme.DEVICEATTEST01}
  507. case acme.WireUser:
  508. chTypes = []acme.ChallengeType{acme.WIREOIDC01}
  509. case acme.WireDevice:
  510. chTypes = []acme.ChallengeType{acme.WIREDPOP01}
  511. case acme.RemoteAttestation:
  512. chTypes = []acme.ChallengeType{acme.REMOTEATTEST01}
  513. default:
  514. chTypes = []acme.ChallengeType{}
  515. }
  516. return chTypes
  517. }