/*
- * Copyright (c) 2014 <copyright holder> <email>
+ * Copyright (c) 2014, 2015 JANET(UK)
+ * All rights reserved.
*
- * For license details, see the LICENSE file in the root of this project.
+ * 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. Neither the name of JANET(UK) nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS 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
+ * COPYRIGHT HOLDER OR 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.
*
*/
-// #include <glib.h>
#include <stdexcept>
-#include <openssl/err.h>
-#include <openssl/rand.h>
-
#include "GSSNameCache.h"
-#include "utils/base64.h"
+#include "utils/util_base64.h"
+#include "utils/util_random.h"
#define KEYLEN 128
// Store the key/value pair in the map
// Store the key in the context for convenience
// std::cout << "\n==> In GSSNameCache::store, about to store data in the names hash.\n";
- names[key] = data;
+ names[key] = &data;
/* Cleanup */
/* Return */
bool GSSNameCache::generateKey(std::string &key)
{
/* Variables */
- int osslReturn = 0;
unsigned char theKey[KEYLEN];
- bool existingErrors = false;
-
- /* Error checking */
- // See if there are any queued OpenSSL errors already.
- existingErrors = ( 0 == ERR_peek_error() );
/* Setup */
/* Main */
// Generate random byte string
- osslReturn = RAND_pseudo_bytes(theKey, KEYLEN);
-
- // Discard the error message if there weren't any OpenSSL errors to begin with.
- if (osslReturn == 1 && !existingErrors)
- {
- while (0 != ERR_get_error() );
+ if (!randGenPseudoRandom(theKey, KEYLEN))
return(false);
- }
// Encode the binary string
- key = (char *)theKey;
- key = base64_encode(key);
-
+ base64EncodeStr(theKey, KEYLEN, key);
/* Cleanup */
/* Return */
return(true);
/* Cleanup */
/* Return */
- return names[key];
+ return *(names[key]);
}
GSSNameCache* GSSNameCache::instance()