Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
5ad92910
Commit
5ad92910
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Version the pickled objects and check for errors when unpickling them
parent
b6e248c9
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/olm/error.hh
+2
-0
2 additions, 0 deletions
include/olm/error.hh
src/account.cpp
+12
-0
12 additions, 0 deletions
src/account.cpp
src/olm.cpp
+25
-4
25 additions, 4 deletions
src/olm.cpp
src/session.cpp
+11
-0
11 additions, 0 deletions
src/session.cpp
with
50 additions
and
4 deletions
include/olm/error.hh
+
2
−
0
View file @
5ad92910
...
...
@@ -27,6 +27,8 @@ enum struct ErrorCode {
BAD_MESSAGE_KEY_ID
=
6
,
/*!< The message references an unknown key id */
INVALID_BASE64
=
7
,
/*!< The input base64 was invalid */
BAD_ACCOUNT_KEY
=
8
,
/*!< The supplied account key is invalid */
UNKNOWN_PICKLE_VERSION
=
9
,
/*!< The pickled object is too new */
CORRUPTED_PICKLE
=
10
,
/*!< The pickled object couldn't be decoded */
};
}
// namespace olm
...
...
This diff is collapsed.
Click to expand it.
src/account.cpp
+
12
−
0
View file @
5ad92910
...
...
@@ -360,11 +360,16 @@ static std::uint8_t const * unpickle(
}
// namespace olm
namespace
{
static
const
std
::
uint32_t
ACCOUNT_PICKLE_VERSION
=
1
;
}
std
::
size_t
olm
::
pickle_length
(
olm
::
Account
const
&
value
)
{
std
::
size_t
length
=
0
;
length
+=
olm
::
pickle_length
(
ACCOUNT_PICKLE_VERSION
);
length
+=
olm
::
pickle_length
(
value
.
identity_keys
);
length
+=
olm
::
pickle_length
(
value
.
one_time_keys
);
length
+=
olm
::
pickle_length
(
value
.
next_one_time_key_id
);
...
...
@@ -376,6 +381,7 @@ std::uint8_t * olm::pickle(
std
::
uint8_t
*
pos
,
olm
::
Account
const
&
value
)
{
pos
=
olm
::
pickle
(
pos
,
ACCOUNT_PICKLE_VERSION
);
pos
=
olm
::
pickle
(
pos
,
value
.
identity_keys
);
pos
=
olm
::
pickle
(
pos
,
value
.
one_time_keys
);
pos
=
olm
::
pickle
(
pos
,
value
.
next_one_time_key_id
);
...
...
@@ -387,6 +393,12 @@ std::uint8_t const * olm::unpickle(
std
::
uint8_t
const
*
pos
,
std
::
uint8_t
const
*
end
,
olm
::
Account
&
value
)
{
uint32_t
pickle_version
;
pos
=
olm
::
unpickle
(
pos
,
end
,
pickle_version
);
if
(
pickle_version
!=
ACCOUNT_PICKLE_VERSION
)
{
value
.
last_error
=
olm
::
ErrorCode
::
UNKNOWN_PICKLE_VERSION
;
return
end
;
}
pos
=
olm
::
unpickle
(
pos
,
end
,
value
.
identity_keys
);
pos
=
olm
::
unpickle
(
pos
,
end
,
value
.
one_time_keys
);
pos
=
olm
::
unpickle
(
pos
,
end
,
value
.
next_one_time_key_id
);
...
...
This diff is collapsed.
Click to expand it.
src/olm.cpp
+
25
−
4
View file @
5ad92910
...
...
@@ -151,7 +151,7 @@ std::size_t b64_input(
return
raw_length
;
}
const
char
*
errors
[
9
]
{
const
char
*
errors
[
11
]
{
"SUCCESS"
,
"NOT_ENOUGH_RANDOM"
,
"OUTPUT_BUFFER_TOO_SMALL"
,
...
...
@@ -161,6 +161,8 @@ const char * errors[9] {
"BAD_MESSAGE_KEY_ID"
,
"INVALID_BASE64"
,
"BAD_ACCOUNT_KEY"
,
"UNKNOWN_PICKLE_VERSION"
,
"CORRUPTED_PICKLE"
,
};
}
// namespace
...
...
@@ -282,7 +284,16 @@ size_t olm_unpickle_account(
return
std
::
size_t
(
-
1
);
}
std
::
uint8_t
*
const
end
=
pos
+
raw_length
;
unpickle
(
pos
,
end
,
object
);
/* On success unpickle will return (pos + raw_length). If unpickling
* terminates too soon then it will return a pointer before
* (pos + raw_length). On error unpickle will return (pos + raw_length + 1).
*/
if
(
end
!=
unpickle
(
pos
,
end
+
1
,
object
))
{
if
(
object
.
last_error
==
olm
::
ErrorCode
::
SUCCESS
)
{
object
.
last_error
=
olm
::
ErrorCode
::
CORRUPTED_PICKLE
;
}
return
std
::
size_t
(
-
1
);
}
return
pickled_length
;
}
...
...
@@ -300,8 +311,18 @@ size_t olm_unpickle_session(
if
(
raw_length
==
std
::
size_t
(
-
1
))
{
return
std
::
size_t
(
-
1
);
}
std
::
uint8_t
*
const
end
=
pos
+
raw_length
;
unpickle
(
pos
,
end
,
object
);
std
::
uint8_t
*
const
end
=
pos
+
raw_length
+
1
;
/* On success unpickle will return (pos + raw_length). If unpickling
* terminates too soon then it will return a pointer before
* (pos + raw_length). On error unpickle will return (pos + raw_length + 1).
*/
if
(
end
!=
unpickle
(
pos
,
end
+
1
,
object
))
{
if
(
object
.
last_error
==
olm
::
ErrorCode
::
SUCCESS
)
{
object
.
last_error
=
olm
::
ErrorCode
::
CORRUPTED_PICKLE
;
}
return
std
::
size_t
(
-
1
);
}
return
pickled_length
;
}
...
...
This diff is collapsed.
Click to expand it.
src/session.cpp
+
11
−
0
View file @
5ad92910
...
...
@@ -353,11 +353,15 @@ std::size_t olm::Session::decrypt(
return
result
;
}
namespace
{
static
const
std
::
uint32_t
SESSION_PICKLE_VERSION
=
1
;
}
std
::
size_t
olm
::
pickle_length
(
Session
const
&
value
)
{
std
::
size_t
length
=
0
;
length
+=
olm
::
pickle_length
(
SESSION_PICKLE_VERSION
);
length
+=
olm
::
pickle_length
(
value
.
received_message
);
length
+=
olm
::
pickle_length
(
value
.
alice_identity_key
);
length
+=
olm
::
pickle_length
(
value
.
alice_base_key
);
...
...
@@ -371,6 +375,7 @@ std::uint8_t * olm::pickle(
std
::
uint8_t
*
pos
,
Session
const
&
value
)
{
pos
=
olm
::
pickle
(
pos
,
SESSION_PICKLE_VERSION
);
pos
=
olm
::
pickle
(
pos
,
value
.
received_message
);
pos
=
olm
::
pickle
(
pos
,
value
.
alice_identity_key
);
pos
=
olm
::
pickle
(
pos
,
value
.
alice_base_key
);
...
...
@@ -384,6 +389,12 @@ std::uint8_t const * olm::unpickle(
std
::
uint8_t
const
*
pos
,
std
::
uint8_t
const
*
end
,
Session
&
value
)
{
uint32_t
pickle_version
;
pos
=
olm
::
unpickle
(
pos
,
end
,
pickle_version
);
if
(
pickle_version
!=
SESSION_PICKLE_VERSION
)
{
value
.
last_error
=
olm
::
ErrorCode
::
UNKNOWN_PICKLE_VERSION
;
return
end
;
}
pos
=
olm
::
unpickle
(
pos
,
end
,
value
.
received_message
);
pos
=
olm
::
unpickle
(
pos
,
end
,
value
.
alice_identity_key
);
pos
=
olm
::
unpickle
(
pos
,
end
,
value
.
alice_base_key
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment