Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
44b4efe3
Commit
44b4efe3
authored
21 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Tests, headers, and debugging for onion skin backend
svn:r263
parent
96759a60
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/or/onion.c
+41
-8
41 additions, 8 deletions
src/or/onion.c
src/or/or.h
+15
-0
15 additions, 0 deletions
src/or/or.h
src/or/test.c
+43
-1
43 additions, 1 deletion
src/or/test.c
with
99 additions
and
9 deletions
src/or/onion.c
+
41
−
8
View file @
44b4efe3
...
@@ -855,7 +855,7 @@ onion_skin_create(crypto_pk_env_t *router_key,
...
@@ -855,7 +855,7 @@ onion_skin_create(crypto_pk_env_t *router_key,
*
handshake_state_out
=
NULL
;
*
handshake_state_out
=
NULL
;
memset
(
onion_skin_out
,
0
,
208
);
memset
(
onion_skin_out
,
0
,
208
);
memset
(
iv
,
0
,
16
);
/* XXXX This can't be safe, can it? */
memset
(
iv
,
0
,
16
);
if
(
!
(
dh
=
crypto_dh_new
()))
if
(
!
(
dh
=
crypto_dh_new
()))
goto
err
;
goto
err
;
...
@@ -863,29 +863,51 @@ onion_skin_create(crypto_pk_env_t *router_key,
...
@@ -863,29 +863,51 @@ onion_skin_create(crypto_pk_env_t *router_key,
dhbytes
=
crypto_dh_get_bytes
(
dh
);
dhbytes
=
crypto_dh_get_bytes
(
dh
);
pkbytes
=
crypto_pk_keysize
(
router_key
);
pkbytes
=
crypto_pk_keysize
(
router_key
);
assert
(
dhbytes
+
16
==
208
);
assert
(
dhbytes
+
16
==
208
);
if
(
!
(
pubkey
=
malloc
(
dhbytes
)))
if
(
!
(
pubkey
=
malloc
(
dhbytes
+
16
)))
goto
err
;
goto
err
;
if
(
crypto_rand
(
16
,
pubkey
))
if
(
crypto_rand
(
16
,
pubkey
))
goto
err
;
goto
err
;
/* XXXX You can't just run around RSA-encrypting any bitstream: if it's
* greater than the RSA key, then OpenSSL will happily encrypt,
* and later decrypt to the wrong value. So we set the first bit
* of 'pubkey' to 0. This means that our symmetric key is really only
* 127 bits long, but since it shouldn't be necessary to encrypt
* DH public keys values in the first place, we should be fine.
*/
pubkey
[
0
]
&=
0x7f
;
if
(
crypto_dh_get_public
(
dh
,
pubkey
+
16
,
dhbytes
))
if
(
crypto_dh_get_public
(
dh
,
pubkey
+
16
,
dhbytes
))
goto
err
;
goto
err
;
#if 0
printf("Client DH sent: %x %x %x ... %x %x %x\n",
(int) pubkey[16], (int) pubkey[17], (int) pubkey[18],
(int) pubkey[205], (int) pubkey[206], (int) pubkey[207]);
printf("Client key sent: %x %x %x ... %x %x %x\n",
pubkey[0],pubkey[1],pubkey[2],
pubkey[13],pubkey[14],pubkey[15]);
#endif
cipher
=
crypto_create_init_cipher
(
CRYPTO_CIPHER_3DES
,
pubkey
,
iv
,
1
);
if
(
!
cipher
)
goto
err
;
if
(
crypto_pk_public_encrypt
(
router_key
,
pubkey
,
pkbytes
,
if
(
crypto_pk_public_encrypt
(
router_key
,
pubkey
,
pkbytes
,
onion_skin_out
,
RSA_NO_PADDING
))
onion_skin_out
,
RSA_NO_PADDING
)
==-
1
)
goto
err
;
goto
err
;
cipher
=
crypto_create_init_cipher
(
CRYPTO_CIPHER_3DES
,
pubkey
,
iv
,
1
);
if
(
crypto_cipher_encrypt
(
cipher
,
pubkey
+
pkbytes
,
dhbytes
+
16
-
pkbytes
,
if
(
crypto_cipher_encrypt
(
cipher
,
pubkey
+
pkbytes
,
dhbytes
-
16
-
pkbytes
,
onion_skin_out
+
pkbytes
))
onion_skin_out
+
pkbytes
))
goto
err
;
goto
err
;
free
(
pubkey
);
free
(
pubkey
);
crypto_free_cipher_env
(
cipher
);
crypto_free_cipher_env
(
cipher
);
*
handshake_state_out
=
dh
;
*
handshake_state_out
=
dh
;
return
0
;
return
0
;
err:
err:
if
(
pubkey
)
free
(
pubkey
);
if
(
pubkey
)
free
(
pubkey
);
...
@@ -916,14 +938,25 @@ onion_skin_server_handshake(char *onion_skin, /* 208 bytes long */
...
@@ -916,14 +938,25 @@ onion_skin_server_handshake(char *onion_skin, /* 208 bytes long */
if
(
crypto_pk_private_decrypt
(
private_key
,
if
(
crypto_pk_private_decrypt
(
private_key
,
onion_skin
,
pkbytes
,
onion_skin
,
pkbytes
,
buf
,
RSA_NO_PADDING
))
buf
,
RSA_NO_PADDING
)
==
-
1
)
goto
err
;
goto
err
;
#if 0
printf("Client key got: %x %x %x ... %x %x %x\n",
buf[0],buf[1],buf[2], buf[13],buf[14],buf[15]);
#endif
cipher
=
crypto_create_init_cipher
(
CRYPTO_CIPHER_3DES
,
buf
,
iv
,
0
);
cipher
=
crypto_create_init_cipher
(
CRYPTO_CIPHER_3DES
,
buf
,
iv
,
0
);
if
(
crypto_cipher_decrypt
(
cipher
,
onion_skin
+
pkbytes
,
208
-
pkbytes
,
if
(
crypto_cipher_decrypt
(
cipher
,
onion_skin
+
pkbytes
,
208
-
pkbytes
,
buf
+
pkbytes
))
buf
+
pkbytes
))
goto
err
;
goto
err
;
#if 0
printf("Client DH got: %x %x %x ... %x %x %x\n",
(int) buf[16], (int) buf[17], (int) buf[18],
(int) buf[205], (int) buf[206], (int) buf[207]);
#endif
dh
=
crypto_dh_new
();
dh
=
crypto_dh_new
();
if
(
crypto_dh_get_public
(
dh
,
handshake_reply_out
,
192
))
if
(
crypto_dh_get_public
(
dh
,
handshake_reply_out
,
192
))
...
...
This diff is collapsed.
Click to expand it.
src/or/or.h
+
15
−
0
View file @
44b4efe3
...
@@ -793,6 +793,21 @@ void init_tracked_tree(void);
...
@@ -793,6 +793,21 @@ void init_tracked_tree(void);
void
onion_pack
(
char
*
dest
,
onion_layer_t
*
src
);
void
onion_pack
(
char
*
dest
,
onion_layer_t
*
src
);
void
onion_unpack
(
onion_layer_t
*
dest
,
char
*
src
);
void
onion_unpack
(
onion_layer_t
*
dest
,
char
*
src
);
int
onion_skin_create
(
crypto_pk_env_t
*
router_key
,
crypto_dh_env_t
**
handshake_state_out
,
char
*
onion_skin_out
);
/* Must be 208 bytes long */
int
onion_skin_server_handshake
(
char
*
onion_skin
,
/* 208 bytes long */
crypto_pk_env_t
*
private_key
,
char
*
handshake_reply_out
,
/* 192 bytes long */
char
*
key_out
,
int
key_out_len
);
int
onion_skin_client_handshake
(
crypto_dh_env_t
*
handshake_state
,
char
*
handshake_reply
,
/* Must be 192 bytes long*/
char
*
key_out
,
int
key_out_len
);
/********************************* routers.c ***************************/
/********************************* routers.c ***************************/
int
learn_my_address
(
struct
sockaddr_in
*
me
);
int
learn_my_address
(
struct
sockaddr_in
*
me
);
...
...
This diff is collapsed.
Click to expand it.
src/or/test.c
+
43
−
1
View file @
44b4efe3
...
@@ -460,6 +460,46 @@ test_util() {
...
@@ -460,6 +460,46 @@ test_util() {
}
}
void
test_onion_handshake
()
{
int
i
;
/* client-side */
crypto_dh_env_t
*
c_dh
=
NULL
;
char
c_buf
[
208
];
char
c_keys
[
40
];
/* server-side */
char
s_buf
[
192
];
char
s_keys
[
40
];
/* shared */
crypto_pk_env_t
*
pk
=
NULL
;
pk
=
crypto_new_pk_env
(
CRYPTO_PK_RSA
);
test_assert
(
!
crypto_pk_generate_key
(
pk
));
/* client handshake 1. */
memset
(
c_buf
,
0
,
208
);
test_assert
(
!
onion_skin_create
(
pk
,
&
c_dh
,
c_buf
));
/* server handshake */
memset
(
s_buf
,
0
,
192
);
memset
(
s_keys
,
0
,
40
);
test_assert
(
!
onion_skin_server_handshake
(
c_buf
,
pk
,
s_buf
,
s_keys
,
40
));
/* client handshake 2 */
memset
(
c_keys
,
0
,
40
);
test_assert
(
!
onion_skin_client_handshake
(
c_dh
,
s_buf
,
c_keys
,
40
));
crypto_dh_free
(
c_dh
);
crypto_free_pk_env
(
pk
);
test_memeq
(
c_keys
,
s_keys
,
40
);
memset
(
s_buf
,
0
,
40
);
test_memneq
(
c_keys
,
s_buf
,
40
);
}
int
int
main
(
int
c
,
char
**
v
)
{
main
(
int
c
,
char
**
v
)
{
#if 0
#if 0
...
@@ -476,8 +516,10 @@ main(int c, char**v) {
...
@@ -476,8 +516,10 @@ main(int c, char**v) {
puts
(
"========================== Crypto =========================="
);
puts
(
"========================== Crypto =========================="
);
test_crypto_dh
();
test_crypto_dh
();
test_crypto
();
test_crypto
();
puts
(
"
\n
=========================
=
Util ============================"
);
puts
(
"
\n
========================= Util ============================"
);
test_util
();
test_util
();
puts
(
"
\n
========================= Onion Skins======================"
);
test_onion_handshake
();
puts
(
""
);
puts
(
""
);
return
0
;
return
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