Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastian Schrader
Kea
Commits
efdf126e
Commit
efdf126e
authored
May 03, 2011
by
JINMEI Tatuya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[trac893] added another constructor for TSIGContext: from key params and keyring.
parent
35a7c63a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
1 deletion
+56
-1
src/lib/dns/tests/tsig_unittest.cc
src/lib/dns/tests/tsig_unittest.cc
+28
-0
src/lib/dns/tsig.cc
src/lib/dns/tsig.cc
+24
-1
src/lib/dns/tsig.h
src/lib/dns/tsig.h
+4
-0
No files found.
src/lib/dns/tests/tsig_unittest.cc
View file @
efdf126e
...
...
@@ -111,6 +111,7 @@ protected:
boost
::
scoped_ptr
<
TSIGContext
>
tsig_ctx
;
boost
::
scoped_ptr
<
TSIGContext
>
tsig_verify_ctx
;
TSIGKeyRing
keyring
;
const
uint16_t
qid
;
const
Name
test_name
;
const
RRClass
test_class
;
...
...
@@ -199,6 +200,33 @@ TEST_F(TSIGTest, initialState) {
EXPECT_EQ
(
TSIGError
(
Rcode
::
NOERROR
()),
tsig_ctx
->
getError
());
}
TEST_F
(
TSIGTest
,
constructFromKeyRing
)
{
// Construct a TSIG context with an empty key ring. Key shouldn't be
// found, and the BAD_KEY error should be recorded.
TSIGContext
ctx1
(
test_name
,
TSIGKey
::
HMACMD5_NAME
(),
keyring
);
EXPECT_EQ
(
TSIGContext
::
INIT
,
ctx1
.
getState
());
EXPECT_EQ
(
TSIGError
::
BAD_KEY
(),
ctx1
.
getError
());
// Add a matching key (we don't use the secret so leave it empty), and
// construct it again. This time it should be constructed with a valid
// key.
keyring
.
add
(
TSIGKey
(
test_name
,
TSIGKey
::
HMACMD5_NAME
(),
NULL
,
0
));
TSIGContext
ctx2
(
test_name
,
TSIGKey
::
HMACMD5_NAME
(),
keyring
);
EXPECT_EQ
(
TSIGContext
::
INIT
,
ctx2
.
getState
());
EXPECT_EQ
(
TSIGError
::
NOERROR
(),
ctx2
.
getError
());
// Similar to the first case except that the key ring isn't empty but
// it doesn't contain a matching key.
TSIGContext
ctx3
(
test_name
,
TSIGKey
::
HMACSHA1_NAME
(),
keyring
);
EXPECT_EQ
(
TSIGContext
::
INIT
,
ctx3
.
getState
());
EXPECT_EQ
(
TSIGError
::
BAD_KEY
(),
ctx3
.
getError
());
TSIGContext
ctx4
(
Name
(
"different-key.example"
),
TSIGKey
::
HMACMD5_NAME
(),
keyring
);
EXPECT_EQ
(
TSIGContext
::
INIT
,
ctx4
.
getState
());
EXPECT_EQ
(
TSIGError
::
BAD_KEY
(),
ctx4
.
getError
());
}
// Example output generated by
// "dig -y www.example.com:SFuWd/q99SzF8Yzd1QbB9g== www.example.com
// QID: 0x2d65
...
...
src/lib/dns/tsig.cc
View file @
efdf126e
...
...
@@ -44,6 +44,16 @@ namespace isc {
namespace
dns
{
namespace
{
typedef
boost
::
shared_ptr
<
HMAC
>
HMACPtr
;
// This singleton key is used when the TSIG context is constructed with no
// matching key. The key name and algorithm won't be used in subsequent
// sign/verify, so the their values don't matter.
const
TSIGKey
&
getDummyTSIGKey
()
{
static
TSIGKey
dummy_key
(
Name
::
ROOT_NAME
(),
TSIGKey
::
HMACMD5_NAME
(),
NULL
,
0
);
return
(
dummy_key
);
}
}
struct
TSIGContext
::
TSIGContextImpl
{
...
...
@@ -52,7 +62,7 @@ struct TSIGContext::TSIGContextImpl {
previous_timesigned_
(
0
)
{}
State
state_
;
TSIGKey
key_
;
const
TSIGKey
key_
;
vector
<
uint8_t
>
previous_digest_
;
TSIGError
error_
;
uint64_t
previous_timesigned_
;
// only meaningful for response with BADTIME
...
...
@@ -62,6 +72,19 @@ TSIGContext::TSIGContext(const TSIGKey& key) : impl_(new TSIGContextImpl(key))
{
}
TSIGContext
::
TSIGContext
(
const
Name
&
key_name
,
const
Name
&
algorithm_name
,
const
TSIGKeyRing
&
keyring
)
:
impl_
(
NULL
)
{
const
TSIGKeyRing
::
FindResult
result
(
keyring
.
find
(
key_name
,
algorithm_name
));
if
(
result
.
code
==
TSIGKeyRing
::
NOTFOUND
)
{
impl_
=
new
TSIGContextImpl
(
getDummyTSIGKey
());
impl_
->
error_
=
TSIGError
::
BAD_KEY
();
}
else
{
impl_
=
new
TSIGContextImpl
(
*
result
.
key
);
}
}
TSIGContext
::~
TSIGContext
()
{
delete
impl_
;
}
...
...
src/lib/dns/tsig.h
View file @
efdf126e
...
...
@@ -124,6 +124,10 @@ public:
/// \param key The TSIG key to be used for TSIG sessions with this context.
explicit
TSIGContext
(
const
TSIGKey
&
key
);
/// Constructor from key parameters and key ring.
TSIGContext
(
const
Name
&
key_name
,
const
Name
&
algorithm_name
,
const
TSIGKeyRing
&
keyring
);
/// The destructor.
~
TSIGContext
();
//@}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment