]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Make rgw_main use HMAC-SHA1 via compatibility shim.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Thu, 10 Mar 2011 20:38:25 +0000 (12:38 -0800)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Fri, 11 Mar 2011 21:13:40 +0000 (13:13 -0800)
Signed-off-by: Tommi Virtanen <tommi.virtanen@dreamhost.com>
src/common/ceph_crypto.h
src/rgw/rgw_main.cc

index bad620933145f546bbd07460f98dbcce94c20444..11c2ce89ef81b56aea756c0c914d2c540b102082 100644 (file)
@@ -6,12 +6,22 @@
 #ifdef USE_CRYPTOPP
 # define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
 # include <cryptopp/md5.h>
+# include <cryptopp/sha.h>
+# include <cryptopp/hmac.h>
 namespace ceph {
   namespace crypto {
     static inline void init() {
       // nothing
     }
     using CryptoPP::Weak::MD5;
+
+    class HMACSHA1: public CryptoPP::HMAC<CryptoPP::SHA1> {
+    public:
+      HMACSHA1 (const byte *key, size_t length)
+       : CryptoPP::HMAC<CryptoPP::SHA1>(key, length)
+       {
+       }
+    };
   }
 }
 #elif USE_NSS
index 5b0a5c05af042c82a5a622ef84c88333ab461cbb..2e87cb49a5b20e586c4df376aae0629bbdfc4107 100644 (file)
@@ -8,9 +8,6 @@
 #include <errno.h>
 #include <signal.h>
 
-#include <cryptopp/sha.h>
-#include <cryptopp/hmac.h>
-
 #include "fcgiapp.h"
 
 #include "rgw_common.h"
@@ -31,7 +28,7 @@
 #include "common/BackTrace.h"
 
 using namespace std;
-using namespace CryptoPP;
+using ceph::crypto::HMACSHA1;
 
 #define CGI_PRINTF(stream, format, ...) do { \
    FCGX_FPrintF(stream, format, __VA_ARGS__); \
@@ -122,15 +119,15 @@ static int calc_hmac_sha1(const char *key, int key_len,
                            const char *msg, int msg_len,
                            char *dest, int *len) /* dest should be large enough to hold result */
 {
-  if (*len < HMAC<SHA1>::DIGESTSIZE)
+  if (*len < HMACSHA1::DIGESTSIZE)
     return -EINVAL;
 
-  char hex_str[HMAC<SHA1>::DIGESTSIZE * 2 + 1];
+  char hex_str[HMACSHA1::DIGESTSIZE * 2 + 1];
 
-  HMAC<SHA1> hmac((const unsigned char *)key, key_len);
+  HMACSHA1 hmac((const unsigned char *)key, key_len);
   hmac.Update((const unsigned char *)msg, msg_len);
   hmac.Final((unsigned char *)dest);
-  *len = HMAC<SHA1>::DIGESTSIZE;
+  *len = HMACSHA1::DIGESTSIZE;
   
   buf_to_hex((unsigned char *)dest, *len, hex_str);
 
@@ -194,7 +191,7 @@ static bool verify_signature(struct req_state *s)
   const char *key = s->user.secret_key.c_str();
   int key_len = strlen(key);
 
-  char hmac_sha1[HMAC<SHA1>::DIGESTSIZE];
+  char hmac_sha1[HMACSHA1::DIGESTSIZE];
   int len = sizeof(hmac_sha1);
   if (calc_hmac_sha1(key, key_len, auth_hdr.c_str(), auth_hdr.size(), hmac_sha1, &len) < 0)
     return false;