00001 /* 00002 * Distributed under the OpenDDS License. 00003 * See: http://www.OpenDDS.org/license.html 00004 */ 00005 00006 #ifndef OPENDDS_SECURITY_SSL_SignedDocument_H 00007 #define OPENDDS_SECURITY_SSL_SignedDocument_H 00008 00009 #include "dds/DCPS/security/DdsSecurity_Export.h" 00010 #include "dds/DCPS/unique_ptr.h" 00011 #include "dds/DdsSecurityCoreC.h" 00012 #include "Certificate.h" 00013 #include <string> 00014 #include <openssl/pkcs7.h> 00015 00016 namespace OpenDDS { 00017 namespace Security { 00018 namespace SSL { 00019 00020 class DdsSecurity_Export SignedDocument 00021 { 00022 public: 00023 typedef DCPS::unique_ptr<SignedDocument> unique_ptr; 00024 00025 friend DdsSecurity_Export bool operator==(const SignedDocument& lhs, 00026 const SignedDocument& rhs); 00027 00028 SignedDocument(const std::string& uri); 00029 00030 SignedDocument(const DDS::OctetSeq& src); 00031 00032 SignedDocument(const SignedDocument& rhs); 00033 00034 SignedDocument(); 00035 00036 virtual ~SignedDocument(); 00037 00038 SignedDocument& operator=(const SignedDocument& rhs); 00039 00040 bool load(const std::string& uri, DDS::Security::SecurityException& ex); 00041 00042 void get_original(std::string& dst) const; 00043 00044 const DDS::OctetSeq& get_original() const 00045 { 00046 return original_; 00047 } 00048 00049 const std::string& get_verifiable() const 00050 { 00051 return verifiable_; 00052 } 00053 00054 bool get_original_minus_smime(std::string& dst) const; 00055 00056 /** 00057 * @return int 0 on success; 1 on failure. 00058 */ 00059 int verify_signature(const Certificate& ca) const; 00060 00061 /** 00062 * @return int 0 on success; 1 on failure. 00063 */ 00064 int serialize(DDS::OctetSeq& dst) const; 00065 00066 /** 00067 * @return int 0 on success; 1 on failure. 00068 */ 00069 int deserialize(const DDS::OctetSeq& src); 00070 00071 /** 00072 * @return int 0 on success; 1 on failure. 00073 */ 00074 int deserialize(const std::string& src); 00075 00076 private: 00077 00078 bool loaded() { 00079 return (doc_ != NULL) && 00080 (0 < original_.length()) && 00081 (0 < verifiable_.length()); 00082 } 00083 00084 /** 00085 * @return int 0 on success; 1 on failure. 00086 * 00087 * @param from BIO containing data populated by a call to SMIME_read_PKCS7. 00088 */ 00089 int cache_verifiable(BIO* from); 00090 00091 PKCS7* PKCS7_from_SMIME_file(const std::string& path); 00092 00093 PKCS7* PKCS7_from_data(const DDS::OctetSeq& s_mime_data); 00094 00095 PKCS7* doc_; 00096 DDS::OctetSeq original_; 00097 std::string verifiable_; 00098 }; 00099 00100 DdsSecurity_Export bool operator==(const SignedDocument& lhs, 00101 const SignedDocument& rhs); 00102 00103 } // namespace SSL 00104 } // namespace Security 00105 } // namespace OpenDDS 00106 00107 #endif