Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dhtnet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
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
dhtnet
Commits
c8354043
Commit
c8354043
authored
11 months ago
by
Amna Snene
Browse files
Options
Downloads
Patches
Plain Diff
check error when creating directory
Change-Id: Iccff91eea9c3a5ab7b84a24688d80d3ea6fdec5e
parent
f81d36bd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp
+6
-2
6 additions, 2 deletions
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp
tools/dhtnet_crtmgr/main.cpp
+41
-3
41 additions, 3 deletions
tools/dhtnet_crtmgr/main.cpp
with
47 additions
and
5 deletions
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp
+
6
−
2
View file @
c8354043
...
...
@@ -43,8 +43,12 @@ loadIdentity(const std::filesystem::path& privatekey, const std::filesystem::pat
dht
::
crypto
::
Identity
generateIdentity
(
const
std
::
filesystem
::
path
&
path_id
,
const
std
::
string
&
name
,
const
dht
::
crypto
::
Identity
&
ca
)
{
auto
identity
=
dht
::
crypto
::
generateIdentity
(
name
,
ca
);
if
(
!
std
::
filesystem
::
exists
(
path_id
))
std
::
filesystem
::
create_directories
(
path_id
);
std
::
error_code
ec
;
std
::
filesystem
::
create_directories
(
path_id
,
ec
);
if
(
ec
)
{
fmt
::
print
(
stderr
,
"Error: failed to create directory {}
\n
"
,
path_id
.
string
());
return
{};
}
dht
::
crypto
::
saveIdentity
(
identity
,
path_id
/
name
);
return
identity
;
}
...
...
This diff is collapsed.
Click to expand it.
tools/dhtnet_crtmgr/main.cpp
+
41
−
3
View file @
c8354043
...
...
@@ -269,7 +269,13 @@ main(int argc, char** argv)
folder
=
input_folder
;
}
folder
=
std
::
filesystem
::
absolute
(
folder
);
std
::
filesystem
::
create_directories
(
folder
);
std
::
error_code
e
;
std
::
filesystem
::
create_directories
(
folder
,
e
);
if
(
e
)
{
fmt
::
print
(
stderr
,
"Error: Could not create directory {}. {}
\n
"
,
folder
,
e
.
message
());
return
EXIT_FAILURE
;
}
if
(
usage
==
"client"
)
{
// Use existing CA or generate new CA
...
...
@@ -288,11 +294,19 @@ main(int argc, char** argv)
}
}
else
{
ca
=
dhtnet
::
generateIdentity
(
folder
,
"ca"
);
if
(
!
ca
.
first
||
!
ca
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate CA.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated CA in {}: {} {}
\n
"
,
folder
,
"ca"
,
ca
.
second
->
getId
());
}
// Generate client certificate
auto
id
=
dhtnet
::
generateIdentity
(
folder
,
"certificate"
,
ca
);
if
(
!
id
.
first
||
!
id
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate certificate.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated certificate in {}: {} {}
\n
"
,
folder
,
"certificate"
,
id
.
second
->
getId
());
// Create configuration file with generated keys
...
...
@@ -321,7 +335,7 @@ main(int argc, char** argv)
return
EXIT_SUCCESS
;
}
else
{
// Create configuration file with generated keys
std
::
filesystem
::
path
yaml_config
{
folder
/
"
config
.yml"
};
std
::
filesystem
::
path
yaml_config
{
folder
/
"
dnc
.y
a
ml"
};
std
::
string
overwrite
=
""
;
if
(
std
::
filesystem
::
exists
(
yaml_config
))
{
do
{
...
...
@@ -336,7 +350,7 @@ main(int argc, char** argv)
overwrite
=
"yes"
;
// File doesn't exist, create it
}
if
(
overwrite
==
"yes"
)
{
if
(
create_yaml_config
(
yaml_config
,
folder
/
"
certificate
.crt"
,
folder
/
"
certificate
.pem"
,
tru
e
)
!=
0
)
{
if
(
create_yaml_config
(
yaml_config
,
folder
/
"
id"
/
"id-server
.crt"
,
folder
/
"
id"
/
"id-server
.pem"
,
fals
e
)
!=
0
)
{
return
EXIT_FAILURE
;
}
}
...
...
@@ -350,10 +364,18 @@ main(int argc, char** argv)
// create CA with name ca-server
std
::
filesystem
::
path
path_ca
=
params
.
id
/
"CA"
;
auto
ca
=
dhtnet
::
generateIdentity
(
path_ca
,
"ca-server"
);
if
(
!
ca
.
first
||
!
ca
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate CA.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated CA in {}: {} {}
\n
"
,
path_ca
,
"ca-server"
,
ca
.
second
->
getId
());
// create identity with name id-server
std
::
filesystem
::
path
path_id
=
params
.
id
/
"id"
;
auto
identity
=
dhtnet
::
generateIdentity
(
path_id
,
"id-server"
,
ca
);
if
(
!
identity
.
first
||
!
identity
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate certificate.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated certificate in {}: {} {}
\n
"
,
path_id
,
"id-server"
,
identity
.
second
->
getId
());
return
EXIT_SUCCESS
;
}
...
...
@@ -361,18 +383,34 @@ main(int argc, char** argv)
if
(
params
.
ca
.
empty
()
||
params
.
privatekey
.
empty
())
{
if
(
params
.
name
.
empty
())
{
auto
ca
=
dhtnet
::
generateIdentity
(
params
.
id
,
"ca"
);
if
(
!
ca
.
first
||
!
ca
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate CA.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated certificate in {}: {} {}
\n
"
,
params
.
id
,
"ca"
,
ca
.
second
->
getId
());
}
else
{
auto
ca
=
dhtnet
::
generateIdentity
(
params
.
id
,
params
.
name
);
if
(
!
ca
.
first
||
!
ca
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate CA.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated certificate in {}: {} {}
\n
"
,
params
.
id
,
params
.
name
,
ca
.
second
->
getId
());
}
}
else
{
auto
ca
=
dhtnet
::
loadIdentity
(
params
.
privatekey
,
params
.
ca
);
if
(
params
.
name
.
empty
())
{
auto
id
=
dhtnet
::
generateIdentity
(
params
.
id
,
"certificate"
,
ca
);
if
(
!
id
.
first
||
!
id
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate certificate.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated certificate in {}: {} {}
\n
"
,
params
.
id
,
"certificate"
,
id
.
second
->
getId
());
}
else
{
auto
id
=
dhtnet
::
generateIdentity
(
params
.
id
,
params
.
name
,
ca
);
if
(
!
id
.
first
||
!
id
.
second
)
{
fmt
::
print
(
stderr
,
"Error: Could not generate certificate.
\n
"
);
return
EXIT_FAILURE
;
}
fmt
::
print
(
"Generated certificate in {}: {} {}
\n
"
,
params
.
id
,
params
.
name
,
id
.
second
->
getId
());
}
}
...
...
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