authority.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package authority
  2. import (
  3. "context"
  4. "crypto"
  5. "crypto/sha256"
  6. "crypto/x509"
  7. "encoding/hex"
  8. "log"
  9. "strings"
  10. "sync"
  11. "time"
  12. "github.com/pkg/errors"
  13. "github.com/smallstep/certificates/authority/admin"
  14. adminDBNosql "github.com/smallstep/certificates/authority/admin/db/nosql"
  15. "github.com/smallstep/certificates/authority/administrator"
  16. "github.com/smallstep/certificates/authority/config"
  17. "github.com/smallstep/certificates/authority/provisioner"
  18. "github.com/smallstep/certificates/cas"
  19. casapi "github.com/smallstep/certificates/cas/apiv1"
  20. "github.com/smallstep/certificates/db"
  21. "github.com/smallstep/certificates/kms"
  22. kmsapi "github.com/smallstep/certificates/kms/apiv1"
  23. "github.com/smallstep/certificates/kms/sshagentkms"
  24. "github.com/smallstep/certificates/scep"
  25. "github.com/smallstep/certificates/templates"
  26. "github.com/smallstep/nosql"
  27. "go.step.sm/crypto/pemutil"
  28. "go.step.sm/linkedca"
  29. "golang.org/x/crypto/ssh"
  30. )
  31. // Authority implements the Certificate Authority internal interface.
  32. type Authority struct {
  33. config *config.Config
  34. keyManager kms.KeyManager
  35. provisioners *provisioner.Collection
  36. admins *administrator.Collection
  37. db db.AuthDB
  38. adminDB admin.DB
  39. templates *templates.Templates
  40. linkedCAToken string
  41. // X509 CA
  42. password []byte
  43. issuerPassword []byte
  44. x509CAService cas.CertificateAuthorityService
  45. rootX509Certs []*x509.Certificate
  46. rootX509CertPool *x509.CertPool
  47. federatedX509Certs []*x509.Certificate
  48. certificates *sync.Map
  49. x509Enforcers []provisioner.CertificateEnforcer
  50. // SCEP CA
  51. scepService *scep.Service
  52. // SSH CA
  53. sshHostPassword []byte
  54. sshUserPassword []byte
  55. sshCAUserCertSignKey ssh.Signer
  56. sshCAHostCertSignKey ssh.Signer
  57. sshCAUserCerts []ssh.PublicKey
  58. sshCAHostCerts []ssh.PublicKey
  59. sshCAUserFederatedCerts []ssh.PublicKey
  60. sshCAHostFederatedCerts []ssh.PublicKey
  61. // Do not re-initialize
  62. initOnce bool
  63. startTime time.Time
  64. // Custom functions
  65. sshBastionFunc func(ctx context.Context, user, hostname string) (*config.Bastion, error)
  66. sshCheckHostFunc func(ctx context.Context, principal string, tok string, roots []*x509.Certificate) (bool, error)
  67. sshGetHostsFunc func(ctx context.Context, cert *x509.Certificate) ([]config.Host, error)
  68. getIdentityFunc provisioner.GetIdentityFunc
  69. authorizeRenewFunc provisioner.AuthorizeRenewFunc
  70. authorizeSSHRenewFunc provisioner.AuthorizeSSHRenewFunc
  71. adminMutex sync.RWMutex
  72. }
  73. // New creates and initiates a new Authority type.
  74. func New(cfg *config.Config, opts ...Option) (*Authority, error) {
  75. err := cfg.Validate()
  76. if err != nil {
  77. return nil, err
  78. }
  79. var a = &Authority{
  80. config: cfg,
  81. certificates: new(sync.Map),
  82. }
  83. // Apply options.
  84. for _, fn := range opts {
  85. if err := fn(a); err != nil {
  86. return nil, err
  87. }
  88. }
  89. // Initialize authority from options or configuration.
  90. if err := a.init(); err != nil {
  91. return nil, err
  92. }
  93. return a, nil
  94. }
  95. // NewEmbedded initializes an authority that can be embedded in a different
  96. // project without the limitations of the config.
  97. func NewEmbedded(opts ...Option) (*Authority, error) {
  98. a := &Authority{
  99. config: &config.Config{},
  100. certificates: new(sync.Map),
  101. }
  102. // Apply options.
  103. for _, fn := range opts {
  104. if err := fn(a); err != nil {
  105. return nil, err
  106. }
  107. }
  108. // Validate required options
  109. switch {
  110. case a.config == nil:
  111. return nil, errors.New("cannot create an authority without a configuration")
  112. case len(a.rootX509Certs) == 0 && a.config.Root.HasEmpties():
  113. return nil, errors.New("cannot create an authority without a root certificate")
  114. case a.x509CAService == nil && a.config.IntermediateCert == "":
  115. return nil, errors.New("cannot create an authority without an issuer certificate")
  116. case a.x509CAService == nil && a.config.IntermediateKey == "":
  117. return nil, errors.New("cannot create an authority without an issuer signer")
  118. }
  119. // Initialize config required fields.
  120. a.config.Init()
  121. // Initialize authority from options or configuration.
  122. if err := a.init(); err != nil {
  123. return nil, err
  124. }
  125. return a, nil
  126. }
  127. // reloadAdminResources reloads admins and provisioners from the DB.
  128. func (a *Authority) reloadAdminResources(ctx context.Context) error {
  129. var (
  130. provList provisioner.List
  131. adminList []*linkedca.Admin
  132. )
  133. if a.config.AuthorityConfig.EnableAdmin {
  134. provs, err := a.adminDB.GetProvisioners(ctx)
  135. if err != nil {
  136. return admin.WrapErrorISE(err, "error getting provisioners to initialize authority")
  137. }
  138. provList, err = provisionerListToCertificates(provs)
  139. if err != nil {
  140. return admin.WrapErrorISE(err, "error converting provisioner list to certificates")
  141. }
  142. adminList, err = a.adminDB.GetAdmins(ctx)
  143. if err != nil {
  144. return admin.WrapErrorISE(err, "error getting admins to initialize authority")
  145. }
  146. } else {
  147. provList = a.config.AuthorityConfig.Provisioners
  148. adminList = a.config.AuthorityConfig.Admins
  149. }
  150. provisionerConfig, err := a.generateProvisionerConfig(ctx)
  151. if err != nil {
  152. return admin.WrapErrorISE(err, "error generating provisioner config")
  153. }
  154. // Create provisioner collection.
  155. provClxn := provisioner.NewCollection(provisionerConfig.Audiences)
  156. for _, p := range provList {
  157. if err := p.Init(provisionerConfig); err != nil {
  158. return err
  159. }
  160. if err := provClxn.Store(p); err != nil {
  161. return err
  162. }
  163. }
  164. // Create admin collection.
  165. adminClxn := administrator.NewCollection(provClxn)
  166. for _, adm := range adminList {
  167. p, ok := provClxn.Load(adm.ProvisionerId)
  168. if !ok {
  169. return admin.NewErrorISE("provisioner %s not found when loading admin %s",
  170. adm.ProvisionerId, adm.Id)
  171. }
  172. if err := adminClxn.Store(adm, p); err != nil {
  173. return err
  174. }
  175. }
  176. a.config.AuthorityConfig.Provisioners = provList
  177. a.provisioners = provClxn
  178. a.config.AuthorityConfig.Admins = adminList
  179. a.admins = adminClxn
  180. return nil
  181. }
  182. // init performs validation and initializes the fields of an Authority struct.
  183. func (a *Authority) init() error {
  184. // Check if handler has already been validated/initialized.
  185. if a.initOnce {
  186. return nil
  187. }
  188. var err error
  189. // Set password if they are not set.
  190. var configPassword []byte
  191. if a.config.Password != "" {
  192. configPassword = []byte(a.config.Password)
  193. }
  194. if configPassword != nil && a.password == nil {
  195. a.password = configPassword
  196. }
  197. if a.sshHostPassword == nil {
  198. a.sshHostPassword = a.password
  199. }
  200. if a.sshUserPassword == nil {
  201. a.sshUserPassword = a.password
  202. }
  203. // Automatically enable admin for all linked cas.
  204. if a.linkedCAToken != "" {
  205. a.config.AuthorityConfig.EnableAdmin = true
  206. }
  207. // Initialize step-ca Database if it's not already initialized with WithDB.
  208. // If a.config.DB is nil then a simple, barebones in memory DB will be used.
  209. if a.db == nil {
  210. if a.db, err = db.New(a.config.DB); err != nil {
  211. return err
  212. }
  213. }
  214. // Initialize key manager if it has not been set in the options.
  215. if a.keyManager == nil {
  216. var options kmsapi.Options
  217. if a.config.KMS != nil {
  218. options = *a.config.KMS
  219. }
  220. a.keyManager, err = kms.New(context.Background(), options)
  221. if err != nil {
  222. return err
  223. }
  224. }
  225. // Initialize linkedca client if necessary. On a linked RA, the issuer
  226. // configuration might come from majordomo.
  227. var linkedcaClient *linkedCaClient
  228. if a.config.AuthorityConfig.EnableAdmin && a.linkedCAToken != "" && a.adminDB == nil {
  229. linkedcaClient, err = newLinkedCAClient(a.linkedCAToken)
  230. if err != nil {
  231. return err
  232. }
  233. // If authorityId is configured make sure it matches the one in the token
  234. if id := a.config.AuthorityConfig.AuthorityID; id != "" && !strings.EqualFold(id, linkedcaClient.authorityID) {
  235. return errors.New("error initializing linkedca: token authority and configured authority do not match")
  236. }
  237. linkedcaClient.Run()
  238. }
  239. // Initialize the X.509 CA Service if it has not been set in the options.
  240. if a.x509CAService == nil {
  241. var options casapi.Options
  242. if a.config.AuthorityConfig.Options != nil {
  243. options = *a.config.AuthorityConfig.Options
  244. }
  245. // Configure linked RA
  246. if linkedcaClient != nil && options.CertificateAuthority == "" {
  247. conf, err := linkedcaClient.GetConfiguration(context.Background())
  248. if err != nil {
  249. return err
  250. }
  251. if conf.RaConfig != nil {
  252. options.CertificateAuthority = conf.RaConfig.CaUrl
  253. options.CertificateAuthorityFingerprint = conf.RaConfig.Fingerprint
  254. options.CertificateIssuer = &casapi.CertificateIssuer{
  255. Type: conf.RaConfig.Provisioner.Type.String(),
  256. Provisioner: conf.RaConfig.Provisioner.Name,
  257. }
  258. }
  259. }
  260. // Set the issuer password if passed in the flags.
  261. if options.CertificateIssuer != nil && a.issuerPassword != nil {
  262. options.CertificateIssuer.Password = string(a.issuerPassword)
  263. }
  264. // Read intermediate and create X509 signer for default CAS.
  265. if options.Is(casapi.SoftCAS) {
  266. options.CertificateChain, err = pemutil.ReadCertificateBundle(a.config.IntermediateCert)
  267. if err != nil {
  268. return err
  269. }
  270. options.Signer, err = a.keyManager.CreateSigner(&kmsapi.CreateSignerRequest{
  271. SigningKey: a.config.IntermediateKey,
  272. Password: []byte(a.password),
  273. })
  274. if err != nil {
  275. return err
  276. }
  277. }
  278. a.x509CAService, err = cas.New(context.Background(), options)
  279. if err != nil {
  280. return err
  281. }
  282. // Get root certificate from CAS.
  283. if srv, ok := a.x509CAService.(casapi.CertificateAuthorityGetter); ok {
  284. resp, err := srv.GetCertificateAuthority(&casapi.GetCertificateAuthorityRequest{
  285. Name: options.CertificateAuthority,
  286. })
  287. if err != nil {
  288. return err
  289. }
  290. a.rootX509Certs = append(a.rootX509Certs, resp.RootCertificate)
  291. sum := sha256.Sum256(resp.RootCertificate.Raw)
  292. log.Printf("Using root fingerprint '%s'", hex.EncodeToString(sum[:]))
  293. }
  294. }
  295. // Read root certificates and store them in the certificates map.
  296. if len(a.rootX509Certs) == 0 {
  297. a.rootX509Certs = make([]*x509.Certificate, len(a.config.Root))
  298. for i, path := range a.config.Root {
  299. crt, err := pemutil.ReadCertificate(path)
  300. if err != nil {
  301. return err
  302. }
  303. a.rootX509Certs[i] = crt
  304. }
  305. }
  306. for _, crt := range a.rootX509Certs {
  307. sum := sha256.Sum256(crt.Raw)
  308. a.certificates.Store(hex.EncodeToString(sum[:]), crt)
  309. }
  310. a.rootX509CertPool = x509.NewCertPool()
  311. for _, cert := range a.rootX509Certs {
  312. a.rootX509CertPool.AddCert(cert)
  313. }
  314. // Read federated certificates and store them in the certificates map.
  315. if len(a.federatedX509Certs) == 0 {
  316. a.federatedX509Certs = make([]*x509.Certificate, len(a.config.FederatedRoots))
  317. for i, path := range a.config.FederatedRoots {
  318. crt, err := pemutil.ReadCertificate(path)
  319. if err != nil {
  320. return err
  321. }
  322. a.federatedX509Certs[i] = crt
  323. }
  324. }
  325. for _, crt := range a.federatedX509Certs {
  326. sum := sha256.Sum256(crt.Raw)
  327. a.certificates.Store(hex.EncodeToString(sum[:]), crt)
  328. }
  329. // Decrypt and load SSH keys
  330. var tmplVars templates.Step
  331. if a.config.SSH != nil {
  332. if a.config.SSH.HostKey != "" {
  333. signer, err := a.keyManager.CreateSigner(&kmsapi.CreateSignerRequest{
  334. SigningKey: a.config.SSH.HostKey,
  335. Password: []byte(a.sshHostPassword),
  336. })
  337. if err != nil {
  338. return err
  339. }
  340. // If our signer is from sshagentkms, just unwrap it instead of
  341. // wrapping it in another layer, and this prevents crypto from
  342. // erroring out with: ssh: unsupported key type *agent.Key
  343. switch s := signer.(type) {
  344. case *sshagentkms.WrappedSSHSigner:
  345. a.sshCAHostCertSignKey = s.Sshsigner
  346. case crypto.Signer:
  347. a.sshCAHostCertSignKey, err = ssh.NewSignerFromSigner(s)
  348. default:
  349. return errors.Errorf("unsupported signer type %T", signer)
  350. }
  351. if err != nil {
  352. return errors.Wrap(err, "error creating ssh signer")
  353. }
  354. // Append public key to list of host certs
  355. a.sshCAHostCerts = append(a.sshCAHostCerts, a.sshCAHostCertSignKey.PublicKey())
  356. a.sshCAHostFederatedCerts = append(a.sshCAHostFederatedCerts, a.sshCAHostCertSignKey.PublicKey())
  357. }
  358. if a.config.SSH.UserKey != "" {
  359. signer, err := a.keyManager.CreateSigner(&kmsapi.CreateSignerRequest{
  360. SigningKey: a.config.SSH.UserKey,
  361. Password: []byte(a.sshUserPassword),
  362. })
  363. if err != nil {
  364. return err
  365. }
  366. // If our signer is from sshagentkms, just unwrap it instead of
  367. // wrapping it in another layer, and this prevents crypto from
  368. // erroring out with: ssh: unsupported key type *agent.Key
  369. switch s := signer.(type) {
  370. case *sshagentkms.WrappedSSHSigner:
  371. a.sshCAUserCertSignKey = s.Sshsigner
  372. case crypto.Signer:
  373. a.sshCAUserCertSignKey, err = ssh.NewSignerFromSigner(s)
  374. default:
  375. return errors.Errorf("unsupported signer type %T", signer)
  376. }
  377. if err != nil {
  378. return errors.Wrap(err, "error creating ssh signer")
  379. }
  380. // Append public key to list of user certs
  381. a.sshCAUserCerts = append(a.sshCAUserCerts, a.sshCAUserCertSignKey.PublicKey())
  382. a.sshCAUserFederatedCerts = append(a.sshCAUserFederatedCerts, a.sshCAUserCertSignKey.PublicKey())
  383. }
  384. // Append other public keys and add them to the template variables.
  385. for _, key := range a.config.SSH.Keys {
  386. publicKey := key.PublicKey()
  387. switch key.Type {
  388. case provisioner.SSHHostCert:
  389. if key.Federated {
  390. a.sshCAHostFederatedCerts = append(a.sshCAHostFederatedCerts, publicKey)
  391. } else {
  392. a.sshCAHostCerts = append(a.sshCAHostCerts, publicKey)
  393. }
  394. case provisioner.SSHUserCert:
  395. if key.Federated {
  396. a.sshCAUserFederatedCerts = append(a.sshCAUserFederatedCerts, publicKey)
  397. } else {
  398. a.sshCAUserCerts = append(a.sshCAUserCerts, publicKey)
  399. }
  400. default:
  401. return errors.Errorf("unsupported type %s", key.Type)
  402. }
  403. }
  404. }
  405. // Configure template variables. On the template variables HostFederatedKeys
  406. // and UserFederatedKeys we will skip the actual CA that will be available
  407. // in HostKey and UserKey.
  408. //
  409. // We cannot do it in the previous blocks because this configuration can be
  410. // injected using options.
  411. if a.sshCAHostCertSignKey != nil {
  412. tmplVars.SSH.HostKey = a.sshCAHostCertSignKey.PublicKey()
  413. tmplVars.SSH.HostFederatedKeys = append(tmplVars.SSH.HostFederatedKeys, a.sshCAHostFederatedCerts[1:]...)
  414. } else {
  415. tmplVars.SSH.HostFederatedKeys = append(tmplVars.SSH.HostFederatedKeys, a.sshCAHostFederatedCerts...)
  416. }
  417. if a.sshCAUserCertSignKey != nil {
  418. tmplVars.SSH.UserKey = a.sshCAUserCertSignKey.PublicKey()
  419. tmplVars.SSH.UserFederatedKeys = append(tmplVars.SSH.UserFederatedKeys, a.sshCAUserFederatedCerts[1:]...)
  420. } else {
  421. tmplVars.SSH.UserFederatedKeys = append(tmplVars.SSH.UserFederatedKeys, a.sshCAUserFederatedCerts...)
  422. }
  423. // Check if a KMS with decryption capability is required and available
  424. if a.requiresDecrypter() {
  425. if _, ok := a.keyManager.(kmsapi.Decrypter); !ok {
  426. return errors.New("keymanager doesn't provide crypto.Decrypter")
  427. }
  428. }
  429. // TODO: decide if this is a good approach for providing the SCEP functionality
  430. // It currently mirrors the logic for the x509CAService
  431. if a.requiresSCEPService() && a.scepService == nil {
  432. var options scep.Options
  433. // Read intermediate and create X509 signer and decrypter for default CAS.
  434. options.CertificateChain, err = pemutil.ReadCertificateBundle(a.config.IntermediateCert)
  435. if err != nil {
  436. return err
  437. }
  438. options.CertificateChain = append(options.CertificateChain, a.rootX509Certs...)
  439. options.Signer, err = a.keyManager.CreateSigner(&kmsapi.CreateSignerRequest{
  440. SigningKey: a.config.IntermediateKey,
  441. Password: []byte(a.password),
  442. })
  443. if err != nil {
  444. return err
  445. }
  446. if km, ok := a.keyManager.(kmsapi.Decrypter); ok {
  447. options.Decrypter, err = km.CreateDecrypter(&kmsapi.CreateDecrypterRequest{
  448. DecryptionKey: a.config.IntermediateKey,
  449. Password: []byte(a.password),
  450. })
  451. if err != nil {
  452. return err
  453. }
  454. }
  455. a.scepService, err = scep.NewService(context.Background(), options)
  456. if err != nil {
  457. return err
  458. }
  459. // TODO: mimick the x509CAService GetCertificateAuthority here too?
  460. }
  461. if a.config.AuthorityConfig.EnableAdmin {
  462. // Initialize step-ca Admin Database if it's not already initialized using
  463. // WithAdminDB.
  464. if a.adminDB == nil {
  465. if linkedcaClient != nil {
  466. a.adminDB = linkedcaClient
  467. } else {
  468. a.adminDB, err = adminDBNosql.New(a.db.(nosql.DB), admin.DefaultAuthorityID)
  469. if err != nil {
  470. return err
  471. }
  472. }
  473. }
  474. provs, err := a.adminDB.GetProvisioners(context.Background())
  475. if err != nil {
  476. return admin.WrapErrorISE(err, "error loading provisioners to initialize authority")
  477. }
  478. if len(provs) == 0 && !strings.EqualFold(a.config.AuthorityConfig.DeploymentType, "linked") {
  479. // Create First Provisioner
  480. prov, err := CreateFirstProvisioner(context.Background(), a.adminDB, string(a.password))
  481. if err != nil {
  482. return admin.WrapErrorISE(err, "error creating first provisioner")
  483. }
  484. // Create first admin
  485. if err := a.adminDB.CreateAdmin(context.Background(), &linkedca.Admin{
  486. ProvisionerId: prov.Id,
  487. Subject: "step",
  488. Type: linkedca.Admin_SUPER_ADMIN,
  489. }); err != nil {
  490. return admin.WrapErrorISE(err, "error creating first admin")
  491. }
  492. }
  493. }
  494. // Load Provisioners and Admins
  495. if err := a.reloadAdminResources(context.Background()); err != nil {
  496. return err
  497. }
  498. // Configure templates, currently only ssh templates are supported.
  499. if a.sshCAHostCertSignKey != nil || a.sshCAUserCertSignKey != nil {
  500. a.templates = a.config.Templates
  501. if a.templates == nil {
  502. a.templates = templates.DefaultTemplates()
  503. }
  504. if a.templates.Data == nil {
  505. a.templates.Data = make(map[string]interface{})
  506. }
  507. a.templates.Data["Step"] = tmplVars
  508. }
  509. // JWT numeric dates are seconds.
  510. a.startTime = time.Now().Truncate(time.Second)
  511. // Set flag indicating that initialization has been completed, and should
  512. // not be repeated.
  513. a.initOnce = true
  514. return nil
  515. }
  516. // GetDatabase returns the authority database. If the configuration does not
  517. // define a database, GetDatabase will return a db.SimpleDB instance.
  518. func (a *Authority) GetDatabase() db.AuthDB {
  519. return a.db
  520. }
  521. // GetAdminDatabase returns the admin database, if one exists.
  522. func (a *Authority) GetAdminDatabase() admin.DB {
  523. return a.adminDB
  524. }
  525. // IsAdminAPIEnabled returns a boolean indicating whether the Admin API has
  526. // been enabled.
  527. func (a *Authority) IsAdminAPIEnabled() bool {
  528. return a.config.AuthorityConfig.EnableAdmin
  529. }
  530. // Shutdown safely shuts down any clients, databases, etc. held by the Authority.
  531. func (a *Authority) Shutdown() error {
  532. if err := a.keyManager.Close(); err != nil {
  533. log.Printf("error closing the key manager: %v", err)
  534. }
  535. return a.db.Shutdown()
  536. }
  537. // CloseForReload closes internal services, to allow a safe reload.
  538. func (a *Authority) CloseForReload() {
  539. if err := a.keyManager.Close(); err != nil {
  540. log.Printf("error closing the key manager: %v", err)
  541. }
  542. if client, ok := a.adminDB.(*linkedCaClient); ok {
  543. client.Stop()
  544. }
  545. }
  546. // IsRevoked returns whether or not a certificate has been
  547. // revoked before.
  548. func (a *Authority) IsRevoked(sn string) (bool, error) {
  549. // Check the passive revocation table.
  550. if lca, ok := a.adminDB.(interface {
  551. IsRevoked(string) (bool, error)
  552. }); ok {
  553. return lca.IsRevoked(sn)
  554. }
  555. return a.db.IsRevoked(sn)
  556. }
  557. // requiresDecrypter returns whether the Authority
  558. // requires a KMS that provides a crypto.Decrypter
  559. // Currently this is only required when SCEP is
  560. // enabled.
  561. func (a *Authority) requiresDecrypter() bool {
  562. return a.requiresSCEPService()
  563. }
  564. // requiresSCEPService iterates over the configured provisioners
  565. // and determines if one of them is a SCEP provisioner.
  566. func (a *Authority) requiresSCEPService() bool {
  567. for _, p := range a.config.AuthorityConfig.Provisioners {
  568. if p.GetType() == provisioner.TypeSCEP {
  569. return true
  570. }
  571. }
  572. return false
  573. }
  574. // GetSCEPService returns the configured SCEP Service
  575. // TODO: this function is intended to exist temporarily
  576. // in order to make SCEP work more easily. It can be
  577. // made more correct by using the right interfaces/abstractions
  578. // after it works as expected.
  579. func (a *Authority) GetSCEPService() *scep.Service {
  580. return a.scepService
  581. }