BIND 10 trac781, updated. aa0ddfbb4f0aa61cfee383f5459c2183b353674b [trac781] Merge branch 'trac781' of ssh://bind10.isc.org/var/bind10/git/bind10 into trac781
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Apr 13 07:24:15 UTC 2011
The branch, trac781 has been updated
via aa0ddfbb4f0aa61cfee383f5459c2183b353674b (commit)
via a7c4e0bc10a5430008d12081f4cb30d1d0d26723 (commit)
via 3987357f56e0fc2feca75001b963a11f1b7120ff (commit)
via 6cece2fc1d8a086b65421a583cf35b40f6ee1751 (commit)
from 4f1d8d0f2ce99880306f7926a23b28f1aa8e4fd9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit aa0ddfbb4f0aa61cfee383f5459c2183b353674b
Merge: a7c4e0bc10a5430008d12081f4cb30d1d0d26723 4f1d8d0f2ce99880306f7926a23b28f1aa8e4fd9
Author: Jelte Jansen <jelte at isc.org>
Date: Wed Apr 13 09:20:56 2011 +0200
[trac781] Merge branch 'trac781' of ssh://bind10.isc.org/var/bind10/git/bind10 into trac781
Conflicts:
src/lib/dns/tsigkey.cc
commit a7c4e0bc10a5430008d12081f4cb30d1d0d26723
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Apr 12 09:23:22 2011 +0200
[trac781] document exceptions
commit 3987357f56e0fc2feca75001b963a11f1b7120ff
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Apr 12 09:21:12 2011 +0200
[trac781] removed spaces, added one more check
commit 6cece2fc1d8a086b65421a583cf35b40f6ee1751
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Apr 12 09:09:13 2011 +0200
[trac781] pydnspp additions for tsigkey to/from str
-----------------------------------------------------------------------
Summary of changes:
src/lib/Makefile.am | 2 +-
src/lib/crypto/crypto.h | 7 +++-
src/lib/crypto/tests/crypto_unittests.cc | 6 ---
src/lib/dns/python/tests/tsigkey_python_test.py | 9 +++++
src/lib/dns/python/tsigkey_python.cc | 40 +++++++++++++++-------
src/lib/dns/tests/tsigkey_unittest.cc | 3 ++
src/lib/dns/tsigkey.cc | 2 +-
7 files changed, 47 insertions(+), 22 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index bb7b06d..c3323c0 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -1,2 +1,2 @@
-SUBDIRS = exceptions crypto dns cc config python xfr bench log \
+SUBDIRS = exceptions dns crypto cc config python xfr bench log \
asiolink nsas cache resolve testutils datasrc server_common
diff --git a/src/lib/crypto/crypto.h b/src/lib/crypto/crypto.h
index 3533c4c..08e86d2 100644
--- a/src/lib/crypto/crypto.h
+++ b/src/lib/crypto/crypto.h
@@ -36,19 +36,24 @@
namespace isc {
namespace crypto {
+/// General exception class that is the base for all crypto-related
+/// exceptions
class CryptoError : public Exception {
public:
CryptoError(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
};
+/// This exception is thrown when a cryptographic action is requested
+/// for an algorithm that is not supported by the underlying algorithm.
class UnsupportedAlgorithm : public CryptoError {
public:
UnsupportedAlgorithm(const char* file, size_t line, const char* what) :
CryptoError(file, line, what) {}
};
-// The underlying library could not handle this key
+/// This exception is thrown when the underlying library could not
+/// handle this key
class BadKey : public CryptoError {
public:
BadKey(const char* file, size_t line, const char* what) :
diff --git a/src/lib/crypto/tests/crypto_unittests.cc b/src/lib/crypto/tests/crypto_unittests.cc
index 30196b9..a25dcd8 100644
--- a/src/lib/crypto/tests/crypto_unittests.cc
+++ b/src/lib/crypto/tests/crypto_unittests.cc
@@ -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,
diff --git a/src/lib/dns/python/tests/tsigkey_python_test.py b/src/lib/dns/python/tests/tsigkey_python_test.py
index 06e6868..023b9e6 100644
--- a/src/lib/dns/python/tests/tsigkey_python_test.py
+++ b/src/lib/dns/python/tests/tsigkey_python_test.py
@@ -44,6 +44,15 @@ class TSIGKeyTest(unittest.TestCase):
TSIGKey.HMACMD5_NAME,
'should be binary') # signature mismatch
+ def test_str(self):
+ k1 = TSIGKey('test.example:CwsLCwsLCwsLCwsLCwsLCw==:hmac-md5.sig-alg.reg.int')
+ self.assertEqual(Name('test.example.'), k1.get_key_name())
+ self.assertEqual(Name('hmac-md5.sig-alg.reg.int.'), k1.get_algorithm_name())
+ self.assertEqual(b'\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b',
+ k1.get_secret())
+ self.assertEqual('test.example.:CwsLCwsLCwsLCwsLCwsLCw==:hmac-md5.sig-alg.reg.int.',
+ k1.to_text())
+
class TSIGKeyRingTest(unittest.TestCase):
key_name = Name('example.com')
secret = b'someRandomData'
diff --git a/src/lib/dns/python/tsigkey_python.cc b/src/lib/dns/python/tsigkey_python.cc
index aa87909..906dfc0 100644
--- a/src/lib/dns/python/tsigkey_python.cc
+++ b/src/lib/dns/python/tsigkey_python.cc
@@ -55,6 +55,7 @@ void TSIGKey_destroy(s_TSIGKey* self);
PyObject* TSIGKey_getKeyName(const s_TSIGKey* self);
PyObject* TSIGKey_getAlgorithmName(const s_TSIGKey* self);
PyObject* TSIGKey_getSecret(const s_TSIGKey* self);
+PyObject* TSIGKey_toText(const s_TSIGKey* self);
// This list contains the actual set of functions we have in
// python. Each entry has
@@ -72,6 +73,8 @@ PyMethodDef TSIGKey_methods[] = {
{ "get_secret",
reinterpret_cast<PyCFunction>(TSIGKey_getSecret), METH_NOARGS,
"Return the value of the TSIG secret." },
+ { "to_text", reinterpret_cast<PyCFunction>(TSIGKey_toText), METH_NOARGS,
+ "Returns the string representation (name:secret:algorithm)" },
{ NULL, NULL, 0, NULL }
};
@@ -148,27 +151,33 @@ createNameObject(const Name& source) {
int
TSIGKey_init(s_TSIGKey* self, PyObject* args) {
+ const char* str;
+
const s_Name* key_name;
const s_Name* algorithm_name;
PyObject* bytes_obj;
const char* secret;
Py_ssize_t secret_len;
- if (PyArg_ParseTuple(args, "O!O!O", &name_type, &key_name,
+
+ try {
+ if (PyArg_ParseTuple(args, "s", &str)) {
+ self->tsigkey = new TSIGKey(str);
+ return (0);
+ } else if (PyArg_ParseTuple(args, "O!O!O", &name_type, &key_name,
&name_type, &algorithm_name, &bytes_obj) &&
- PyObject_AsCharBuffer(bytes_obj, &secret, &secret_len) != -1) {
- try {
- self->tsigkey = new TSIGKey(*key_name->name,
- *algorithm_name->name,
- secret, secret_len);
- } catch (const isc::InvalidParameter& ex) {
- PyErr_SetString(po_InvalidParameter, ex.what());
- return (-1);
- } catch (...) {
- PyErr_SetString(po_IscException, "Unexpected exception");
- return (-1);
+ PyObject_AsCharBuffer(bytes_obj, &secret, &secret_len) != -1) {
+ self->tsigkey = new TSIGKey(*key_name->name,
+ *algorithm_name->name,
+ secret, secret_len);
+ return (0);
}
- return (0);
+ } catch (const isc::InvalidParameter& ex) {
+ PyErr_SetString(po_InvalidParameter, ex.what());
+ return (-1);
+ } catch (...) {
+ PyErr_SetString(po_IscException, "Unexpected exception");
+ return (-1);
}
PyErr_Clear();
@@ -201,6 +210,11 @@ TSIGKey_getSecret(const s_TSIGKey* const self) {
self->tsigkey->getSecretLength()));
}
+PyObject*
+TSIGKey_toText(const s_TSIGKey* self) {
+ return (Py_BuildValue("s", self->tsigkey->toText().c_str()));
+}
+
// Module Initialization, all statics are initialized here
bool
initModulePart_TSIGKey(PyObject* mod) {
diff --git a/src/lib/dns/tests/tsigkey_unittest.cc b/src/lib/dns/tests/tsigkey_unittest.cc
index f372c45..2cb91f8 100644
--- a/src/lib/dns/tests/tsigkey_unittest.cc
+++ b/src/lib/dns/tests/tsigkey_unittest.cc
@@ -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);
}
diff --git a/src/lib/dns/tsigkey.cc b/src/lib/dns/tsigkey.cc
index 6ada878..550c2a2 100644
--- a/src/lib/dns/tsigkey.cc
+++ b/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");
}
More information about the bind10-changes
mailing list