Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dcs_classifier
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
dcs_classifier
Commits
ba33583b
Commit
ba33583b
authored
Jul 11, 2014
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support plain text database input
parent
5da8b391
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
18 deletions
+44
-18
gen_dcs_classifier.pl
src/gen_dcs_classifier.pl
+44
-18
No files found.
src/gen_dcs_classifier.pl
View file @
ba33583b
...
...
@@ -34,6 +34,7 @@ use Carp;
use
Crypt::
RC4
;
use
Digest::
MD5
(
qw(md5)
);
use
MIME::
Base64
;
use
Fcntl
qw(SEEK_SET)
;
# avoid dependency
# use Carp::Assert;
...
...
@@ -380,31 +381,56 @@ sub load_classifier_db($$) {
open
(
$fh
,
'<'
,
$fname
)
||
die
'cant open '
.
$fname
.
' '
.
$!
;
binmode
(
$fh
);
my
$crypt_data
;
{
my
$b64
;
# files starting with a # are considered un-encrypted
my
$plainmode
;
die
'error reading '
.
$fname
.
' '
.
$!
unless
(
defined
(
read
(
$fh
,
$plainmode
,
1
)));
die
'seek error on '
.
$fname
.
' '
.
$!
unless
(
seek
(
$fh
,
0
,
SEEK_SET
));
undef
$plainmode
if
(
$plainmode
ne
"#"
);
my
$plain
;
my
$hash_plain
;
unless
(
defined
(
$plainmode
))
{
my
$crypt_data
;
{
my
$b64
;
my
$sz
=
(
-
s
$fh
);
my
$res
=
read
(
$fh
,
$b64
,
$sz
);
die
'error reading '
.
$fname
.
' '
.
$!
if
(
!
defined
(
$res
));
die
'only read '
.
$res
.
' bytes of '
.
$sz
if
(
$res
<
$sz
);
$crypt_data
=
decode_base64
(
$b64
);
die
'no data after base64 decode'
unless
(
defined
(
$crypt_data
)
&&
(
length
(
$crypt_data
))
>
0
);
}
$plain
=
RC4
(
compute_key
(
$secret
),
substr
(
$crypt_data
,
32
));
die
'no data after decrypt'
unless
(
defined
(
$plain
)
&&
(
length
(
$plain
))
>
0
);
# check hash
my
$h_file
=
substr
(
$crypt_data
,
0
,
32
);
$hash_plain
=
unpack
(
'H*'
,
md5
(
$plain
));
die
'checksum error: file '
.
$h_file
.
' decrypt '
.
$hash_plain
if
(
$h_file
ne
$hash_plain
);
}
else
{
my
$sz
=
(
-
s
$fh
);
my
$res
=
read
(
$fh
,
$
b64
,
$sz
);
my
$res
=
read
(
$fh
,
$
plain
,
$sz
);
die
'error reading '
.
$fname
.
' '
.
$!
if
(
!
defined
(
$res
));
die
'only read '
.
$res
.
' bytes of '
.
$sz
if
(
$res
<
$sz
);
$crypt_data
=
decode_base64
(
$b64
);
die
'no data after base64 decode'
unless
(
defined
(
$crypt_data
)
&&
(
length
(
$crypt_data
))
>
0
)
$hash_plain
=
unpack
(
'H*'
,
md5
(
$plain
));
die
'no data from plain file'
unless
(
defined
(
$plain
)
&&
(
length
(
$plain
))
>
0
);
}
close
(
$fh
);
my
$decrypt
=
RC4
(
compute_key
(
$secret
),
substr
(
$crypt_data
,
32
));
my
$h_file
;
{
$h_file
=
substr
(
$crypt_data
,
0
,
32
);
my
$h_decrypt
=
unpack
(
'H*'
,
md5($d
ecrypt
));
die
'checksum error: file '
.
$h_file
.
' decrypt '
.
$h_decrypt
if
(
$h_file
ne
$h_decrypt
);
}
return
wantarray
?
(
\
$decrypt
,
$h_file
)
:
\
$decrypt
;
return
wantarray
?
(
\
$plain
,
$hash_plain
)
:
\
$plain
;
}
sub
enum_name
($$)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment