OpenDDS  Snapshot(2023/04/28-20:55)
Certificate.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.OpenDDS.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_SECURITY_SSL_CERTIFICATE_H
7 #define OPENDDS_DCPS_SECURITY_SSL_CERTIFICATE_H
8 
10 #include <dds/DCPS/unique_ptr.h>
11 
12 #include <dds/DdsDcpsCoreC.h>
13 #include <dds/DdsSecurityCoreC.h>
14 
15 #include <openssl/x509.h>
16 
17 #include <string>
18 #include <vector>
19 #include <iostream>
20 
22 
23 namespace OpenDDS {
24 namespace Security {
25 namespace SSL {
26 
27 class verify_signature_impl;
28 
30 public:
31  friend class verify_signature_impl;
32 
34 
35  friend OpenDDS_Security_Export std::ostream& operator<<(std::ostream&,
36  const Certificate&);
37 
38  friend OpenDDS_Security_Export bool operator==(const Certificate& lhs,
39  const Certificate& rhs);
40 
41  explicit Certificate(const std::string& uri, const std::string& password = "");
42 
43  explicit Certificate(const DDS::OctetSeq& src);
44 
45  Certificate(const Certificate& other);
46 
47  Certificate();
48 
49  virtual ~Certificate();
50 
51  Certificate& operator=(const Certificate& rhs);
52 
54  const std::string& uri,
55  const std::string& password = "");
56 
57  /**
58  * @return int 0 on success; 1 on failure.
59  */
60  int validate(const Certificate& ca, unsigned long int flags = 0u) const;
61 
62  /**
63  * @return int 0 on success; 1 on failure.
64  */
65  int verify_signature(
66  const DDS::OctetSeq& src,
67  const std::vector<const DDS::OctetSeq*>& expected_contents) const;
68 
69  /**
70  * @return int 0 on success; 1 on failure.
71  */
72  int subject_name_to_str(std::string& dst,
73  unsigned long flags = XN_FLAG_ONELINE) const;
74 
75  /**
76  * @return int 0 on success; 1 on failure.
77  */
78  int subject_name_digest(std::vector<CORBA::Octet>& dst) const;
79 
80  /**
81  * @return int 0 on success; 1 on failure.
82  */
83  int serialize(DDS::OctetSeq& dst) const;
84 
85  /**
86  * @return int 0 on success; 1 on failure.
87  */
88  int deserialize(const DDS::OctetSeq& src);
89 
90  const DDS::OctetSeq& original_bytes() const { return original_bytes_; }
91 
92  const char* dsign_algo() const { return dsign_algo_.c_str(); }
93 
94  const char* keypair_algo() const;
95 
96  X509* x509() const { return x_; }
97 
98  private:
99 
100  bool loaded()
101  {
102  return (x_ != NULL) &&
103  (0 < original_bytes_.length());
104  }
105 
106  /**
107  * @return int 0 on success; 1 on failure.
108  */
109  int cache_dsign_algo();
110 
111 
112  void load_cert_bytes(const std::string& path);
113 
114  void load_cert_data_bytes(const std::string& data);
115 
116  static X509* x509_from_pem(const std::string& path,
117  const std::string& password = "");
118  static X509* x509_from_pem(const DDS::OctetSeq& bytes,
119  const std::string& password = "");
120 
123  std::string dsign_algo_;
124 };
125 
126 OpenDDS_Security_Export std::ostream& operator<<(std::ostream&, const Certificate&);
127 
129  const Certificate& rhs);
130 } // namespace SSL
131 } // namespace Security
132 } // namespace OpenDDS
133 
135 
136 #endif
const DDS::OctetSeq & original_bytes() const
Definition: Certificate.h:90
static int load
DCPS::unique_ptr< Certificate > unique_ptr
Definition: Certificate.h:33
bool operator==(const Certificate &lhs, const Certificate &rhs)
std::ostream & operator<<(std::ostream &lhs, const Certificate &rhs)
const char * dsign_algo() const
Definition: Certificate.h:92
sequence< octet > OctetSeq
Definition: DdsDcpsCore.idl:64
#define OpenDDS_Security_Export
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
struct x509_st X509