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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
4c2a9744
Commit
4c2a9744
authored
Oct 25, 2019
by
Sébastien Blin
Committed by
Adrien Béraud
Oct 25, 2019
Browse files
Options
Downloads
Patches
Plain Diff
rust: link to certificate C-bindings
parent
a4832059
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
rust/examples/dhtnode.rs
+10
-1
10 additions, 1 deletion
rust/examples/dhtnode.rs
rust/src/crypto.rs
+58
-1
58 additions, 1 deletion
rust/src/crypto.rs
rust/src/dhtrunner.rs
+7
-2
7 additions, 2 deletions
rust/src/dhtrunner.rs
rust/src/ffi.rs
+11
-1
11 additions, 1 deletion
rust/src/ffi.rs
with
86 additions
and
5 deletions
rust/examples/dhtnode.rs
+
10
−
1
View file @
4c2a9744
...
...
@@ -20,6 +20,7 @@ extern crate opendht;
use
std
::{
thread
,
time
};
use
opendht
::{
InfoHash
,
DhtRunner
,
DhtRunnerConfig
,
Value
};
use
opendht
::
crypto
::
*
;
fn
main
()
{
println!
(
"{}"
,
InfoHash
::
random
());
...
...
@@ -28,10 +29,18 @@ fn main() {
println!
(
"{}"
,
InfoHash
::
get
(
"alice"
));
println!
(
"{}"
,
InfoHash
::
get
(
"alice"
)
.is_zero
());
let
mut
dht
=
DhtRunner
::
new
();
let
config
=
DhtRunnerConfig
::
new
();
let
mut
config
=
DhtRunnerConfig
::
new
();
//// If you want to inject a certificate, uncomment the following lines and previous mut.
//// Note: you can generate a certificate with
//// openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout example.key -out example.crt -subj /CN=example.com
//let cert = DhtCertificate::import("example.crt").ok().expect("Invalid cert file");
//let pk = PrivateKey::import("example.key", "");
//config.set_identity(cert, pk);
dht
.run_config
(
1412
,
config
);
dht
.bootstrap
(
"bootstrap.jami.net"
,
4222
);
println!
(
"Current node id: {}"
,
dht
.node_id
());
let
/* mut */
data
=
42
;
let
mut
get_cb
=
|
v
:
Box
<
Value
>
|
{
...
...
This diff is collapsed.
Click to expand it.
rust/src/crypto.rs
+
58
−
1
View file @
4c2a9744
...
...
@@ -18,8 +18,11 @@
#![allow(dead_code)]
use
crate
::
ffi
::
*
;
pub
use
crate
::
ffi
::
*
;
use
std
::
ffi
::
CString
;
use
std
::
io
;
use
std
::
io
::
prelude
::
*
;
use
std
::
fs
::
File
;
impl
PublicKey
{
pub
fn
new
()
->
Box
<
PublicKey
>
{
...
...
@@ -112,3 +115,57 @@ impl Drop for PrivateKey {
}
}
}
impl
DhtCertificate
{
pub
fn
import
(
file
:
&
str
)
->
io
::
Result
<
Box
<
DhtCertificate
>>
{
let
mut
f
=
File
::
open
(
file
)
?
;
let
mut
buffer
=
Vec
::
new
();
f
.read_to_end
(
&
mut
buffer
)
?
;
unsafe
{
Ok
(
Box
::
from_raw
(
dht_certificate_import
((
&*
buffer
)
.as_ptr
(),
buffer
.len
())))
}
}
pub
fn
id
(
&
self
)
->
InfoHash
{
unsafe
{
dht_certificate_get_id
(
&*
self
)
}
}
pub
fn
long_id
(
&
self
)
->
PkId
{
unsafe
{
dht_certificate_get_long_id
(
&*
self
)
}
}
pub
fn
publickey
(
&
self
)
->
Box
<
PublicKey
>
{
unsafe
{
Box
::
from_raw
(
dht_certificate_get_publickey
(
&*
self
))
}
}
}
impl
Drop
for
DhtCertificate
{
fn
drop
(
&
mut
self
)
{
unsafe
{
dht_certificate_delete
(
&
mut
*
self
)
}
}
}
impl
DhtIdentity
{
pub
fn
generate
(
common_name
:
&
str
,
ca
:
Box
<
DhtIdentity
>
)
->
DhtIdentity
{
let
common_name
=
CString
::
new
(
common_name
)
.unwrap
();
unsafe
{
dht_identity_generate
(
common_name
.as_ptr
(),
&*
ca
)
}
}
}
impl
Drop
for
DhtIdentity
{
fn
drop
(
&
mut
self
)
{
unsafe
{
dht_identity_delete
(
&
mut
*
self
)
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rust/src/dhtrunner.rs
+
7
−
2
View file @
4c2a9744
...
...
@@ -39,7 +39,7 @@ impl DhtRunnerConfig {
persist_path
:
ptr
::
null
(),
},
id
:
DhtIdentity
{
privkey
:
ptr
::
null_mut
(),
priv
ate
key
:
ptr
::
null_mut
(),
certificate
:
ptr
::
null_mut
(),
},
},
...
...
@@ -51,7 +51,7 @@ impl DhtRunnerConfig {
peer_publish
:
false
,
server_ca
:
ptr
::
null_mut
(),
client_identity
:
DhtIdentity
{
privkey
:
ptr
::
null_mut
(),
priv
ate
key
:
ptr
::
null_mut
(),
certificate
:
ptr
::
null_mut
(),
},
});
...
...
@@ -73,6 +73,11 @@ impl DhtRunnerConfig {
self
.push_token
=
CString
::
new
(
push_token
)
.unwrap
()
.as_ptr
();
}
pub
fn
set_identity
(
&
mut
self
,
certificate
:
Box
<
DhtCertificate
>
,
privatekey
:
Box
<
PrivateKey
>
)
{
self
.dht_config.id.privatekey
=
Box
::
into_raw
(
privatekey
);
self
.dht_config.id.certificate
=
Box
::
into_raw
(
certificate
);
}
}
impl
DhtNodeConfig
...
...
This diff is collapsed.
Click to expand it.
rust/src/ffi.rs
+
11
−
1
View file @
4c2a9744
...
...
@@ -98,7 +98,7 @@ pub struct DhtCertificate
#[repr(C)]
pub
struct
DhtIdentity
{
pub
privkey
:
*
mut
PrivateKey
,
pub
priv
ate
key
:
*
mut
PrivateKey
,
pub
certificate
:
*
mut
DhtCertificate
,
}
...
...
@@ -162,6 +162,16 @@ extern {
pub
fn
dht_privatekey_get_publickey
(
pk
:
*
const
PrivateKey
)
->
*
mut
PublicKey
;
pub
fn
dht_privatekey_delete
(
pk
:
*
mut
PrivateKey
);
// dht::crypto::Certificate
pub
fn
dht_certificate_import
(
dat
:
*
const
u8
,
dat_size
:
size_t
)
->
*
mut
DhtCertificate
;
pub
fn
dht_certificate_get_id
(
cert
:
*
const
DhtCertificate
)
->
InfoHash
;
pub
fn
dht_certificate_get_long_id
(
cert
:
*
const
DhtCertificate
)
->
PkId
;
pub
fn
dht_certificate_get_publickey
(
cert
:
*
const
DhtCertificate
)
->
*
mut
PublicKey
;
pub
fn
dht_certificate_delete
(
cert
:
*
mut
DhtCertificate
);
pub
fn
dht_identity_generate
(
common_name
:
*
const
c_char
,
ca
:
*
const
DhtIdentity
)
->
DhtIdentity
;
pub
fn
dht_identity_delete
(
ca
:
*
mut
DhtIdentity
);
// dht::OpToken
pub
fn
dht_op_token_delete
(
token
:
*
mut
OpToken
);
...
...
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