Browse Source

[trac781] removed spaces, added one more check

Jelte Jansen 14 years ago
parent
commit
3987357f56

+ 6 - 12
src/lib/crypto/tests/crypto_unittests.cc

@@ -31,15 +31,15 @@ namespace {
             ASSERT_EQ(buf_d[i], data[i]);
         }
     }
-    
+
     void doHMACTest(std::string data, std::string key_str,
                     uint8_t* expected_hmac, size_t hmac_len) {
         OutputBuffer data_buf(data.size());
         data_buf.writeData(data.c_str(), data.size());
         OutputBuffer hmac_sig(1);
-        
+
         TSIGKey key(key_str);
-        
+
         signHMAC(data_buf, key, hmac_sig);
         checkBuffer(hmac_sig, expected_hmac, hmac_len);
         EXPECT_TRUE(verifyHMAC(data_buf, key, hmac_sig));
@@ -91,7 +91,7 @@ TEST(CryptoTest, HMAC_MD5_RFC2202_SIGN) {
     doHMACTest("Test With Truncation",
                "test.example:DAwMDAwMDAwMDAwMDAwMDA==:hmac-md5.sig-alg.reg.int",
                hmac_expected5, 16);
-               
+
     uint8_t hmac_expected6[] = { 0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7,
                                  0xbf, 0x8f, 0x0b, 0x62, 0xe6, 0xce,
                                  0x61, 0xb9, 0xd0, 0xcd };
@@ -164,7 +164,7 @@ TEST(CryptoTest, HMAC_SHA1_RFC2202_SIGN) {
     doHMACTest("Test With Truncation",
                "test.example:DAwMDAwMDAwMDAwMDAwMDAwMDAw=:hmac-sha1",
                hmac_expected5, 20);
-               
+
     uint8_t hmac_expected6[] = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72,
                                  0xd0, 0x0e, 0x95, 0x70, 0x56, 0x37,
                                  0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40,
@@ -239,12 +239,6 @@ TEST(CryptoTest, HMAC_SHA256_RFC2202_SIGN) {
                "test.example:AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGQ==:hmac-sha256",
                hmac_expected4, 32);
 
-/*
-    uint8_t hmac_expected5[] = {  };
-    doHMACTest("Test With Truncation",
-               "test.example:DAwMDAwMDAwMDAwMDAwMDAwMDAw=:hmac-sha256",
-               hmac_expected5, 32);
-*/
     uint8_t hmac_expected6[] = { 0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0,
                                  0xb6, 0x7f, 0x0d, 0x8a, 0x26, 0xaa,
                                  0xcb, 0xf5, 0xb7, 0x7f, 0x8e, 0x0b,
@@ -278,7 +272,7 @@ TEST(CryptoTest, BadKey) {
 
     OutputBuffer data_buf(0);
     OutputBuffer hmac_sig(1);
-    
+
     EXPECT_THROW(signHMAC(data_buf, bad_key, hmac_sig), BadKey);
     EXPECT_THROW(verifyHMAC(data_buf, bad_key, hmac_sig), BadKey);
 }

+ 4 - 1
src/lib/dns/tests/tsigkey_unittest.cc

@@ -232,7 +232,7 @@ TEST(TSIGTest, TSIGKeyFromToString) {
     TSIGKey k2 = TSIGKey("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.");
     TSIGKey k3 = TSIGKey("test.example:MSG6Ng==");
     TSIGKey k4 = TSIGKey(Name("test.example."), Name("hmac-sha1."), NULL, 0);
-    
+
     EXPECT_EQ("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.",
               k1.toText());
     EXPECT_EQ("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.",
@@ -242,10 +242,13 @@ TEST(TSIGTest, TSIGKeyFromToString) {
     EXPECT_EQ("test.example.::hmac-sha1.", k4.toText());
 
     EXPECT_THROW(TSIGKey(""), isc::InvalidParameter);
+    EXPECT_THROW(TSIGKey(":"), isc::InvalidParameter);
     EXPECT_THROW(TSIGKey("::"), isc::InvalidParameter);
     EXPECT_THROW(TSIGKey("..:aa:"), isc::InvalidParameter);
     EXPECT_THROW(TSIGKey("test.example:xxxx:"), isc::InvalidParameter);
     EXPECT_THROW(TSIGKey("test.example.::"), isc::InvalidParameter);
+    EXPECT_THROW(TSIGKey("test.example.:"), isc::InvalidParameter);
+    EXPECT_THROW(TSIGKey("test.example.:MSG6Ng==:"), isc::InvalidParameter);
     EXPECT_THROW(TSIGKey("test.example.:MSG6Ng==:unknown"), isc::InvalidParameter);
 
 }

+ 3 - 3
src/lib/dns/tsigkey.cc

@@ -62,7 +62,7 @@ TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name,
 
 TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
     size_t pos = str.find(':');
-    if (pos == 0 || pos == str.npos) {
+    if (pos == 0 || pos == str.npos || pos == str.size()-1) {
         // error
         isc_throw(InvalidParameter, "Invalid TSIG key string");
     }
@@ -82,7 +82,7 @@ TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
         }
 
         std::string secret_str = str.substr(pos + 1, pos2 - pos - 1);
-    
+
         vector<uint8_t> secret;
         decodeBase64(secret_str, secret);
         unsigned char secret_b[secret.size()];
@@ -155,7 +155,7 @@ TSIGKey::toText() const {
         secret_v.push_back(secret_b[i]);
     }
     std::string secret_str = encodeBase64(secret_v);
-    
+
     return getKeyName().toText() + ":" + secret_str + ":" +
            getAlgorithmName().toText();
 }