Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cppack
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
passwords
cppack
Commits
169ef6ff
Commit
169ef6ff
authored
Feb 4, 2020
by
Mathieu Valois
Browse files
Options
Downloads
Patches
Plain Diff
Use more oriented-objet code
parent
21487cbd
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+2
-0
2 additions, 0 deletions
CMakeLists.txt
include/Statsgen.h
+4
-61
4 additions, 61 deletions
include/Statsgen.h
src/core/Statsgen.cpp
+30
-76
30 additions, 76 deletions
src/core/Statsgen.cpp
with
36 additions
and
137 deletions
CMakeLists.txt
+
2
−
0
View file @
169ef6ff
...
@@ -16,6 +16,7 @@ set(CMAKE_LD_FLAGS "-lpthread")
...
@@ -16,6 +16,7 @@ set(CMAKE_LD_FLAGS "-lpthread")
add_executable
(
cppack
add_executable
(
cppack
src/core/Statsgen.cpp
src/core/Statsgen.cpp
src/core/Policy.cpp
src/core/Policy.cpp
src/core/ThreadData.cpp
src/cli/Main.cpp
)
src/cli/Main.cpp
)
target_link_libraries
(
cppack
${
CMAKE_THREAD_LIBS_INIT
}
)
target_link_libraries
(
cppack
${
CMAKE_THREAD_LIBS_INIT
}
)
...
@@ -42,6 +43,7 @@ if(Qt5Core_FOUND)
...
@@ -42,6 +43,7 @@ if(Qt5Core_FOUND)
src/gui/MainGui.cpp
src/gui/MainGui.cpp
src/core/Statsgen.cpp
src/core/Statsgen.cpp
src/core/Policy.cpp
src/core/Policy.cpp
src/core/ThreadData.cpp
ressources/logos.qrc
ressources/logos.qrc
)
)
...
...
This diff is collapsed.
Click to expand it.
include/Statsgen.h
+
4
−
61
View file @
169ef6ff
...
@@ -16,21 +16,15 @@
...
@@ -16,21 +16,15 @@
#include
<string>
#include
<string>
#include
<unordered_map>
#include
<iostream>
#include
<iostream>
#include
<regex>
#include
<queue>
#include
<thread>
#include
<thread>
#include
<climits>
#include
"Policy.h"
#include
"Policy.h"
#include
"SecurityRules.h"
#include
"SecurityRules.h"
#include
"ThreadData.h"
#define MAX_THREADS 32
#define MAX_THREADS 32
typedef
std
::
unordered_map
<
std
::
string
,
uint64_t
>
StringOccurrence
;
typedef
std
::
unordered_map
<
int
,
uint64_t
>
IntOccurrence
;
struct
PasswordStats
{
struct
PasswordStats
{
int
pass_length
=
0
;
int
pass_length
=
0
;
...
@@ -39,56 +33,6 @@ struct PasswordStats {
...
@@ -39,56 +33,6 @@ struct PasswordStats {
Policy
pol
;
Policy
pol
;
};
};
/**
* @brief Simplify number of arguments for functions
* minimal number of digits of a password, etc.
*/
struct
minMax
{
uint
mindigit
=
UINT_MAX
;
uint
maxdigit
=
0
;
uint
minlower
=
UINT_MAX
;
uint
maxlower
=
0
;
uint
minupper
=
UINT_MAX
;
uint
maxupper
=
0
;
uint
minspecial
=
UINT_MAX
;
uint
maxspecial
=
0
;
};
/**
* @brief All needed variables to give to each thread
*/
struct
thread_data
{
int
thread_id
;
std
::
string
filename
;
uint64_t
lineBegin
=
0
;
uint64_t
lineEnd
=
0
;
uint64_t
total_counter
=
0
;
uint64_t
total_filter
=
0
;
IntOccurrence
length
;
StringOccurrence
simplemasks
;
StringOccurrence
advancedmasks
;
StringOccurrence
charactersets
;
std
::
queue
<
std
::
string
>
password_queue
;
minMax
minMaxValue
;
std
::
regex
current_regex
;
bool
use_regex
=
false
;
bool
withcount
=
false
;
uint
limitSimplemask
;
uint
limitAdvancedmask
;
SecurityRules
sr
;
bool
finished
=
false
;
};
/**
/**
* @brief Calcul and save all analysed statistics
* @brief Calcul and save all analysed statistics
*/
*/
...
@@ -158,8 +102,7 @@ public:
...
@@ -158,8 +102,7 @@ public:
}
}
}
}
void
configureThread
(
thread_data
&
td
)
const
;
void
configureThread
(
ThreadData
&
td
)
const
;
void
mergeThread
(
const
thread_data
&
td
);
/**
/**
...
@@ -200,11 +143,11 @@ public:
...
@@ -200,11 +143,11 @@ public:
inline
const
StringOccurrence
&
getStatsCharsets
()
const
{
return
stats_charactersets
;
}
inline
const
StringOccurrence
&
getStatsCharsets
()
const
{
return
stats_charactersets
;
}
inline
const
StringOccurrence
&
getStatsSimple
()
const
{
return
stats_simplemasks
;
}
inline
const
StringOccurrence
&
getStatsSimple
()
const
{
return
stats_simplemasks
;
}
inline
const
StringOccurrence
&
getStatsAdvanced
()
const
{
return
stats_advancedmasks
;
}
inline
const
StringOccurrence
&
getStatsAdvanced
()
const
{
return
stats_advancedmasks
;
}
inline
const
t
hread
_d
ata
*
getThreadsData
()
const
{
return
td
;
}
inline
const
T
hread
D
ata
*
getThreadsData
()
const
{
return
td
;
}
private
:
private
:
std
::
string
filename
;
std
::
string
filename
;
struct
t
hread
_d
ata
td
[
MAX_THREADS
];
T
hread
D
ata
td
[
MAX_THREADS
];
// Filters
// Filters
...
...
This diff is collapsed.
Click to expand it.
src/core/Statsgen.cpp
+
30
−
76
View file @
169ef6ff
...
@@ -52,7 +52,7 @@ void Statsgen::setSecurityRules(const uint& length, const uint& special, const u
...
@@ -52,7 +52,7 @@ void Statsgen::setSecurityRules(const uint& length, const uint& special, const u
_sr
=
{
_sr
.
nbSecurePassword
,
length
,
special
,
digit
,
upper
,
lower
};
_sr
=
{
_sr
.
nbSecurePassword
,
length
,
special
,
digit
,
upper
,
lower
};
}
}
void
Statsgen
::
configureThread
(
t
hread
_d
ata
&
td
)
const
{
void
Statsgen
::
configureThread
(
T
hread
D
ata
&
td
)
const
{
td
.
filename
=
filename
;
td
.
filename
=
filename
;
td
.
current_regex
=
current_regex
;
td
.
current_regex
=
current_regex
;
td
.
use_regex
=
use_regex
;
td
.
use_regex
=
use_regex
;
...
@@ -62,44 +62,6 @@ void Statsgen::configureThread(thread_data& td) const {
...
@@ -62,44 +62,6 @@ void Statsgen::configureThread(thread_data& td) const {
td
.
sr
=
{
0
,
_sr
.
minLength
,
_sr
.
minSpecial
,
_sr
.
minDigit
,
_sr
.
minLower
,
_sr
.
minUpper
};
td
.
sr
=
{
0
,
_sr
.
minLength
,
_sr
.
minSpecial
,
_sr
.
minDigit
,
_sr
.
minLower
,
_sr
.
minUpper
};
}
}
void
Statsgen
::
mergeThread
(
const
thread_data
&
td
){
total_counter
+=
td
.
total_counter
;
total_filter
+=
td
.
total_filter
;
Policy
min
,
max
;
min
.
digit
=
td
.
minMaxValue
.
mindigit
;
min
.
lower
=
td
.
minMaxValue
.
minlower
;
min
.
upper
=
td
.
minMaxValue
.
minupper
;
min
.
special
=
td
.
minMaxValue
.
minspecial
;
max
.
digit
=
td
.
minMaxValue
.
maxdigit
;
max
.
lower
=
td
.
minMaxValue
.
maxlower
;
max
.
upper
=
td
.
minMaxValue
.
maxupper
;
max
.
special
=
td
.
minMaxValue
.
maxspecial
;
_sr
.
nbSecurePassword
+=
td
.
sr
.
nbSecurePassword
;
updateMinMax
(
minMaxValue
,
min
);
updateMinMax
(
minMaxValue
,
max
);
for
(
pair
<
int
,
uint64_t
>
occ
:
td
.
length
){
stats_length
[
occ
.
first
]
+=
occ
.
second
;
}
for
(
pair
<
string
,
int
>
occ
:
td
.
charactersets
){
stats_charactersets
[
occ
.
first
]
+=
occ
.
second
;
}
for
(
pair
<
string
,
int
>
occ
:
td
.
simplemasks
){
stats_simplemasks
[
occ
.
first
]
+=
occ
.
second
;
}
for
(
pair
<
string
,
int
>
occ
:
td
.
advancedmasks
){
stats_advancedmasks
[
occ
.
first
]
+=
occ
.
second
;
}
}
int
Statsgen
::
generate_stats
()
{
int
Statsgen
::
generate_stats
()
{
uint64_t
nbline
=
0
;
uint64_t
nbline
=
0
;
if
(
!
is_stdin
){
if
(
!
is_stdin
){
...
@@ -162,10 +124,12 @@ int Statsgen::generate_stats() {
...
@@ -162,10 +124,12 @@ int Statsgen::generate_stats() {
exit
(
-
1
);
exit
(
-
1
);
}
}
td
[
i
].
finished
=
true
;
td
[
i
].
finished
=
true
;
mergeThread
(
td
[
i
]);
if
(
i
>=
1
){
td
[
0
]
+=
td
[
i
];
}
}
}
if
(
!
total_counter
)
{
if
(
!
td
[
0
].
total_counter
)
{
cerr
<<
"[ERROR] Empty file or not existing file"
<<
endl
;
cerr
<<
"[ERROR] Empty file or not existing file"
<<
endl
;
return
0
;
return
0
;
}
}
...
@@ -175,59 +139,60 @@ int Statsgen::generate_stats() {
...
@@ -175,59 +139,60 @@ int Statsgen::generate_stats() {
void
Statsgen
::
print_stats
()
{
void
Statsgen
::
print_stats
()
{
ThreadData
&
data
=
td
[
0
];
int
count
;
int
count
;
float
perc
=
percentage
(
total_filter
,
total_counter
);
float
perc
=
percentage
(
data
.
total_filter
,
data
.
total_counter
);
cout
<<
"
\n\t
Selected "
<<
total_filter
<<
" on "
<<
total_counter
<<
" passwords
\t
("
cout
<<
"
\n\t
Selected "
<<
data
.
total_filter
<<
" on "
<<
data
.
total_counter
<<
" passwords
\t
("
<<
perc
<<
" %)"
<<
endl
;
<<
perc
<<
" %)"
<<
endl
;
cout
<<
"
\n
Security rules : "
<<
endl
;
cout
<<
"
\n
Security rules : "
<<
endl
;
cout
<<
"
\t
Minimal length of a password: "
<<
_
sr
.
minLength
<<
endl
;
cout
<<
"
\t
Minimal length of a password: "
<<
data
.
sr
.
minLength
<<
endl
;
cout
<<
"
\t
Minimum of special characters in a password: "
<<
_
sr
.
minSpecial
<<
endl
;
cout
<<
"
\t
Minimum of special characters in a password: "
<<
data
.
sr
.
minSpecial
<<
endl
;
cout
<<
"
\t
Minimum of digits in a password: "
<<
_
sr
.
minDigit
<<
endl
;
cout
<<
"
\t
Minimum of digits in a password: "
<<
data
.
sr
.
minDigit
<<
endl
;
cout
<<
"
\t
Minimum of lower characters in a password: "
<<
_
sr
.
minLower
<<
endl
;
cout
<<
"
\t
Minimum of lower characters in a password: "
<<
data
.
sr
.
minLower
<<
endl
;
cout
<<
"
\t
Minimum of upper characters in a password: "
<<
_
sr
.
minUpper
<<
endl
;
cout
<<
"
\t
Minimum of upper characters in a password: "
<<
data
.
sr
.
minUpper
<<
endl
;
float
perce
=
percentage
(
_
sr
.
nbSecurePassword
,
total_counter
);
float
perce
=
percentage
(
data
.
sr
.
nbSecurePassword
,
data
.
total_counter
);
cout
<<
"
\n\t\t
--> "
<<
_
sr
.
nbSecurePassword
<<
" passwords
\t
("
<<
perce
<<
" %) respect the security rules
\n
"
<<
endl
;
cout
<<
"
\n\t\t
--> "
<<
data
.
sr
.
nbSecurePassword
<<
" passwords
\t
("
<<
perce
<<
" %) respect the security rules
\n
"
<<
endl
;
cout
<<
"
\n
min - max
\n
"
<<
endl
;
cout
<<
"
\n
min - max
\n
"
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"digit: "
cout
<<
setw
(
43
)
<<
right
<<
"digit: "
<<
setw
(
2
)
<<
right
<<
minMaxValue
.
mindigit
<<
" - "
<<
minMaxValue
.
maxdigit
<<
endl
;
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
mindigit
<<
" - "
<<
data
.
minMaxValue
.
maxdigit
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"lower: "
cout
<<
setw
(
43
)
<<
right
<<
"lower: "
<<
setw
(
2
)
<<
right
<<
minMaxValue
.
minlower
<<
" - "
<<
minMaxValue
.
maxlower
<<
endl
;
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
minlower
<<
" - "
<<
data
.
minMaxValue
.
maxlower
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"upper: "
cout
<<
setw
(
43
)
<<
right
<<
"upper: "
<<
setw
(
2
)
<<
right
<<
minMaxValue
.
minupper
<<
" - "
<<
minMaxValue
.
maxupper
<<
endl
;
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
minupper
<<
" - "
<<
data
.
minMaxValue
.
maxupper
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"special: "
cout
<<
setw
(
43
)
<<
right
<<
"special: "
<<
setw
(
2
)
<<
right
<<
minMaxValue
.
minspecial
<<
" - "
<<
minMaxValue
.
maxspecial
<<
endl
;
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
minspecial
<<
" - "
<<
data
.
minMaxValue
.
maxspecial
<<
endl
;
cout
<<
"
\n
Statistics relative to length:
\n
"
<<
endl
;
cout
<<
"
\n
Statistics relative to length:
\n
"
<<
endl
;
showMap
(
stats_
length
,
top
,
total_counter
,
hiderare
,
count
);
showMap
(
data
.
length
,
top
,
data
.
total_counter
,
hiderare
,
count
);
cout
<<
"
\n
Statistics relative to charsets:
\n
"
<<
endl
;
cout
<<
"
\n
Statistics relative to charsets:
\n
"
<<
endl
;
showMap
(
stats_
charactersets
,
-
1
,
total_counter
,
hiderare
,
count
);
showMap
(
data
.
charactersets
,
-
1
,
data
.
total_counter
,
hiderare
,
count
);
cout
<<
"
\n
Statistics relative to simplemasks:
\n
"
<<
endl
;
cout
<<
"
\n
Statistics relative to simplemasks:
\n
"
<<
endl
;
showMap
(
stats_
simplemasks
,
top
,
total_counter
,
hiderare
,
count
);
showMap
(
data
.
simplemasks
,
top
,
data
.
total_counter
,
hiderare
,
count
);
if
(
limitSimplemask
>
0
)
{
if
(
limitSimplemask
>
0
)
{
cout
<<
endl
;
cout
<<
endl
;
readResult
(
stats_
simplemasks
[
"othermasks"
],
"othermasks"
,
count
,
total_counter
,
hiderare
);
readResult
(
data
.
simplemasks
[
"othermasks"
],
"othermasks"
,
count
,
data
.
total_counter
,
hiderare
);
}
}
cout
<<
"
\n
Statistics relative to advancedmask:
\n
"
<<
endl
;
cout
<<
"
\n
Statistics relative to advancedmask:
\n
"
<<
endl
;
showMap
(
stats_
advancedmasks
,
top
,
total_counter
,
hiderare
,
count
);
showMap
(
data
.
advancedmasks
,
top
,
data
.
total_counter
,
hiderare
,
count
);
if
(
!
outfile_name
.
empty
()){
if
(
!
outfile_name
.
empty
()){
locale
::
global
(
locale
(
"C"
));
locale
::
global
(
locale
(
"C"
));
ofstream
outfile_stream
(
outfile_name
);
ofstream
outfile_stream
(
outfile_name
);
map
<
uint64_t
,
string
,
greater
<
uint64_t
>>
reverse
=
flip_map
(
stats_
advancedmasks
);
map
<
uint64_t
,
string
,
greater
<
uint64_t
>>
reverse
=
flip_map
(
data
.
advancedmasks
);
for
(
pair
<
uint64_t
,
string
>
it
:
reverse
){
for
(
pair
<
uint64_t
,
string
>
it
:
reverse
){
if
(
it
.
second
==
"othermasks"
)
continue
;
if
(
it
.
second
==
"othermasks"
)
continue
;
outfile_stream
<<
it
.
second
<<
","
<<
it
.
first
<<
endl
;
outfile_stream
<<
it
.
second
<<
","
<<
it
.
first
<<
endl
;
...
@@ -237,7 +202,7 @@ void Statsgen::print_stats() {
...
@@ -237,7 +202,7 @@ void Statsgen::print_stats() {
if
(
limitAdvancedmask
>
0
)
{
if
(
limitAdvancedmask
>
0
)
{
cout
<<
endl
;
cout
<<
endl
;
readResult
(
stats_
advancedmasks
[
"othermasks"
],
"othermasks"
,
count
,
total_counter
,
hiderare
);
readResult
(
data
.
advancedmasks
[
"othermasks"
],
"othermasks"
,
count
,
data
.
total_counter
,
hiderare
);
}
}
}
}
...
@@ -290,18 +255,7 @@ pair<uint, uint> get_masks(const string& password, PasswordStats& c){
...
@@ -290,18 +255,7 @@ pair<uint, uint> get_masks(const string& password, PasswordStats& c){
return
make_pair
(
sizeSimpleMask
,
sizeAdvancedMask
);
return
make_pair
(
sizeSimpleMask
,
sizeAdvancedMask
);
}
}
void
updateMinMax
(
minMax
&
m
,
const
Policy
&
pol
)
{
void
handle_password
(
const
string
&
password
,
const
uint64_t
&
nbPasswords
,
ThreadData
*
my_data
){
m
.
mindigit
=
min
(
m
.
mindigit
,
pol
.
digit
);
m
.
maxdigit
=
max
(
m
.
maxdigit
,
pol
.
digit
);
m
.
minlower
=
min
(
m
.
minlower
,
pol
.
lower
);
m
.
maxlower
=
max
(
m
.
maxlower
,
pol
.
lower
);
m
.
minupper
=
min
(
m
.
minupper
,
pol
.
upper
);
m
.
maxupper
=
max
(
m
.
maxupper
,
pol
.
upper
);
m
.
minspecial
=
min
(
m
.
minspecial
,
pol
.
special
);
m
.
maxspecial
=
max
(
m
.
maxspecial
,
pol
.
special
);
}
void
handle_password
(
const
string
&
password
,
const
uint64_t
&
nbPasswords
,
thread_data
*
my_data
){
my_data
->
total_counter
+=
nbPasswords
;
my_data
->
total_counter
+=
nbPasswords
;
if
(
my_data
->
use_regex
&&
!
regex_match
(
password
,
my_data
->
current_regex
)){
if
(
my_data
->
use_regex
&&
!
regex_match
(
password
,
my_data
->
current_regex
)){
return
;
return
;
...
@@ -326,11 +280,11 @@ void handle_password(const string& password, const uint64_t& nbPasswords, thread
...
@@ -326,11 +280,11 @@ void handle_password(const string& password, const uint64_t& nbPasswords, thread
my_data
->
charactersets
[
c
.
pol
]
+=
nbPasswords
;
my_data
->
charactersets
[
c
.
pol
]
+=
nbPasswords
;
my_data
->
simplemasks
[
c
.
simplemask_string
]
+=
nbPasswords
;
my_data
->
simplemasks
[
c
.
simplemask_string
]
+=
nbPasswords
;
my_data
->
advancedmasks
[
c
.
advancedmask_string
]
+=
nbPasswords
;
my_data
->
advancedmasks
[
c
.
advancedmask_string
]
+=
nbPasswords
;
updateMinMax
(
my_data
->
minMaxValue
,
c
.
pol
);
my_data
->
minMaxValue
.
updateMinMax
(
c
.
pol
);
}
}
void
*
generate_stats_thread_queue
(
void
*
threadarg
)
{
void
*
generate_stats_thread_queue
(
void
*
threadarg
)
{
struct
t
hread
_d
ata
*
my_data
=
(
struct
t
hread
_d
ata
*
)
threadarg
;
T
hread
D
ata
*
my_data
=
(
T
hread
D
ata
*
)
threadarg
;
string
line
;
string
line
;
uint64_t
nbline
=
0
;
uint64_t
nbline
=
0
;
...
@@ -346,7 +300,7 @@ void* generate_stats_thread_queue(void* threadarg) {
...
@@ -346,7 +300,7 @@ void* generate_stats_thread_queue(void* threadarg) {
}
}
void
*
generate_stats_thread
(
void
*
threadarg
)
{
void
*
generate_stats_thread
(
void
*
threadarg
)
{
struct
t
hread
_d
ata
*
my_data
=
(
struct
t
hread
_d
ata
*
)
threadarg
;
T
hread
D
ata
*
my_data
=
(
T
hread
D
ata
*
)
threadarg
;
ifstream
readfile
(
my_data
->
filename
);
ifstream
readfile
(
my_data
->
filename
);
uint64_t
nbline
=
0
;
uint64_t
nbline
=
0
;
...
...
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