Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
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
savoirfairelinux
opendht
Commits
2fbafc35
Commit
2fbafc35
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
crypto: cache Certificate Id
parent
19fe3441
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/crypto.h
+2
-0
2 additions, 0 deletions
include/opendht/crypto.h
src/crypto.cpp
+6
-0
6 additions, 0 deletions
src/crypto.cpp
with
8 additions
and
0 deletions
include/opendht/crypto.h
+
2
−
0
View file @
2fbafc35
...
...
@@ -598,6 +598,8 @@ struct OPENDHT_PUBLIC Certificate {
private
:
Certificate
(
const
Certificate
&
)
=
delete
;
Certificate
&
operator
=
(
const
Certificate
&
)
=
delete
;
InfoHash
cachedId_
{};
PkId
cachedLongId_
{};
struct
crlNumberCmp
{
bool
operator
()
(
const
std
::
shared_ptr
<
RevocationList
>&
lhs
,
const
std
::
shared_ptr
<
RevocationList
>&
rhs
)
const
{
...
...
This diff is collapsed.
Click to expand it.
src/crypto.cpp
+
6
−
0
View file @
2fbafc35
...
...
@@ -853,12 +853,15 @@ Certificate::getId() const
{
if
(
not
cert
)
return
{};
if
(
cachedId_
)
return
cachedId_
;
InfoHash
id
;
size_t
sz
=
id
.
size
();
if
(
auto
err
=
gnutls_x509_crt_get_key_id
(
cert
,
0
,
id
.
data
(),
&
sz
))
throw
CryptoException
(
std
::
string
(
"Can't get certificate public key ID: "
)
+
gnutls_strerror
(
err
));
if
(
sz
!=
id
.
size
())
throw
CryptoException
(
"Can't get certificate public key ID: wrong output length."
);
cachedId_
=
id
;
return
id
;
}
...
...
@@ -867,6 +870,8 @@ Certificate::getLongId() const
{
if
(
not
cert
)
return
{};
if
(
cachedLongId_
)
return
cachedLongId_
;
#if GNUTLS_VERSION_NUMBER < 0x030401
throw
CryptoException
(
"Can't get certificate 256 bits public key ID: GnuTLS 3.4.1 or higher required."
);
#else
...
...
@@ -876,6 +881,7 @@ Certificate::getLongId() const
throw
CryptoException
(
std
::
string
(
"Can't get certificate 256 bits public key ID: "
)
+
gnutls_strerror
(
err
));
if
(
sz
!=
id
.
size
())
throw
CryptoException
(
"Can't get certificate 256 bits public key ID: wrong output length."
);
cachedLongId_
=
id
;
return
id
;
#endif
}
...
...
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