blautenb 2003/10/26 02:32:33
Modified: c/src/dsig DSIGConstants.cpp DSIGConstants.hpp
c/src/xenc XENCEncryptedType.hpp
c/src/xenc/impl XENCCipherImpl.cpp XENCEncryptedDataImpl.hpp
XENCEncryptedKeyImpl.hpp XENCEncryptedTypeImpl.cpp
XENCEncryptedTypeImpl.hpp
Log:
Support for Type Attribute in EncryptedType structures
Revision Changes Path
1.15 +11 -1 xml-security/c/src/dsig/DSIGConstants.cpp
Index: DSIGConstants.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/dsig/DSIGConstants.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DSIGConstants.cpp 19 Oct 2003 11:01:39 -0000 1.14
+++ DSIGConstants.cpp 26 Oct 2003 10:32:32 -0000 1.15
@@ -108,6 +108,10 @@
const XMLCh * DSIGConstants::s_unicodeStrURIKW_AES192;
const XMLCh * DSIGConstants::s_unicodeStrURIKW_AES256;
const XMLCh * DSIGConstants::s_unicodeStrURIRSA_1_5;
+
+const XMLCh * DSIGConstants::s_unicodeStrURIXENC_ELEMENT;
+const XMLCh * DSIGConstants::s_unicodeStrURIXENC_CONTENT;
+
const XMLCh * DSIGConstants::s_unicodeStrPROVOpenSSL;
const XMLCh * DSIGConstants::s_unicodeStrPROVWinCAPI;
@@ -155,6 +159,9 @@
s_unicodeStrURIKW_AES256 = XMLString::transcode(URI_ID_KW_AES256);
s_unicodeStrURIRSA_1_5 = XMLString::transcode(URI_ID_RSA_1_5);
+ s_unicodeStrURIXENC_ELEMENT = XMLString::transcode(URI_ID_XENC_ELEMENT);
+ s_unicodeStrURIXENC_CONTENT = XMLString::transcode(URI_ID_XENC_CONTENT);
+
s_unicodeStrPROVOpenSSL = XMLString::transcode(PROV_OPENSSL);
s_unicodeStrPROVWinCAPI = XMLString::transcode(PROV_WINCAPI);
@@ -199,6 +206,9 @@
delete[] (XMLCh *) s_unicodeStrURIKW_AES192;
delete[] (XMLCh *) s_unicodeStrURIKW_AES256;
delete[] (XMLCh *) s_unicodeStrURIRSA_1_5;
+
+ delete[] (XMLCh *) s_unicodeStrURIXENC_ELEMENT;
+ delete[] (XMLCh *) s_unicodeStrURIXENC_CONTENT;
delete[] (XMLCh *) s_unicodeStrPROVOpenSSL;
delete[] (XMLCh *) s_unicodeStrPROVWinCAPI;
1.17 +8 -1 xml-security/c/src/dsig/DSIGConstants.hpp
Index: DSIGConstants.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/dsig/DSIGConstants.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DSIGConstants.hpp 19 Oct 2003 11:01:39 -0000 1.16
+++ DSIGConstants.hpp 26 Oct 2003 10:32:32 -0000 1.17
@@ -131,6 +131,10 @@
#define URI_ID_HMAC_SHA1 "http://www.w3.org/2000/09/xmldsig#hmac-sha1"
#define URI_ID_RSA_SHA1
"http://www.w3.org/2000/09/xmldsig#rsa-sha1"
+// Encryption defines
+#define URI_ID_XENC_ELEMENT "http://www.w3.org/2001/04/xmlenc#Element"
+#define URI_ID_XENC_CONTENT "http://www.w3.org/2001/04/xmlenc#Content"
+
// General
#define URI_ID_XMLNS "http://www.w3.org/2000/xmlns/"
@@ -417,6 +421,9 @@
static const XMLCh * s_unicodeStrURIKW_AES192;
static const XMLCh * s_unicodeStrURIKW_AES256;
static const XMLCh * s_unicodeStrURIRSA_1_5;
+
+ static const XMLCh * s_unicodeStrURIXENC_ELEMENT;
+ static const XMLCh * s_unicodeStrURIXENC_CONTENT;
// Internal Crypto Providers
static const XMLCh * s_unicodeStrPROVOpenSSL;
1.7 +39 -1 xml-security/c/src/xenc/XENCEncryptedType.hpp
Index: XENCEncryptedType.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/XENCEncryptedType.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XENCEncryptedType.hpp 3 Oct 2003 09:50:05 -0000 1.6
+++ XENCEncryptedType.hpp 26 Oct 2003 10:32:32 -0000 1.7
@@ -157,6 +157,44 @@
//@}
+ /** @name Getter interface Methods */
+ //@{
+
+ /**
+ * \brief Get the Type URI for the EncryptedType
+ *
+ * If this object is an EncryptedData, it <em>may</em> have a
+ * Type attribute that defines whether it is an encrypted
+ * Element or Element Content. This method allows the caller
+ * to see this type URI.
+ *
+ * @returns a pointer to the URI string (owned by the library)
+ * or NULL if no type is set
+ */
+
+ virtual const XMLCh * getTypeURI(void) const = 0;
+
+ //@}
+
+ /** @name Setter interface methods */
+ //@{
+
+ /**
+ * \brief Set the Type URI for the EncryptedType
+ *
+ * Allows a calling application to set a particular Type URI for
+ * the EncryptedType.
+ *
+ * @note calls to encryptElement and encryptElementContent
+ * automatically set the appropriate Type URI.
+ *
+ * @param uri The URI to set
+ */
+
+ virtual void setTypeURI(const XMLCh * uri) = 0;
+
+ //@}
+
/** @name KeyInfo Element Manipulation */
//@{
1.11 +15 -45 xml-security/c/src/xenc/impl/XENCCipherImpl.cpp
Index: XENCCipherImpl.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherImpl.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XENCCipherImpl.cpp 25 Oct 2003 10:29:15 -0000 1.10
+++ XENCCipherImpl.cpp 26 Oct 2003 10:32:33 -0000 1.11
@@ -453,6 +453,18 @@
// Load
mp_encryptedData->load();
+ // Check that this is a valid type
+ const XMLCh * typeURI = mp_encryptedData->getTypeURI();
+
+ if (typeURI != NULL &&
+ !strEquals(typeURI, DSIGConstants::s_unicodeStrURIXENC_ELEMENT)
&&
+ !strEquals(typeURI,
DSIGConstants::s_unicodeStrURIXENC_CONTENT)) {
+
+ throw XSECException(XSECException::CipherError,
+ "XENCCipherImpl::decryptElement - Type not Element or
Content");
+
+ }
+
// Make sure we have a key before we do anything else too drastic
if (mp_key == NULL) {
@@ -463,50 +475,6 @@
mp_key =
decryptKeyFromKeyInfoList(mp_encryptedData->getKeyInfoList());
-#if 0
- // See if we can decrypt a key in the KeyInfo list
- DSIGKeyInfoList * kil =
mp_encryptedData->getKeyInfoList();
- int kLen = kil->getSize();
-
- for (int i = 0; i < kLen ; ++ i) {
-
- if (kil->item(i)->getKeyInfoType() ==
DSIGKeyInfo::KEYINFO_ENCRYPTEDKEY) {
-
- XENCEncryptedKey * ek =
dynamic_cast<XENCEncryptedKey*>(kil->item(i));
- volatile XMLByte buffer[1024];
- try {
- // Have to cast off volatile
- int keySize = decryptKey(ek,
(XMLByte *) buffer, 1024);
-
- if (keySize > 0) {
- // Try to map the key
-
- XENCEncryptionMethod *
encryptionMethod =
-
mp_encryptedData->getEncryptionMethod();
-
- if (encryptionMethod !=
NULL) {
-
- handler =
-
XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(
-
mp_encryptedData->getEncryptionMethod()->getAlgorithm());
-
- if (handler !=
NULL)
- mp_key
= handler->createKeyForURI(
-
mp_encryptedData->getEncryptionMethod()->getAlgorithm(),
-
(XMLByte *) buffer,
-
keySize);
- }
- }
- } catch (...) {
- memset((void *) buffer, 0,
1024);
- throw;
- }
-
- // Clear out the key buffer
- memset((void *) buffer, 0, 1024);
- }
- }
-#endif
}
if (mp_key == NULL) {
@@ -1039,6 +1007,8 @@
// Do the hard work
encryptTXFMChain(c, em, algorithmURI);
+
+
mp_encryptedData->setTypeURI(DSIGConstants::s_unicodeStrURIXENC_ELEMENT);
// Replace original element
DOMNode * p = element->getParentNode();
1.7 +10 -1 xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp
Index: XENCEncryptedDataImpl.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XENCEncryptedDataImpl.hpp 3 Oct 2003 09:50:05 -0000 1.6
+++ XENCEncryptedDataImpl.hpp 26 Oct 2003 10:32:33 -0000 1.7
@@ -117,6 +117,15 @@
virtual void appendEncryptedKey(XENCEncryptedKey * encryptedKey)
{XENCEncryptedTypeImpl::appendEncryptedKey(encryptedKey);}
+ // Get methods
+ virtual const XMLCh * getTypeURI(void) const
+ {return XENCEncryptedTypeImpl::getTypeURI();}
+
+ // Set methods
+ virtual void setTypeURI(const XMLCh * uri)
+ {XENCEncryptedTypeImpl::setTypeURI(uri);}
+
+
private:
// Unimplemented
1.2 +8 -1 xml-security/c/src/xenc/impl/XENCEncryptedKeyImpl.hpp
Index: XENCEncryptedKeyImpl.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedKeyImpl.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XENCEncryptedKeyImpl.hpp 3 Oct 2003 09:50:51 -0000 1.1
+++ XENCEncryptedKeyImpl.hpp 26 Oct 2003 10:32:33 -0000 1.2
@@ -120,6 +120,13 @@
virtual void appendEncryptedKey(XENCEncryptedKey * encryptedKey)
{XENCEncryptedTypeImpl::appendEncryptedKey(encryptedKey);}
+ // Get methods
+ virtual const XMLCh * getTypeURI(void) const
+ {return XENCEncryptedTypeImpl::getTypeURI();}
+
+ // Set methods
+ virtual void setTypeURI(const XMLCh * uri)
+ {XENCEncryptedTypeImpl::setTypeURI(uri);}
private:
1.8 +59 -3 xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp
Index: XENCEncryptedTypeImpl.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XENCEncryptedTypeImpl.cpp 6 Oct 2003 12:16:37 -0000 1.7
+++ XENCEncryptedTypeImpl.cpp 26 Oct 2003 10:32:33 -0000 1.8
@@ -140,6 +140,15 @@
chNull,
};
+static XMLCh s_Type[] = {
+
+ chLatin_T,
+ chLatin_y,
+ chLatin_p,
+ chLatin_e,
+ chNull
+};
+
//
--------------------------------------------------------------------------------
// Constructors and Destructors
//
--------------------------------------------------------------------------------
@@ -151,7 +160,8 @@
mp_cipherDataNode(NULL),
mp_cipherData(NULL),
mp_encryptionMethod(NULL),
-m_keyInfoList(env) {
+m_keyInfoList(env),
+mp_typeAttributeNode(NULL) {
}
@@ -163,7 +173,8 @@
mp_cipherDataNode(NULL),
mp_cipherData(NULL),
mp_encryptionMethod(NULL),
-m_keyInfoList(env) {
+m_keyInfoList(env),
+mp_typeAttributeNode(NULL) {
}
@@ -191,6 +202,13 @@
}
+ // See if any attributes of interest are set
+ DOMNamedNodeMap *atts = mp_encryptedTypeNode->getAttributes();
+
+ // Type
+ mp_typeAttributeNode =
atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
+
s_Type);
+
// Don't know what the node name should be (held by super class),
// so go straight to the children
@@ -442,4 +460,42 @@
createKeyInfoElement();
m_keyInfoList.addAndInsertKeyInfo(encryptedKey);
+}
+
+//
--------------------------------------------------------------------------------
+// Type URI handling
+//
--------------------------------------------------------------------------------
+
+const XMLCh * XENCEncryptedTypeImpl::getTypeURI(void) const {
+
+ if (mp_typeAttributeNode != NULL)
+ return mp_typeAttributeNode->getNodeValue();
+
+ return NULL;
+
+}
+
+void XENCEncryptedTypeImpl::setTypeURI(const XMLCh * uri) {
+
+ if (mp_typeAttributeNode != NULL) {
+ mp_typeAttributeNode->setNodeValue(uri);
+ }
+ else {
+
+ // Need to create the node
+ DOMElement * typeElt = static_cast<DOMElement
*>(mp_encryptedTypeNode);
+
+ typeElt->setAttributeNS(DSIGConstants::s_unicodeStrURIXENC,
s_Type, uri);
+
+ DOMNamedNodeMap *atts = mp_encryptedTypeNode->getAttributes();
+ mp_typeAttributeNode =
atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
+
s_Type);
+ if (mp_typeAttributeNode = NULL) {
+
+ throw XSECException(XSECException::InternalError,
+ "XENCEncryptedTypeImpl::setTypeURI - Cannot
find the attribute I just added");
+
+ }
+
+ }
}
1.8 +11 -1 xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp
Index: XENCEncryptedTypeImpl.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XENCEncryptedTypeImpl.hpp 3 Oct 2003 09:50:05 -0000 1.7
+++ XENCEncryptedTypeImpl.hpp 26 Oct 2003 10:32:33 -0000 1.8
@@ -119,6 +119,12 @@
{return mp_encryptedTypeNode;}
virtual void appendEncryptedKey(XENCEncryptedKey * encryptedKey);
+ // Get methods
+ virtual const XMLCh * getTypeURI(void) const;
+
+ // Set methods
+ virtual void setTypeURI(const XMLCh * uri);
+
protected:
@@ -143,6 +149,10 @@
// Hold the XML Digital Signature KeyInfo list
DSIGKeyInfoList m_keyInfoList;
+
+ // Type URI
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMNode
+ *
mp_typeAttributeNode;
friend class XENCCipherImpl;
};