Certificate.h

Go to the documentation of this file.
00001 /*
00002  * Distributed under the OpenDDS License.
00003  * See: http://www.OpenDDS.org/license.html
00004  */
00005 
00006 #ifndef OPENDDS_SECURITY_SSL_CERTIFICATE_H
00007 #define OPENDDS_SECURITY_SSL_CERTIFICATE_H
00008 
00009 #include "dds/DCPS/security/DdsSecurity_Export.h"
00010 #include "dds/DCPS/unique_ptr.h"
00011 #include "dds/DdsDcpsCoreC.h"
00012 #include "dds/DdsSecurityCoreC.h"
00013 #include <string>
00014 #include <vector>
00015 #include <iostream>
00016 #include <openssl/x509.h>
00017 
00018 namespace OpenDDS {
00019 namespace Security {
00020 namespace SSL {
00021 
00022   class verify_signature_impl;
00023 
00024   class DdsSecurity_Export Certificate
00025   {
00026    public:
00027     friend class verify_signature_impl;
00028 
00029     typedef DCPS::unique_ptr<Certificate> unique_ptr;
00030 
00031     friend DdsSecurity_Export std::ostream& operator<<(std::ostream&,
00032                                                        const Certificate&);
00033 
00034     friend DdsSecurity_Export bool operator==(const Certificate& lhs,
00035                                               const Certificate& rhs);
00036 
00037     Certificate(const std::string& uri, const std::string& password = "");
00038 
00039     Certificate(const DDS::OctetSeq& src);
00040 
00041     Certificate(const Certificate& other);
00042 
00043     Certificate();
00044 
00045     virtual ~Certificate();
00046 
00047     Certificate& operator=(const Certificate& rhs);
00048 
00049     bool load(DDS::Security::SecurityException& ex,
00050               const std::string& uri,
00051               const std::string& password = "");
00052 
00053     /**
00054      * @return int 0 on success; 1 on failure.
00055      */
00056     int validate(const Certificate& ca, unsigned long int flags = 0u) const;
00057 
00058     /**
00059      * @return int 0 on success; 1 on failure.
00060      */
00061     int verify_signature(
00062       const DDS::OctetSeq& src,
00063       const std::vector<const DDS::OctetSeq*>& expected_contents) const;
00064 
00065     /**
00066      * @return int 0 on success; 1 on failure.
00067      */
00068     int subject_name_to_str(std::string& dst,
00069                             unsigned long flags = XN_FLAG_ONELINE) const;
00070 
00071     /**
00072      * @return int 0 on success; 1 on failure.
00073      */
00074     int subject_name_digest(std::vector<CORBA::Octet>& dst) const;
00075 
00076     /**
00077      * @return int 0 on success; 1 on failure.
00078      */
00079     int serialize(DDS::OctetSeq& dst) const;
00080 
00081     /**
00082      * @return int 0 on success; 1 on failure.
00083      */
00084     int deserialize(const DDS::OctetSeq& src);
00085 
00086     const DDS::OctetSeq& original_bytes() const { return original_bytes_; }
00087 
00088     const char* dsign_algo() const { return dsign_algo_.c_str(); }
00089 
00090     const char* keypair_algo() const;
00091 
00092    private:
00093 
00094     bool loaded() {
00095       return (x_ != NULL) &&
00096                 (0 < original_bytes_.length());
00097     }
00098 
00099     /**
00100      * @return int 0 on success; 1 on failure.
00101      */
00102     int cache_dsign_algo();
00103 
00104 
00105     void load_cert_bytes(const std::string& path);
00106 
00107     void load_cert_data_bytes(const std::string& data);
00108 
00109     static X509* x509_from_pem(const std::string& path,
00110                                const std::string& password = "");
00111     static X509* x509_from_pem(const DDS::OctetSeq& bytes,
00112                                const std::string& password = "");
00113 
00114     X509* x_;
00115     DDS::OctetSeq original_bytes_;
00116     std::string dsign_algo_;
00117   };
00118 
00119   DdsSecurity_Export std::ostream& operator<<(std::ostream&,
00120                                               const Certificate&);
00121 
00122   DdsSecurity_Export bool operator==(const Certificate& lhs,
00123                                      const Certificate& rhs);
00124 }  // namespace SSL
00125 }  // namespace Security
00126 }  // namespace OpenDDS
00127 
00128 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1