You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2016/12/16 23:13:40 UTC
svn commit: r1774687 [1/3] - in /santuario/xml-security-cpp/trunk/xsec/tools:
cipher/XencInteropResolver.cpp cipher/XencInteropResolver.hpp
cipher/cipher.cpp templatesign/templatesign.cpp xklient/xklient.cpp
Author: scantor
Date: Fri Dec 16 23:13:40 2016
New Revision: 1774687
URL: http://svn.apache.org/viewvc?rev=1774687&view=rev
Log:
OpenSSL 1.1 compatibility - tools - tabs to spaces
Modified:
santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.cpp
santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.hpp
santuario/xml-security-cpp/trunk/xsec/tools/cipher/cipher.cpp
santuario/xml-security-cpp/trunk/xsec/tools/templatesign/templatesign.cpp
santuario/xml-security-cpp/trunk/xsec/tools/xklient/xklient.cpp
Modified: santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.cpp?rev=1774687&r1=1774686&r2=1774687&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.cpp Fri Dec 16 23:13:40 2016
@@ -21,7 +21,7 @@
* XSEC
*
* XencInteropResolver := Class to resolve key elements into certificates for
- * interop test
+ * interop test
*
* $Id$
*
@@ -47,14 +47,14 @@ XERCES_CPP_NAMESPACE_USE
#include <iostream>
#if !defined (XSEC_HAVE_OPENSSL) && !defined (XSEC_HAVE_WINCAPI) && !defined (XSEC_HAVE_NSS)
-# error Require OpenSSL or Windows Crypto API for the Merlin Resolver
+# error Require OpenSSL or Windows Crypto API for the Merlin Resolver
#endif
#if defined (XSEC_HAVE_OPENSSL)
-# include <openssl/x509.h>
-# include <openssl/pem.h>
-# include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
-# include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
+# include <openssl/x509.h>
+# include <openssl/pem.h>
+# include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
+# include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
# include <xsec/enc/OpenSSL/OpenSSLCryptoSymmetricKey.hpp>
#endif
@@ -73,31 +73,31 @@ XERCES_CPP_NAMESPACE_USE
// --------------------------------------------------------------------------------
static XMLCh s_bobName[] = {
- chLatin_b,
- chLatin_o,
- chLatin_b,
- chNull
+ chLatin_b,
+ chLatin_o,
+ chLatin_b,
+ chNull
};
static XMLCh s_jobName[] = {
- chLatin_j,
- chLatin_o,
- chLatin_b,
- chNull
+ chLatin_j,
+ chLatin_o,
+ chLatin_b,
+ chNull
};
static XMLCh s_jebName[] = {
- chLatin_j,
- chLatin_e,
- chLatin_b,
- chNull
+ chLatin_j,
+ chLatin_e,
+ chLatin_b,
+ chNull
};
static XMLCh s_jedName[] = {
- chLatin_j,
- chLatin_e,
- chLatin_d,
- chNull
+ chLatin_j,
+ chLatin_e,
+ chLatin_d,
+ chNull
};
static char s_bobKey[] = "abcdefghijklmnopqrstuvwx";
@@ -110,134 +110,134 @@ static char s_jedKey[] = "abcdefghijklmn
// --------------------------------------------------------------------------------
static XMLCh s_phaosRSAName[] = {
- chLatin_m,
- chLatin_y,
- chDash,
- chLatin_r,
- chLatin_s,
- chLatin_a,
- chDash,
- chLatin_k,
- chLatin_e,
- chLatin_y,
- chNull
+ chLatin_m,
+ chLatin_y,
+ chDash,
+ chLatin_r,
+ chLatin_s,
+ chLatin_a,
+ chDash,
+ chLatin_k,
+ chLatin_e,
+ chLatin_y,
+ chNull
};
static XMLCh s_phaosTripleDESName[] = {
- chLatin_m,
- chLatin_y,
- chDash,
- chLatin_t,
- chLatin_r,
- chLatin_i,
- chLatin_p,
- chLatin_l,
- chLatin_e,
- chLatin_d,
- chLatin_e,
- chLatin_s,
- chDash,
- chLatin_k,
- chLatin_e,
- chLatin_y,
- chNull
+ chLatin_m,
+ chLatin_y,
+ chDash,
+ chLatin_t,
+ chLatin_r,
+ chLatin_i,
+ chLatin_p,
+ chLatin_l,
+ chLatin_e,
+ chLatin_d,
+ chLatin_e,
+ chLatin_s,
+ chDash,
+ chLatin_k,
+ chLatin_e,
+ chLatin_y,
+ chNull
};
static XMLCh s_phaos3DESName[] = {
- chLatin_m,
- chLatin_y,
- chDash,
- chDigit_3,
- chLatin_d,
- chLatin_e,
- chLatin_s,
- chDash,
- chLatin_k,
- chLatin_e,
- chLatin_y,
- chNull
+ chLatin_m,
+ chLatin_y,
+ chDash,
+ chDigit_3,
+ chLatin_d,
+ chLatin_e,
+ chLatin_s,
+ chDash,
+ chLatin_k,
+ chLatin_e,
+ chLatin_y,
+ chNull
};
static XMLCh s_phaosAES128Name[] = {
- chLatin_m,
- chLatin_y,
- chDash,
- chLatin_a,
- chLatin_e,
- chLatin_s,
- chDigit_1,
- chDigit_2,
- chDigit_8,
- chDash,
- chLatin_k,
- chLatin_e,
- chLatin_y,
- chNull
+ chLatin_m,
+ chLatin_y,
+ chDash,
+ chLatin_a,
+ chLatin_e,
+ chLatin_s,
+ chDigit_1,
+ chDigit_2,
+ chDigit_8,
+ chDash,
+ chLatin_k,
+ chLatin_e,
+ chLatin_y,
+ chNull
};
static XMLCh s_phaosAES192Name[] = {
- chLatin_m,
- chLatin_y,
- chDash,
- chLatin_a,
- chLatin_e,
- chLatin_s,
- chDigit_1,
- chDigit_9,
- chDigit_2,
- chDash,
- chLatin_k,
- chLatin_e,
- chLatin_y,
- chNull
+ chLatin_m,
+ chLatin_y,
+ chDash,
+ chLatin_a,
+ chLatin_e,
+ chLatin_s,
+ chDigit_1,
+ chDigit_9,
+ chDigit_2,
+ chDash,
+ chLatin_k,
+ chLatin_e,
+ chLatin_y,
+ chNull
};
static XMLCh s_phaosAES256Name[] = {
- chLatin_m,
- chLatin_y,
- chDash,
- chLatin_a,
- chLatin_e,
- chLatin_s,
- chDigit_2,
- chDigit_5,
- chDigit_6,
- chDash,
- chLatin_k,
- chLatin_e,
- chLatin_y,
- chNull
+ chLatin_m,
+ chLatin_y,
+ chDash,
+ chLatin_a,
+ chLatin_e,
+ chLatin_s,
+ chDigit_2,
+ chDigit_5,
+ chDigit_6,
+ chDash,
+ chLatin_k,
+ chLatin_e,
+ chLatin_y,
+ chNull
};
unsigned char s_phaos3DESKey[] = {
- 0xc8, 0x8f, 0x89, 0xd5, 0xfd, 0xe9, 0xb9, 0x80,
- 0x04, 0x46, 0x32, 0x1c, 0x4f, 0xab, 0xdf, 0x83,
- 0xa4, 0x62, 0xb6, 0x62, 0x97, 0xf2, 0x70, 0xf4
+ 0xc8, 0x8f, 0x89, 0xd5, 0xfd, 0xe9, 0xb9, 0x80,
+ 0x04, 0x46, 0x32, 0x1c, 0x4f, 0xab, 0xdf, 0x83,
+ 0xa4, 0x62, 0xb6, 0x62, 0x97, 0xf2, 0x70, 0xf4
};
unsigned char s_phaosAES128Key[] = {
- 0xd3, 0x5f, 0xb2, 0xb9, 0x0d, 0xa1, 0xb8, 0xf4,
- 0xb5, 0xf9, 0x0b, 0xf4, 0x2c, 0x7f, 0xb3, 0x69
+ 0xd3, 0x5f, 0xb2, 0xb9, 0x0d, 0xa1, 0xb8, 0xf4,
+ 0xb5, 0xf9, 0x0b, 0xf4, 0x2c, 0x7f, 0xb3, 0x69
};
unsigned char s_phaosAES192Key[] = {
-
- 0x22, 0x57, 0xee, 0x4b, 0x8d, 0x0b, 0xbd, 0x2b,
- 0x55, 0x53, 0x43, 0x23, 0xf1, 0xe3, 0xeb, 0xac,
- 0x61, 0xd5, 0x84, 0x06, 0xf8, 0xf3, 0x2f, 0xbe
+
+ 0x22, 0x57, 0xee, 0x4b, 0x8d, 0x0b, 0xbd, 0x2b,
+ 0x55, 0x53, 0x43, 0x23, 0xf1, 0xe3, 0xeb, 0xac,
+ 0x61, 0xd5, 0x84, 0x06, 0xf8, 0xf3, 0x2f, 0xbe
};
unsigned char s_phaosAES256Key[] = {
-
- 0x66, 0x16, 0x78, 0xbf, 0x74, 0x65, 0xc1, 0x39,
- 0x42, 0x10, 0xea, 0x48, 0xac, 0x77, 0xcb, 0x29,
- 0x5c, 0x89, 0x38, 0x10, 0xed, 0x10, 0x93, 0x8e,
- 0x40, 0x36, 0xad, 0xff, 0x8c, 0x51, 0xd5, 0xb0
+
+ 0x66, 0x16, 0x78, 0xbf, 0x74, 0x65, 0xc1, 0x39,
+ 0x42, 0x10, 0xea, 0x48, 0xac, 0x77, 0xcb, 0x29,
+ 0x5c, 0x89, 0x38, 0x10, 0xed, 0x10, 0x93, 0x8e,
+ 0x40, 0x36, 0xad, 0xff, 0x8c, 0x51, 0xd5, 0xb0
};
@@ -248,79 +248,79 @@ unsigned char s_phaosAES256Key[] = {
XencInteropResolver::XencInteropResolver(DOMDocument * doc, const XMLCh * baseURI) {
- if (baseURI != NULL)
- mp_baseURI = XMLString::replicate(baseURI);
- else
- mp_baseURI = NULL;
+ if (baseURI != NULL)
+ mp_baseURI = XMLString::replicate(baseURI);
+ else
+ mp_baseURI = NULL;
#if !defined(_WIN32)
- m_fcount = 0;
+ m_fcount = 0;
#endif
- mp_doc = doc;
+ mp_doc = doc;
}
XencInteropResolver::~XencInteropResolver() {
- if (mp_baseURI != NULL)
- XSEC_RELEASE_XMLCH(mp_baseURI);
+ if (mp_baseURI != NULL)
+ XSEC_RELEASE_XMLCH(mp_baseURI);
}
// --------------------------------------------------------------------------------
-// Utility functions
+// Utility functions
// --------------------------------------------------------------------------------
#if defined(_WIN32)
void reverseSlash(safeBuffer &path) {
- for (int i = 0; i < (int) strlen(path.rawCharBuffer()); ++i) {
+ for (int i = 0; i < (int) strlen(path.rawCharBuffer()); ++i) {
- if (path[i] == '/')
- path[i] = '\\';
+ if (path[i] == '/')
+ path[i] = '\\';
- }
+ }
}
#endif
-
+
XSECCryptoSymmetricKey * XencInteropResolver::makeSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type) {
- XSECCryptoSymmetricKey * k = XSECPlatformUtils::g_cryptoProvider->keySymmetric(type);
- return k;
+ XSECCryptoSymmetricKey * k = XSECPlatformUtils::g_cryptoProvider->keySymmetric(type);
+ return k;
}
#if defined (XSEC_HAVE_OPENSSL)
BIO * createFileBIO(const XMLCh * baseURI, const char * name) {
- // Open file URI relative to the encrypted file
+ // Open file URI relative to the encrypted file
- BIO * bioFile;
- if ((bioFile = BIO_new(BIO_s_file())) == NULL) {
-
- return NULL;
-
- }
-
- safeBuffer fname;
- fname.sbTranscodeIn(baseURI);
- fname.sbStrcatIn("/");
- fname.sbStrcatIn(name);
+ BIO * bioFile;
+ if ((bioFile = BIO_new(BIO_s_file())) == NULL) {
+
+ return NULL;
+
+ }
+
+ safeBuffer fname;
+ fname.sbTranscodeIn(baseURI);
+ fname.sbStrcatIn("/");
+ fname.sbStrcatIn(name);
#if defined(_WIN32)
- reverseSlash(fname);
+ reverseSlash(fname);
#endif
- if (BIO_read_filename(bioFile, fname.rawCharBuffer()) <= 0) {
-
- return NULL;
+ if (BIO_read_filename(bioFile, fname.rawCharBuffer()) <= 0) {
+
+ return NULL;
- }
+ }
- return bioFile;
+ return bioFile;
}
#endif
// --------------------------------------------------------------------------------
@@ -329,239 +329,236 @@ BIO * createFileBIO(const XMLCh * baseUR
XSECCryptoKey * XencInteropResolver::resolveKey(DSIGKeyInfoList * lst) {
- int lstSize = (int) lst->getSize();
+ int lstSize = (int) lst->getSize();
- for (int i = 0; i < lstSize; ++i) {
+ for (int i = 0; i < lstSize; ++i) {
- DSIGKeyInfo * ki = lst->item(i);
+ DSIGKeyInfo * ki = lst->item(i);
- if (ki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_NAME) {
+ if (ki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_NAME) {
- DSIGKeyInfoName * kn = (DSIGKeyInfoName *) ki;
-
- const XMLCh * name = kn->getKeyName();
-
- // Check if this is a key we know
-
- if (strEquals(s_bobName, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
- try {
- k->setKey((unsigned char *) s_bobKey, (unsigned int) strlen(s_bobKey));
- } catch (...) {
- delete k;
- throw;
- }
- return k;
- }
- if (strEquals(s_jobName, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_128);
- try {
- k->setKey((unsigned char *) s_jobKey, (unsigned int) strlen(s_jobKey));
- } catch(...) {
- delete k;
- throw;
- }
- return k;
- }
- if (strEquals(s_jebName, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_192);
- try {
- k->setKey((unsigned char *) s_jebKey, (unsigned int) strlen(s_jebKey));
- } catch(...) {
- delete k;
- throw;
- }
- return k;
- }
- if (strEquals(s_jedName, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_256);
- try {
- k->setKey((unsigned char *) s_jedKey, (unsigned int) strlen(s_jedKey));
- } catch(...) {
- delete k;
- throw;
- }
- return k;
- }
- // PHAOS Keys
- if (strEquals(s_phaos3DESName, name) || strEquals(s_phaosTripleDESName, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
- try {
- k->setKey(s_phaos3DESKey, 24);
- } catch (...) {
- delete k;
- throw;
- }
- return k;
- }
- if (strEquals(s_phaosAES128Name, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_128);
- try {
- k->setKey(s_phaosAES128Key, 16);
- } catch(...) {
- delete k;
- throw;
- }
- return k;
- }
- if (strEquals(s_phaosAES192Name, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_192);
- try {
- k->setKey(s_phaosAES192Key, 24);
- } catch(...) {
- delete k;
- throw;
- }
- return k;
- }
- if (strEquals(s_phaosAES256Name, name)) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_256);
- try {
- k->setKey(s_phaosAES256Key, 32);
- } catch(...) {
- delete k;
- throw;
- }
- return k;
- }
+ DSIGKeyInfoName * kn = (DSIGKeyInfoName *) ki;
+
+ const XMLCh * name = kn->getKeyName();
+
+ // Check if this is a key we know
+
+ if (strEquals(s_bobName, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
+ try {
+ k->setKey((unsigned char *) s_bobKey, (unsigned int) strlen(s_bobKey));
+ } catch (...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ if (strEquals(s_jobName, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_128);
+ try {
+ k->setKey((unsigned char *) s_jobKey, (unsigned int) strlen(s_jobKey));
+ } catch(...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ if (strEquals(s_jebName, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_192);
+ try {
+ k->setKey((unsigned char *) s_jebKey, (unsigned int) strlen(s_jebKey));
+ } catch(...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ if (strEquals(s_jedName, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_256);
+ try {
+ k->setKey((unsigned char *) s_jedKey, (unsigned int) strlen(s_jedKey));
+ } catch(...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ // PHAOS Keys
+ if (strEquals(s_phaos3DESName, name) || strEquals(s_phaosTripleDESName, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
+ try {
+ k->setKey(s_phaos3DESKey, 24);
+ } catch (...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ if (strEquals(s_phaosAES128Name, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_128);
+ try {
+ k->setKey(s_phaosAES128Key, 16);
+ } catch(...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ if (strEquals(s_phaosAES192Name, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_192);
+ try {
+ k->setKey(s_phaosAES192Key, 24);
+ } catch(...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
+ if (strEquals(s_phaosAES256Name, name)) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_256);
+ try {
+ k->setKey(s_phaosAES256Key, 32);
+ } catch(...) {
+ delete k;
+ throw;
+ }
+ return k;
+ }
#if defined (XSEC_HAVE_OPENSSL)
- if (strEquals(s_phaosRSAName, name)) {
+ if (strEquals(s_phaosRSAName, name)) {
- // This is the Phaos RSA key
- BIO * rsaFile = createFileBIO(mp_baseURI, "rsa-priv-key.der");
- if (rsaFile == NULL)
- return NULL;
-
- PKCS8_PRIV_KEY_INFO * p8inf;
- p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(rsaFile, NULL);
-
- EVP_PKEY * pk = EVP_PKCS82PKEY(p8inf);
- OpenSSLCryptoKeyRSA * k = new OpenSSLCryptoKeyRSA(pk);
- PKCS8_PRIV_KEY_INFO_free(p8inf);
- BIO_free_all(rsaFile);
- return k;
+ // This is the Phaos RSA key
+ BIO * rsaFile = createFileBIO(mp_baseURI, "rsa-priv-key.der");
+ if (rsaFile == NULL)
+ return NULL;
+
+ PKCS8_PRIV_KEY_INFO * p8inf;
+ p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(rsaFile, NULL);
+
+ EVP_PKEY * pk = EVP_PKCS82PKEY(p8inf);
+ OpenSSLCryptoKeyRSA * k = new OpenSSLCryptoKeyRSA(pk);
+ PKCS8_PRIV_KEY_INFO_free(p8inf);
+ BIO_free_all(rsaFile);
+ return k;
- }
+ }
#endif
- // If we get this far, we don't know it. So look for EncryptedKey elements
- // containing this name as a CarriedKeyName
+ // If we get this far, we don't know it. So look for EncryptedKey elements
+ // containing this name as a CarriedKeyName
- DOMNode * c = mp_doc->getDocumentElement()->getFirstChild();
- while (c != NULL) {
+ DOMNode * c = mp_doc->getDocumentElement()->getFirstChild();
+ while (c != NULL) {
- if (c->getNodeType() == DOMNode::ELEMENT_NODE &&
- strEquals(getDSIGLocalName(c), MAKE_UNICODE_STRING("KeyInfo"))) {
+ if (c->getNodeType() == DOMNode::ELEMENT_NODE &&
+ strEquals(getDSIGLocalName(c), MAKE_UNICODE_STRING("KeyInfo"))) {
- DOMNode * ek = c->getFirstChild();
- while (ek != NULL) {
-
- if (ek->getNodeType() == DOMNode::ELEMENT_NODE &&
- strEquals(getXENCLocalName(ek), MAKE_UNICODE_STRING("EncryptedKey"))) {
-
- // Load
- XSECProvider prov;
- XENCCipher * cipher = prov.newCipher(mp_doc);
-
- XENCEncryptedKey * xek = cipher->loadEncryptedKey(static_cast<DOMElement*>(ek));
- Janitor<XENCEncryptedKey> j_xek(xek);
-
- if (strEquals(xek->getCarriedKeyName(), name) &&
- strEquals(xek->getRecipient(), MAKE_UNICODE_STRING("you"))) {
-
- // This is it!
- cipher->setKeyInfoResolver(this);
- unsigned char keyBuf[1024];
- int sz = cipher->decryptKey(xek, keyBuf, 1024);
-
- if (sz > 0) {
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_256);
- try {
- k->setKey(keyBuf, sz);
- } catch (...) {
- delete k;
- throw;
- }
-
- return k;
- }
- }
- }
- ek = ek->getNextSibling();
- }
- }
-
- c = c->getNextSibling();
- }
-
- }
+ DOMNode * ek = c->getFirstChild();
+ while (ek != NULL) {
+
+ if (ek->getNodeType() == DOMNode::ELEMENT_NODE &&
+ strEquals(getXENCLocalName(ek), MAKE_UNICODE_STRING("EncryptedKey"))) {
+
+ // Load
+ XSECProvider prov;
+ XENCCipher * cipher = prov.newCipher(mp_doc);
+
+ XENCEncryptedKey * xek = cipher->loadEncryptedKey(static_cast<DOMElement*>(ek));
+ Janitor<XENCEncryptedKey> j_xek(xek);
+
+ if (strEquals(xek->getCarriedKeyName(), name) &&
+ strEquals(xek->getRecipient(), MAKE_UNICODE_STRING("you"))) {
+
+ // This is it!
+ cipher->setKeyInfoResolver(this);
+ unsigned char keyBuf[1024];
+ int sz = cipher->decryptKey(xek, keyBuf, 1024);
+
+ if (sz > 0) {
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_AES_256);
+ try {
+ k->setKey(keyBuf, sz);
+ } catch (...) {
+ delete k;
+ throw;
+ }
+
+ return k;
+ }
+ }
+ }
+ ek = ek->getNextSibling();
+ }
+ }
+
+ c = c->getNextSibling();
+ }
+
+ }
- else if (ki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_X509) {
+ else if (ki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_X509) {
- DSIGKeyInfoX509 * kix = (DSIGKeyInfoX509 *) ki;
+ DSIGKeyInfoX509 * kix = (DSIGKeyInfoX509 *) ki;
- XSECCryptoX509 * XCX509 = kix->getCertificateCryptoItem(0);
+ XSECCryptoX509 * XCX509 = kix->getCertificateCryptoItem(0);
- if (XCX509 != 0) {
+ if (XCX509 != 0) {
#if defined (XSEC_HAVE_OPENSSL)
- if (strEquals(XCX509->getProviderName(),DSIGConstants::s_unicodeStrPROVOpenSSL)) {
+ if (strEquals(XCX509->getProviderName(),DSIGConstants::s_unicodeStrPROVOpenSSL)) {
- OpenSSLCryptoX509 * OSSLX509 = (OpenSSLCryptoX509 *) XCX509;
- X509 * x509 = OSSLX509->getOpenSSLX509();
+ OpenSSLCryptoX509 * OSSLX509 = (OpenSSLCryptoX509 *) XCX509;
+ X509 * x509 = OSSLX509->getOpenSSLX509();
- // Check the serial number
- BIGNUM * bnserial = ASN1_INTEGER_to_BN(x509->cert_info->serialNumber, NULL);
- BN_free(bnserial);
+ // Check the serial number
+ BIGNUM * bnserial = ASN1_INTEGER_to_BN(x509->cert_info->serialNumber, NULL);
+ BN_free(bnserial);
- BIO * rsaFile = createFileBIO(mp_baseURI, "rsa.p8");
- if (rsaFile == NULL)
- return NULL;
+ BIO * rsaFile = createFileBIO(mp_baseURI, "rsa.p8");
+ if (rsaFile == NULL)
+ return NULL;
- PKCS8_PRIV_KEY_INFO * p8inf;
- p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(rsaFile, NULL);
+ PKCS8_PRIV_KEY_INFO * p8inf;
+ p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(rsaFile, NULL);
- EVP_PKEY * pk = EVP_PKCS82PKEY(p8inf);
- OpenSSLCryptoKeyRSA * k = new OpenSSLCryptoKeyRSA(pk);
- PKCS8_PRIV_KEY_INFO_free(p8inf);
- BIO_free_all(rsaFile);
- return k;
+ EVP_PKEY * pk = EVP_PKCS82PKEY(p8inf);
+ OpenSSLCryptoKeyRSA * k = new OpenSSLCryptoKeyRSA(pk);
+ PKCS8_PRIV_KEY_INFO_free(p8inf);
+ BIO_free_all(rsaFile);
+ return k;
- }
+ }
#if defined (XSEC_HAVE_WINCAPI)
- else {
+ else {
#endif /* XSEC_HAVE_WINCAPI */
#endif /* XSEC_HAVE_OPENSSL */
#if defined (XSEC_HAVE_WINCAPI)
- std::cerr << "WARNING - Unable to load PKCS8 private key file into Windows CAPI" << std::endl;
+ std::cerr << "WARNING - Unable to load PKCS8 private key file into Windows CAPI" << std::endl;
#if defined (XSEC_HAVE_OPENSSL)
- }
+ }
#endif /* XSEC_HAVE_WINCAPI */
#endif /* XSEC_HAVE_OPENSSL */
- }
- }
- }
+ }
+ }
+ }
- return NULL;
+ return NULL;
}
XSECKeyInfoResolver * XencInteropResolver::clone(void) const {
- return new XencInteropResolver(mp_doc, mp_baseURI);
+ return new XencInteropResolver(mp_doc, mp_baseURI);
}
-
-
-
Modified: santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.hpp?rev=1774687&r1=1774686&r2=1774687&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/tools/cipher/XencInteropResolver.hpp Fri Dec 16 23:13:40 2016
@@ -21,7 +21,7 @@
* XSEC
*
* XencInteropResolver := Class to resolve key elements into certificates for
- * interop test
+ * interop test
*
* Author(s): Berin Lautenbach
*
@@ -45,27 +45,27 @@ class XencInteropResolver : public XSECK
public :
- XencInteropResolver(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc, const XMLCh * baseURI);
- ~XencInteropResolver();
+ XencInteropResolver(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc, const XMLCh * baseURI);
+ ~XencInteropResolver();
- // Interface functions
+ // Interface functions
- virtual XSECCryptoKey * resolveKey(DSIGKeyInfoList * lst);
- virtual XSECKeyInfoResolver * clone(void) const;
+ virtual XSECCryptoKey * resolveKey(DSIGKeyInfoList * lst);
+ virtual XSECKeyInfoResolver * clone(void) const;
- // Internal functions
+ // Internal functions
private:
- XSECCryptoSymmetricKey * makeSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType);
+ XSECCryptoSymmetricKey * makeSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType);
- XMLCh * mp_baseURI;
- XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument
- *mp_doc;
+ XMLCh * mp_baseURI;
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument
+ *mp_doc;
#if defined (_WIN32)
- _finddata_t m_finder;
- long m_handle;
+ _finddata_t m_finder;
+ long m_handle;
#else
glob_t m_globbuf;
int m_fcount;
Modified: santuario/xml-security-cpp/trunk/xsec/tools/cipher/cipher.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/tools/cipher/cipher.cpp?rev=1774687&r1=1774686&r2=1774687&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/tools/cipher/cipher.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/tools/cipher/cipher.cpp Fri Dec 16 23:13:40 2016
@@ -45,9 +45,9 @@
// ugly :<
#if defined(_WIN32)
-# include <xsec/utils/winutils/XSECURIResolverGenericWin32.hpp>
+# include <xsec/utils/winutils/XSECURIResolverGenericWin32.hpp>
#else
-# include <xsec/utils/unixutils/XSECURIResolverGenericUnix.hpp>
+# include <xsec/utils/unixutils/XSECURIResolverGenericUnix.hpp>
#endif
// General
@@ -105,34 +105,34 @@ XALAN_USING_XALAN(XalanTransformer)
#endif
#if !defined (XSEC_HAVE_OPENSSL) && !defined(XSEC_HAVE_WINCAPI) && !defined(XSEC_HAVE_NSS)
-# error No available cryptoAPI
+# error No available cryptoAPI
#endif
#if defined (XSEC_HAVE_OPENSSL)
// OpenSSL
-# include <xsec/enc/OpenSSL/OpenSSLCryptoKeyHMAC.hpp>
-# include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
-# include <openssl/err.h>
-# include <openssl/bio.h>
-# include <openssl/evp.h>
-# include <openssl/pem.h>
+# include <xsec/enc/OpenSSL/OpenSSLCryptoKeyHMAC.hpp>
+# include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
+# include <openssl/err.h>
+# include <openssl/bio.h>
+# include <openssl/evp.h>
+# include <openssl/pem.h>
#endif
#if defined (XSEC_HAVE_WINCAPI)
-# include <xsec/enc/WinCAPI/WinCAPICryptoProvider.hpp>
-# include <xsec/enc/WinCAPI/WinCAPICryptoSymmetricKey.hpp>
-# include <xsec/enc/WinCAPI/WinCAPICryptoKeyHMAC.hpp>
+# include <xsec/enc/WinCAPI/WinCAPICryptoProvider.hpp>
+# include <xsec/enc/WinCAPI/WinCAPICryptoSymmetricKey.hpp>
+# include <xsec/enc/WinCAPI/WinCAPICryptoKeyHMAC.hpp>
#endif
#if defined (XSEC_HAVE_NSS)
-# include <xsec/enc/NSS/NSSCryptoProvider.hpp>
-# include <xsec/enc/NSS/NSSCryptoSymmetricKey.hpp>
-# include <xsec/enc/NSS/NSSCryptoKeyHMAC.hpp>
+# include <xsec/enc/NSS/NSSCryptoProvider.hpp>
+# include <xsec/enc/NSS/NSSCryptoSymmetricKey.hpp>
+# include <xsec/enc/NSS/NSSCryptoKeyHMAC.hpp>
#endif
@@ -157,612 +157,612 @@ std::ostream& operator<< (std::ostream&
void printUsage(void) {
- cerr << "\nUsage: cipher [options] <input file name>\n\n";
- cerr << " Where options are :\n\n";
- cerr << " --decrypt/-d\n";
- cerr << " Operate in decrypt mode (default) - outputs the decrypted octet stream\n";
- cerr << " Reads in the input file as an XML file, searches for an EncryptedData node\n";
- cerr << " and decrypts the content\n";
- cerr << " --decrypt-element/-de\n";
- cerr << " Operate in decrypt and XML mode.\n";
- cerr << " This will output the original XML document with the first encrypted\n";
- cerr << " element decrypted.\n";
- cerr << " --encrypt-file/-ef\n";
- cerr << " Encrypt the contents of the input file as raw data and create an\n";
- cerr << " XML Encrypted Data outpu\n";
- cerr << " --encrypt-xml/-ex\n";
- cerr << " Parse the input file and encrypt the doc element down, storing the\n";
- cerr << " output as a XML Encrypted Data\n";
- cerr << " --key/-k [kek] <KEY_TYPE> [options]\n";
- cerr << " Set the key to use.\n";
- cerr << " If the first parameter is \"kek\", the key arguments will be used\n";
- cerr << " as a Key EncryptionKey\n";
- cerr << " KEY_TYPE defines what the key is. Can be one of :\n";
- cerr << " X509, RSA, AES128, AES192, AES256, AES128-GCM, AES192-GCM, AES256-GCM or 3DES\n";
- cerr << " options are :\n";
- cerr << " <filename> - for X509 PEM files (must be an RSA KEK certificate\n";
- cerr << " <filename> <password> - for RSA private key files (MUST be a KEK)\n";
- cerr << " <key-string> - For a string to use as the key for AES or DES keys\n";
- cerr << " --xkms/-x\n";
- cerr << " The key that follows on the command line is to be interpreted as\n";
- cerr << " an XKMS RSAKeyPair encryption key\n";
- cerr << " --interop/-i\n";
- cerr << " Use the interop resolver for Baltimore interop examples\n";
- cerr << " --out-file/-o\n";
- cerr << " Output the result to the indicated file (rather than stdout)\n";
+ cerr << "\nUsage: cipher [options] <input file name>\n\n";
+ cerr << " Where options are :\n\n";
+ cerr << " --decrypt/-d\n";
+ cerr << " Operate in decrypt mode (default) - outputs the decrypted octet stream\n";
+ cerr << " Reads in the input file as an XML file, searches for an EncryptedData node\n";
+ cerr << " and decrypts the content\n";
+ cerr << " --decrypt-element/-de\n";
+ cerr << " Operate in decrypt and XML mode.\n";
+ cerr << " This will output the original XML document with the first encrypted\n";
+ cerr << " element decrypted.\n";
+ cerr << " --encrypt-file/-ef\n";
+ cerr << " Encrypt the contents of the input file as raw data and create an\n";
+ cerr << " XML Encrypted Data outpu\n";
+ cerr << " --encrypt-xml/-ex\n";
+ cerr << " Parse the input file and encrypt the doc element down, storing the\n";
+ cerr << " output as a XML Encrypted Data\n";
+ cerr << " --key/-k [kek] <KEY_TYPE> [options]\n";
+ cerr << " Set the key to use.\n";
+ cerr << " If the first parameter is \"kek\", the key arguments will be used\n";
+ cerr << " as a Key EncryptionKey\n";
+ cerr << " KEY_TYPE defines what the key is. Can be one of :\n";
+ cerr << " X509, RSA, AES128, AES192, AES256, AES128-GCM, AES192-GCM, AES256-GCM or 3DES\n";
+ cerr << " options are :\n";
+ cerr << " <filename> - for X509 PEM files (must be an RSA KEK certificate\n";
+ cerr << " <filename> <password> - for RSA private key files (MUST be a KEK)\n";
+ cerr << " <key-string> - For a string to use as the key for AES or DES keys\n";
+ cerr << " --xkms/-x\n";
+ cerr << " The key that follows on the command line is to be interpreted as\n";
+ cerr << " an XKMS RSAKeyPair encryption key\n";
+ cerr << " --interop/-i\n";
+ cerr << " Use the interop resolver for Baltimore interop examples\n";
+ cerr << " --out-file/-o\n";
+ cerr << " Output the result to the indicated file (rather than stdout)\n";
#if defined (XSEC_HAVE_WINCAPI)
- cerr << " --wincapi/-w\n";
- cerr << " Force use of Windows Crypto API\n";
+ cerr << " --wincapi/-w\n";
+ cerr << " Force use of Windows Crypto API\n";
#endif
#if defined (XSEC_HAVE_NSS)
- cerr << " --nss/-n\n";
- cerr << " Force use of NSS Crypto API\n";
+ cerr << " --nss/-n\n";
+ cerr << " Force use of NSS Crypto API\n";
#endif
- cerr << "\n Exits with codes :\n";
- cerr << " 0 = Decrypt/Encrypt OK\n";
- cerr << " 1 = Decrypt/Encrypt failed\n";
- cerr << " 2 = Processing error\n";
+ cerr << "\n Exits with codes :\n";
+ cerr << " 0 = Decrypt/Encrypt OK\n";
+ cerr << " 1 = Decrypt/Encrypt failed\n";
+ cerr << " 2 = Processing error\n";
}
int evaluate(int argc, char ** argv) {
-
- char * filename = NULL;
- char * outfile = NULL;
- unsigned char * keyStr = NULL;
- bool doDecrypt = true;
- bool errorsOccured = false;
- bool doDecryptElement = false;
- bool useInteropResolver = false;
- bool encryptFileAsData = false;
- bool parseXMLInput = true;
- bool doXMLOutput = false;
- bool isXKMSKey = false;
- XSECCryptoKey * kek = NULL;
- XSECCryptoKey * key = NULL;
- int keyLen = 0;
- encryptionMethod kekAlg = ENCRYPT_NONE;
- encryptionMethod keyAlg = ENCRYPT_NONE;
- DOMDocument *doc;
- unsigned char keyBuf[24];
- XMLFormatTarget *formatTarget ;
+
+ char * filename = NULL;
+ char * outfile = NULL;
+ unsigned char * keyStr = NULL;
+ bool doDecrypt = true;
+ bool errorsOccured = false;
+ bool doDecryptElement = false;
+ bool useInteropResolver = false;
+ bool encryptFileAsData = false;
+ bool parseXMLInput = true;
+ bool doXMLOutput = false;
+ bool isXKMSKey = false;
+ XSECCryptoKey * kek = NULL;
+ XSECCryptoKey * key = NULL;
+ int keyLen = 0;
+ encryptionMethod kekAlg = ENCRYPT_NONE;
+ encryptionMethod keyAlg = ENCRYPT_NONE;
+ DOMDocument *doc;
+ unsigned char keyBuf[24];
+ XMLFormatTarget *formatTarget ;
#if defined(_WIN32) && defined (XSEC_HAVE_WINCAPI)
- HCRYPTPROV win32DSSCSP = 0; // Crypto Providers
- HCRYPTPROV win32RSACSP = 0;
+ HCRYPTPROV win32DSSCSP = 0; // Crypto Providers
+ HCRYPTPROV win32RSACSP = 0;
- CryptAcquireContext(&win32DSSCSP, NULL, NULL, PROV_DSS, CRYPT_VERIFYCONTEXT);
- CryptAcquireContext(&win32RSACSP, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
+ CryptAcquireContext(&win32DSSCSP, NULL, NULL, PROV_DSS, CRYPT_VERIFYCONTEXT);
+ CryptAcquireContext(&win32RSACSP, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
#endif
- if (argc < 2) {
-
- printUsage();
- return 2;
- }
-
- // Run through parameters
- int paramCount = 1;
-
- while (paramCount < argc - 1) {
-
- if (_stricmp(argv[paramCount], "--decrypt-element") == 0 || _stricmp(argv[paramCount], "-de") == 0) {
- paramCount++;
- doDecrypt = true;
- doDecryptElement = true;
- doXMLOutput = true;
- parseXMLInput = true;
- }
- else if (_stricmp(argv[paramCount], "--interop") == 0 || _stricmp(argv[paramCount], "-i") == 0) {
- // Use the interop key resolver
- useInteropResolver = true;
- paramCount++;
- }
- else if (_stricmp(argv[paramCount], "--encrypt-file") == 0 || _stricmp(argv[paramCount], "-ef") == 0) {
- // Use this file as the input
- doDecrypt = false;
- encryptFileAsData = true;
- doXMLOutput = true;
- parseXMLInput = false;
- paramCount++;
- }
- else if (_stricmp(argv[paramCount], "--encrypt-xml") == 0 || _stricmp(argv[paramCount], "-ex") == 0) {
- // Us this file as an XML input file
- doDecrypt = false;
- encryptFileAsData = false;
- doXMLOutput = true;
- parseXMLInput = true;
- paramCount++;
- }
- else if (_stricmp(argv[paramCount], "--out-file") == 0 || _stricmp(argv[paramCount], "-o") == 0) {
- if (paramCount +2 >= argc) {
- printUsage();
- return 1;
- }
- paramCount++;
- outfile = argv[paramCount];
- paramCount++;
- }
- else if (_stricmp(argv[paramCount], "--xkms") == 0 || _stricmp(argv[paramCount], "-x") == 0) {
- paramCount++;
- isXKMSKey = true;
- }
+ if (argc < 2) {
+
+ printUsage();
+ return 2;
+ }
+
+ // Run through parameters
+ int paramCount = 1;
+
+ while (paramCount < argc - 1) {
+
+ if (_stricmp(argv[paramCount], "--decrypt-element") == 0 || _stricmp(argv[paramCount], "-de") == 0) {
+ paramCount++;
+ doDecrypt = true;
+ doDecryptElement = true;
+ doXMLOutput = true;
+ parseXMLInput = true;
+ }
+ else if (_stricmp(argv[paramCount], "--interop") == 0 || _stricmp(argv[paramCount], "-i") == 0) {
+ // Use the interop key resolver
+ useInteropResolver = true;
+ paramCount++;
+ }
+ else if (_stricmp(argv[paramCount], "--encrypt-file") == 0 || _stricmp(argv[paramCount], "-ef") == 0) {
+ // Use this file as the input
+ doDecrypt = false;
+ encryptFileAsData = true;
+ doXMLOutput = true;
+ parseXMLInput = false;
+ paramCount++;
+ }
+ else if (_stricmp(argv[paramCount], "--encrypt-xml") == 0 || _stricmp(argv[paramCount], "-ex") == 0) {
+ // Us this file as an XML input file
+ doDecrypt = false;
+ encryptFileAsData = false;
+ doXMLOutput = true;
+ parseXMLInput = true;
+ paramCount++;
+ }
+ else if (_stricmp(argv[paramCount], "--out-file") == 0 || _stricmp(argv[paramCount], "-o") == 0) {
+ if (paramCount +2 >= argc) {
+ printUsage();
+ return 1;
+ }
+ paramCount++;
+ outfile = argv[paramCount];
+ paramCount++;
+ }
+ else if (_stricmp(argv[paramCount], "--xkms") == 0 || _stricmp(argv[paramCount], "-x") == 0) {
+ paramCount++;
+ isXKMSKey = true;
+ }
#if defined (XSEC_HAVE_WINCAPI)
- else if (_stricmp(argv[paramCount], "--wincapi") == 0 || _stricmp(argv[paramCount], "-w") == 0) {
- // Use the interop key resolver
- WinCAPICryptoProvider * cp = new WinCAPICryptoProvider();
- XSECPlatformUtils::SetCryptoProvider(cp);
- paramCount++;
- }
+ else if (_stricmp(argv[paramCount], "--wincapi") == 0 || _stricmp(argv[paramCount], "-w") == 0) {
+ // Use the interop key resolver
+ WinCAPICryptoProvider * cp = new WinCAPICryptoProvider();
+ XSECPlatformUtils::SetCryptoProvider(cp);
+ paramCount++;
+ }
#endif
#if defined (XSEC_HAVE_NSS)
- else if (_stricmp(argv[paramCount], "--nss") == 0 || _stricmp(argv[paramCount], "-n") == 0) {
- // NSS Crypto Provider
- NSSCryptoProvider * cp = new NSSCryptoProvider();
- XSECPlatformUtils::SetCryptoProvider(cp);
- paramCount++;
- }
-#endif
- else if (_stricmp(argv[paramCount], "--key") == 0 || _stricmp(argv[paramCount], "-k") == 0) {
-
- // Have a key!
- paramCount++;
- bool isKEK = false;
- XSECCryptoSymmetricKey::SymmetricKeyType loadKeyAs =
- XSECCryptoSymmetricKey::KEY_NONE;
-
- if (_stricmp(argv[paramCount], "kek") == 0) {
- isKEK = true;
- paramCount++;
- if (paramCount >= argc) {
- printUsage();
- return 2;
- }
- }
-
- if (_stricmp(argv[paramCount], "3DES") == 0 ||
- _stricmp(argv[paramCount], "AES128") == 0 ||
- _stricmp(argv[paramCount], "AES192") == 0 ||
- _stricmp(argv[paramCount], "AES256") == 0 ||
- _stricmp(argv[paramCount], "AES128-GCM") == 0 ||
- _stricmp(argv[paramCount], "AES192-GCM") == 0 ||
- _stricmp(argv[paramCount], "AES256-GCM") == 0) {
-
- if (paramCount +2 >= argc) {
- printUsage();
- return 2;
- }
-
- switch(argv[paramCount][4]) {
- case '\0' :
- keyLen = 24;
- loadKeyAs = XSECCryptoSymmetricKey::KEY_3DES_192;
- keyAlg = ENCRYPT_3DES_CBC;
- break;
- case '2' :
- keyLen = 16;
- loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_128;
- if (isKEK) {
- kekAlg = ENCRYPT_KW_AES128;
- }
- else if (strlen(argv[paramCount]) == 6) {
- keyAlg = ENCRYPT_AES128_CBC;
- }
+ else if (_stricmp(argv[paramCount], "--nss") == 0 || _stricmp(argv[paramCount], "-n") == 0) {
+ // NSS Crypto Provider
+ NSSCryptoProvider * cp = new NSSCryptoProvider();
+ XSECPlatformUtils::SetCryptoProvider(cp);
+ paramCount++;
+ }
+#endif
+ else if (_stricmp(argv[paramCount], "--key") == 0 || _stricmp(argv[paramCount], "-k") == 0) {
+
+ // Have a key!
+ paramCount++;
+ bool isKEK = false;
+ XSECCryptoSymmetricKey::SymmetricKeyType loadKeyAs =
+ XSECCryptoSymmetricKey::KEY_NONE;
+
+ if (_stricmp(argv[paramCount], "kek") == 0) {
+ isKEK = true;
+ paramCount++;
+ if (paramCount >= argc) {
+ printUsage();
+ return 2;
+ }
+ }
+
+ if (_stricmp(argv[paramCount], "3DES") == 0 ||
+ _stricmp(argv[paramCount], "AES128") == 0 ||
+ _stricmp(argv[paramCount], "AES192") == 0 ||
+ _stricmp(argv[paramCount], "AES256") == 0 ||
+ _stricmp(argv[paramCount], "AES128-GCM") == 0 ||
+ _stricmp(argv[paramCount], "AES192-GCM") == 0 ||
+ _stricmp(argv[paramCount], "AES256-GCM") == 0) {
+
+ if (paramCount +2 >= argc) {
+ printUsage();
+ return 2;
+ }
+
+ switch(argv[paramCount][4]) {
+ case '\0' :
+ keyLen = 24;
+ loadKeyAs = XSECCryptoSymmetricKey::KEY_3DES_192;
+ keyAlg = ENCRYPT_3DES_CBC;
+ break;
+ case '2' :
+ keyLen = 16;
+ loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_128;
+ if (isKEK) {
+ kekAlg = ENCRYPT_KW_AES128;
+ }
+ else if (strlen(argv[paramCount]) == 6) {
+ keyAlg = ENCRYPT_AES128_CBC;
+ }
else {
keyAlg = ENCRYPT_AES128_GCM;
}
- break;
- case '9' :
- keyLen = 24;
- loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_192;
- if (isKEK) {
- kekAlg = ENCRYPT_KW_AES192;
- }
- else if (strlen(argv[paramCount]) == 6) {
- keyAlg = ENCRYPT_AES192_CBC;
- }
+ break;
+ case '9' :
+ keyLen = 24;
+ loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_192;
+ if (isKEK) {
+ kekAlg = ENCRYPT_KW_AES192;
+ }
+ else if (strlen(argv[paramCount]) == 6) {
+ keyAlg = ENCRYPT_AES192_CBC;
+ }
else {
keyAlg = ENCRYPT_AES192_GCM;
}
- break;
- case '5' :
- keyLen = 32;
- loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_256;
- if (isKEK) {
- kekAlg = ENCRYPT_KW_AES256;
- }
- else if (strlen(argv[paramCount]) == 6) {
- keyAlg = ENCRYPT_AES256_CBC;
- }
+ break;
+ case '5' :
+ keyLen = 32;
+ loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_256;
+ if (isKEK) {
+ kekAlg = ENCRYPT_KW_AES256;
+ }
+ else if (strlen(argv[paramCount]) == 6) {
+ keyAlg = ENCRYPT_AES256_CBC;
+ }
else {
keyAlg = ENCRYPT_AES256_GCM;
}
- break;
- }
+ break;
+ }
- paramCount++;
- unsigned char keyStr[64];
- if (strlen(argv[paramCount]) > 64) {
- cerr << "Key string too long\n";
- return 2;
- }
- XSECCryptoSymmetricKey * sk =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(loadKeyAs);
-
- if (isXKMSKey) {
- unsigned char kbuf[XSEC_MAX_HASH_SIZE];
- CalculateXKMSKEK((unsigned char *) argv[paramCount], (int) strlen(argv[paramCount]), kbuf, XSEC_MAX_HASH_SIZE);
- sk->setKey(kbuf, keyLen);
- }
- else {
- memset(keyStr, 0, 64);
- strcpy((char *) keyStr, argv[paramCount]);
- sk->setKey(keyStr, keyLen);
- }
- paramCount++;
- if (isKEK)
- kek = sk;
- else
- key = sk;
- }
+ paramCount++;
+ unsigned char keyStr[64];
+ if (strlen(argv[paramCount]) > 64) {
+ cerr << "Key string too long\n";
+ return 2;
+ }
+ XSECCryptoSymmetricKey * sk =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(loadKeyAs);
+
+ if (isXKMSKey) {
+ unsigned char kbuf[XSEC_MAX_HASH_SIZE];
+ CalculateXKMSKEK((unsigned char *) argv[paramCount], (int) strlen(argv[paramCount]), kbuf, XSEC_MAX_HASH_SIZE);
+ sk->setKey(kbuf, keyLen);
+ }
+ else {
+ memset(keyStr, 0, 64);
+ strcpy((char *) keyStr, argv[paramCount]);
+ sk->setKey(keyStr, keyLen);
+ }
+ paramCount++;
+ if (isKEK)
+ kek = sk;
+ else
+ key = sk;
+ }
#if defined (XSEC_HAVE_OPENSSL)
- else if (_stricmp(argv[paramCount], "RSA") == 0) {
- // RSA private key file
+ else if (_stricmp(argv[paramCount], "RSA") == 0) {
+ // RSA private key file
- if (paramCount + 3 >= argc) {
+ if (paramCount + 3 >= argc) {
- printUsage();
- return 2;
+ printUsage();
+ return 2;
- }
+ }
- if (!isKEK) {
- cerr << "RSA private keys may only be KEKs\n";
- return 2;
- }
+ if (!isKEK) {
+ cerr << "RSA private keys may only be KEKs\n";
+ return 2;
+ }
- BIO * bioKey;
- if ((bioKey = BIO_new(BIO_s_file())) == NULL) {
+ BIO * bioKey;
+ if ((bioKey = BIO_new(BIO_s_file())) == NULL) {
- cerr << "Error opening private key file\n\n";
- return 1;
+ cerr << "Error opening private key file\n\n";
+ return 1;
- }
+ }
- if (BIO_read_filename(bioKey, argv[paramCount + 1]) <= 0) {
+ if (BIO_read_filename(bioKey, argv[paramCount + 1]) <= 0) {
- cerr << "Error opening private key file\n\n";
- return 1;
+ cerr << "Error opening private key file\n\n";
+ return 1;
- }
+ }
- EVP_PKEY * pkey;
- pkey = PEM_read_bio_PrivateKey(bioKey,NULL,NULL,argv[paramCount + 2]);
+ EVP_PKEY * pkey;
+ pkey = PEM_read_bio_PrivateKey(bioKey,NULL,NULL,argv[paramCount + 2]);
- if (pkey == NULL) {
+ if (pkey == NULL) {
- cerr << "Error loading private key\n\n";
- return 1;
+ cerr << "Error loading private key\n\n";
+ return 1;
- }
+ }
- kek = new OpenSSLCryptoKeyRSA(pkey);
- kekAlg = ENCRYPT_RSA_15;
- EVP_PKEY_free(pkey);
- BIO_free(bioKey);
- paramCount += 3;
- }
+ kek = new OpenSSLCryptoKeyRSA(pkey);
+ kekAlg = ENCRYPT_RSA_15;
+ EVP_PKEY_free(pkey);
+ BIO_free(bioKey);
+ paramCount += 3;
+ }
- else if (_stricmp(argv[paramCount], "X509") == 0) {
+ else if (_stricmp(argv[paramCount], "X509") == 0) {
- // X509 cert used to load an encrypting key
+ // X509 cert used to load an encrypting key
- if (paramCount + 2 >= argc) {
+ if (paramCount + 2 >= argc) {
- printUsage();
- exit (1);
+ printUsage();
+ exit (1);
- }
+ }
- if (!isKEK) {
- cerr << "X509 private keys may only be KEKs\n";
- return 2;
- }
+ if (!isKEK) {
+ cerr << "X509 private keys may only be KEKs\n";
+ return 2;
+ }
- // Load the encrypting key
- // For now just read a particular file
+ // Load the encrypting key
+ // For now just read a particular file
- BIO * bioX509;
+ BIO * bioX509;
- if ((bioX509 = BIO_new(BIO_s_file())) == NULL) {
+ if ((bioX509 = BIO_new(BIO_s_file())) == NULL) {
- cerr << "Error opening file\n\n";
- exit (1);
+ cerr << "Error opening file\n\n";
+ exit (1);
- }
+ }
- if (BIO_read_filename(bioX509, argv[paramCount + 1]) <= 0) {
+ if (BIO_read_filename(bioX509, argv[paramCount + 1]) <= 0) {
- cerr << "Error opening X509 Certificate " << argv[paramCount + 1] << "\n\n";
- exit (1);
+ cerr << "Error opening X509 Certificate " << argv[paramCount + 1] << "\n\n";
+ exit (1);
- }
+ }
- X509 * x
- ;
- x = PEM_read_bio_X509_AUX(bioX509,NULL,NULL,NULL);
+ X509 * x
+ ;
+ x = PEM_read_bio_X509_AUX(bioX509,NULL,NULL,NULL);
- if (x == NULL) {
+ if (x == NULL) {
- BIO * bio_err;
-
- if ((bio_err=BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
+ BIO * bio_err;
+
+ if ((bio_err=BIO_new(BIO_s_file())) != NULL)
+ BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
- cerr << "Error loading certificate key\n\n";
- ERR_print_errors(bio_err);
- BIO_free(bio_err);
- exit (1);
+ cerr << "Error loading certificate key\n\n";
+ ERR_print_errors(bio_err);
+ BIO_free(bio_err);
+ exit (1);
- }
+ }
- // Now load the key
- EVP_PKEY *pkey;
+ // Now load the key
+ EVP_PKEY *pkey;
- pkey = X509_get_pubkey(x);
+ pkey = X509_get_pubkey(x);
- if (pkey == NULL || pkey->type != EVP_PKEY_RSA) {
- cerr << "Error extracting RSA key from certificate" << endl;
- }
+ if (pkey == NULL || pkey->type != EVP_PKEY_RSA) {
+ cerr << "Error extracting RSA key from certificate" << endl;
+ }
- kek = new OpenSSLCryptoKeyRSA(pkey);
- kekAlg = ENCRYPT_RSA_15;
+ kek = new OpenSSLCryptoKeyRSA(pkey);
+ kekAlg = ENCRYPT_RSA_15;
- // Clean up
+ // Clean up
- EVP_PKEY_free (pkey);
- X509_free(x);
- BIO_free(bioX509);
+ EVP_PKEY_free (pkey);
+ X509_free(x);
+ BIO_free(bioX509);
- paramCount += 2;
-
- } /* argv[1] = "--x509cert" */
+ paramCount += 2;
+
+ } /* argv[1] = "--x509cert" */
#endif /* XSEC_HAVE_OPENSSL */
- else {
- printUsage();
- return 2;
- }
- }
-
- else {
- cerr << "Unknown option: " << argv[paramCount] << endl;
- printUsage();
- return 2;
- }
- }
-
- if (paramCount >= argc) {
- printUsage();
- return 2;
- }
-
- if (outfile != NULL) {
- formatTarget = new LocalFileFormatTarget(outfile);
- }
- else {
- formatTarget = new StdOutFormatTarget();
- }
-
- filename = argv[paramCount];
-
- if (parseXMLInput) {
-
- XercesDOMParser * parser = new XercesDOMParser;
- Janitor<XercesDOMParser> j_parser(parser);
-
- parser->setDoNamespaces(true);
- parser->setCreateEntityReferenceNodes(true);
-
- // Now parse out file
-
- xsecsize_t errorCount = 0;
- try
- {
- parser->parse(filename);
- errorCount = parser->getErrorCount();
- if (errorCount > 0)
- errorsOccured = true;
- }
-
- catch (const XMLException& e)
- {
- cerr << "An error occured during parsing\n Message: "
- << e.getMessage() << endl;
- errorsOccured = true;
- }
-
-
- catch (const DOMException& e)
- {
- cerr << "A DOM error occured during parsing\n DOMException code: "
- << e.code << endl;
- errorsOccured = true;
- }
-
- if (errorsOccured) {
-
- cout << "Errors during parse" << endl;
- return (2);
-
- }
-
- /*
-
- Now that we have the parsed file, get the DOM document and start looking at it
-
- */
-
- doc = parser->adoptDocument();
- }
-
- else {
- // Create an empty document
- XMLCh tempStr[100];
- XMLString::transcode("Core", tempStr, 99);
- DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
- doc = impl->createDocument(
- 0, // root element namespace URI.
- MAKE_UNICODE_STRING("ADoc"), // root element name
- NULL);// DOMDocumentType()); // document type object (DTD).
- }
-
-
- XSECProvider prov;
- XENCCipher * cipher = prov.newCipher(doc);
-
- if (kek != NULL)
- cipher->setKEK(kek);
- if (key != NULL)
- cipher->setKey(key);
+ else {
+ printUsage();
+ return 2;
+ }
+ }
+
+ else {
+ cerr << "Unknown option: " << argv[paramCount] << endl;
+ printUsage();
+ return 2;
+ }
+ }
+
+ if (paramCount >= argc) {
+ printUsage();
+ return 2;
+ }
+
+ if (outfile != NULL) {
+ formatTarget = new LocalFileFormatTarget(outfile);
+ }
+ else {
+ formatTarget = new StdOutFormatTarget();
+ }
+
+ filename = argv[paramCount];
+
+ if (parseXMLInput) {
+
+ XercesDOMParser * parser = new XercesDOMParser;
+ Janitor<XercesDOMParser> j_parser(parser);
+
+ parser->setDoNamespaces(true);
+ parser->setCreateEntityReferenceNodes(true);
+
+ // Now parse out file
+
+ xsecsize_t errorCount = 0;
+ try
+ {
+ parser->parse(filename);
+ errorCount = parser->getErrorCount();
+ if (errorCount > 0)
+ errorsOccured = true;
+ }
+
+ catch (const XMLException& e)
+ {
+ cerr << "An error occured during parsing\n Message: "
+ << e.getMessage() << endl;
+ errorsOccured = true;
+ }
+
+
+ catch (const DOMException& e)
+ {
+ cerr << "A DOM error occured during parsing\n DOMException code: "
+ << e.code << endl;
+ errorsOccured = true;
+ }
+
+ if (errorsOccured) {
+
+ cout << "Errors during parse" << endl;
+ return (2);
+
+ }
+
+ /*
+
+ Now that we have the parsed file, get the DOM document and start looking at it
+
+ */
+
+ doc = parser->adoptDocument();
+ }
+
+ else {
+ // Create an empty document
+ XMLCh tempStr[100];
+ XMLString::transcode("Core", tempStr, 99);
+ DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
+ doc = impl->createDocument(
+ 0, // root element namespace URI.
+ MAKE_UNICODE_STRING("ADoc"), // root element name
+ NULL);// DOMDocumentType()); // document type object (DTD).
+ }
+
+
+ XSECProvider prov;
+ XENCCipher * cipher = prov.newCipher(doc);
+
+ if (kek != NULL)
+ cipher->setKEK(kek);
+ if (key != NULL)
+ cipher->setKey(key);
- try {
+ try {
- if (doDecrypt) {
+ if (doDecrypt) {
- if (useInteropResolver == true) {
+ if (useInteropResolver == true) {
- // Map out base path of the file
+ // Map out base path of the file
#if XSEC_HAVE_GETCWD_DYN
- char *path = getcwd(NULL, 0);
- char *baseURI = (char*)malloc(strlen(path) + 8 + 1 + strlen(filename) + 1);
+ char *path = getcwd(NULL, 0);
+ char *baseURI = (char*)malloc(strlen(path) + 8 + 1 + strlen(filename) + 1);
#else
- char path[PATH_MAX];
- char baseURI[(PATH_MAX * 2) + 10];
- getcwd(path, PATH_MAX);
-#endif
- strcpy(baseURI, "file:///");
-
- // Ugly and nasty but quick
- if (filename[0] != '\\' && filename[0] != '/' && filename[1] != ':') {
- strcat(baseURI, path);
- strcat(baseURI, "/");
- } else if (path[1] == ':') {
- path[2] = '\0';
- strcat(baseURI, path);
- }
-
- strcat(baseURI, filename);
-
- // Find any ':' and "\" characters
- int lastSlash = 0;
- for (unsigned int i = 8; i < strlen(baseURI); ++i) {
- if (baseURI[i] == '\\') {
- lastSlash = i;
- baseURI[i] = '/';
- }
- else if (baseURI[i] == '/')
- lastSlash = i;
- }
+ char path[PATH_MAX];
+ char baseURI[(PATH_MAX * 2) + 10];
+ getcwd(path, PATH_MAX);
+#endif
+ strcpy(baseURI, "file:///");
+
+ // Ugly and nasty but quick
+ if (filename[0] != '\\' && filename[0] != '/' && filename[1] != ':') {
+ strcat(baseURI, path);
+ strcat(baseURI, "/");
+ } else if (path[1] == ':') {
+ path[2] = '\0';
+ strcat(baseURI, path);
+ }
+
+ strcat(baseURI, filename);
+
+ // Find any ':' and "\" characters
+ int lastSlash = 0;
+ for (unsigned int i = 8; i < strlen(baseURI); ++i) {
+ if (baseURI[i] == '\\') {
+ lastSlash = i;
+ baseURI[i] = '/';
+ }
+ else if (baseURI[i] == '/')
+ lastSlash = i;
+ }
- // The last "\\" must prefix the filename
- baseURI[lastSlash + 1] = '\0';
+ // The last "\\" must prefix the filename
+ baseURI[lastSlash + 1] = '\0';
- XMLCh * uriT = XMLString::transcode(baseURI);
+ XMLCh * uriT = XMLString::transcode(baseURI);
#if XSEC_HAVE_GETCWD_DYN
- free(path);
- free(baseURI);
+ free(path);
+ free(baseURI);
#endif
- XencInteropResolver ires(doc, &(uriT[8]));
- XSEC_RELEASE_XMLCH(uriT);
- cipher->setKeyInfoResolver(&ires);
-
- }
- // Find the EncryptedData node
- DOMNode * n = findXENCNode(doc, "EncryptedData");
-
- if (doDecryptElement) {
- while (n != NULL) {
-
- // decrypt
- cipher->decryptElement(static_cast<DOMElement *>(n));
-
- // Find the next EncryptedData node
- n = findXENCNode(doc, "EncryptedData");
- }
-
- }
- else {
- XSECBinTXFMInputStream * bis = cipher->decryptToBinInputStream(static_cast<DOMElement *>(n));
- Janitor<XSECBinTXFMInputStream> j_bis(bis);
-
- XMLByte buf[1024];
- xsecsize_t read = bis->readBytes(buf, 1023);
- while (read > 0) {
- formatTarget->writeChars(buf, read, NULL);
- read = bis->readBytes(buf, 1023);
- }
- }
- }
- else {
-
- XENCEncryptedData *xenc = NULL;
- // Encrypting
- if (kek != NULL && key == NULL) {
- XSECPlatformUtils::g_cryptoProvider->getRandom(keyBuf, 24);
- XSECCryptoSymmetricKey * k =
- XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
- k->setKey(keyBuf, 24);
- cipher->setKey(k);
- keyAlg = ENCRYPT_3DES_CBC;
- keyStr = keyBuf;
- keyLen = 24;
- }
+ XencInteropResolver ires(doc, &(uriT[8]));
+ XSEC_RELEASE_XMLCH(uriT);
+ cipher->setKeyInfoResolver(&ires);
+
+ }
+ // Find the EncryptedData node
+ DOMNode * n = findXENCNode(doc, "EncryptedData");
+
+ if (doDecryptElement) {
+ while (n != NULL) {
+
+ // decrypt
+ cipher->decryptElement(static_cast<DOMElement *>(n));
+
+ // Find the next EncryptedData node
+ n = findXENCNode(doc, "EncryptedData");
+ }
+
+ }
+ else {
+ XSECBinTXFMInputStream * bis = cipher->decryptToBinInputStream(static_cast<DOMElement *>(n));
+ Janitor<XSECBinTXFMInputStream> j_bis(bis);
+
+ XMLByte buf[1024];
+ xsecsize_t read = bis->readBytes(buf, 1023);
+ while (read > 0) {
+ formatTarget->writeChars(buf, read, NULL);
+ read = bis->readBytes(buf, 1023);
+ }
+ }
+ }
+ else {
+
+ XENCEncryptedData *xenc = NULL;
+ // Encrypting
+ if (kek != NULL && key == NULL) {
+ XSECPlatformUtils::g_cryptoProvider->getRandom(keyBuf, 24);
+ XSECCryptoSymmetricKey * k =
+ XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
+ k->setKey(keyBuf, 24);
+ cipher->setKey(k);
+ keyAlg = ENCRYPT_3DES_CBC;
+ keyStr = keyBuf;
+ keyLen = 24;
+ }
- if (encryptFileAsData) {
+ if (encryptFileAsData) {
- // Create a BinInputStream
+ // Create a BinInputStream
#if defined(XSEC_XERCES_REQUIRES_MEMMGR)
- BinFileInputStream * is = new BinFileInputStream(filename, XMLPlatformUtils::fgMemoryManager);
+ BinFileInputStream * is = new BinFileInputStream(filename, XMLPlatformUtils::fgMemoryManager);
#else
- BinFileInputStream * is = new BinFileInputStream(filename);
+ BinFileInputStream * is = new BinFileInputStream(filename);
#endif
- xenc = cipher->encryptBinInputStream(is, keyAlg);
+ xenc = cipher->encryptBinInputStream(is, keyAlg);
- // Replace the document element
- DOMElement * elt = doc->getDocumentElement();
- doc->replaceChild(xenc->getElement(), elt);
- elt->release();
- }
- else {
- // Document encryption
- cipher->encryptElement(doc->getDocumentElement(), keyAlg);
- }
-
- // Do we encrypt a created key?
- if (kek != NULL && xenc != NULL) {
- XENCEncryptedKey *xkey = cipher->encryptKey(keyStr, keyLen, kekAlg);
- // Add to the EncryptedData
- xenc->appendEncryptedKey(xkey);
- }
- }
-
- if (doXMLOutput) {
- // Output the result
-
- XMLCh core[] = {
- XERCES_CPP_NAMESPACE_QUALIFIER chLatin_C,
- XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o,
- XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r,
- XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e,
- XERCES_CPP_NAMESPACE_QUALIFIER chNull
- };
+ // Replace the document element
+ DOMElement * elt = doc->getDocumentElement();
+ doc->replaceChild(xenc->getElement(), elt);
+ elt->release();
+ }
+ else {
+ // Document encryption
+ cipher->encryptElement(doc->getDocumentElement(), keyAlg);
+ }
+
+ // Do we encrypt a created key?
+ if (kek != NULL && xenc != NULL) {
+ XENCEncryptedKey *xkey = cipher->encryptKey(keyStr, keyLen, kekAlg);
+ // Add to the EncryptedData
+ xenc->appendEncryptedKey(xkey);
+ }
+ }
+
+ if (doXMLOutput) {
+ // Output the result
+
+ XMLCh core[] = {
+ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_C,
+ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o,
+ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r,
+ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e,
+ XERCES_CPP_NAMESPACE_QUALIFIER chNull
+ };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(core);
@@ -784,141 +784,141 @@ int evaluate(int argc, char ** argv) {
theSerializer->write(doc, theOutput);
-#else
- DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
- Janitor<DOMWriter> j_theSerializer(theSerializer);
-
- theSerializer->setEncoding(MAKE_UNICODE_STRING("UTF-8"));
- if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false))
- theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false);
-
- theSerializer->writeNode(formatTarget, *doc);
-#endif
- cout << endl;
-
- }
- }
-
- catch (XSECException &e) {
- char * msg = XMLString::transcode(e.getMsg());
- cerr << "An error occured during encryption/decryption operation\n Message: "
- << msg << endl;
- XSEC_RELEASE_XMLCH(msg);
- errorsOccured = true;
- if (formatTarget != NULL)
- delete formatTarget;
- doc->release();
- return 2;
- }
- catch (XSECCryptoException &e) {
- cerr << "An error occured during encryption/decryption operation\n Message: "
- << e.getMsg() << endl;
- errorsOccured = true;
- if (formatTarget != NULL)
- delete formatTarget;
- doc->release();
+#else
+ DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
+ Janitor<DOMWriter> j_theSerializer(theSerializer);
+
+ theSerializer->setEncoding(MAKE_UNICODE_STRING("UTF-8"));
+ if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false))
+ theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false);
+
+ theSerializer->writeNode(formatTarget, *doc);
+#endif
+ cout << endl;
+
+ }
+ }
+
+ catch (XSECException &e) {
+ char * msg = XMLString::transcode(e.getMsg());
+ cerr << "An error occured during encryption/decryption operation\n Message: "
+ << msg << endl;
+ XSEC_RELEASE_XMLCH(msg);
+ errorsOccured = true;
+ if (formatTarget != NULL)
+ delete formatTarget;
+ doc->release();
+ return 2;
+ }
+ catch (XSECCryptoException &e) {
+ cerr << "An error occured during encryption/decryption operation\n Message: "
+ << e.getMsg() << endl;
+ errorsOccured = true;
+ if (formatTarget != NULL)
+ delete formatTarget;
+ doc->release();
#if defined (XSEC_HAVE_OPENSSL)
- ERR_load_crypto_strings();
- BIO * bio_err;
- if ((bio_err=BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
-
- ERR_print_errors(bio_err);
-#endif
- return 2;
- }
-
- if (formatTarget != NULL)
- delete formatTarget;
+ ERR_load_crypto_strings();
+ BIO * bio_err;
+ if ((bio_err=BIO_new(BIO_s_file())) != NULL)
+ BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
+
+ ERR_print_errors(bio_err);
+#endif
+ return 2;
+ }
+
+ if (formatTarget != NULL)
+ delete formatTarget;
- doc->release();
- return 0;
+ doc->release();
+ return 0;
}
int main(int argc, char **argv) {
- int retResult;
+ int retResult;
#if defined (_DEBUG) && defined (_MSC_VER)
- // Do some memory debugging under Visual C++
+ // Do some memory debugging under Visual C++
- _CrtMemState s1, s2, s3;
+ _CrtMemState s1, s2, s3;
- // At this point we are about to start really using XSEC, so
- // Take a "before" checkpoing
+ // At this point we are about to start really using XSEC, so
+ // Take a "before" checkpoing
- _CrtMemCheckpoint( &s1 );
+ _CrtMemCheckpoint( &s1 );
#endif
- // Initialise the XML system
+ // Initialise the XML system
- try {
+ try {
- XMLPlatformUtils::Initialize();
+ XMLPlatformUtils::Initialize();
#ifndef XSEC_NO_XALAN
- XPathEvaluator::initialize();
- XalanTransformer::initialize();
+ XPathEvaluator::initialize();
+ XalanTransformer::initialize();
#endif
- XSECPlatformUtils::Initialise();
+ XSECPlatformUtils::Initialise();
- }
- catch (const XMLException &e) {
+ }
+ catch (const XMLException &e) {
- cerr << "Error during initialisation of Xerces" << endl;
- cerr << "Error Message = : "
- << e.getMessage() << endl;
+ cerr << "Error during initialisation of Xerces" << endl;
+ cerr << "Error Message = : "
+ << e.getMessage() << endl;
- }
+ }
- retResult = evaluate(argc, argv);
+ retResult = evaluate(argc, argv);
- XSECPlatformUtils::Terminate();
+ XSECPlatformUtils::Terminate();
#ifndef XSEC_NO_XALAN
- XalanTransformer::terminate();
- XPathEvaluator::terminate();
+ XalanTransformer::terminate();
+ XPathEvaluator::terminate();
#endif
- XMLPlatformUtils::Terminate();
+ XMLPlatformUtils::Terminate();
#if defined (_DEBUG) && defined (_MSC_VER)
- _CrtMemCheckpoint( &s2 );
+ _CrtMemCheckpoint( &s2 );
- if ( _CrtMemDifference( &s3, &s1, &s2 ) && (
- s3.lCounts[0] > 0 ||
- s3.lCounts[1] > 1 ||
- // s3.lCounts[2] > 2 || We don't worry about C Runtime
- s3.lCounts[3] > 0 ||
- s3.lCounts[4] > 0)) {
+ if ( _CrtMemDifference( &s3, &s1, &s2 ) && (
+ s3.lCounts[0] > 0 ||
+ s3.lCounts[1] > 1 ||
+ // s3.lCounts[2] > 2 || We don't worry about C Runtime
+ s3.lCounts[3] > 0 ||
+ s3.lCounts[4] > 0)) {
- // Note that there is generally 1 Normal and 1 CRT block
- // still taken. 1 is from Xalan and 1 from stdio
+ // Note that there is generally 1 Normal and 1 CRT block
+ // still taken. 1 is from Xalan and 1 from stdio
- // Send all reports to STDOUT
- _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
- _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
- _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
- _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
- _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
- _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
+ // Send all reports to STDOUT
+ _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
+ _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
+ _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
+ _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
+ _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
+ _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
- // Dumpy memory stats
+ // Dumpy memory stats
- _CrtMemDumpAllObjectsSince( &s3 );
- _CrtMemDumpStatistics( &s3 );
- }
+ _CrtMemDumpAllObjectsSince( &s3 );
+ _CrtMemDumpStatistics( &s3 );
+ }
- // Now turn off memory leak checking and end as there are some
- // Globals that are allocated that get seen as leaks (Xalan?)
+ // Now turn off memory leak checking and end as there are some
+ // Globals that are allocated that get seen as leaks (Xalan?)
- int dbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
- dbgFlag &= ~(_CRTDBG_LEAK_CHECK_DF);
- _CrtSetDbgFlag( dbgFlag );
+ int dbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+ dbgFlag &= ~(_CRTDBG_LEAK_CHECK_DF);
+ _CrtSetDbgFlag( dbgFlag );
#endif
- return retResult;
+ return retResult;
}