Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
bc6909f4
Commit
bc6909f4
authored
Aug 10, 2019
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only allow keys configured on a given interface.
We used to accept packets signed by any key.
parent
f6bdc786
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
20 deletions
+16
-20
hmac.c
hmac.c
+13
-18
hmac.h
hmac.h
+2
-1
message.c
message.c
+1
-1
No files found.
hmac.c
View file @
bc6909f4
...
...
@@ -242,26 +242,20 @@ add_hmac(struct buffered *buf, struct interface *ifp,
static
int
compare_hmac
(
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
,
const
unsigned
char
*
packet
,
int
bodylen
,
const
unsigned
char
*
hmac
,
int
hmaclen
)
const
unsigned
char
*
hmac
,
int
hmaclen
,
struct
key
*
key
)
{
unsigned
char
true_hmac
[
MAX_DIGEST_LEN
];
int
true_hmaclen
;
int
i
;
for
(
i
=
0
;
i
<
numkeys
;
i
++
)
{
true_hmaclen
=
compute_hmac
(
src
,
dst
,
packet
,
packet
+
4
,
bodylen
,
keys
[
i
],
true_hmac
);
if
(
true_hmaclen
!=
hmaclen
)
continue
;
if
(
memcmp
(
true_hmac
,
hmac
,
hmaclen
)
==
0
)
return
1
;
}
return
0
;
unsigned
char
buf
[
MAX_DIGEST_LEN
];
int
len
;
len
=
compute_hmac
(
src
,
dst
,
packet
,
packet
+
4
,
bodylen
,
key
,
buf
);
return
len
==
hmaclen
&&
(
memcmp
(
buf
,
hmac
,
hmaclen
)
==
0
);
}
int
check_hmac
(
const
unsigned
char
*
packet
,
int
packetlen
,
int
bodylen
,
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
)
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
,
struct
interface
*
ifp
)
{
int
i
=
bodylen
+
4
;
int
len
;
...
...
@@ -275,15 +269,16 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
}
len
=
packet
[
i
+
1
];
if
(
packet
[
i
]
==
MESSAGE_HMAC
)
{
int
ok
;
if
(
i
+
len
+
2
>
packetlen
)
{
fprintf
(
stderr
,
"Received truncated message.
\n
"
);
return
-
1
;
}
if
(
compare_hmac
(
src
,
dst
,
packet
,
bodylen
,
packet
+
i
+
2
,
len
)
==
1
)
{
ok
=
compare_hmac
(
src
,
dst
,
packet
,
bodylen
,
packet
+
i
+
2
,
len
,
ifp
->
key
);
if
(
ok
)
return
1
;
}
}
i
+=
len
+
2
;
}
return
0
;
...
...
hmac.h
View file @
bc6909f4
...
...
@@ -29,4 +29,5 @@ struct key *add_key(char *id, int type, int len, unsigned char *value);
int
add_hmac
(
struct
buffered
*
buf
,
struct
interface
*
ifp
,
unsigned
char
*
packet_header
);
int
check_hmac
(
const
unsigned
char
*
packet
,
int
packetlen
,
int
bodylen
,
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
);
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
,
struct
interface
*
ifp
);
message.c
View file @
bc6909f4
...
...
@@ -581,7 +581,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
}
if
(
ifp
->
key
!=
NULL
&&
!
(
ifp
->
flags
&
IF_NO_HMAC_VERIFY
))
{
if
(
check_hmac
(
packet
,
packetlen
,
bodylen
,
from
,
to
)
!=
1
)
{
if
(
check_hmac
(
packet
,
packetlen
,
bodylen
,
from
,
to
,
ifp
)
!=
1
)
{
fprintf
(
stderr
,
"Received wrong hmac.
\n
"
);
return
;
}
...
...
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