blautenb 2003/09/15 04:55:55
Modified: c/src/tools/cipher cipher.cpp
Added: c/src/tools/cipher MerlinFiveInteropResolver.hpp
MerlinFiveInteropResolver.cpp
Log:
Integrate a dedicated KeyInfoResolver for Merlin XENC Five interop tests
Revision Changes Path
1.3 +28 -6 xml-security/c/src/tools/cipher/cipher.cpp
Index: cipher.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/tools/cipher/cipher.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- cipher.cpp 11 Sep 2003 11:11:55 -0000 1.2
+++ cipher.cpp 15 Sep 2003 11:55:55 -0000 1.3
@@ -76,6 +76,8 @@
#include <xsec/enc/XSECCryptoException.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoSymmetricKey.hpp>
+#include "MerlinFiveInteropResolver.hpp"
+
// ugly :<
#if defined(_WIN32)
@@ -176,9 +178,13 @@
cerr << " --decrypt-element/-de\n";
cerr << " Decrypt the first encrypted element found\n";
cerr << " --key/-k [key string]\n";
- cerr << " Use the key provided in [key string] to
encrypt/decrypt\n\n";
+ cerr << " Use the key provided in [key string] to
encrypt/decrypt\n";
+#if defined (HAVE_OPENSSL)
+ cerr << " --interop/-i\n";
+ cerr << " Use the interop resolver for Baltimore interop
examples\n";
+#endif
- cerr << " Exits with codes :\n";
+ cerr << "\n Exits with codes :\n";
cerr << " 0 = Decrypt/Encrypt OK\n";
cerr << " 1 = Decrypt/Encrypt failed\n";
cerr << " 2 = Processing error\n";
@@ -190,6 +196,8 @@
char * filename = NULL;
char * keyStr = NULL;
bool doDecryptElement = false;
+ bool useInteropResolver = false;
+
#if defined(_WIN32) && defined (HAVE_WINCAPI)
HCRYPTPROV win32DSSCSP = 0;
// Crypto Providers
@@ -211,15 +219,20 @@
paramCount++;
doDecryptElement = true;
}
-
- if (stricmp(argv[paramCount], "--key") == 0 ||
stricmp(argv[paramCount], "-k") == 0) {
+#if defined (HAVE_OPENSSL)
+ else if (stricmp(argv[paramCount], "--interop") == 0 ||
stricmp(argv[paramCount], "-i") == 0) {
+ // Use the interop key resolver
+ useInteropResolver = true;
+ paramCount++;
+ }
+#endif
+ else if (stricmp(argv[paramCount], "--key") == 0 ||
stricmp(argv[paramCount], "-k") == 0) {
// Have set a key string
paramCount++;
keyStr = argv[paramCount];
paramCount++;
}
-
else {
printUsage();
return 2;
@@ -301,6 +314,15 @@
k->setKey((unsigned char *) keyStr, strlen(keyStr));
cipher->setKey(k);
}
+
+#if defined (HAVE_OPENSSL)
+ if (useInteropResolver == true) {
+
+ MerlinFiveInteropResolver ires(NULL);
+ cipher->setKeyInfoResolver(&ires);
+
+ }
+#endif
cipher->decryptElement(static_cast<DOMElement *>(n));
// Output the result
1.1
xml-security/c/src/tools/cipher/MerlinFiveInteropResolver.hpp
Index: MerlinFiveInteropResolver.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* MerlinFiveInteropResolver := Class to resolve key elements into
certificates for
* merlin-xenc-five interop test
*
* Author(s): Berin Lautenbach
*
* $Id: MerlinFiveInteropResolver.hpp,v 1.1 2003/09/15 11:55:55 blautenb Exp $
*
*/
// XSEC
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/enc/XSECKeyInfoResolver.hpp>
#if defined (_WIN32)
# include <io.h>
#else
# include <glob.h>
#endif
#if defined (HAVE_OPENSSL)
# include <openssl/x509.h>
class MerlinFiveInteropResolver : public XSECKeyInfoResolver {
public :
MerlinFiveInteropResolver(const XMLCh * baseURI);
~MerlinFiveInteropResolver();
// Interface functions
virtual XSECCryptoKey * resolveKey(DSIGKeyInfoList * lst);
virtual XSECKeyInfoResolver * clone(void) const;
// Internal functions
private:
XMLCh * mp_baseURI;
#if defined (_WIN32)
_finddata_t m_finder;
long m_handle;
#else
glob_t m_globbuf;
int m_fcount;
#endif
};
#endif /* HAVE_OPENSSL */
1.1
xml-security/c/src/tools/cipher/MerlinFiveInteropResolver.cpp
Index: MerlinFiveInteropResolver.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* InteropResolver := Class to resolve key elements into certificates for
* merlin-18 interop test
*
* $Id: MerlinFiveInteropResolver.cpp,v 1.1 2003/09/15 11:55:55 blautenb Exp $
*
*/
// XSEC
#include "MerlinFiveInteropResolver.hpp"
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/enc/XSECKeyInfoResolver.hpp>
#include <xsec/dsig/DSIGKeyInfoName.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoSymmetricKey.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
XERCES_CPP_NAMESPACE_USE
#include <iostream>
#if defined (HAVE_OPENSSL)
//
--------------------------------------------------------------------------------
// Strings and keys
//
--------------------------------------------------------------------------------
static XMLCh s_bobName[] = {
chLatin_b,
chLatin_o,
chLatin_b,
chNull
};
static char s_bobKey[] = "abcdefghijklmnopqrstuvwx";
//
--------------------------------------------------------------------------------
// Construct/Destruct
//
--------------------------------------------------------------------------------
MerlinFiveInteropResolver::MerlinFiveInteropResolver(const XMLCh * baseURI) {
if (baseURI != NULL)
mp_baseURI = XMLString::replicate(baseURI);
else
mp_baseURI = NULL;
#if !defined(_WIN32)
m_fcount = 0;
#endif
}
MerlinFiveInteropResolver::~MerlinFiveInteropResolver() {
if (mp_baseURI != NULL)
delete[]mp_baseURI;
}
XSECCryptoKey * MerlinFiveInteropResolver::resolveKey(DSIGKeyInfoList * lst) {
int lstSize = lst->getSize();
for (int i = 0; i < lstSize; ++i) {
DSIGKeyInfo * ki = lst->item(i);
if (ki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_NAME) {
DSIGKeyInfoName * kn = dynamic_cast<DSIGKeyInfoName
*>(ki);
const XMLCh * name = kn->getKeyName();
// Check if this is a key we know
if (strEquals(s_bobName, name)) {
OpenSSLCryptoSymmetricKey * k;
k = new
OpenSSLCryptoSymmetricKey(XSECCryptoSymmetricKey::KEY_3DES_CBC_192);
k->setKey((unsigned char *) s_bobKey,
strlen(s_bobKey));
return k;
}
}
}
return NULL;
}
XSECKeyInfoResolver * MerlinFiveInteropResolver::clone(void) const {
return new MerlinFiveInteropResolver(mp_baseURI);
}
#endif /* HAVE_OPENSSL */