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
0c4afc22
Commit
0c4afc22
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
7de67155
Changes
3
Hide 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 @
0c4afc22
...
@@ -242,26 +242,20 @@ add_hmac(struct buffered *buf, struct interface *ifp,
...
@@ -242,26 +242,20 @@ add_hmac(struct buffered *buf, struct interface *ifp,
static
int
static
int
compare_hmac
(
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
,
compare_hmac
(
const
unsigned
char
*
src
,
const
unsigned
char
*
dst
,
const
unsigned
char
*
packet
,
int
bodylen
,
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
];
unsigned
char
buf
[
MAX_DIGEST_LEN
];
int
true_hmaclen
;
int
len
;
int
i
;
for
(
i
=
0
;
i
<
numkeys
;
i
++
)
{
len
=
compute_hmac
(
src
,
dst
,
packet
,
packet
+
4
,
bodylen
,
key
,
buf
);
true_hmaclen
=
compute_hmac
(
src
,
dst
,
packet
,
return
len
==
hmaclen
&&
(
memcmp
(
buf
,
hmac
,
hmaclen
)
==
0
);
packet
+
4
,
bodylen
,
keys
[
i
],
true_hmac
);
if
(
true_hmaclen
!=
hmaclen
)
continue
;
if
(
memcmp
(
true_hmac
,
hmac
,
hmaclen
)
==
0
)
return
1
;
}
return
0
;
}
}
int
int
check_hmac
(
const
unsigned
char
*
packet
,
int
packetlen
,
int
bodylen
,
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
i
=
bodylen
+
4
;
int
len
;
int
len
;
...
@@ -275,14 +269,15 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
...
@@ -275,14 +269,15 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
}
}
len
=
packet
[
i
+
1
];
len
=
packet
[
i
+
1
];
if
(
packet
[
i
]
==
MESSAGE_HMAC
)
{
if
(
packet
[
i
]
==
MESSAGE_HMAC
)
{
int
ok
;
if
(
i
+
len
+
2
>
packetlen
)
{
if
(
i
+
len
+
2
>
packetlen
)
{
fprintf
(
stderr
,
"Received truncated message.
\n
"
);
fprintf
(
stderr
,
"Received truncated message.
\n
"
);
return
-
1
;
return
-
1
;
}
}
if
(
compare_hmac
(
src
,
dst
,
packet
,
bodylen
,
ok
=
compare_hmac
(
src
,
dst
,
packet
,
bodylen
,
packet
+
i
+
2
,
len
)
==
1
)
{
packet
+
i
+
2
,
len
,
ifp
->
key
);
if
(
ok
)
return
1
;
return
1
;
}
}
}
i
+=
len
+
2
;
i
+=
len
+
2
;
}
}
...
...
hmac.h
View file @
0c4afc22
...
@@ -29,4 +29,5 @@ struct key *add_key(char *id, int type, int len, unsigned char *value);
...
@@ -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
,
int
add_hmac
(
struct
buffered
*
buf
,
struct
interface
*
ifp
,
unsigned
char
*
packet_header
);
unsigned
char
*
packet_header
);
int
check_hmac
(
const
unsigned
char
*
packet
,
int
packetlen
,
int
bodylen
,
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 @
0c4afc22
...
@@ -588,7 +588,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
...
@@ -588,7 +588,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
}
}
if
(
ifp
->
key
!=
NULL
&&
!
(
ifp
->
flags
&
IF_NO_HMAC_VERIFY
))
{
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
"
);
fprintf
(
stderr
,
"Received wrong hmac.
\n
"
);
return
;
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