r3354 - in trunk/libmnetutil: include/libmnetutil source
mikaelsv at minisip.org
mikaelsv at minisip.org
Wed Aug 8 10:51:14 CEST 2007
Author: mikaelsv
Date: 2007-08-08 10:51:14 +0200 (Wed, 08 Aug 2007)
New Revision: 3354
Modified:
trunk/libmnetutil/include/libmnetutil/LdapEntry.h
trunk/libmnetutil/include/libmnetutil/LdapUrl.h
trunk/libmnetutil/source/FileUrl.cxx
trunk/libmnetutil/source/LdapEntry.cxx
trunk/libmnetutil/source/LdapUrl.cxx
Log:
* Extended the LDAP classes with support for binary pair attributes (normal attributes
have only a single value, but in order to support cross certificates it is necessary
to also support attributes with multiple values). Note that this is *not* the same thing
as supporting LDAP objects with multiple single-valued attributes.
Modified: trunk/libmnetutil/include/libmnetutil/LdapEntry.h
===================================================================
--- trunk/libmnetutil/include/libmnetutil/LdapEntry.h 2007-08-08 08:42:26 UTC (rev 3353)
+++ trunk/libmnetutil/include/libmnetutil/LdapEntry.h 2007-08-08 08:51:14 UTC (rev 3354)
@@ -31,8 +31,6 @@
#include <map>
#include <vector>
-class LIBMNETUTIL_API certificate_pair {}; //Dummy entry
-
/**
* Class used internally by LdapEntry
*
@@ -51,6 +49,16 @@
int length;
};
+class LIBMNETUTIL_API LdapEntryBinaryPairValue : public MObject {
+ public:
+ LdapEntryBinaryPairValue(MRef<LdapEntryBinaryValue*> first, MRef<LdapEntryBinaryValue*> second) {
+ this->first = first;
+ this->second = second;
+ }
+ MRef<LdapEntryBinaryValue*> first;
+ MRef<LdapEntryBinaryValue*> second;
+};
+
/**
* Represents one object in the LDAP directory, including its attribute values.
*
@@ -67,7 +75,7 @@
*
* @author Mikael Svensson
*/
-class LdapEntry : public MObject {
+class LIBMNETUTIL_API LdapEntry : public MObject {
public:
LdapEntry(LDAP* ld, LDAPMessage* entry);
//~LdapEntry();
@@ -80,20 +88,33 @@
/**
* Return all binary values for a given attribute.
*/
+ std::vector< MRef<LdapEntryBinaryValue*> > getAttrValuesBinary(std::string attr) throw (LdapAttributeNotFoundException);
- std::vector< MRef<LdapEntryBinaryValue*> > getAttrValuesBinary(std::string attr) throw (LdapAttributeNotFoundException);
/**
- * Return ALL string values for a given attribute.
+ * Return all "binary pair values" for a given attribute.
+ *
+ * This function is tailored to aid in the retrieval of crossCertificatePair attributes
+ * stored in certificationAuthority objects in LDAP directories.
+ *
+ * What the function does is this:
+ * - Read the raw binary attribute into internal LdapEntryBinaryValue variable
+ * - Assume that the raw data represents this ASN.1 data structure:
+ * CertificatePair ::= SEQUENCE {
+ * issuedToThisCA [0] Certificate OPTIONAL,
+ * issuedByThisCA [1] Certificate OPTIONAL
+ * }
+ * - Read the two "array elements" and store them as new LdapEntryBinaryValue objects
+ * - Put the two "entry objects" in a LdapEntryBinaryPairValue ojbect
+ *
+ * @note This function does not return parsed certificates, only the raw bytes constituting the certificates!
*/
- std::vector<std::string> getAttrValuesStrings(std::string attr) throw (LdapAttributeNotFoundException);
+ std::vector< MRef<LdapEntryBinaryPairValue*> > getAttrValuesBinaryPairs(std::string attr) throw (LdapAttributeNotFoundException);
/**
- * Specialized method that returns all certificate pair attribute values (given a specific attribute name).
+ * Return ALL string values for a given attribute.
*/
- std::vector<MRef<certificate_pair*> > getAttrValuesCertificatePairs(std::string attr) throw (LdapAttributeNotFoundException);
+ std::vector<std::string> getAttrValuesStrings(std::string attr) throw (LdapAttributeNotFoundException);
- //std::string getDn();
-
/**
* Returns list of all attribute names.
*/
Modified: trunk/libmnetutil/include/libmnetutil/LdapUrl.h
===================================================================
--- trunk/libmnetutil/include/libmnetutil/LdapUrl.h 2007-08-08 08:42:26 UTC (rev 3353)
+++ trunk/libmnetutil/include/libmnetutil/LdapUrl.h 2007-08-08 08:51:14 UTC (rev 3354)
@@ -65,7 +65,7 @@
*
* At the moment an LDAP URL is considered invalid only if it doesn't start with "ldap://".
*/
- bool isValid();
+ bool isValid() const;
/**
* Parse URL
Modified: trunk/libmnetutil/source/FileUrl.cxx
===================================================================
--- trunk/libmnetutil/source/FileUrl.cxx 2007-08-08 08:42:26 UTC (rev 3353)
+++ trunk/libmnetutil/source/FileUrl.cxx 2007-08-08 08:51:14 UTC (rev 3354)
@@ -176,7 +176,11 @@
this->host = host;
}
std::string FileUrl::getPath() const {
+#ifdef WIN32
return path;
+#else
+ return "/" + path;
+#endif
}
void FileUrl::setPath(std::string path) {
this->path = path;
Modified: trunk/libmnetutil/source/LdapEntry.cxx
===================================================================
--- trunk/libmnetutil/source/LdapEntry.cxx 2007-08-08 08:42:26 UTC (rev 3353)
+++ trunk/libmnetutil/source/LdapEntry.cxx 2007-08-08 08:51:14 UTC (rev 3354)
@@ -23,6 +23,7 @@
#include <config.h>
#include <libmnetutil/LdapEntry.h>
+#include <string>
LdapEntry::LdapEntry(LDAP* ld, LDAPMessage* entry) {
BerElement* ber;
@@ -102,6 +103,72 @@
throw LdapAttributeNotFoundException(attr);
}
+std::vector< MRef<LdapEntryBinaryPairValue*> > LdapEntry::getAttrValuesBinaryPairs(std::string attr) throw (LdapAttributeNotFoundException) {
+ std::vector< MRef<LdapEntryBinaryValue*> > rawBinary;
+ std::vector< MRef<LdapEntryBinaryValue*> >::iterator rawIter;
+ std::vector< MRef<LdapEntryBinaryPairValue*> > result;
+
+ try {
+ rawBinary = getAttrValuesBinary(attr);
+ if (rawBinary.size() > 0) {
+ for (rawIter = rawBinary.begin(); rawIter != rawBinary.end(); rawIter++) {
+
+ int len = (*rawIter)->length;
+ char* dataPair = new char[len];
+ memcpy(dataPair, (*rawIter)->value, len);
+
+ BerElement *berPair;
+ struct berval *bervalPair;
+
+
+ bervalPair = new struct berval;
+ bervalPair->bv_val = dataPair;
+ bervalPair->bv_len = len;
+
+ berPair = ber_init(bervalPair);
+
+ struct berval *bervalCertIssuedTo, *bervalCertIssuedBy;
+ bervalCertIssuedTo = new struct berval;
+ bervalCertIssuedBy = new struct berval;
+
+ ber_scanf(berPair, "{oo}", bervalCertIssuedTo, bervalCertIssuedBy);
+
+ /*
+ std::cout << "Analysis of certificate-pair file generated for inclusion in directory of " << params->shortNameA << ":" << std::endl;
+ std::cout << " Length of certificate in issued-TO-this-CA field: " << bervalCaACertIssuedTo->bv_len << std::endl;
+ std::cout << " Length of certificate in issued-BY-this-CA field: " << bervalCaACertIssuedBy->bv_len << std::endl;
+
+ std::cout << "Analysis of certificate-pair file generated for inclusion in directory of " << params->shortNameB << ":" << std::endl;
+ std::cout << " Length of certificate in issued-TO-this-CA field: " << bervalCaBCertIssuedTo->bv_len << std::endl;
+ std::cout << " Length of certificate in issued-BY-this-CA field: " << bervalCaBCertIssuedBy->bv_len << std::endl;
+ */
+ char* dataCertIssuedTo = new char[bervalCertIssuedTo->bv_len];
+ char* dataCertIssuedBy = new char[bervalCertIssuedBy->bv_len];
+ memcpy(dataCertIssuedTo, bervalCertIssuedTo->bv_val, bervalCertIssuedTo->bv_len);
+ memcpy(dataCertIssuedBy, bervalCertIssuedBy->bv_val, bervalCertIssuedBy->bv_len);
+
+ MRef<LdapEntryBinaryValue*> first(new LdapEntryBinaryValue(dataCertIssuedTo, bervalCertIssuedTo->bv_len));
+ MRef<LdapEntryBinaryValue*> second(new LdapEntryBinaryValue(dataCertIssuedBy, bervalCertIssuedBy->bv_len));
+
+ result.push_back(MRef<LdapEntryBinaryPairValue*>(new LdapEntryBinaryPairValue(first, second)));
+
+ ber_bvfree(bervalPair);
+ ber_bvfree(bervalCertIssuedTo);
+ ber_bvfree(bervalCertIssuedBy);
+ /*
+ delete bervalPair;
+ delete bervalCertIssuedTo;
+ delete bervalCertIssuedBy;
+ */
+ ber_free(berPair, 1);
+ }
+ }
+ } catch (LdapAttributeNotFoundException & ex) {
+ throw; // Re-throw exception
+ }
+ return result;
+}
+
std::vector<std::string> LdapEntry::getAttrNames() {
std::vector<std::string> res;
std::map<std::string, std::vector<std::string> >::iterator i;
Modified: trunk/libmnetutil/source/LdapUrl.cxx
===================================================================
--- trunk/libmnetutil/source/LdapUrl.cxx 2007-08-08 08:42:26 UTC (rev 3353)
+++ trunk/libmnetutil/source/LdapUrl.cxx 2007-08-08 08:51:14 UTC (rev 3354)
@@ -48,7 +48,7 @@
extensions = std::vector<LdapUrlExtension>();
}
-bool LdapUrl::isValid() {
+bool LdapUrl::isValid() const {
return validUrl;
}
More information about the Minisip-devel
mailing list