]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_crypto: fix undefined references
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 23 Mar 2011 22:23:57 +0000 (15:23 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 23 Mar 2011 22:33:51 +0000 (15:33 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/ceph_crypto.cc
src/common/ceph_crypto.h
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_os_auth.cc
src/rgw/rgw_rest_s3.cc

index a625732a5be493d98092a071f91b42bf5decd565..31b6f572516f54efa1978691f55893013bd0892e 100644 (file)
@@ -2,12 +2,23 @@
 
 #ifdef USE_CRYPTOPP
 // nothing
+ceph::crypto::HMACSHA1::~HMACSHA1()
+{
+}
+
 #elif USE_NSS
 
 void ceph::crypto::init() {
   NSS_NoDB_Init(NULL);
 }
 
+ceph::crypto::HMACSHA1::~HMACSHA1()
+{
+  PK11_DestroyContext(ctx, PR_TRUE);
+  PK11_FreeSymKey(symkey);
+  PK11_FreeSlot(slot);
+}
+
 #else
 # error "No supported crypto implementation found."
 #endif
index bf4dbfc7f529e73994d364b7a513ef311664d169..abaf95cfdec9b8a3884eec35f4e3869e886a429d 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "acconfig.h"
 
+#define CEPH_CRYPTO_MD5_DIGESTSIZE 16
+#define CEPH_CRYPTO_HMACSHA1_DIGESTSIZE 20
+
 #ifdef USE_CRYPTOPP
 # define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
 #include <string.h>
@@ -22,6 +25,7 @@ namespace ceph {
        : CryptoPP::HMAC<CryptoPP::SHA1>(key, length)
        {
        }
+      ~HMACSHA1();
     };
   }
 }
@@ -48,7 +52,6 @@ namespace ceph {
     private:
       PK11Context *ctx;
     public:
-      static const int DIGESTSIZE = 16;
       MD5 () {
        ctx = PK11_CreateDigestContext(SEC_OID_MD5);
        assert(ctx);
@@ -70,9 +73,9 @@ namespace ceph {
       void Final (byte *digest) {
        SECStatus s;
        unsigned int dummy;
-       s = PK11_DigestFinal(ctx, digest, &dummy, DIGESTSIZE);
+       s = PK11_DigestFinal(ctx, digest, &dummy, CEPH_CRYPTO_MD5_DIGESTSIZE);
        assert(s == SECSuccess);
-       assert(dummy == (unsigned int)DIGESTSIZE);
+       assert(dummy == CEPH_CRYPTO_MD5_DIGESTSIZE);
        Restart();
       }
     };
@@ -83,7 +86,7 @@ namespace ceph {
       PK11SymKey *symkey;
       PK11Context *ctx;
     public:
-      static const int DIGESTSIZE = 20;
+      static const int DIGESTSIZE;
       HMACSHA1 (const byte *key, size_t length) {
        slot = PK11_GetBestSlot(CKM_SHA_1_HMAC, NULL);
        assert(slot);
@@ -102,11 +105,7 @@ namespace ceph {
        assert(ctx);
        Restart();
       }
-      ~HMACSHA1 () {
-       PK11_DestroyContext(ctx, PR_TRUE);
-       PK11_FreeSymKey(symkey);
-       PK11_FreeSlot(slot);
-      }
+      ~HMACSHA1 ();
       void Restart() {
        SECStatus s;
        s = PK11_DigestBegin(ctx);
@@ -120,9 +119,9 @@ namespace ceph {
       void Final (byte *digest) {
        SECStatus s;
        unsigned int dummy;
-       s = PK11_DigestFinal(ctx, digest, &dummy, DIGESTSIZE);
+       s = PK11_DigestFinal(ctx, digest, &dummy, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
        assert(s == SECSuccess);
-       assert(dummy == (unsigned int)DIGESTSIZE);
+       assert(dummy == CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
        Restart();
       }
     };
index a29c17adfc5994549b898e6568234242a072af94..60bf7ac58ecb604c3ebeab7884c584f2eadd7581 100644 (file)
@@ -29,19 +29,19 @@ 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 < HMACSHA1::DIGESTSIZE)
+  if (*len < CEPH_CRYPTO_HMACSHA1_DIGESTSIZE)
     return -EINVAL;
 
-  char hex_str[HMACSHA1::DIGESTSIZE * 2 + 1];
-  char key_buf[HMACSHA1::DIGESTSIZE];
-  key_len = max(key_len, HMACSHA1::DIGESTSIZE);
+  char hex_str[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE * 2 + 1];
+  char key_buf[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE];
+  key_len = max(key_len, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
   memcpy(key_buf, key, key_len);
-  memset(key_buf + key_len, 0, HMACSHA1::DIGESTSIZE - key_len);
+  memset(key_buf + key_len, 0, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE - key_len);
 
   HMACSHA1 hmac((const unsigned char *)key, key_len);
   hmac.Update((const unsigned char *)msg, msg_len);
   hmac.Final((unsigned char *)dest);
-  *len = HMACSHA1::DIGESTSIZE;
+  *len = CEPH_CRYPTO_HMACSHA1_DIGESTSIZE;
   
   buf_to_hex((unsigned char *)dest, *len, hex_str);
 
index f6ce42ca2cbaf8d459d22d2abcc739f7f4066a84..4ff8637e03e59315180145fddbb2b6774413d175 100644 (file)
@@ -262,7 +262,7 @@ struct RGWObjEnt {
   size_t size;
   time_t mtime;
   // two md5 digests and a terminator
-  char etag[ceph::crypto::MD5::DIGESTSIZE * 2 + 1];
+  char etag[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
 
   void encode(bufferlist& bl) const {
     __u8 struct_v = 1;
@@ -292,7 +292,7 @@ struct RGWBucketEnt {
   std::string name;
   size_t size;
   time_t mtime;
-  char etag[MD5::DIGESTSIZE * 2 + 1];
+  char etag[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
   uint64_t count;
 
   void encode(bufferlist& bl) const {
index f39ee299239843743a1715e3480ea9d20e7b77f2..7bb653d7842a799e406eb88ec6259586014561fc 100644 (file)
@@ -353,23 +353,23 @@ void RGWPutObj::execute()
        goto done;
     }
 
-    char supplied_md5_bin[MD5::DIGESTSIZE + 1];
-    char supplied_md5[MD5::DIGESTSIZE * 2 + 1];
-    char calc_md5[MD5::DIGESTSIZE * 2 + 1];
-    unsigned char m[MD5::DIGESTSIZE];
+    char supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1];
+    char supplied_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
+    char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
+    unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE];
 
     if (supplied_md5_b64) {
       RGW_LOG(15) << "supplied_md5_b64=" << supplied_md5_b64 << endl;
-      ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[MD5::DIGESTSIZE + 1], 
+      ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1],
                             supplied_md5_b64, supplied_md5_b64 + strlen(supplied_md5_b64));
       RGW_LOG(15) << "ceph_armor ret=" << ret << endl;
-      if (ret != MD5::DIGESTSIZE) {
+      if (ret != CEPH_CRYPTO_MD5_DIGESTSIZE) {
         err.code = "InvalidDigest";
         ret = -EINVAL;
         goto done;
       }
 
-      buf_to_hex((const unsigned char *)supplied_md5_bin, MD5::DIGESTSIZE, supplied_md5);
+      buf_to_hex((const unsigned char *)supplied_md5_bin, CEPH_CRYPTO_MD5_DIGESTSIZE, supplied_md5);
       RGW_LOG(15) << "supplied_md5=" << supplied_md5 << endl;
     }
 
@@ -388,7 +388,7 @@ void RGWPutObj::execute()
 
     hash.Final(m);
 
-    buf_to_hex(m, MD5::DIGESTSIZE, calc_md5);
+    buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5);
 
     if (supplied_md5_b64 && strcmp(calc_md5, supplied_md5)) {
        err.code = "BadDigest";
index 8f850fae05ecf6df9540c9fb16793ecc468795ba..fe2e4d94ec5ec1a45bbd84b7cef56c5e0603f6ec 100644 (file)
@@ -16,25 +16,25 @@ static int build_token(string& os_user, string& key, uint64_t nonce, utime_t& ex
   ::encode(nonce, bl);
   ::encode(expiration, bl);
 
-  bufferptr p(HMACSHA1::DIGESTSIZE);
+  bufferptr p(CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
   int len = p.length();
 
   char buf[bl.length() * 2 + 1];
   buf_to_hex((const unsigned char *)bl.c_str(), bl.length(), buf);
   RGW_LOG(0) << "bl=" << buf << std::endl;
 
-  char k[HMACSHA1::DIGESTSIZE];
+  char k[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE];
   memset(k, 0, sizeof(k));
   const char *s = key.c_str();
   for (int i = 0; i < (int)key.length(); i++, s++) {
-    k[i % HMACSHA1::DIGESTSIZE] |= *s;
+    k[i % CEPH_CRYPTO_HMACSHA1_DIGESTSIZE] |= *s;
   }
   int ret = calc_hmac_sha1(k, sizeof(k), bl.c_str(), bl.length(),
                             p.c_str(), &len);
   if (ret < 0)
      return ret;
 
-  if (len != HMACSHA1::DIGESTSIZE)
+  if (len != CEPH_CRYPTO_HMACSHA1_DIGESTSIZE)
     return -EINVAL;
 
   bl.append(p);
index cb960e4e9e05feaee5f9d328e668460df8cf8b53..e9c2a07559aaa426f7b59f767afcaa96145790cc 100644 (file)
@@ -414,7 +414,7 @@ bool RGWHandler_REST_S3::authorize(struct req_state *s)
   const char *key = s->user.secret_key.c_str();
   int key_len = strlen(key);
 
-  char hmac_sha1[HMACSHA1::DIGESTSIZE];
+  char hmac_sha1[CEPH_CRYPTO_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;