limal-ca-mgm
CA.hpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | _ _ _ _ __ _ |
4 | | | | | | \_/ | / \ | | |
5 | | | | | | |_| | / /\ \ | | |
6 | | |__ | | | | | | / ____ \ | |__ |
7 | |____||_| |_| |_|/ / \ \|____| |
8 | |
9 | ca-mgm library |
10 | |
11 | (C) SUSE Linux Products GmbH |
12 \----------------------------------------------------------------------/
13 
14  File: CA.hpp
15 
16  Author: <Michael Calmer> <mc@suse.de>
17  Maintainer: <Michael Calmer> <mc@suse.de>
18 
19  Purpose:
20 
21 /-*/
22 
27 #ifndef LIMAL_CA_HPP
28 #define LIMAL_CA_HPP
29 
30 #include <limal/ca-mgm/config.h>
35 #include <limal/ca-mgm/CRLData.hpp>
39 #include <limal/ByteBuffer.hpp>
40 #include <blocxx/COWIntrusiveReference.hpp>
41 
42 namespace LIMAL_NAMESPACE
43 {
44 namespace CA_MGM_NAMESPACE
45 {
46  class CAImpl;
47 
56  class CA
57  {
58  public:
59 
67  CA(const String& caName, const String& caPasswd, const String& repos=REPOSITORY);
68 
72  ~CA();
73 
74 
86  String
87  createSubCA(const String& newCaName,
88  const String& keyPasswd,
89  const RequestGenerationData& caRequestData,
90  const CertificateIssueData& caIssueData);
91 
102  String
103  createRequest(const String& keyPasswd,
104  const RequestGenerationData& requestData,
105  Type requestType);
106 
107 
118  String
119  issueCertificate(const String& requestName,
120  const CertificateIssueData& issueData,
121  Type certType);
122 
134  String
135  createCertificate(const String& keyPasswd,
136  const RequestGenerationData& requestData,
137  const CertificateIssueData& certificateData,
138  Type type);
139 
140 
152  void
153  revokeCertificate(const String& certificateName,
154  const CRLReason& crlReason = CRLReason());
155 
163  void
164  createCRL(const CRLGenerationData& crlData);
165 
175  String
176  importRequestData(const limal::ByteBuffer& request,
177  FormatType formatType = E_PEM);
178 
188  String
189  importRequest(const String& requestFile,
190  FormatType formatType = E_PEM);
191 
192 
203  getIssueDefaults(Type type);
204 
215  getRequestDefaults(Type type);
216 
225  getCRLDefaults();
226 
235  void
236  setIssueDefaults(Type type,
237  const CertificateIssueData& defaults);
238 
247  void
248  setRequestDefaults(Type type,
249  const RequestGenerationData& defaults);
250 
258  void
259  setCRLDefaults(const CRLGenerationData& defaults);
260 
261 
280  blocxx::Array<blocxx::Map<blocxx::String, blocxx::String> >
281  getCertificateList();
282 
283 
302  blocxx::Array<blocxx::Map<blocxx::String, blocxx::String> >
303  getRequestList();
304 
305 
306 
314  getCA();
315 
325  getRequest(const String& requestName);
326 
336  getCertificate(const String& certificateName);
337 
338 
345  CRLData
346  getCRL();
347 
348 
358  exportCACert(FormatType exportType);
359 
373  exportCAKeyAsPEM(const String& newPassword);
374 
383  exportCAKeyAsDER();
384 
398  exportCAasPKCS12(const String& p12Password,
399  bool withChain = false);
400 
401 
414  exportCertificate(const String& certificateName,
415  FormatType exportType);
416 
432  exportCertificateKeyAsPEM(const String& certificateName,
433  const String& keyPassword,
434  const String& newPassword);
435 
447  exportCertificateKeyAsDER(const String& certificateName,
448  const String& keyPassword);
449 
465  exportCertificateAsPKCS12(const String& certificateName,
466  const String& keyPassword,
467  const String& p12Password,
468  bool withChain = false);
469 
479  exportCRL(FormatType exportType);
480 
481 
490  void
491  deleteRequest(const String& requestName);
492 
504  void
505  deleteCertificate(const String& certificateName,
506  bool requestToo = true);
507 
508 
514  void
515  updateDB();
516 
538  bool
539  verifyCertificate(const String& certificateName,
540  bool crlCheck = true,
541  const String& purpose = String("any"));
542 
548  CAConfig*
549  getConfig();
550 
551 
552  /* ##########################################################################
553  * ### static Functions ###
554  * ##########################################################################
555  */
556 
569  static void
570  createRootCA(const String& caName,
571  const String& caPasswd,
572  const RequestGenerationData& caRequestData,
573  const CertificateIssueData& caIssueData,
574  const String& repos=REPOSITORY);
575 
576 
589  static void
590  importCA(const String& caName,
591  const limal::ByteBuffer& caCertificate,
592  const limal::ByteBuffer& caKey,
593  const String& caPasswd = String(),
594  const String& repos=REPOSITORY);
595 
604  static blocxx::Array<blocxx::String>
605  getCAList(const String& repos=REPOSITORY);
606 
624  static blocxx::List<blocxx::Array<blocxx::String> >
625  getCATree(const String& repos=REPOSITORY);
626 
636  static CertificateIssueData
637  getRootCAIssueDefaults(const String& repos=REPOSITORY);
638 
648  static RequestGenerationData
649  getRootCARequestDefaults(const String& repos=REPOSITORY);
650 
651 
667  static void
668  deleteCA(const String& caName,
669  const String& caPasswd,
670  bool force = false,
671  const String& repos = REPOSITORY);
672 
673  private:
674  blocxx::COWIntrusiveReference<CAImpl> m_impl;
675 
676 
677  CA();
678  CA(const CA&);
679 
680  CA&
681  operator=(const CA&);
682 
692  void
693  checkDNPolicy(const DNObject& dn, Type type);
694 
703  String
704  initConfigFile();
705 
710  void
711  commitConfig2Template();
712 
716  void
717  removeDefaultsFromConfig();
718  };
719 
720 } // End of CA_MGM_NAMESPACE
721 } // End of LIMAL_NAMESPACE
722 
723 
746 #endif // LIMAL_CA_MGM_HPP
747