Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
1f3d263c
Commit
1f3d263c
authored
Nov 17, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix difference in captcha hash calculation between js and py
parent
c4c42a6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
15 deletions
+37
-15
base_form.html
base_form.html
+7
-3
comex_merci_pour_les_infos.py.cgi
cgi-bin/comex_merci_pour_les_infos.py.cgi
+20
-7
comex_reg_form_controllers.js
static/js/comex_reg_form_controllers.js
+0
-2
jquery.realperson.js
static/js/realperson/jquery.realperson.js
+10
-3
No files found.
base_form.html
View file @
1f3d263c
...
@@ -18,8 +18,14 @@
...
@@ -18,8 +18,14 @@
<!-- libs -->
<!-- libs -->
<script
type=
"text/javascript"
src=
"static/js/jquery-3.1.1.min.js"
></script>
<script
type=
"text/javascript"
src=
"static/js/jquery-3.1.1.min.js"
></script>
<script
type=
"text/javascript"
src=
"static/js/jquery-ui-1.12.1/jquery-ui.min.js"
></script>
<script
type=
"text/javascript"
src=
"static/js/jquery-ui-1.12.1/jquery-ui.min.js"
></script>
<!-- possible to change it and send it each time with makeSalt-->
<script
type=
"text/javascript"
>
$
.
salt
=
'verylonverylongverylonverylongverylonverylong'
</script>
<script
type=
"text/javascript"
src=
"static/js/realperson/jquery.plugin.min.js"
></script>
<script
type=
"text/javascript"
src=
"static/js/realperson/jquery.plugin.min.js"
></script>
<script
type=
"text/javascript"
src=
"static/js/realperson/jquery.realperson.min.js"
></script>
<!-- for some reason jquery.realperson.min.js reacts differently to salt than jquery.realperson.js -->
<script
type=
"text/javascript"
src=
"static/js/realperson/jquery.realperson.js"
></script>
<!-- our js is at the end -->
<!-- our js is at the end -->
<!-- Piwik -->
<!-- Piwik -->
...
@@ -69,8 +75,6 @@
...
@@ -69,8 +75,6 @@
</div>
</div>
<!-- ########################### ( debg ) ########################## -->
<!-- ########################### ( debg ) ########################## -->
<!-- test cgi user from submit point of view -->
<!-- test cgi user from submit point of view -->
<!-- <form id="test_user_form" enctype="multipart/form-data"
<!-- <form id="test_user_form" enctype="multipart/form-data"
...
...
cgi-bin/comex_merci_pour_les_infos.py.cgi
View file @
1f3d263c
...
@@ -20,7 +20,7 @@ __status__ = "Test"
...
@@ -20,7 +20,7 @@ __status__ = "Test"
from
cgi
import
FieldStorage
from
cgi
import
FieldStorage
from
traceback
import
format_exc
,
format_tb
from
traceback
import
format_exc
,
format_tb
from
ctypes
import
c_int
from
ctypes
import
c_int
32
from
re
import
sub
from
re
import
sub
from
jinja2
import
Template
,
Environment
,
FileSystemLoader
from
jinja2
import
Template
,
Environment
,
FileSystemLoader
from
sys
import
stdout
# for direct buffer write of utf-8 bytes
from
sys
import
stdout
# for direct buffer write of utf-8 bytes
...
@@ -62,25 +62,34 @@ COLS = [ ("doors_uid", True, 36),
...
@@ -62,25 +62,34 @@ COLS = [ ("doors_uid", True, 36),
########### SUBS ###########
########### SUBS ###########
def
re_hash
(
userinput
,
salt
=
""
):
def
re_hash
(
userinput
,
salt
=
"
verylonverylongverylonverylongverylonverylong
"
):
"""
"""
Build the captcha's verification hash server side
Build the captcha's verification hash server side
(my rewrite of keith-wood.name/realPerson.html python's version)
(my rewrite of keith-wood.name/realPerson.html python's version)
NB the number of iterations is prop to salt length
<< 5 pads binary repr by 5 zeros on the right (including possible change of sign)
NB in all languages except python it truncates on the left
=> here we need to emulate the same mechanism
=> using c_int32() works well
"""
"""
hashk
=
5381
hashk
=
5381
value
=
userinput
.
upper
()
+
salt
value
=
userinput
.
upper
()
+
salt
for
i
,
char
in
enumerate
(
value
):
hashk
=
c_int
(
((
hashk
<<
5
)
+
hashk
+
ord
(
char
))
&
0xFFFFFFFF
)
.
value
# debug
# bitwise masks 0xFFFFFFFF to go back to int32 each time
# print_to_buffer("<br/><br/><br/><br/><br/><br/>evaluated value:"+value)
# c_int( previous ).value to go from unsigned ints to c signed ints each time
for
i
,
char
in
enumerate
(
value
):
hashk
=
c_int32
(
hashk
<<
5
)
.
value
+
hashk
+
ord
(
char
)
# debug iterations
# debug iterations
# print
(i, hashk,
'<br/>')
# print
_to_buffer(str(i) + ": " + str(hashk) +
'<br/>')
return
hashk
return
hashk
def
get_template
(
filename
):
def
get_template
(
filename
):
"""
"""
Retrieve a jinja2 template from ../templates
Retrieve a jinja2 template from ../templates
...
@@ -157,6 +166,10 @@ if __name__ == "__main__":
...
@@ -157,6 +166,10 @@ if __name__ == "__main__":
if
'my-captcha'
in
incoming_data
:
if
'my-captcha'
in
incoming_data
:
captcha_userinput
=
incoming_data
[
'my-captcha'
]
.
value
captcha_userinput
=
incoming_data
[
'my-captcha'
]
.
value
captcha_verifhash
=
int
(
incoming_data
[
'my-captchaHash'
]
.
value
)
captcha_verifhash
=
int
(
incoming_data
[
'my-captchaHash'
]
.
value
)
# dbg
# print_to_buffer(str(captcha_verifhash))
captcha_userhash
=
re_hash
(
captcha_userinput
)
captcha_userhash
=
re_hash
(
captcha_userinput
)
captcha_accepted
=
(
captcha_userhash
==
captcha_verifhash
)
captcha_accepted
=
(
captcha_userhash
==
captcha_verifhash
)
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
...
...
static/js/comex_reg_form_controllers.js
View file @
1f3d263c
...
@@ -624,9 +624,7 @@ $(function() {
...
@@ -624,9 +624,7 @@ $(function() {
// pseudo captcha
// pseudo captcha
$
.
salt
=
''
$
(
'#my-captcha'
).
realperson
({
length
:
realCaptchaLength
});
$
(
'#my-captcha'
).
realperson
({
length
:
realCaptchaLength
});
$
(
'#my-captcha'
).
val
(
''
)
$
(
'#my-captcha'
).
val
(
''
)
...
...
static/js/realperson/jquery.realperson.js
View file @
1f3d263c
...
@@ -155,6 +155,7 @@
...
@@ -155,6 +155,7 @@
@return {number} The hash value. */
@return {number} The hash value. */
getHash
:
function
(
elem
)
{
getHash
:
function
(
elem
)
{
var
inst
=
this
.
_getInst
(
elem
);
var
inst
=
this
.
_getInst
(
elem
);
// console.log("inst", inst)
return
inst
?
inst
.
hash
:
0
;
return
inst
?
inst
.
hash
:
0
;
},
},
...
@@ -202,15 +203,21 @@
...
@@ -202,15 +203,21 @@
@param value {string} The text to hash.
@param value {string} The text to hash.
@return {number} The corresponding hash value. */
@return {number} The corresponding hash value. */
function
hash
(
value
)
{
function
hash
(
value
)
{
console
.
log
(
"original value:"
,
value
)
// dbg
// console.log("original value:", value)
var
hash
=
5381
;
var
hash
=
5381
;
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
hash
=
((
hash
<<
5
)
+
hash
)
+
value
.
charCodeAt
(
i
);
hash
=
((
hash
<<
5
)
+
hash
)
+
value
.
charCodeAt
(
i
);
console
.
log
(
i
,
hash
)
// dbg
// console.log(i, hash)
}
}
console
.
log
(
"hashed value:"
,
hash
)
// dbg
// console.log("hashed value:", hash)
return
hash
;
return
hash
;
}
}
})(
jQuery
);
})(
jQuery
);
// console.log("loaded realperson")
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