mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 20:30:38 +09:00
Compare commits
625 Commits
libssh-0.6
...
libssh-0.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64a2d37c30 | ||
|
|
9d5cf209df | ||
|
|
1039732154 | ||
|
|
7ad80ba1cc | ||
|
|
acb0e4f401 | ||
|
|
3fe7510b26 | ||
|
|
734e3ce674 | ||
|
|
e4c6d591df | ||
|
|
f81ca61612 | ||
|
|
c20b360c96 | ||
|
|
5e061962c5 | ||
|
|
f1d57223db | ||
|
|
b9033ad56a | ||
|
|
e5ff7aa410 | ||
|
|
3837a0547f | ||
|
|
7985acb768 | ||
|
|
acd6a1ca8a | ||
|
|
ddea46f890 | ||
|
|
e5f0e711b0 | ||
|
|
e765c1400a | ||
|
|
7a7c0a54bc | ||
|
|
9c62d6dfcd | ||
|
|
f3f140e65f | ||
|
|
c977a97093 | ||
|
|
743a34ad9f | ||
|
|
0f9e6598ef | ||
|
|
f8007d7147 | ||
|
|
3d70d4f08d | ||
|
|
bade29d3d5 | ||
|
|
399ff6bbde | ||
|
|
c0d9aeda18 | ||
|
|
82b2d31c29 | ||
|
|
74102dfd7a | ||
|
|
d678f6a9ea | ||
|
|
00b8e6d1f0 | ||
|
|
aeb859e130 | ||
|
|
b393f7e5e9 | ||
|
|
2004617fd0 | ||
|
|
c5fe7c5a72 | ||
|
|
fec4dc4eff | ||
|
|
3d0c9cc6b5 | ||
|
|
4d6048ef88 | ||
|
|
3d2d777e26 | ||
|
|
8520adf609 | ||
|
|
c0be59f876 | ||
|
|
2983b21996 | ||
|
|
88ae595583 | ||
|
|
a228c3f728 | ||
|
|
53ed121a9c | ||
|
|
5a1ebdec9d | ||
|
|
bf2a33b21e | ||
|
|
130194aa0e | ||
|
|
1ebfd3834a | ||
|
|
1eeeace975 | ||
|
|
73ebcb3ab8 | ||
|
|
bd7b509278 | ||
|
|
652acbeb21 | ||
|
|
96e04d4691 | ||
|
|
7113074ae4 | ||
|
|
2db325eb74 | ||
|
|
9937d0b552 | ||
|
|
ae3e2a19c8 | ||
|
|
3567524fb2 | ||
|
|
4814c188eb | ||
|
|
a317188cb7 | ||
|
|
1d4151e51f | ||
|
|
c228fa7631 | ||
|
|
9658d36087 | ||
|
|
bbaa3dc869 | ||
|
|
4f10d6cd57 | ||
|
|
2209fcace3 | ||
|
|
a1847660a3 | ||
|
|
e2b48dc662 | ||
|
|
1a5b6ac472 | ||
|
|
0dd7a963a9 | ||
|
|
1642cec280 | ||
|
|
2f1c6668e7 | ||
|
|
fbeecf388c | ||
|
|
7933756b5a | ||
|
|
837e367d2d | ||
|
|
f81c3ada9c | ||
|
|
83663895f4 | ||
|
|
239d0f75b5 | ||
|
|
d88cc720fb | ||
|
|
ee13becf9c | ||
|
|
95b2dbbeca | ||
|
|
02c0a3b99b | ||
|
|
419731a189 | ||
|
|
2ac987bce9 | ||
|
|
0588cbf9d4 | ||
|
|
a7cce77550 | ||
|
|
5e63b40cde | ||
|
|
7b8b5eb4ea | ||
|
|
8dc3d883b8 | ||
|
|
24a3f7020c | ||
|
|
f74d5d5df4 | ||
|
|
7a21187fb9 | ||
|
|
439d3039e3 | ||
|
|
61cbf160a0 | ||
|
|
ce029c0735 | ||
|
|
8a2deeb3cc | ||
|
|
40164c348e | ||
|
|
9d7f873fd3 | ||
|
|
c5d320811b | ||
|
|
410f722ae5 | ||
|
|
8155b3c0a0 | ||
|
|
6836ffa103 | ||
|
|
b62b822100 | ||
|
|
849f5db5d1 | ||
|
|
a6493efcae | ||
|
|
1b0bf852be | ||
|
|
2b3185ec29 | ||
|
|
d63547b18a | ||
|
|
6697f85b50 | ||
|
|
67fe6f56ea | ||
|
|
b5ce15eefa | ||
|
|
a3688ada1a | ||
|
|
219d0bba42 | ||
|
|
bf3d8f3ad4 | ||
|
|
04a5d5bd74 | ||
|
|
2957aaf9f0 | ||
|
|
8360139506 | ||
|
|
0bf78b0b8b | ||
|
|
faca78f547 | ||
|
|
7da587ba6c | ||
|
|
c7aa51240d | ||
|
|
cdf7690e03 | ||
|
|
7b19719022 | ||
|
|
f8d0026c65 | ||
|
|
6b608e70ee | ||
|
|
a69a1af568 | ||
|
|
32b72555ee | ||
|
|
32af6a2390 | ||
|
|
b470dd943f | ||
|
|
69ca977aed | ||
|
|
728a6349b7 | ||
|
|
ec32174abc | ||
|
|
2172cd234a | ||
|
|
0425ac9ad0 | ||
|
|
367558bb21 | ||
|
|
186e7b5ca4 | ||
|
|
2197704693 | ||
|
|
229eb8715d | ||
|
|
1b18a06f8c | ||
|
|
91b513798e | ||
|
|
25234e510a | ||
|
|
d16eac5704 | ||
|
|
46bff47975 | ||
|
|
f718b50b3f | ||
|
|
58b7d0f5d2 | ||
|
|
30d4581be5 | ||
|
|
83387f957f | ||
|
|
f3620bbbad | ||
|
|
b45933d30d | ||
|
|
1613ed556d | ||
|
|
8f5b7b65eb | ||
|
|
053f72c671 | ||
|
|
63a8f333b8 | ||
|
|
57fd8e3187 | ||
|
|
03972b16c9 | ||
|
|
ac7ed82585 | ||
|
|
196c2e9c1f | ||
|
|
1accbcb98b | ||
|
|
342ae10f08 | ||
|
|
eb98a780ed | ||
|
|
64233fa3bb | ||
|
|
cbf5cf4ac3 | ||
|
|
a3f3f9cb76 | ||
|
|
5aeae08be0 | ||
|
|
64a658acaa | ||
|
|
361940a5d7 | ||
|
|
2721cbc8ee | ||
|
|
5eb7a6ca38 | ||
|
|
3f4b5436e5 | ||
|
|
82cf5ea24c | ||
|
|
90e4786523 | ||
|
|
f65f41acc2 | ||
|
|
8979150745 | ||
|
|
f81d296e54 | ||
|
|
57afe78167 | ||
|
|
ee460dc04b | ||
|
|
f134cb3d57 | ||
|
|
3eaad77de2 | ||
|
|
9244750a63 | ||
|
|
e8720a30e2 | ||
|
|
ad09009201 | ||
|
|
e4e3b3052f | ||
|
|
96882cc58c | ||
|
|
7c79959e94 | ||
|
|
ca501df8c8 | ||
|
|
a4cecf59d5 | ||
|
|
244881b87d | ||
|
|
cf05e653de | ||
|
|
4b9916136d | ||
|
|
33ecff11dd | ||
|
|
83d3ee7fdb | ||
|
|
b1a3f4ee33 | ||
|
|
05498e0e33 | ||
|
|
4948fe21cd | ||
|
|
fe8fcb805c | ||
|
|
c4af6fbce3 | ||
|
|
3091025472 | ||
|
|
bf0c7ae0ae | ||
|
|
b5dc8197f7 | ||
|
|
19e23e6128 | ||
|
|
195f25cfbd | ||
|
|
1cb940c44a | ||
|
|
3f04367fb8 | ||
|
|
6c7e552509 | ||
|
|
b1cb8de385 | ||
|
|
69c9cd029f | ||
|
|
c699b9ca94 | ||
|
|
53586ed4ba | ||
|
|
5236358a48 | ||
|
|
d6fe9dc220 | ||
|
|
e0a73d3dbe | ||
|
|
dbe7df7571 | ||
|
|
a3357b8920 | ||
|
|
7ec798d3e7 | ||
|
|
f32e5f2191 | ||
|
|
cd078c7085 | ||
|
|
2e445d5871 | ||
|
|
5c46fbc680 | ||
|
|
2a780afc57 | ||
|
|
940cb233ce | ||
|
|
a653e27a2e | ||
|
|
d3f30da158 | ||
|
|
760d93e87b | ||
|
|
d42a1a35b0 | ||
|
|
8af829a42a | ||
|
|
ad8fa427dd | ||
|
|
de10a7754b | ||
|
|
6789170799 | ||
|
|
afc9988c93 | ||
|
|
2490404d45 | ||
|
|
fbdb940c46 | ||
|
|
c8d0b724b3 | ||
|
|
9e4700cdc0 | ||
|
|
b76d37b341 | ||
|
|
423fa6818b | ||
|
|
61e2c8f0f7 | ||
|
|
c02b260e7e | ||
|
|
01a6004171 | ||
|
|
4f5660e081 | ||
|
|
46bc11f977 | ||
|
|
119840b0a9 | ||
|
|
4343ac5b08 | ||
|
|
6b9183a20b | ||
|
|
3ec3a926e5 | ||
|
|
2f7886837f | ||
|
|
7febad5821 | ||
|
|
b235c380f2 | ||
|
|
f6a50aff4c | ||
|
|
6b7f275c32 | ||
|
|
4bde48bb2e | ||
|
|
f4154c503b | ||
|
|
8db4520d89 | ||
|
|
9a7d450098 | ||
|
|
7070117dc3 | ||
|
|
433f8fd550 | ||
|
|
c6590bd189 | ||
|
|
929868c691 | ||
|
|
06a0d8ff1c | ||
|
|
af0dd3fb02 | ||
|
|
ce02f6576a | ||
|
|
68e720a3da | ||
|
|
c224508bf8 | ||
|
|
15d71a8c51 | ||
|
|
8536cd9808 | ||
|
|
353751e3e3 | ||
|
|
159ef828dd | ||
|
|
3dd069c0c8 | ||
|
|
a198193723 | ||
|
|
e051135a05 | ||
|
|
bb18442fe8 | ||
|
|
c2aed4ca78 | ||
|
|
b7b535816d | ||
|
|
d8e691b58a | ||
|
|
52968b1a11 | ||
|
|
b35f1f488c | ||
|
|
10f71c6769 | ||
|
|
014fde0542 | ||
|
|
ca2acec34a | ||
|
|
bb197de75d | ||
|
|
03095f1516 | ||
|
|
6895d0b727 | ||
|
|
4745d652b5 | ||
|
|
a48711ae7e | ||
|
|
a25790d343 | ||
|
|
cd2dc3770a | ||
|
|
250f506487 | ||
|
|
9dc932c02b | ||
|
|
aaae6cd97d | ||
|
|
509676e3a4 | ||
|
|
a6d412f0d7 | ||
|
|
59da8dab50 | ||
|
|
7edbedf0dd | ||
|
|
af25c5e668 | ||
|
|
092fe0b727 | ||
|
|
1ddb99c46f | ||
|
|
93c7b81b4e | ||
|
|
93e82fa0c0 | ||
|
|
e9b2d164e0 | ||
|
|
86ae6b2251 | ||
|
|
2cb2587b55 | ||
|
|
86294ad3ea | ||
|
|
173994786b | ||
|
|
81123d6a91 | ||
|
|
25eb9c4914 | ||
|
|
c6210f5aef | ||
|
|
c673543e54 | ||
|
|
edca9d6e96 | ||
|
|
83aed7610c | ||
|
|
5fa4721c6e | ||
|
|
8b7627efd5 | ||
|
|
662217f409 | ||
|
|
19433dca00 | ||
|
|
6961dd79ad | ||
|
|
1b6375ce89 | ||
|
|
64f6abead7 | ||
|
|
f20a6d0a82 | ||
|
|
97c6b76863 | ||
|
|
6019cf1bed | ||
|
|
228dc08038 | ||
|
|
33cd594f1f | ||
|
|
0cd0f685c9 | ||
|
|
664b94d1c5 | ||
|
|
3b4b0f01ec | ||
|
|
7bd62dd652 | ||
|
|
c341da03d3 | ||
|
|
c238136010 | ||
|
|
5a08ddcff2 | ||
|
|
a182926024 | ||
|
|
9457685320 | ||
|
|
e9fd14c7f0 | ||
|
|
cfd2e4894e | ||
|
|
3703389feb | ||
|
|
673990f568 | ||
|
|
97638a1465 | ||
|
|
506e11fa8b | ||
|
|
1dd95675df | ||
|
|
cb10ad0c84 | ||
|
|
1f2c61d6ad | ||
|
|
1d97f75b0a | ||
|
|
835e34d1eb | ||
|
|
13c42bff3f | ||
|
|
59a1799501 | ||
|
|
d9c47a8cfa | ||
|
|
987991a3f2 | ||
|
|
a738507ad2 | ||
|
|
142b2e4ede | ||
|
|
517a01b7ad | ||
|
|
83633d539e | ||
|
|
c2ee63431b | ||
|
|
9e4bc10525 | ||
|
|
f37c844bf7 | ||
|
|
2c7dfb02a8 | ||
|
|
2884bbf5b1 | ||
|
|
f48a99b97c | ||
|
|
11cfb2903e | ||
|
|
c520d97dd9 | ||
|
|
6c74d6f891 | ||
|
|
262c82ac06 | ||
|
|
164b8e99cc | ||
|
|
4a08902664 | ||
|
|
d6e6a453fc | ||
|
|
eb86fd8cdf | ||
|
|
099e2e8438 | ||
|
|
291312c5e4 | ||
|
|
e2805abbf7 | ||
|
|
79d51099ac | ||
|
|
adf23533e0 | ||
|
|
927cd90dc1 | ||
|
|
b5efbe75cd | ||
|
|
01311dd419 | ||
|
|
5865b9436f | ||
|
|
ad1313c2e5 | ||
|
|
0cb9f792b8 | ||
|
|
efe785e711 | ||
|
|
48aca98cd5 | ||
|
|
89e154f78c | ||
|
|
491b407d17 | ||
|
|
2f4589b765 | ||
|
|
acb7161c81 | ||
|
|
437a39c798 | ||
|
|
b3e6d5df53 | ||
|
|
53644a14ac | ||
|
|
aa05248ca8 | ||
|
|
04543c9dbc | ||
|
|
d5aeebe323 | ||
|
|
47bd0b6d1f | ||
|
|
8e2590b535 | ||
|
|
c51f42a566 | ||
|
|
00d4fbe753 | ||
|
|
dee8e5688b | ||
|
|
40d81bb7ca | ||
|
|
10bc5ac203 | ||
|
|
8ba9402282 | ||
|
|
a2fe341da5 | ||
|
|
dbb2de272b | ||
|
|
9423a3a065 | ||
|
|
0c5d4954a7 | ||
|
|
0b8d24f800 | ||
|
|
48354f56ec | ||
|
|
5c0c95bd34 | ||
|
|
c82dd2eb81 | ||
|
|
f6276fe739 | ||
|
|
2a1089d607 | ||
|
|
fbf73ede1e | ||
|
|
577840d7f7 | ||
|
|
3d9b1693eb | ||
|
|
15f3988bc8 | ||
|
|
9c2127b798 | ||
|
|
0bb779904d | ||
|
|
5eeac3566e | ||
|
|
e99246246b | ||
|
|
c96e862c08 | ||
|
|
7021a46617 | ||
|
|
c7cb2d0657 | ||
|
|
fd50a4dd9f | ||
|
|
afe97d6cab | ||
|
|
00949383f4 | ||
|
|
2a1cb323f7 | ||
|
|
4463d89a4a | ||
|
|
9e0fb9f29b | ||
|
|
a277dd9277 | ||
|
|
370d4b014d | ||
|
|
7bd5e4101c | ||
|
|
352c7381a8 | ||
|
|
3e57b54688 | ||
|
|
2a183440c7 | ||
|
|
bb0023b7c7 | ||
|
|
398e8d50b5 | ||
|
|
fa34d11749 | ||
|
|
93370d61ba | ||
|
|
22d6c36800 | ||
|
|
c28ad814d0 | ||
|
|
fdc660f313 | ||
|
|
57418dd2cc | ||
|
|
4e04ec8bf5 | ||
|
|
79a80cdc77 | ||
|
|
95782ada1f | ||
|
|
f7b61bf557 | ||
|
|
adf4d4f147 | ||
|
|
dc93edc932 | ||
|
|
6bbdaceaca | ||
|
|
eedecd0269 | ||
|
|
d904784489 | ||
|
|
31fb4e1e69 | ||
|
|
3bdc2b1d4f | ||
|
|
1e37430dbe | ||
|
|
671f1979a6 | ||
|
|
fdaa42da1a | ||
|
|
8d450ef81a | ||
|
|
c433ac02bd | ||
|
|
1c24a0508f | ||
|
|
f0d6ce8958 | ||
|
|
75be42df75 | ||
|
|
3224506fe0 | ||
|
|
d4d30d0375 | ||
|
|
7ff6b3537f | ||
|
|
368509f5d1 | ||
|
|
7eff889384 | ||
|
|
465816f4a0 | ||
|
|
9fff70fa41 | ||
|
|
d3e081ba44 | ||
|
|
086847f997 | ||
|
|
cb9786b3ae | ||
|
|
9c4144689d | ||
|
|
e745236ae5 | ||
|
|
13eef19000 | ||
|
|
2fe59071b2 | ||
|
|
a7157b7907 | ||
|
|
6007c3c43f | ||
|
|
9d1ddd0547 | ||
|
|
5229253f86 | ||
|
|
a1c4fc07d4 | ||
|
|
6d09104ad3 | ||
|
|
57ef959aa3 | ||
|
|
b617d7fa29 | ||
|
|
4b3363ecf2 | ||
|
|
6fe51b13fb | ||
|
|
8bcbfb1642 | ||
|
|
aecd952d18 | ||
|
|
fedb1b3def | ||
|
|
8fdfa13227 | ||
|
|
9d90d15e91 | ||
|
|
09a715b147 | ||
|
|
42ad55377f | ||
|
|
d771dafe04 | ||
|
|
09af855b6f | ||
|
|
0571360f37 | ||
|
|
f3e3700063 | ||
|
|
41fe03e0d6 | ||
|
|
b514957af7 | ||
|
|
d9c5d0767c | ||
|
|
8f162e3b13 | ||
|
|
32ba84dac7 | ||
|
|
7f806b7c68 | ||
|
|
a6107f7432 | ||
|
|
9829aa2236 | ||
|
|
f8debe9a19 | ||
|
|
8b407f1ca2 | ||
|
|
20b5734649 | ||
|
|
0557f57c63 | ||
|
|
4f4e917187 | ||
|
|
a1f0b2acfc | ||
|
|
d65777b570 | ||
|
|
2df00fd84c | ||
|
|
d1d3beac33 | ||
|
|
ad0abff8b3 | ||
|
|
cdd7a6cb8d | ||
|
|
004240af48 | ||
|
|
4e3d16e291 | ||
|
|
7933aef747 | ||
|
|
136efd6ed5 | ||
|
|
94969cf263 | ||
|
|
68c3c26029 | ||
|
|
fd185acbea | ||
|
|
7a4e8e58f0 | ||
|
|
cbeb2a9de7 | ||
|
|
d61fcbf7b2 | ||
|
|
75e61f498b | ||
|
|
09edee123a | ||
|
|
060171028c | ||
|
|
7ecdc3e0d5 | ||
|
|
67a080874b | ||
|
|
7b63fe2f22 | ||
|
|
3d934f3ddc | ||
|
|
06cc94eecf | ||
|
|
f6443b725a | ||
|
|
d8ead516de | ||
|
|
ccdc0f1805 | ||
|
|
66e7e7023b | ||
|
|
b4fc5d9524 | ||
|
|
811c645f2a | ||
|
|
c2312f9dda | ||
|
|
440d2ec0ea | ||
|
|
47e53deebd | ||
|
|
095a01b70c | ||
|
|
503c729bb0 | ||
|
|
41d99d32e8 | ||
|
|
c481f9dafd | ||
|
|
f240ecf328 | ||
|
|
1972a27fe0 | ||
|
|
097760db17 | ||
|
|
b3a08ba8d3 | ||
|
|
fef7e1dffe | ||
|
|
6d7bbe63fe | ||
|
|
387e26c837 | ||
|
|
e8e99ec6de | ||
|
|
13c4499449 | ||
|
|
4cc7f4ad03 | ||
|
|
a8dc67ded8 | ||
|
|
aa33d18930 | ||
|
|
8c5777554a | ||
|
|
06cd9bc4dc | ||
|
|
0c8984ba9f | ||
|
|
6f0f1ef292 | ||
|
|
b12f3f38c7 | ||
|
|
cb165df64e | ||
|
|
e4c4f57f05 | ||
|
|
c5ef5ed18f | ||
|
|
ebf4a03908 | ||
|
|
4f3ee2fc7e | ||
|
|
f565aeebfa | ||
|
|
04cb94a2dd | ||
|
|
754152aa22 | ||
|
|
1ef00045dd | ||
|
|
a466a624e2 | ||
|
|
643a3b7cc3 | ||
|
|
d2dea8dc2e | ||
|
|
6edb6bcca1 | ||
|
|
d4f5a0e6ab | ||
|
|
ce1d73e0f0 | ||
|
|
20caa68b84 | ||
|
|
b00a6e3885 | ||
|
|
ffc33ca28c | ||
|
|
ee95c05c08 | ||
|
|
cfea381307 | ||
|
|
099b914fd9 | ||
|
|
afd35fa98c | ||
|
|
f02bc4768e | ||
|
|
bcb162816e | ||
|
|
5baa6aed6b | ||
|
|
6a6e85752e | ||
|
|
4421540b7b | ||
|
|
d3c186b04c | ||
|
|
e30acdb58a | ||
|
|
b0cbe88b0b | ||
|
|
3afba83134 | ||
|
|
b8d47a438c | ||
|
|
5201c5850e | ||
|
|
bd8ab422d0 | ||
|
|
33890daf41 | ||
|
|
ac4c5699b1 | ||
|
|
15e31eb464 | ||
|
|
2e81dd61dd | ||
|
|
f2c2687ca6 | ||
|
|
4c300313c3 | ||
|
|
bec13a6ac0 | ||
|
|
423d8c9b6a | ||
|
|
685fe1d0b6 | ||
|
|
e588e2325d | ||
|
|
04fd756c49 | ||
|
|
4cb6afcbd4 | ||
|
|
4eae4d592c | ||
|
|
566d842405 | ||
|
|
5e2fbbc202 | ||
|
|
8e703b9974 | ||
|
|
89853607c5 | ||
|
|
20658abc78 | ||
|
|
8823dee51a | ||
|
|
3e07359a35 | ||
|
|
e9242a7a31 | ||
|
|
b9ada25296 | ||
|
|
33cb1bc08b | ||
|
|
6da54688eb | ||
|
|
ef6d19fbb1 | ||
|
|
acbca6a562 | ||
|
|
fc8081cd06 | ||
|
|
7a64dd1b9a | ||
|
|
5045133dc2 | ||
|
|
7f2049b0d5 | ||
|
|
aa3eeb38f9 |
@@ -4,6 +4,8 @@
|
|||||||
-DWITH_SFTP=1
|
-DWITH_SFTP=1
|
||||||
-DWITH_SSH1=1
|
-DWITH_SSH1=1
|
||||||
-DWITH_PCAP=1
|
-DWITH_PCAP=1
|
||||||
|
-DHAVE_ECDH=1
|
||||||
|
-DHAVE_ECC=1
|
||||||
-Iinclude/libssh
|
-Iinclude/libssh
|
||||||
-Iinclude
|
-Iinclude
|
||||||
-Ibuild
|
-Ibuild
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,6 +3,7 @@
|
|||||||
.*
|
.*
|
||||||
*.swp
|
*.swp
|
||||||
*~$
|
*~$
|
||||||
build
|
|
||||||
cscope.*
|
cscope.*
|
||||||
tags
|
tags
|
||||||
|
/build
|
||||||
|
/obj*
|
||||||
|
|||||||
2
AUTHORS
2
AUTHORS
@@ -1,7 +1,7 @@
|
|||||||
Author(s):
|
Author(s):
|
||||||
Aris Adamantiadis <aris@0xbadc0de.be> (project initiator)
|
Aris Adamantiadis <aris@0xbadc0de.be> (project initiator)
|
||||||
|
|
||||||
Andreas Schneider <mail@cynapses.org> (developer)
|
Andreas Schneider <asn@cryptomilk.org> (developer)
|
||||||
|
|
||||||
Nick Zitzmann <seiryu (at) comcast (dot) net> (mostly client SFTP stuff)
|
Nick Zitzmann <seiryu (at) comcast (dot) net> (mostly client SFTP stuff)
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
project(libssh C)
|
project(libssh C)
|
||||||
|
|
||||||
# Required cmake version
|
# Required cmake version
|
||||||
cmake_minimum_required(VERSION 2.6.0)
|
cmake_minimum_required(VERSION 2.8.5)
|
||||||
|
|
||||||
# global needed variables
|
# global needed variables
|
||||||
set(APPLICATION_NAME ${PROJECT_NAME})
|
set(APPLICATION_NAME ${PROJECT_NAME})
|
||||||
|
|
||||||
set(APPLICATION_VERSION_MAJOR "0")
|
set(APPLICATION_VERSION_MAJOR "0")
|
||||||
set(APPLICATION_VERSION_MINOR "5")
|
set(APPLICATION_VERSION_MINOR "7")
|
||||||
set(APPLICATION_VERSION_PATCH "90")
|
set(APPLICATION_VERSION_PATCH "7")
|
||||||
|
|
||||||
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
|
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
|
||||||
|
|
||||||
@@ -19,12 +19,12 @@ set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
|
|||||||
# Increment AGE. Set REVISION to 0
|
# Increment AGE. Set REVISION to 0
|
||||||
# If the source code was changed, but there were no interface changes:
|
# If the source code was changed, but there were no interface changes:
|
||||||
# Increment REVISION.
|
# Increment REVISION.
|
||||||
set(LIBRARY_VERSION "4.3.0")
|
set(LIBRARY_VERSION "4.4.4")
|
||||||
set(LIBRARY_SOVERSION "4")
|
set(LIBRARY_SOVERSION "4")
|
||||||
|
|
||||||
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
|
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
|
||||||
set(CMAKE_MODULE_PATH
|
set(CMAKE_MODULE_PATH
|
||||||
${CMAKE_SOURCE_DIR}/cmake/Modules
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules
|
||||||
)
|
)
|
||||||
|
|
||||||
# add definitions
|
# add definitions
|
||||||
@@ -39,10 +39,6 @@ include(CPackConfig.cmake)
|
|||||||
include(MacroEnsureOutOfSourceBuild)
|
include(MacroEnsureOutOfSourceBuild)
|
||||||
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
|
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
|
||||||
|
|
||||||
# add macros
|
|
||||||
include(MacroAddPlugin)
|
|
||||||
include(MacroCopyFile)
|
|
||||||
|
|
||||||
# search for libraries
|
# search for libraries
|
||||||
if (WITH_ZLIB)
|
if (WITH_ZLIB)
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
@@ -71,6 +67,13 @@ if (WITH_GSSAPI)
|
|||||||
find_package(GSSAPI)
|
find_package(GSSAPI)
|
||||||
endif (WITH_GSSAPI)
|
endif (WITH_GSSAPI)
|
||||||
|
|
||||||
|
if (WITH_NACL)
|
||||||
|
find_package(NaCl)
|
||||||
|
if (NOT NACL_FOUND)
|
||||||
|
set(WITH_NACL OFF)
|
||||||
|
endif (NOT NACL_FOUND)
|
||||||
|
endif (WITH_NACL)
|
||||||
|
|
||||||
# config.h checks
|
# config.h checks
|
||||||
include(ConfigureChecks.cmake)
|
include(ConfigureChecks.cmake)
|
||||||
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||||
@@ -81,8 +84,8 @@ add_subdirectory(include)
|
|||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
# pkg-config file
|
# pkg-config file
|
||||||
|
if (UNIX)
|
||||||
configure_file(libssh.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc)
|
configure_file(libssh.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc)
|
||||||
configure_file(libssh_threads.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc)
|
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libssh.pc
|
${CMAKE_CURRENT_BINARY_DIR}/libssh.pc
|
||||||
@@ -93,23 +96,43 @@ install(
|
|||||||
pkgconfig
|
pkgconfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (LIBSSH_THREADS)
|
||||||
|
configure_file(libssh_threads.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc)
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/libssh.pc
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc
|
||||||
|
DESTINATION
|
||||||
|
${LIB_INSTALL_DIR}/pkgconfig
|
||||||
|
COMPONENT
|
||||||
|
pkgconfig
|
||||||
|
)
|
||||||
|
endif (LIBSSH_THREADS)
|
||||||
|
endif (UNIX)
|
||||||
|
|
||||||
# cmake config files
|
# cmake config files
|
||||||
configure_file(libssh-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-config.cmake @ONLY)
|
set(LIBSSH_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}ssh${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||||
configure_file(libssh-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-config-version.cmake @ONLY)
|
set(LIBSSH_THREADS_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}ssh${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||||
|
|
||||||
|
configure_file(${PROJECT_NAME}-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake @ONLY)
|
||||||
|
configure_file(${PROJECT_NAME}-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake @ONLY)
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libssh-config.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libssh-config-version.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
|
||||||
DESTINATION
|
DESTINATION
|
||||||
${CMAKE_INSTALL_DIR}
|
${CMAKE_INSTALL_DIR}/${PROJECT_NAME}
|
||||||
COMPONENT
|
COMPONENT
|
||||||
devel
|
devel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# in tree build settings
|
# in tree build settings
|
||||||
configure_file(libssh-build-tree-settings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-build-tree-settings.cmake @ONLY)
|
configure_file(libssh-build-tree-settings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-build-tree-settings.cmake @ONLY)
|
||||||
|
|
||||||
add_subdirectory(examples)
|
if (WITH_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
endif (WITH_EXAMPLES)
|
||||||
|
|
||||||
if (WITH_TESTING)
|
if (WITH_TESTING)
|
||||||
find_package(CMocka REQUIRED)
|
find_package(CMocka REQUIRED)
|
||||||
@@ -123,6 +146,7 @@ message(STATUS "********** ${PROJECT_NAME} build options : **********")
|
|||||||
|
|
||||||
message(STATUS "zlib support: ${WITH_ZLIB}")
|
message(STATUS "zlib support: ${WITH_ZLIB}")
|
||||||
message(STATUS "libgcrypt support: ${WITH_GCRYPT}")
|
message(STATUS "libgcrypt support: ${WITH_GCRYPT}")
|
||||||
|
message(STATUS "libnacl support: ${WITH_NACL}")
|
||||||
message(STATUS "SSH-1 support: ${WITH_SSH1}")
|
message(STATUS "SSH-1 support: ${WITH_SSH1}")
|
||||||
message(STATUS "SFTP support: ${WITH_SFTP}")
|
message(STATUS "SFTP support: ${WITH_SFTP}")
|
||||||
message(STATUS "Server support : ${WITH_SERVER}")
|
message(STATUS "Server support : ${WITH_SERVER}")
|
||||||
|
|||||||
@@ -4,22 +4,22 @@
|
|||||||
### general settings
|
### general settings
|
||||||
set(CPACK_PACKAGE_NAME ${APPLICATION_NAME})
|
set(CPACK_PACKAGE_NAME ${APPLICATION_NAME})
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
|
||||||
set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
|
set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
|
||||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
|
||||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
|
||||||
|
|
||||||
|
|
||||||
### versions
|
### versions
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
set(CPACK_PACKAGE_VERSION_MAJOR ${APPLICATION_VERSION_MAJOR})
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR "5")
|
set(CPACK_PACKAGE_VERSION_MINOR ${APPLICATION_VERSION_MINOR})
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH "90")
|
set(CPACK_PACKAGE_VERSION_PATCH ${APPLICATION_VERSION_PATCH})
|
||||||
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||||
|
|
||||||
|
|
||||||
### source generator
|
### source generator
|
||||||
set(CPACK_SOURCE_GENERATOR "TGZ")
|
set(CPACK_SOURCE_GENERATOR "TXZ")
|
||||||
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;tags;cscope.*")
|
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]git/;.gitignore;/build*;/obj*;tags;cscope.*")
|
||||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ set(UPDATE_TYPE "true")
|
|||||||
set(CTEST_PROJECT_NAME "libssh")
|
set(CTEST_PROJECT_NAME "libssh")
|
||||||
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
|
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
|
||||||
|
|
||||||
set(CTEST_DROP_METHOD "http")
|
set(CTEST_DROP_METHOD "https")
|
||||||
set(CTEST_DROP_SITE "test.libssh.org")
|
set(CTEST_DROP_SITE "test.libssh.org")
|
||||||
set(CTEST_DROP_LOCATION "/submit.php?project=libssh")
|
set(CTEST_DROP_LOCATION "/submit.php?project=libssh")
|
||||||
set(CTEST_DROP_SITE_CDASH TRUE)
|
set(CTEST_DROP_SITE_CDASH TRUE)
|
||||||
|
|||||||
110
ChangeLog
110
ChangeLog
@@ -1,16 +1,124 @@
|
|||||||
ChangeLog
|
ChangeLog
|
||||||
==========
|
==========
|
||||||
|
|
||||||
version 0.6.0 (released 2013-XX-XX)
|
version 0.7.7 (released 2018-10-29)
|
||||||
|
* Fixed issues with MSVC
|
||||||
|
* Fixed keyboard-interactive auth in server mode
|
||||||
|
(regression from CVE-2018-10933)
|
||||||
|
* Fixed gssapi auth in server mode (regression from CVE-2018-10933)
|
||||||
|
* Fixed a memory leak with OpenSSL
|
||||||
|
|
||||||
|
version 0.7.6 (released 2018-10-16)
|
||||||
|
* Fixed CVE-2018-10933
|
||||||
|
* Added support for OpenSSL 1.1
|
||||||
|
* Added SHA256 support for ssh_get_publickey_hash()
|
||||||
|
* Fixed config parsing
|
||||||
|
* Fixed random memory corruption when importing pubkeys
|
||||||
|
|
||||||
|
version 0.7.5 (released 2017-04-13)
|
||||||
|
* Fixed a memory allocation issue with buffers
|
||||||
|
* Fixed PKI on Windows
|
||||||
|
* Fixed some SSHv1 functions
|
||||||
|
* Fixed config hostname expansion
|
||||||
|
|
||||||
|
version 0.7.4 (released 2017-02-03)
|
||||||
|
* Added id_ed25519 to the default identity list
|
||||||
|
* Fixed sftp EOF packet handling
|
||||||
|
* Fixed ssh_send_banner() to confirm with RFC 4253
|
||||||
|
* Fixed some memory leaks
|
||||||
|
|
||||||
|
version 0.7.3 (released 2016-01-23)
|
||||||
|
* Fixed CVE-2016-0739
|
||||||
|
* Fixed ssh-agent on big endian
|
||||||
|
* Fixed some documentation issues
|
||||||
|
|
||||||
|
version 0.7.2 (released 2015-09-15)
|
||||||
|
* Fixed OpenSSL detection on Windows
|
||||||
|
* Fixed return status for ssh_userauth_agent()
|
||||||
|
* Fixed KEX to prefer hmac-sha2-256
|
||||||
|
* Fixed sftp packet handling
|
||||||
|
* Fixed return values of ssh_key_is_(public|private)
|
||||||
|
* Fixed bug in global success reply
|
||||||
|
|
||||||
|
version 0.7.1 (released 2015-06-30)
|
||||||
|
* Fixed SSH_AUTH_PARTIAL auth with auto public key
|
||||||
|
* Fixed memory leak in session options
|
||||||
|
* Fixed allocation of ed25519 public keys
|
||||||
|
* Fixed channel exit-status and exit-signal
|
||||||
|
* Reintroduce ssh_forward_listen()
|
||||||
|
|
||||||
|
version 0.7.0 (released 2015-05-11)
|
||||||
|
* Added support for ed25519 keys
|
||||||
|
* Added SHA2 algorithms for HMAC
|
||||||
|
* Added improved and more secure buffer handling code
|
||||||
|
* Added callback for auth_none_function
|
||||||
|
* Added support for ECDSA private key signing
|
||||||
|
* Added more tests
|
||||||
|
* Fixed a lot of bugs
|
||||||
|
* Improved API documentation
|
||||||
|
|
||||||
|
version 0.6.5 (released 2015-04-29)
|
||||||
|
* Fixed CVE-2015-3146
|
||||||
|
* Fixed port handling in config file
|
||||||
|
* Fixed the build with libgcrypt
|
||||||
|
* Fixed SFTP endian issues (rlo #179)
|
||||||
|
* Fixed uninitilized sig variable (rlo #167)
|
||||||
|
* Fixed polling issues which could result in a hang
|
||||||
|
* Fixed handling of EINTR in ssh_poll() (rlo #186)
|
||||||
|
* Fixed C99 issues with __func__
|
||||||
|
* Fixed some memory leaks
|
||||||
|
* Improved macro detection on Windows
|
||||||
|
|
||||||
|
version 0.6.4 (released 2014-12-19)
|
||||||
|
* Fixed CVE-2014-8132.
|
||||||
|
* Added SHA-2 for session ID signing with ECDSA keys.
|
||||||
|
* Added support for ECDSA host keys.
|
||||||
|
* Added support for more ECDSA hostkey algorithms.
|
||||||
|
* Added ssh_pki_key_ecdsa_name() API.
|
||||||
|
* Fixed setting the bindfd only after successful listen.
|
||||||
|
* Fixed issues with user created sockets.
|
||||||
|
* Fixed several issues in libssh C++ wrapper.
|
||||||
|
* Fixed several documentation issues.
|
||||||
|
* Fixed channel exit-signal request.
|
||||||
|
* Fixed X11 request screen number in messages.
|
||||||
|
* Fixed several memory leaks.
|
||||||
|
|
||||||
|
version 0.6.3 (released 2014-03-04)
|
||||||
|
* Fixed CVE-2014-0017.
|
||||||
|
* Fixed memory leak with ecdsa signatures.
|
||||||
|
|
||||||
|
version 0.6.2 (released 2014-03-04)
|
||||||
|
* security: fix for vulnerability CVE-2014-0017
|
||||||
|
|
||||||
|
version 0.6.1 (released 2014-02-08)
|
||||||
|
* Added support for libgcrypt 1.6.
|
||||||
|
* Added ssh_channel_accept_forward().
|
||||||
|
* Added known_hosts heuristic during connection (#138).
|
||||||
|
* Added getters for session cipher names.
|
||||||
|
* Fixed decrypt of zero length buffer.
|
||||||
|
* Fixed padding in RSA signature blobs.
|
||||||
|
* Fixed DSA signature extraction.
|
||||||
|
* Fixed some memory leaks.
|
||||||
|
* Fixed read of non-connected socket.
|
||||||
|
* Fixed thread dectection.
|
||||||
|
|
||||||
|
version 0.6.0 (released 2014-01-08)
|
||||||
* Added new publicy key API.
|
* Added new publicy key API.
|
||||||
* Added new userauth API.
|
* Added new userauth API.
|
||||||
|
* Added ssh_get_publickey_hash() function.
|
||||||
|
* Added ssh_get_poll_flags() function.
|
||||||
* Added gssapi-mic userauth.
|
* Added gssapi-mic userauth.
|
||||||
|
* Added GSSAPIServerIdentity option.
|
||||||
|
* Added GSSAPIClientIdentity option.
|
||||||
|
* Added GSSAPIDelegateCredentials option.
|
||||||
* Added new callback based server API.
|
* Added new callback based server API.
|
||||||
* Added Elliptic Curve DSA (ECDSA) support (with OpenSSL).
|
* Added Elliptic Curve DSA (ECDSA) support (with OpenSSL).
|
||||||
* Added Elliptic Curve Diffie Hellman (ECDH) support.
|
* Added Elliptic Curve Diffie Hellman (ECDH) support.
|
||||||
|
* Added Curve25519 for ECDH key exchange.
|
||||||
* Added improved logging system.
|
* Added improved logging system.
|
||||||
* Added SSH-agent forwarding.
|
* Added SSH-agent forwarding.
|
||||||
* Added key-reexchange.
|
* Added key-reexchange.
|
||||||
|
* Added more unit tests.
|
||||||
* Improved documentation.
|
* Improved documentation.
|
||||||
* Fixed timeout handling.
|
* Fixed timeout handling.
|
||||||
|
|
||||||
|
|||||||
59
CodingStyle
59
CodingStyle
@@ -1,59 +0,0 @@
|
|||||||
Coding Style Conventions
|
|
||||||
========================
|
|
||||||
|
|
||||||
Coding style guidelines are about reducing the number of unnecessary
|
|
||||||
reformatting patches and making things easier for developers to work together.
|
|
||||||
|
|
||||||
You don't have to like them or even agree with them, but once put in place we
|
|
||||||
all have to abide by them (or vote to change them). However, coding style
|
|
||||||
should never outweigh coding itself and so the guidelines described here are
|
|
||||||
hopefully easy enough to follow as they are very common and supported by tools
|
|
||||||
and editors.
|
|
||||||
|
|
||||||
The basic style for C code is the Linux kernel coding style [1] with one
|
|
||||||
excecption, we use 4 spaces instead of tabs. This closely matches what most
|
|
||||||
libssh developers use already anyways, with a few exceptions as mentioned
|
|
||||||
below.
|
|
||||||
|
|
||||||
To shorthen this here are the highlights:
|
|
||||||
|
|
||||||
* Maximum line width is 80 characters
|
|
||||||
|
|
||||||
The reason is not about people with low-res screens but rather sticking
|
|
||||||
to 80 columns prevents you from easily nesting more than one level of
|
|
||||||
if statements or other code blocks.
|
|
||||||
|
|
||||||
* Use 4 spaces to indent
|
|
||||||
|
|
||||||
* No trailing whitespaces
|
|
||||||
|
|
||||||
* Follow the K&R guidelines. We won't go through all of them here. Do you
|
|
||||||
have a copy of "The C Programming Language" anyways right?
|
|
||||||
|
|
||||||
Editors
|
|
||||||
========
|
|
||||||
|
|
||||||
VIM
|
|
||||||
----
|
|
||||||
|
|
||||||
set ts=4 sw=4 et cindent
|
|
||||||
|
|
||||||
For Vim, the following settings in $HOME/.vimrc will also deal with
|
|
||||||
displaying trailing whitespace:
|
|
||||||
|
|
||||||
if has("syntax") && (&t_Co > 2 || has("gui_running"))
|
|
||||||
syntax on
|
|
||||||
function! ActivateInvisibleCharIndicator()
|
|
||||||
syntax match TrailingSpace "[ \t]\+$" display containedin=ALL
|
|
||||||
highlight TrailingSpace ctermbg=Red
|
|
||||||
endf
|
|
||||||
autocmd BufNewFile,BufRead * call ActivateInvisibleCharIndicator()
|
|
||||||
endif
|
|
||||||
" Show tabs, trailing whitespace, and continued lines visually
|
|
||||||
set list listchars=tab:»·,trail:·,extends:…
|
|
||||||
|
|
||||||
" highlight overly long lines same as TODOs.
|
|
||||||
set textwidth=80
|
|
||||||
autocmd BufNewFile,BufRead *.c,*.h exec 'match Todo /\%>' . &textwidth . 'v.\+/'
|
|
||||||
|
|
||||||
[1] https://www.kernel.org/doc/Documentation/CodingStyle
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
include(CheckIncludeFile)
|
include(CheckIncludeFile)
|
||||||
|
include(CheckIncludeFiles)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
include(CheckFunctionExists)
|
include(CheckFunctionExists)
|
||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
@@ -48,8 +49,15 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
|
|||||||
# HEADER FILES
|
# HEADER FILES
|
||||||
check_include_file(argp.h HAVE_ARGP_H)
|
check_include_file(argp.h HAVE_ARGP_H)
|
||||||
check_include_file(pty.h HAVE_PTY_H)
|
check_include_file(pty.h HAVE_PTY_H)
|
||||||
|
check_include_file(utmp.h HAVE_UTMP_H)
|
||||||
check_include_file(termios.h HAVE_TERMIOS_H)
|
check_include_file(termios.h HAVE_TERMIOS_H)
|
||||||
check_include_file(unistd.h HAVE_UNISTD_H)
|
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||||
|
check_include_file(util.h HAVE_UTIL_H)
|
||||||
|
check_include_file(libutil.h HAVE_LIBUTIL_H)
|
||||||
|
check_include_file(sys/time.h HAVE_SYS_TIME_H)
|
||||||
|
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
|
||||||
|
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
|
||||||
|
check_include_file(byteswap.h HAVE_BYTESWAP_H)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
check_include_files("winsock2.h;ws2tcpip.h;wspiapi.h" HAVE_WSPIAPI_H)
|
check_include_files("winsock2.h;ws2tcpip.h;wspiapi.h" HAVE_WSPIAPI_H)
|
||||||
@@ -59,23 +67,35 @@ if (WIN32)
|
|||||||
check_include_files("winsock2.h;ws2tcpip.h" HAVE_WS2TCPIP_H)
|
check_include_files("winsock2.h;ws2tcpip.h" HAVE_WS2TCPIP_H)
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
if (OPENSSL_FOUND)
|
||||||
check_include_file(openssl/aes.h HAVE_OPENSSL_AES_H)
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
|
check_include_file(openssl/des.h HAVE_OPENSSL_DES_H)
|
||||||
|
if (NOT HAVE_OPENSSL_DES_H)
|
||||||
|
message(FATAL_ERROR "Could not detect openssl/des.h")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
check_include_file(openssl/blowfish.h HAVE_OPENSSL_BLOWFISH_H)
|
check_include_file(openssl/aes.h HAVE_OPENSSL_AES_H)
|
||||||
|
if (NOT HAVE_OPENSSL_AES_H)
|
||||||
|
message(FATAL_ERROR "Could not detect openssl/aes.h")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
check_include_file(openssl/des.h HAVE_OPENSSL_DES_H)
|
check_include_file(openssl/blowfish.h HAVE_OPENSSL_BLOWFISH_H)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
check_include_file(openssl/ecdh.h HAVE_OPENSSL_ECDH_H)
|
check_include_file(openssl/ecdh.h HAVE_OPENSSL_ECDH_H)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
check_include_file(openssl/ec.h HAVE_OPENSSL_EC_H)
|
check_include_file(openssl/ec.h HAVE_OPENSSL_EC_H)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
check_include_file(openssl/ecdsa.h HAVE_OPENSSL_ECDSA_H)
|
check_include_file(openssl/ecdsa.h HAVE_OPENSSL_ECDSA_H)
|
||||||
|
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
|
||||||
|
check_function_exists(CRYPTO_ctr128_encrypt HAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CMAKE_HAVE_PTHREAD_H)
|
if (CMAKE_HAVE_PTHREAD_H)
|
||||||
set(HAVE_PTHREAD_H 1)
|
set(HAVE_PTHREAD_H 1)
|
||||||
@@ -93,35 +113,50 @@ endif (NOT WITH_GCRYPT)
|
|||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
|
check_function_exists(isblank HAVE_ISBLANK)
|
||||||
check_function_exists(strncpy HAVE_STRNCPY)
|
check_function_exists(strncpy HAVE_STRNCPY)
|
||||||
check_function_exists(vsnprintf HAVE_VSNPRINTF)
|
check_function_exists(strndup HAVE_STRNDUP)
|
||||||
check_function_exists(snprintf HAVE_SNPRINTF)
|
check_function_exists(strtoull HAVE_STRTOULL)
|
||||||
check_function_exists(poll HAVE_POLL)
|
|
||||||
check_function_exists(select HAVE_SELECT)
|
if (NOT WIN32)
|
||||||
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
|
check_function_exists(vsnprintf HAVE_VSNPRINTF)
|
||||||
check_function_exists(ntohll HAVE_NTOHLL)
|
check_function_exists(snprintf HAVE_SNPRINTF)
|
||||||
check_function_exists(htonll HAVE_HTONLL)
|
endif (NOT WIN32)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
check_function_exists(_strtoui64 HAVE__STRTOUI64)
|
check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF)
|
||||||
|
check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
|
||||||
|
|
||||||
check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
|
check_symbol_exists(_vsnprintf_s "stdio.h" HAVE__VSNPRINTF_S)
|
||||||
check_function_exists(_vsnprintf HAVE__VSNPRINTF)
|
check_symbol_exists(_vsnprintf "stdio.h" HAVE__VSNPRINTF)
|
||||||
check_function_exists(_snprintf HAVE__SNPRINTF)
|
check_symbol_exists(_snprintf "stdio.h" HAVE__SNPRINTF)
|
||||||
check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
|
check_symbol_exists(_snprintf_s "stdio.h" HAVE__SNPRINTF_S)
|
||||||
|
|
||||||
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
|
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
|
||||||
set(HAVE_GETADDRINFO TRUE)
|
check_symbol_exists(ntohll winsock2.h HAVE_NTOHLL)
|
||||||
set(HAVE_GETHOSTBYNAME TRUE)
|
check_symbol_exists(htonll winsock2.h HAVE_HTONLL)
|
||||||
if (MSVC)
|
|
||||||
set(HAVE_NTOHLL TRUE)
|
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
|
||||||
set(HAVE_HTONLL TRUE)
|
check_symbol_exists(select "winsock2.h;ws2tcpip.h" HAVE_SELECT)
|
||||||
endif (MSVC)
|
check_symbol_exists(poll "winsock2.h;ws2tcpip.h" HAVE_SELECT)
|
||||||
|
# The getaddrinfo function is defined to the WspiapiGetAddrInfo inline function
|
||||||
|
check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" HAVE_GETADDRINFO)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES)
|
||||||
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
|
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
|
||||||
|
|
||||||
|
check_function_exists(_strtoui64 HAVE__STRTOUI64)
|
||||||
|
|
||||||
set(HAVE_SELECT TRUE)
|
set(HAVE_SELECT TRUE)
|
||||||
|
else (WIN32)
|
||||||
|
check_function_exists(poll HAVE_POLL)
|
||||||
|
check_function_exists(select HAVE_SELECT)
|
||||||
|
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
|
||||||
|
|
||||||
|
check_symbol_exists(ntohll arpa/inet.h HAVE_NTOHLL)
|
||||||
|
check_symbol_exists(htonll arpa/inet.h HAVE_HTONLL)
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
if (NOT LINUX)
|
if (NOT LINUX)
|
||||||
# libsocket (Solaris)
|
# libsocket (Solaris)
|
||||||
@@ -148,7 +183,6 @@ if (UNIX)
|
|||||||
|
|
||||||
check_library_exists(util forkpty "" HAVE_LIBUTIL)
|
check_library_exists(util forkpty "" HAVE_LIBUTIL)
|
||||||
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
|
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
|
||||||
check_function_exists(strtoull HAVE_STRTOULL)
|
|
||||||
check_function_exists(__strtoull HAVE___STRTOULL)
|
check_function_exists(__strtoull HAVE___STRTOULL)
|
||||||
endif (UNIX)
|
endif (UNIX)
|
||||||
|
|
||||||
@@ -167,11 +201,9 @@ if (GCRYPT_FOUND)
|
|||||||
endif (GCRYPT_VERSION VERSION_GREATER "1.4.6")
|
endif (GCRYPT_VERSION VERSION_GREATER "1.4.6")
|
||||||
endif (GCRYPT_FOUND)
|
endif (GCRYPT_FOUND)
|
||||||
|
|
||||||
if (CMAKE_HAVE_THREADS_LIBRARY)
|
if (CMAKE_USE_PTHREADS_INIT)
|
||||||
if (CMAKE_USE_PTHREADS_INIT)
|
set(HAVE_PTHREAD 1)
|
||||||
set(HAVE_PTHREAD 1)
|
endif (CMAKE_USE_PTHREADS_INIT)
|
||||||
endif (CMAKE_USE_PTHREADS_INIT)
|
|
||||||
endif (CMAKE_HAVE_THREADS_LIBRARY)
|
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
check_c_source_compiles("
|
check_c_source_compiles("
|
||||||
@@ -200,6 +232,33 @@ int main(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
|
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
|
||||||
|
|
||||||
|
check_c_source_compiles("
|
||||||
|
#include <stdio.h>
|
||||||
|
#define __VA_NARG__(...) (__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
|
||||||
|
#define __VA_NARG_(...) __VA_ARG_N(__VA_ARGS__)
|
||||||
|
#define __VA_ARG_N( _1, _2, _3, _4, _5, _6, _7, _8, _9,_10,N,...) N
|
||||||
|
#define __RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||||
|
#define myprintf(format, ...) printf((format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__)
|
||||||
|
int main(void) {
|
||||||
|
myprintf(\"%d %d %d %d\",1,2,3);
|
||||||
|
return 0;
|
||||||
|
}" HAVE_GCC_NARG_MACRO)
|
||||||
|
|
||||||
|
check_c_source_compiles("
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(void) {
|
||||||
|
printf(\"%s\", __func__);
|
||||||
|
return 0;
|
||||||
|
}" HAVE_COMPILER__FUNC__)
|
||||||
|
|
||||||
|
check_c_source_compiles("
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(void) {
|
||||||
|
printf(\"%s\", __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}" HAVE_COMPILER__FUNCTION__)
|
||||||
|
|
||||||
|
|
||||||
if (WITH_DEBUG_CRYPTO)
|
if (WITH_DEBUG_CRYPTO)
|
||||||
set(DEBUG_CRYPTO 1)
|
set(DEBUG_CRYPTO 1)
|
||||||
endif (WITH_DEBUG_CRYPTO)
|
endif (WITH_DEBUG_CRYPTO)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ option(WITH_INTERNAL_DOC "Compile doxygen internal documentation" OFF)
|
|||||||
option(WITH_TESTING "Build with unit tests" OFF)
|
option(WITH_TESTING "Build with unit tests" OFF)
|
||||||
option(WITH_CLIENT_TESTING "Build with client tests; requires a running sshd" OFF)
|
option(WITH_CLIENT_TESTING "Build with client tests; requires a running sshd" OFF)
|
||||||
option(WITH_BENCHMARKS "Build benchmarks tools" OFF)
|
option(WITH_BENCHMARKS "Build benchmarks tools" OFF)
|
||||||
|
option(WITH_EXAMPLES "Build examples" ON)
|
||||||
|
option(WITH_NACL "Build with libnacl (curve25519" ON)
|
||||||
if (WITH_ZLIB)
|
if (WITH_ZLIB)
|
||||||
set(WITH_LIBZ ON)
|
set(WITH_LIBZ ON)
|
||||||
else (WITH_ZLIB)
|
else (WITH_ZLIB)
|
||||||
@@ -26,3 +27,7 @@ endif(WITH_BENCHMARKS)
|
|||||||
if (WITH_TESTING)
|
if (WITH_TESTING)
|
||||||
set(WITH_STATIC_LIB ON)
|
set(WITH_STATIC_LIB ON)
|
||||||
endif (WITH_TESTING)
|
endif (WITH_TESTING)
|
||||||
|
|
||||||
|
if (WITH_NACL)
|
||||||
|
set(WITH_NACL ON)
|
||||||
|
endif (WITH_NACL)
|
||||||
125
README
125
README
@@ -33,130 +33,11 @@ If you ask yourself how to compile libssh, please read INSTALL before anything.
|
|||||||
|
|
||||||
http://www.libssh.org
|
http://www.libssh.org
|
||||||
|
|
||||||
4* API Changes !
|
4* Contributing
|
||||||
-_-_-_-_-_-_-_-_-_
|
-_-_-_-_-_-_-_-_-_
|
||||||
|
|
||||||
Changes between 0.4 and 0.5
|
Please read the file 'SubmittingPatches' next to this README file. It explains
|
||||||
---------------------------
|
our copyright policy and how you should send patches for upstream inclusion.
|
||||||
|
|
||||||
We use the ssh_ prefix as namespace for every function now. There is a legacy.h
|
|
||||||
which could be used to get the old function names.
|
|
||||||
|
|
||||||
Changes between 0.3 and 0.4
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
We changed libssh to be typesafe now:
|
|
||||||
|
|
||||||
SSH_SESSION *session -> ssh_session session
|
|
||||||
SFTP_SESSION *sftp -> sftp_session sftp
|
|
||||||
CHANNEL *channel -> ssh_channel channel
|
|
||||||
STRING *string -> ssh_string string
|
|
||||||
...
|
|
||||||
|
|
||||||
The options structure has been removed and there is a new function. This
|
|
||||||
function can set all available options now. You can find the enum in the
|
|
||||||
header file and it is documented. Example:
|
|
||||||
|
|
||||||
ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
|
|
||||||
|
|
||||||
5* Copyright policy
|
|
||||||
-_-_-_-_-_-_-_-_-_-_
|
|
||||||
|
|
||||||
libssh is a project with distributed copyright ownership, which means we prefer
|
|
||||||
the copyright on parts of libssh to be held by individuals rather than
|
|
||||||
corporations if possible. There are historical legal reasons for this, but one
|
|
||||||
of the best ways to explain it is that it’s much easier to work with
|
|
||||||
individuals who have ownership than corporate legal departments if we ever need
|
|
||||||
to make reasonable compromises with people using and working with libssh.
|
|
||||||
|
|
||||||
We track the ownership of every part of libssh via git, our source code control
|
|
||||||
system, so we know the provenance of every piece of code that is committed to
|
|
||||||
libssh.
|
|
||||||
|
|
||||||
So if possible, if you’re doing libssh changes on behalf of a company who
|
|
||||||
normally owns all the work you do please get them to assign personal copyright
|
|
||||||
ownership of your changes to you as an individual, that makes things very easy
|
|
||||||
for us to work with and avoids bringing corporate legal departments into the
|
|
||||||
picture.
|
|
||||||
|
|
||||||
If you can’t do this we can still accept patches from you owned by your
|
|
||||||
employer under a standard employment contract with corporate copyright
|
|
||||||
ownership. It just requires a simple set-up process first.
|
|
||||||
|
|
||||||
We use a process very similar to the way things are done in the Linux Kernel
|
|
||||||
community, so it should be very easy to get a sign off from your corporate
|
|
||||||
legal department. The only changes we’ve made are to accommodate the license we
|
|
||||||
use, which is LGPLv2 (or later) whereas the Linux kernel uses GPLv2.
|
|
||||||
|
|
||||||
The process is called signing.
|
|
||||||
|
|
||||||
How to sign your work
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
Once you have permission to contribute to libssh from your employer, simply
|
|
||||||
email a copy of the following text from your corporate email address to:
|
|
||||||
|
|
||||||
contributing@libssh.org
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------
|
|
||||||
libssh Developer's Certificate of Origin. Version 1.0
|
|
||||||
|
|
||||||
By making a contribution to this project, I certify that:
|
|
||||||
|
|
||||||
(a) The contribution was created in whole or in part by me and I
|
|
||||||
have the right to submit it under the appropriate
|
|
||||||
version of the GNU General Public License; or
|
|
||||||
|
|
||||||
(b) The contribution is based upon previous work that, to the best of
|
|
||||||
my knowledge, is covered under an appropriate open source license
|
|
||||||
and I have the right under that license to submit that work with
|
|
||||||
modifications, whether created in whole or in part by me, under
|
|
||||||
the GNU General Public License, in the appropriate version; or
|
|
||||||
|
|
||||||
(c) The contribution was provided directly to me by some other
|
|
||||||
person who certified (a) or (b) and I have not modified it.
|
|
||||||
|
|
||||||
(d) I understand and agree that this project and the contribution are
|
|
||||||
public and that a record of the contribution (including all
|
|
||||||
metadata and personal information I submit with it, including my
|
|
||||||
sign-off) is maintained indefinitely and may be redistributed
|
|
||||||
consistent with the libssh Team's policies and the requirements of
|
|
||||||
the GNU GPL where they are relevant.
|
|
||||||
|
|
||||||
(e) I am granting this work to this project under the terms of the
|
|
||||||
GNU Lesser General Public License as published by the
|
|
||||||
Free Software Foundation; either version 2.1 of
|
|
||||||
the License, or (at the option of the project) any later version.
|
|
||||||
|
|
||||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
|
||||||
--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
We will maintain a copy of that email as a record that you have the rights to
|
|
||||||
contribute code to libssh under the required licenses whilst working for the
|
|
||||||
company where the email came from.
|
|
||||||
|
|
||||||
Then when sending in a patch via the normal mechanisms described above, add a
|
|
||||||
line that states:
|
|
||||||
|
|
||||||
|
|
||||||
Signed-off-by: Random J Developer <random@developer.example.org>
|
|
||||||
|
|
||||||
|
|
||||||
using your real name and the email address you sent the original email you used
|
|
||||||
to send the libssh Developer’s Certificate of Origin to us (sorry, no
|
|
||||||
pseudonyms or anonymous contributions.)
|
|
||||||
|
|
||||||
That’s it! Such code can then quite happily contain changes that have copyright
|
|
||||||
messages such as:
|
|
||||||
|
|
||||||
|
|
||||||
(c) Example Corporation.
|
|
||||||
|
|
||||||
|
|
||||||
and can be merged into the libssh codebase in the same way as patches from any
|
|
||||||
other individual. You don’t need to send in a copy of the libssh Developer’s
|
|
||||||
Certificate of Origin for each patch, or inside each patch. Just the sign-off
|
|
||||||
message is all that is required once we’ve received the initial email.
|
|
||||||
|
|
||||||
Have fun and happy libssh hacking!
|
Have fun and happy libssh hacking!
|
||||||
|
|
||||||
|
|||||||
354
README.CodingStyle
Normal file
354
README.CodingStyle
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
Coding conventions in the libssh tree
|
||||||
|
======================================
|
||||||
|
|
||||||
|
===========
|
||||||
|
Quick Start
|
||||||
|
===========
|
||||||
|
|
||||||
|
Coding style guidelines are about reducing the number of unnecessary
|
||||||
|
reformatting patches and making things easier for developers to work together.
|
||||||
|
|
||||||
|
You don't have to like them or even agree with them, but once put in place we
|
||||||
|
all have to abide by them (or vote to change them). However, coding style
|
||||||
|
should never outweigh coding itself and so the guidelines described here are
|
||||||
|
hopefully easy enough to follow as they are very common and supported by tools
|
||||||
|
and editors.
|
||||||
|
|
||||||
|
The basic style for C code, is the Linux kernel coding style (See
|
||||||
|
Documentation/CodingStyle in the kernel source tree). This closely matches what
|
||||||
|
libssh developers use already anyways, with a few exceptions as mentioned
|
||||||
|
below.
|
||||||
|
|
||||||
|
But to save you the trouble of reading the Linux kernel style guide, here
|
||||||
|
are the highlights.
|
||||||
|
|
||||||
|
* Maximum Line Width is 80 Characters
|
||||||
|
The reason is not about people with low-res screens but rather sticking
|
||||||
|
to 80 columns prevents you from easily nesting more than one level of
|
||||||
|
if statements or other code blocks.
|
||||||
|
|
||||||
|
* Use 4 Spaces to Indent
|
||||||
|
|
||||||
|
* No Trailing Whitespace
|
||||||
|
Clean up your files before committing.
|
||||||
|
|
||||||
|
* Follow the K&R guidelines. We won't go through all of them here. Do you
|
||||||
|
have a copy of "The C Programming Language" anyways right?
|
||||||
|
|
||||||
|
|
||||||
|
=============
|
||||||
|
Editor Hints
|
||||||
|
=============
|
||||||
|
|
||||||
|
Emacs
|
||||||
|
------
|
||||||
|
Add the follow to your $HOME/.emacs file:
|
||||||
|
|
||||||
|
(add-hook 'c-mode-hook
|
||||||
|
(lambda ()
|
||||||
|
(c-set-style "linux")
|
||||||
|
(c-toggle-auto-state)))
|
||||||
|
|
||||||
|
|
||||||
|
Vim
|
||||||
|
----
|
||||||
|
|
||||||
|
For the basic vi editor included with all variants of \*nix, add the
|
||||||
|
following to $HOME/.vimrc:
|
||||||
|
|
||||||
|
set ts=4 sw=4 et cindent
|
||||||
|
|
||||||
|
You can use the Vim gitmodline plugin to store this in the git config:
|
||||||
|
|
||||||
|
http://git.cryptomilk.org/projects/vim-gitmodeline.git/
|
||||||
|
|
||||||
|
For Vim, the following settings in $HOME/.vimrc will also deal with
|
||||||
|
displaying trailing whitespace:
|
||||||
|
|
||||||
|
if has("syntax") && (&t_Co > 2 || has("gui_running"))
|
||||||
|
syntax on
|
||||||
|
function! ActivateInvisibleCharIndicator()
|
||||||
|
syntax match TrailingSpace "[ \t]\+$" display containedin=ALL
|
||||||
|
highlight TrailingSpace ctermbg=Red
|
||||||
|
endf
|
||||||
|
autocmd BufNewFile,BufRead * call ActivateInvisibleCharIndicator()
|
||||||
|
endif
|
||||||
|
" Show tabs, trailing whitespace, and continued lines visually
|
||||||
|
set list listchars=tab:»·,trail:·,extends:…
|
||||||
|
|
||||||
|
" highlight overly long lines same as TODOs.
|
||||||
|
set textwidth=80
|
||||||
|
autocmd BufNewFile,BufRead *.c,*.h exec 'match Todo /\%>' . &textwidth . 'v.\+/'
|
||||||
|
|
||||||
|
|
||||||
|
==========================
|
||||||
|
FAQ & Statement Reference
|
||||||
|
==========================
|
||||||
|
|
||||||
|
Comments
|
||||||
|
---------
|
||||||
|
|
||||||
|
Comments should always use the standard C syntax. C++ style comments are not
|
||||||
|
currently allowed.
|
||||||
|
|
||||||
|
The lines before a comment should be empty. If the comment directly belongs to
|
||||||
|
the following code, there should be no empty line after the comment, except if
|
||||||
|
the comment contains a summary of multiple following code blocks.
|
||||||
|
|
||||||
|
This is good:
|
||||||
|
|
||||||
|
...
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a multi line comment,
|
||||||
|
* which explains the logical steps we have to do:
|
||||||
|
*
|
||||||
|
* 1. We need to set i=5, because...
|
||||||
|
* 2. We need to call complex_fn1
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This is a one line comment about i = 5. */
|
||||||
|
i = 5;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a multi line comment,
|
||||||
|
* explaining the call to complex_fn1()
|
||||||
|
*/
|
||||||
|
ret = complex_fn1();
|
||||||
|
if (ret != 0) {
|
||||||
|
...
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a doxygen comment.
|
||||||
|
*
|
||||||
|
* This is a more detailed explanation of
|
||||||
|
* this simple function.
|
||||||
|
*
|
||||||
|
* @param[in] param1 The parameter value of the function.
|
||||||
|
*
|
||||||
|
* @param[out] result1 The result value of the function.
|
||||||
|
*
|
||||||
|
* @return 0 on success and -1 on error.
|
||||||
|
*/
|
||||||
|
int example(int param1, int *result1);
|
||||||
|
|
||||||
|
This is bad:
|
||||||
|
|
||||||
|
...
|
||||||
|
int i;
|
||||||
|
/*
|
||||||
|
* This is a multi line comment,
|
||||||
|
* which explains the logical steps we have to do:
|
||||||
|
*
|
||||||
|
* 1. We need to set i=5, because...
|
||||||
|
* 2. We need to call complex_fn1
|
||||||
|
*/
|
||||||
|
/* This is a one line comment about i = 5. */
|
||||||
|
i = 5;
|
||||||
|
/*
|
||||||
|
* This is a multi line comment,
|
||||||
|
* explaining the call to complex_fn1()
|
||||||
|
*/
|
||||||
|
ret = complex_fn1();
|
||||||
|
if (ret != 0) {
|
||||||
|
...
|
||||||
|
|
||||||
|
/*This is a one line comment.*/
|
||||||
|
|
||||||
|
/* This is a multi line comment,
|
||||||
|
with some more words...*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a multi line comment,
|
||||||
|
* with some more words...*/
|
||||||
|
|
||||||
|
Indention & Whitespace & 80 columns
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
To avoid confusion, indentations have to be 4 spaces. Do not use tabs!. When
|
||||||
|
wrapping parameters for function calls, align the parameter list with the first
|
||||||
|
parameter on the previous line. For example,
|
||||||
|
|
||||||
|
var1 = foo(arg1,
|
||||||
|
arg2,
|
||||||
|
arg3);
|
||||||
|
|
||||||
|
The previous example is intended to illustrate alignment of function
|
||||||
|
parameters across lines and not as encourage for gratuitous line
|
||||||
|
splitting. Never split a line before columns 70 - 79 unless you
|
||||||
|
have a really good reason. Be smart about formatting.
|
||||||
|
|
||||||
|
|
||||||
|
If, switch, & Code blocks
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Always follow an 'if' keyword with a space but don't include additional
|
||||||
|
spaces following or preceding the parentheses in the conditional.
|
||||||
|
This is good:
|
||||||
|
|
||||||
|
if (x == 1)
|
||||||
|
|
||||||
|
This is bad:
|
||||||
|
|
||||||
|
if ( x == 1 )
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
if (x==1)
|
||||||
|
|
||||||
|
Yes we have a lot of code that uses the second and third form and we are trying
|
||||||
|
to clean it up without being overly intrusive.
|
||||||
|
|
||||||
|
Note that this is a rule about parentheses following keywords and not
|
||||||
|
functions. Don't insert a space between the name and left parentheses when
|
||||||
|
invoking functions.
|
||||||
|
|
||||||
|
Braces for code blocks used by for, if, switch, while, do..while, etc. should
|
||||||
|
begin on the same line as the statement keyword and end on a line of their own.
|
||||||
|
You should always include braces, even if the block only contains one
|
||||||
|
statement. NOTE: Functions are different and the beginning left brace should
|
||||||
|
be located in the first column on the next line.
|
||||||
|
|
||||||
|
If the beginning statement has to be broken across lines due to length, the
|
||||||
|
beginning brace should be on a line of its own.
|
||||||
|
|
||||||
|
The exception to the ending rule is when the closing brace is followed by
|
||||||
|
another language keyword such as else or the closing while in a do..while loop.
|
||||||
|
|
||||||
|
Good examples:
|
||||||
|
|
||||||
|
if (x == 1) {
|
||||||
|
printf("good\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = 1; x < 10; x++) {
|
||||||
|
print("%d\n", x);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (really_really_really_really_long_var_name = 0;
|
||||||
|
really_really_really_really_long_var_name < 10;
|
||||||
|
really_really_really_really_long_var_name++)
|
||||||
|
{
|
||||||
|
print("%d\n", really_really_really_really_long_var_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
printf("also good\n");
|
||||||
|
} while (1);
|
||||||
|
|
||||||
|
Bad examples:
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
print("I'm in a loop!\n"); }
|
||||||
|
|
||||||
|
for (x=1;
|
||||||
|
x<10;
|
||||||
|
x++)
|
||||||
|
{
|
||||||
|
print("no good\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < 10)
|
||||||
|
print("I should be in braces.\n");
|
||||||
|
|
||||||
|
|
||||||
|
Goto
|
||||||
|
-----
|
||||||
|
|
||||||
|
While many people have been academically taught that "goto"s are fundamentally
|
||||||
|
evil, they can greatly enhance readability and reduce memory leaks when used as
|
||||||
|
the single exit point from a function. But in no libssh world what so ever is a
|
||||||
|
goto outside of a function or block of code a good idea.
|
||||||
|
|
||||||
|
Good Examples:
|
||||||
|
|
||||||
|
int function foo(int y)
|
||||||
|
{
|
||||||
|
int *z = NULL;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (y < 10) {
|
||||||
|
z = malloc(sizeof(int)*y);
|
||||||
|
if (z == NULL) {
|
||||||
|
rc = 1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Allocated %d elements.\n", y);
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (z != NULL) {
|
||||||
|
free(z);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Typedefs
|
||||||
|
---------
|
||||||
|
|
||||||
|
libssh tries to avoid "typedef struct { .. } x_t;" so we do always try to use
|
||||||
|
"struct x { .. };". We know there are still such typedefs in the code, but for
|
||||||
|
new code, please don't do that anymore.
|
||||||
|
|
||||||
|
Make use of helper variables
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Please try to avoid passing function calls as function parameters in new code.
|
||||||
|
This makes the code much easier to read and it's also easier to use the "step"
|
||||||
|
command within gdb.
|
||||||
|
|
||||||
|
Good Example:
|
||||||
|
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
name = get_some_name();
|
||||||
|
if (name == NULL) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = some_function_my_name(name);
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
Bad Example:
|
||||||
|
|
||||||
|
rc = some_function_my_name(get_some_name());
|
||||||
|
...
|
||||||
|
|
||||||
|
Please try to avoid passing function return values to if- or while-conditions.
|
||||||
|
The reason for this is better handling of code under a debugger.
|
||||||
|
|
||||||
|
Good example:
|
||||||
|
|
||||||
|
x = malloc(sizeof(short) * 10);
|
||||||
|
if (x == NULL) {
|
||||||
|
fprintf(stderr, "Unable to alloc memory!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bad example:
|
||||||
|
|
||||||
|
if ((x = malloc(sizeof(short)*10)) == NULL ) {
|
||||||
|
fprintf(stderr, "Unable to alloc memory!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
There are exceptions to this rule. One example is walking a data structure in
|
||||||
|
an iterator style:
|
||||||
|
|
||||||
|
while ((opt = poptGetNextOpt(pc)) != -1) {
|
||||||
|
... do something with opt ...
|
||||||
|
}
|
||||||
|
|
||||||
|
But in general, please try to avoid this pattern.
|
||||||
|
|
||||||
|
|
||||||
|
Control-Flow changing macros
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Macros like STATUS_NOT_OK_RETURN that change control flow (return/goto/etc)
|
||||||
|
from within the macro are considered bad, because they look like function calls
|
||||||
|
that never change control flow. Please do not introduce them.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN)
|
# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN)
|
||||||
|
|
||||||
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
|
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
|
||||||
# Copyright (c) 2007-2010 Andreas Schneider <asn@cynapses.org>
|
# Copyright (c) 2007-2010 Andreas Schneider <asn@cryptomilk.org>
|
||||||
#
|
#
|
||||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
@@ -10,10 +10,17 @@ enable_testing()
|
|||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
|
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
|
||||||
|
# Profiling
|
||||||
set(CMAKE_C_FLAGS_PROFILING "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Compiler Flags")
|
set(CMAKE_C_FLAGS_PROFILING "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Compiler Flags")
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
|
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
|
||||||
set(CMAKE_MODULE_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
|
set(CMAKE_MODULE_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
|
||||||
set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
|
set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
|
||||||
|
|
||||||
|
# Address Sanitizer
|
||||||
|
set(CMAKE_C_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer" CACHE STRING "Address sanitizer compiler flags")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Address sanitizer shared linker flags")
|
||||||
|
set(CMAKE_MODULE_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Address sanitizer module linker flags")
|
||||||
|
set(CMAKE_EXEC_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Address sanitizer executable linker flags")
|
||||||
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
|
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
|
||||||
|
|
||||||
function (ADD_CMOCKA_TEST _testName _testSource)
|
function (ADD_CMOCKA_TEST _testName _testSource)
|
||||||
|
|||||||
@@ -25,3 +25,6 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||||||
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
|
||||||
)
|
)
|
||||||
endif (NOT CMAKE_BUILD_TYPE)
|
endif (NOT CMAKE_BUILD_TYPE)
|
||||||
|
|
||||||
|
# Create the compile command database for clang by default
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|||||||
@@ -75,3 +75,10 @@ if (MSVC)
|
|||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
|
||||||
endif (MSVC)
|
endif (MSVC)
|
||||||
|
|
||||||
|
# This removes this annoying warning
|
||||||
|
# "warning: 'BN_CTX_free' is deprecated: first deprecated in OS X 10.7 [-Wdeprecated-declarations]"
|
||||||
|
if (OSX)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
|
||||||
|
endif (OSX)
|
||||||
|
|
||||||
|
|||||||
@@ -26,3 +26,7 @@ endif (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
|
|||||||
if (CMAKE_SYSTEM_NAME MATCHES "OS2")
|
if (CMAKE_SYSTEM_NAME MATCHES "OS2")
|
||||||
set(OS2 TRUE)
|
set(OS2 TRUE)
|
||||||
endif (CMAKE_SYSTEM_NAME MATCHES "OS2")
|
endif (CMAKE_SYSTEM_NAME MATCHES "OS2")
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||||
|
set (OSX TRUE)
|
||||||
|
endif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
# ARGP_LIBRARIES - Link these to use Argp
|
# ARGP_LIBRARIES - Link these to use Argp
|
||||||
# ARGP_DEFINITIONS - Compiler switches required for using Argp
|
# ARGP_DEFINITIONS - Compiler switches required for using Argp
|
||||||
#
|
#
|
||||||
# Copyright (c) 2010 Andreas Schneider <asn@cynapses.org>
|
# Copyright (c) 2010 Andreas Schneider <asn@cryptomilk.org>
|
||||||
#
|
#
|
||||||
# Redistribution and use is allowed according to the terms of the New
|
# Redistribution and use is allowed according to the terms of the New
|
||||||
# BSD license.
|
# BSD license.
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ find_path(GCRYPT_INCLUDE_DIR
|
|||||||
gcrypt.h
|
gcrypt.h
|
||||||
HINTS
|
HINTS
|
||||||
${_GCRYPT_ROOT_HINTS_AND_PATHS}
|
${_GCRYPT_ROOT_HINTS_AND_PATHS}
|
||||||
|
PATH_SUFFIXES
|
||||||
|
include
|
||||||
)
|
)
|
||||||
|
|
||||||
find_library(GCRYPT_LIBRARY
|
find_library(GCRYPT_LIBRARY
|
||||||
@@ -44,6 +46,8 @@ find_library(GCRYPT_LIBRARY
|
|||||||
libgcrypt-11
|
libgcrypt-11
|
||||||
HINTS
|
HINTS
|
||||||
${_GCRYPT_ROOT_HINTS_AND_PATHS}
|
${_GCRYPT_ROOT_HINTS_AND_PATHS}
|
||||||
|
PATH_SUFFIXES
|
||||||
|
lib
|
||||||
)
|
)
|
||||||
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
|
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
|
||||||
|
|
||||||
|
|||||||
61
cmake/Modules/FindNaCl.cmake
Normal file
61
cmake/Modules/FindNaCl.cmake
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# - Try to find NaCl
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# NACL_FOUND - system has NaCl
|
||||||
|
# NACL_INCLUDE_DIRS - the NaCl include directory
|
||||||
|
# NACL_LIBRARIES - Link these to use NaCl
|
||||||
|
# NACL_DEFINITIONS - Compiler switches required for using NaCl
|
||||||
|
#
|
||||||
|
# Copyright (c) 2010 Andreas Schneider <asn@cryptomilk.org>
|
||||||
|
# Copyright (c) 2013 Aris Adamantiadis <aris@badcode.be>
|
||||||
|
#
|
||||||
|
# Redistribution and use is allowed according to the terms of the New
|
||||||
|
# BSD license.
|
||||||
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
if (NACL_LIBRARIES AND NACL_INCLUDE_DIRS)
|
||||||
|
# in cache already
|
||||||
|
set(NACL_FOUND TRUE)
|
||||||
|
else (NACL_LIBRARIES AND NACL_INCLUDE_DIRS)
|
||||||
|
|
||||||
|
find_path(NACL_INCLUDE_DIR
|
||||||
|
NAMES
|
||||||
|
nacl/crypto_box_curve25519xsalsa20poly1305.h
|
||||||
|
PATHS
|
||||||
|
/usr/include
|
||||||
|
/usr/local/include
|
||||||
|
/opt/local/include
|
||||||
|
/sw/include
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(NACL_LIBRARY
|
||||||
|
NAMES
|
||||||
|
nacl
|
||||||
|
PATHS
|
||||||
|
/usr/lib
|
||||||
|
/usr/local/lib
|
||||||
|
/opt/local/lib
|
||||||
|
/sw/lib
|
||||||
|
)
|
||||||
|
|
||||||
|
set(NACL_INCLUDE_DIRS
|
||||||
|
${NACL_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NACL_LIBRARY)
|
||||||
|
set(NACL_LIBRARIES
|
||||||
|
${NACL_LIBRARIES}
|
||||||
|
${NACL_LIBRARY}
|
||||||
|
)
|
||||||
|
endif (NACL_LIBRARY)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(NaCl DEFAULT_MSG NACL_LIBRARIES NACL_INCLUDE_DIRS)
|
||||||
|
|
||||||
|
# show the NACL_INCLUDE_DIRS and NACL_LIBRARIES variables only in the advanced view
|
||||||
|
mark_as_advanced(NACL_INCLUDE_DIRS NACL_LIBRARIES)
|
||||||
|
|
||||||
|
endif (NACL_LIBRARIES AND NACL_INCLUDE_DIRS)
|
||||||
|
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
# - Try to find OpenSSL
|
|
||||||
# Once done this will define
|
|
||||||
#
|
|
||||||
# OPENSSL_ROOT_DIR - Set this variable to the root installation of OpenSSL
|
|
||||||
#
|
|
||||||
# Read-Only variables:
|
|
||||||
# OPENSSL_FOUND - system has OpenSSL
|
|
||||||
# OPENSSL_INCLUDE_DIRS - the OpenSSL include directory
|
|
||||||
# OPENSSL_LIBRARIES - Link these to use OpenSSL
|
|
||||||
# OPENSSL_DEFINITIONS - Compiler switches required for using OpenSSL
|
|
||||||
#
|
|
||||||
#=============================================================================
|
|
||||||
# Copyright (c) 2006-2009 Kitware, Inc.
|
|
||||||
# Copyright (c) 2006 Alexander Neundorf <neundorf@kde.org>
|
|
||||||
# Copyright (c) 2009-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
|
|
||||||
# Copyright (c) 2011 Andreas Schneider <asn@cryptomilk.org>
|
|
||||||
#
|
|
||||||
# Distributed under the OSI-approved BSD License (the "License");
|
|
||||||
# see accompanying file Copyright.txt for details.
|
|
||||||
#
|
|
||||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
||||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the License for more information.
|
|
||||||
#=============================================================================
|
|
||||||
#
|
|
||||||
|
|
||||||
if (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
|
|
||||||
# in cache already
|
|
||||||
set(OPENSSL_FOUND TRUE)
|
|
||||||
else (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
|
|
||||||
|
|
||||||
if (UNIX)
|
|
||||||
find_package(PkgConfig)
|
|
||||||
if (PKG_CONFIG_FOUND)
|
|
||||||
pkg_check_modules(_OPENSSL openssl)
|
|
||||||
endif (PKG_CONFIG_FOUND)
|
|
||||||
endif (UNIX)
|
|
||||||
|
|
||||||
# http://www.slproweb.com/products/Win32OpenSSL.html
|
|
||||||
set(_OPENSSL_ROOT_HINTS
|
|
||||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]"
|
|
||||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]"
|
|
||||||
)
|
|
||||||
|
|
||||||
set(_OPENSSL_ROOT_PATHS
|
|
||||||
"C:/OpenSSL/"
|
|
||||||
"C:/OpenSSL-Win32/"
|
|
||||||
"C:/OpenSSL-Win64/"
|
|
||||||
"$ENV{PROGRAMFILES}/OpenSSL"
|
|
||||||
"$ENV{PROGRAMFILES}/OpenSSL-Win32"
|
|
||||||
"$ENV{PROGRAMFILES}/OpenSSL-Win64"
|
|
||||||
)
|
|
||||||
|
|
||||||
find_path(OPENSSL_ROOT_DIR
|
|
||||||
NAMES
|
|
||||||
include/openssl/ssl.h
|
|
||||||
HINTS
|
|
||||||
${_OPENSSL_ROOT_HINTS}
|
|
||||||
PATHS
|
|
||||||
${_OPENSSL_ROOT_PATHS}
|
|
||||||
)
|
|
||||||
mark_as_advanced(OPENSSL_ROOT_DIR)
|
|
||||||
|
|
||||||
find_path(OPENSSL_INCLUDE_DIR
|
|
||||||
NAMES
|
|
||||||
openssl/ssl.h
|
|
||||||
PATHS
|
|
||||||
/usr/local/include
|
|
||||||
/opt/local/include
|
|
||||||
/sw/include
|
|
||||||
/usr/lib/sfw/include
|
|
||||||
${OPENSSL_ROOT_DIR}/include
|
|
||||||
)
|
|
||||||
|
|
||||||
set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
|
|
||||||
mark_as_advanced(OPENSSL_INCLUDE_DIRS)
|
|
||||||
|
|
||||||
if (WIN32 AND NOT CYGWIN)
|
|
||||||
# MINGW should go here too
|
|
||||||
if (MSVC)
|
|
||||||
# /MD and /MDd are the standard values - if someone wants to use
|
|
||||||
# others, the libnames have to change here too
|
|
||||||
# use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b
|
|
||||||
# TODO: handle /MT and static lib
|
|
||||||
# In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix:
|
|
||||||
# * MD for dynamic-release
|
|
||||||
# * MDd for dynamic-debug
|
|
||||||
# * MT for static-release
|
|
||||||
# * MTd for static-debug
|
|
||||||
|
|
||||||
# Implementation details:
|
|
||||||
# We are using the libraries located in the VC subdir instead of the parent directory eventhough :
|
|
||||||
# libeay32MD.lib is identical to ../libeay32.lib, and
|
|
||||||
# ssleay32MD.lib is identical to ../ssleay32.lib
|
|
||||||
find_library(LIB_EAY_DEBUG
|
|
||||||
NAMES
|
|
||||||
libeay32MDd
|
|
||||||
libeay32
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib/VC
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(LIB_EAY_RELEASE
|
|
||||||
NAMES
|
|
||||||
libeay32MD
|
|
||||||
libeay32
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib/VC
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(SSL_EAY_DEBUG
|
|
||||||
NAMES
|
|
||||||
ssleay32MDd
|
|
||||||
ssleay32
|
|
||||||
ssl
|
|
||||||
PATHS ${OPENSSL_ROOT_DIR}/lib/VC
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(SSL_EAY_RELEASE
|
|
||||||
NAMES
|
|
||||||
ssleay32MD
|
|
||||||
ssleay32
|
|
||||||
ssl
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib/VC
|
|
||||||
)
|
|
||||||
|
|
||||||
if (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
|
|
||||||
set(OPENSSL_LIBRARIES
|
|
||||||
optimized ${SSL_EAY_RELEASE} debug ${SSL_EAY_DEBUG}
|
|
||||||
optimized ${LIB_EAY_RELEASE} debug ${LIB_EAY_DEBUG}
|
|
||||||
)
|
|
||||||
else (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
|
|
||||||
set( OPENSSL_LIBRARIES ${SSL_EAY_RELEASE} ${LIB_EAY_RELEASE} )
|
|
||||||
endif (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
|
|
||||||
|
|
||||||
mark_as_advanced(SSL_EAY_DEBUG SSL_EAY_RELEASE)
|
|
||||||
mark_as_advanced(LIB_EAY_DEBUG LIB_EAY_RELEASE)
|
|
||||||
elseif (MINGW)
|
|
||||||
# same player, for MingW
|
|
||||||
find_library(LIB_EAY
|
|
||||||
NAMES
|
|
||||||
libeay32
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib/MinGW
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(SSL_EAY
|
|
||||||
NAMES
|
|
||||||
ssleay32
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib/MinGW
|
|
||||||
)
|
|
||||||
|
|
||||||
mark_as_advanced(SSL_EAY LIB_EAY)
|
|
||||||
set(OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY})
|
|
||||||
else(MSVC)
|
|
||||||
# Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues:
|
|
||||||
find_library(LIB_EAY
|
|
||||||
NAMES
|
|
||||||
libeay32
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(SSL_EAY
|
|
||||||
NAMES
|
|
||||||
ssleay32
|
|
||||||
PATHS
|
|
||||||
${OPENSSL_ROOT_DIR}/lib
|
|
||||||
)
|
|
||||||
|
|
||||||
mark_as_advanced(SSL_EAY LIB_EAY)
|
|
||||||
set(OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY})
|
|
||||||
endif(MSVC)
|
|
||||||
else (WIN32 AND NOT CYGWIN)
|
|
||||||
find_library(OPENSSL_SSL_LIBRARIES
|
|
||||||
NAMES
|
|
||||||
ssl
|
|
||||||
ssleay32
|
|
||||||
ssleay32MD
|
|
||||||
PATHS
|
|
||||||
${_OPENSSL_LIBDIR}
|
|
||||||
/opt/local/lib
|
|
||||||
/sw/lib
|
|
||||||
/usr/sfw/lib/64
|
|
||||||
/usr/sfw/lib
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(OPENSSL_CRYPTO_LIBRARIES
|
|
||||||
NAMES
|
|
||||||
crypto
|
|
||||||
PATHS
|
|
||||||
${_OPENSSL_LIBDIR}
|
|
||||||
/opt/local/lib
|
|
||||||
/sw/lib
|
|
||||||
/usr/sfw/lib/64
|
|
||||||
/usr/sfw/lib
|
|
||||||
)
|
|
||||||
|
|
||||||
mark_as_advanced(OPENSSL_CRYPTO_LIBRARIES OPENSSL_SSL_LIBRARIES)
|
|
||||||
set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES})
|
|
||||||
endif (WIN32 AND NOT CYGWIN)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(OpenSSL DEFAULT_MSG OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIRS)
|
|
||||||
|
|
||||||
endif (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
# - Try to find ZLIB
|
|
||||||
# Once done this will define
|
|
||||||
#
|
|
||||||
# ZLIB_ROOT_DIR - Set this variable to the root installation of ZLIB
|
|
||||||
#
|
|
||||||
# Read-Only variables:
|
|
||||||
# ZLIB_FOUND - system has ZLIB
|
|
||||||
# ZLIB_INCLUDE_DIRS - the ZLIB include directory
|
|
||||||
# ZLIB_LIBRARIES - Link these to use ZLIB
|
|
||||||
#
|
|
||||||
# ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
|
|
||||||
# ZLIB_VERSION_MAJOR - The major version of zlib
|
|
||||||
# ZLIB_VERSION_MINOR - The minor version of zlib
|
|
||||||
# ZLIB_VERSION_PATCH - The patch version of zlib
|
|
||||||
# ZLIB_VERSION_TWEAK - The tweak version of zlib
|
|
||||||
#
|
|
||||||
# The following variable are provided for backward compatibility
|
|
||||||
#
|
|
||||||
# ZLIB_MAJOR_VERSION - The major version of zlib
|
|
||||||
# ZLIB_MINOR_VERSION - The minor version of zlib
|
|
||||||
# ZLIB_PATCH_VERSION - The patch version of zlib
|
|
||||||
#
|
|
||||||
#=============================================================================
|
|
||||||
# Copyright (c) 2001-2009 Kitware, Inc.
|
|
||||||
# Copyright (c) 2011 Andreas Schneider <asn@cryptomilk.org>
|
|
||||||
#
|
|
||||||
# Distributed under the OSI-approved BSD License (the "License");
|
|
||||||
# see accompanying file Copyright.txt for details.
|
|
||||||
#
|
|
||||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
||||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the License for more information.
|
|
||||||
#=============================================================================
|
|
||||||
#
|
|
||||||
|
|
||||||
if (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
|
|
||||||
# in cache already
|
|
||||||
set(ZLIB_FOUND TRUE)
|
|
||||||
else (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
|
|
||||||
|
|
||||||
set(_ZLIB_ROOT_HINTS
|
|
||||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include"
|
|
||||||
)
|
|
||||||
|
|
||||||
set(_ZLIB_ROOT_PATHS
|
|
||||||
"$ENV{PROGRAMFILES}/zlib"
|
|
||||||
)
|
|
||||||
|
|
||||||
find_path(ZLIB_ROOT_DIR
|
|
||||||
NAMES
|
|
||||||
include/zlib.h
|
|
||||||
HINTS
|
|
||||||
${_ZLIB_ROOT_HINTS}
|
|
||||||
PATHS
|
|
||||||
${_ZLIB_ROOT_PATHS}
|
|
||||||
)
|
|
||||||
mark_as_advanced(ZLIB_ROOT_DIR)
|
|
||||||
|
|
||||||
# check for header file
|
|
||||||
find_path(ZLIB_INCLUDE_DIR
|
|
||||||
NAMES
|
|
||||||
zlib.h
|
|
||||||
PATHS
|
|
||||||
/usr/local/include
|
|
||||||
/opt/local/include
|
|
||||||
/sw/include
|
|
||||||
/usr/lib/sfw/include
|
|
||||||
${ZLIB_ROOT_DIR}/include
|
|
||||||
)
|
|
||||||
mark_as_advanced(ZLIB_INCLUDE_DIR)
|
|
||||||
|
|
||||||
# check version number
|
|
||||||
if (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
|
|
||||||
file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
|
|
||||||
|
|
||||||
string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
|
|
||||||
string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
|
|
||||||
string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
|
|
||||||
|
|
||||||
set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
|
|
||||||
|
|
||||||
# only append a TWEAK version if it exists:
|
|
||||||
set(ZLIB_VERSION_TWEAK "")
|
|
||||||
if ("${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
|
|
||||||
set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
|
|
||||||
set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
|
|
||||||
endif ("${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
|
|
||||||
|
|
||||||
set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
|
|
||||||
set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
|
|
||||||
set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
|
|
||||||
endif (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
|
|
||||||
|
|
||||||
find_library(ZLIB_LIBRARY
|
|
||||||
NAMES
|
|
||||||
z
|
|
||||||
zdll
|
|
||||||
zlib
|
|
||||||
zlib1
|
|
||||||
zlibd
|
|
||||||
PATHS
|
|
||||||
/usr/local/lib
|
|
||||||
/opt/local/lib
|
|
||||||
/sw/lib
|
|
||||||
/usr/sfw/lib/64
|
|
||||||
/usr/sfw/lib
|
|
||||||
${ZLIB_ROOT_DIR}/lib
|
|
||||||
)
|
|
||||||
mark_as_advanced(ZLIB_LIBRARY)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(ZLIB DEFAULT_MSG ZLIB_INCLUDE_DIR ZLIB_LIBRARY)
|
|
||||||
#find_package_handle_standard_args(ZLIB REQUIRED_VARS ZLIB_INCLUDE_DIR ZLIB_LIBRARY
|
|
||||||
# VERSION_VAR ZLIB_VERSION_STRING)
|
|
||||||
|
|
||||||
if (ZLIB_FOUND)
|
|
||||||
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
|
|
||||||
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
|
|
||||||
endif (ZLIB_FOUND)
|
|
||||||
endif (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# - MACRO_ADD_COMPILE_FLAGS(target_name flag1 ... flagN)
|
|
||||||
|
|
||||||
# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
|
|
||||||
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
|
|
||||||
#
|
|
||||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
|
||||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
|
||||||
|
|
||||||
|
|
||||||
macro (MACRO_ADD_COMPILE_FLAGS _target)
|
|
||||||
|
|
||||||
get_target_property(_flags ${_target} COMPILE_FLAGS)
|
|
||||||
if (_flags)
|
|
||||||
set(_flags ${_flags} ${ARGN})
|
|
||||||
else (_flags)
|
|
||||||
set(_flags ${ARGN})
|
|
||||||
endif (_flags)
|
|
||||||
|
|
||||||
set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${_flags})
|
|
||||||
|
|
||||||
endmacro (MACRO_ADD_COMPILE_FLAGS)
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# - MACRO_ADD_LINK_FLAGS(target_name flag1 ... flagN)
|
|
||||||
|
|
||||||
# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
|
|
||||||
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
|
|
||||||
#
|
|
||||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
|
||||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
|
||||||
|
|
||||||
macro (MACRO_ADD_LINK_FLAGS _target)
|
|
||||||
|
|
||||||
get_target_property(_flags ${_target} LINK_FLAGS)
|
|
||||||
if (_flags)
|
|
||||||
set(_flags "${_flags} ${ARGN}")
|
|
||||||
else (_flags)
|
|
||||||
set(_flags "${ARGN}")
|
|
||||||
endif (_flags)
|
|
||||||
|
|
||||||
set_target_properties(${_target} PROPERTIES LINK_FLAGS "${_flags}")
|
|
||||||
|
|
||||||
endmacro (MACRO_ADD_LINK_FLAGS)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# - MACRO_ADD_PLUGIN(name [WITH_PREFIX] file1 .. fileN)
|
|
||||||
#
|
|
||||||
# Create a plugin from the given source files.
|
|
||||||
# If WITH_PREFIX is given, the resulting plugin will have the
|
|
||||||
# prefix "lib", otherwise it won't.
|
|
||||||
#
|
|
||||||
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
|
|
||||||
# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
|
|
||||||
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
|
|
||||||
#
|
|
||||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
|
||||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
|
||||||
|
|
||||||
|
|
||||||
macro (MACRO_ADD_PLUGIN _target_NAME _with_PREFIX)
|
|
||||||
|
|
||||||
if (${_with_PREFIX} STREQUAL "WITH_PREFIX")
|
|
||||||
set(_first_SRC)
|
|
||||||
else (${_with_PREFIX} STREQUAL "WITH_PREFIX")
|
|
||||||
set(_first_SRC ${_with_PREFIX})
|
|
||||||
endif (${_with_PREFIX} STREQUAL "WITH_PREFIX")
|
|
||||||
|
|
||||||
add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
|
|
||||||
|
|
||||||
if (_first_SRC)
|
|
||||||
set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
|
|
||||||
endif (_first_SRC)
|
|
||||||
|
|
||||||
endmacro (MACRO_ADD_PLUGIN _name _sources)
|
|
||||||
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# - macro_copy_file(_src _dst)
|
|
||||||
# Copies a file to ${_dst} only if ${_src} is different (newer) than ${_dst}
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# macro_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/icon.png ${CMAKE_CURRENT_BINARY_DIR}/.)
|
|
||||||
# Copies file icon.png to ${CMAKE_CURRENT_BINARY_DIR} directory
|
|
||||||
#
|
|
||||||
# Copyright (c) 2006-2007 Wengo
|
|
||||||
# Copyright (c) 2006-2008 Andreas Schneider <mail@cynapses.org>
|
|
||||||
#
|
|
||||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
|
||||||
# For details see the accompanying COPYING file.
|
|
||||||
|
|
||||||
|
|
||||||
macro (macro_copy_file _src _dst)
|
|
||||||
# Removes all path containing .svn or CVS or CMakeLists.txt during the copy
|
|
||||||
if (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
|
|
||||||
|
|
||||||
if (CMAKE_VERBOSE_MAKEFILE)
|
|
||||||
message(STATUS "Copy file from ${_src} to ${_dst}")
|
|
||||||
endif (CMAKE_VERBOSE_MAKEFILE)
|
|
||||||
|
|
||||||
# Creates directory if necessary
|
|
||||||
get_filename_component(_path ${_dst} PATH)
|
|
||||||
file(MAKE_DIRECTORY ${_path})
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND
|
|
||||||
${CMAKE_COMMAND} -E copy_if_different ${_src} ${_dst}
|
|
||||||
OUTPUT_QUIET
|
|
||||||
)
|
|
||||||
endif (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
|
|
||||||
endmacro (macro_copy_file)
|
|
||||||
@@ -2,10 +2,18 @@
|
|||||||
#
|
#
|
||||||
# Adds a doxygen target that runs doxygen to generate the html
|
# Adds a doxygen target that runs doxygen to generate the html
|
||||||
# and optionally the LaTeX API documentation.
|
# and optionally the LaTeX API documentation.
|
||||||
# The doxygen target is added to the doc target as dependency.
|
# The doxygen target is added to the doc target as a dependency.
|
||||||
# i.e.: the API documentation is built with:
|
# i.e.: the API documentation is built with:
|
||||||
# make doc
|
# make doc
|
||||||
#
|
#
|
||||||
|
# USAGE: GLOBAL INSTALL
|
||||||
|
#
|
||||||
|
# Install it with:
|
||||||
|
# cmake ./ && sudo make install
|
||||||
|
# Add the following to the CMakeLists.txt of your project:
|
||||||
|
# include(UseDoxygen OPTIONAL)
|
||||||
|
# Optionally copy Doxyfile.in in the directory of CMakeLists.txt and edit it.
|
||||||
|
#
|
||||||
# USAGE: INCLUDE IN PROJECT
|
# USAGE: INCLUDE IN PROJECT
|
||||||
#
|
#
|
||||||
# set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
# set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
@@ -13,88 +21,120 @@
|
|||||||
# Add the Doxyfile.in and UseDoxygen.cmake files to the projects source directory.
|
# Add the Doxyfile.in and UseDoxygen.cmake files to the projects source directory.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
# CONFIGURATION
|
||||||
|
#
|
||||||
|
# To configure Doxygen you can edit Doxyfile.in and set some variables in cmake.
|
||||||
# Variables you may define are:
|
# Variables you may define are:
|
||||||
# DOXYFILE_OUTPUT_DIR - Path where the Doxygen output is stored. Defaults to "doc".
|
# DOXYFILE_SOURCE_DIR - Path where the Doxygen input files are.
|
||||||
#
|
# Defaults to the current source directory.
|
||||||
# DOXYFILE_LATEX_DIR - Directory where the Doxygen LaTeX output is stored. Defaults to "latex".
|
# DOXYFILE_EXTRA_SOURCES - Additional source diretories/files for Doxygen to scan.
|
||||||
#
|
# The Paths should be in double quotes and separated by space. e.g.:
|
||||||
# DOXYFILE_HTML_DIR - Directory where the Doxygen html output is stored. Defaults to "html".
|
# "${CMAKE_CURRENT_BINARY_DIR}/foo.c" "${CMAKE_CURRENT_BINARY_DIR}/bar/"
|
||||||
|
#
|
||||||
|
# DOXYFILE_OUTPUT_DIR - Path where the Doxygen output is stored.
|
||||||
|
# Defaults to "${CMAKE_CURRENT_BINARY_DIR}/doc".
|
||||||
|
#
|
||||||
|
# DOXYFILE_LATEX - ON/OFF; Set to "ON" if you want the LaTeX documentation
|
||||||
|
# to be built.
|
||||||
|
# DOXYFILE_LATEX_DIR - Directory relative to DOXYFILE_OUTPUT_DIR where
|
||||||
|
# the Doxygen LaTeX output is stored. Defaults to "latex".
|
||||||
|
#
|
||||||
|
# DOXYFILE_HTML_DIR - Directory relative to DOXYFILE_OUTPUT_DIR where
|
||||||
|
# the Doxygen html output is stored. Defaults to "html".
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
|
# Copyright (c) 2009, 2010, 2011 Tobias Rautenkranz <tobias@rautenkranz.ch>
|
||||||
# Copyright (c) 2010 Andreas Schneider <mail@cynapses.org>
|
|
||||||
#
|
#
|
||||||
# Redistribution and use is allowed according to the terms of the New
|
# Redistribution and use is allowed according to the terms of the New
|
||||||
# BSD license.
|
# BSD license.
|
||||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
#
|
#
|
||||||
|
|
||||||
macro(usedoxygen_set_default name value)
|
macro(usedoxygen_set_default name value type docstring)
|
||||||
if(NOT DEFINED "${name}")
|
if(NOT DEFINED "${name}")
|
||||||
set("${name}" "${value}")
|
set("${name}" "${value}" CACHE "${type}" "${docstring}")
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
|
|
||||||
if(DOXYGEN_FOUND)
|
if(DOXYGEN_FOUND)
|
||||||
find_file(DOXYFILE_IN
|
find_file(DOXYFILE_IN "Doxyfile.in"
|
||||||
NAMES
|
PATHS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_ROOT}/Modules/"
|
||||||
doxy.config.in
|
NO_DEFAULT_PATH
|
||||||
PATHS
|
DOC "Path to the doxygen configuration template file")
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
set(DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
|
||||||
${CMAKE_ROOT}/Modules/
|
include(FindPackageHandleStandardArgs)
|
||||||
NO_DEFAULT_PATH)
|
find_package_handle_standard_args(DOXYFILE_IN DEFAULT_MSG "DOXYFILE_IN")
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(DOXYFILE_IN DEFAULT_MSG "DOXYFILE_IN")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
|
if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
|
||||||
add_custom_target(doxygen ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config)
|
usedoxygen_set_default(DOXYFILE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc"
|
||||||
|
PATH "Doxygen output directory")
|
||||||
|
usedoxygen_set_default(DOXYFILE_HTML_DIR "html"
|
||||||
|
STRING "Doxygen HTML output directory")
|
||||||
|
usedoxygen_set_default(DOXYFILE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
PATH "Input files source directory")
|
||||||
|
usedoxygen_set_default(DOXYFILE_EXTRA_SOURCE_DIRS ""
|
||||||
|
STRING "Additional source files/directories separated by space")
|
||||||
|
set(DOXYFILE_SOURCE_DIRS "\"${DOXYFILE_SOURCE_DIR}\" ${DOXYFILE_EXTRA_SOURCES}")
|
||||||
|
|
||||||
usedoxygen_set_default(DOXYFILE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
usedoxygen_set_default(DOXYFILE_LATEX YES BOOL "Generate LaTeX API documentation" OFF)
|
||||||
usedoxygen_set_default(DOXYFILE_HTML_DIR "html")
|
usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex" STRING "LaTex output directory")
|
||||||
|
|
||||||
set_property(DIRECTORY APPEND PROPERTY
|
mark_as_advanced(DOXYFILE_OUTPUT_DIR DOXYFILE_HTML_DIR DOXYFILE_LATEX_DIR
|
||||||
ADDITIONAL_MAKE_CLEAN_FILES "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
|
DOXYFILE_SOURCE_DIR DOXYFILE_EXTRA_SOURCE_DIRS DOXYFILE_IN)
|
||||||
|
|
||||||
set(DOXYFILE_LATEX FALSE)
|
|
||||||
set(DOXYFILE_PDFLATEX FALSE)
|
|
||||||
set(DOXYFILE_DOT FALSE)
|
|
||||||
|
|
||||||
#find_package(LATEX)
|
set_property(DIRECTORY
|
||||||
#if(LATEX_COMPILER AND MAKEINDEX_COMPILER)
|
APPEND PROPERTY
|
||||||
# set(DOXYFILE_LATEX TRUE)
|
ADDITIONAL_MAKE_CLEAN_FILES
|
||||||
# usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex")
|
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
|
||||||
#
|
|
||||||
# set_property(DIRECTORY APPEND PROPERTY
|
|
||||||
# ADDITIONAL_MAKE_CLEAN_FILES
|
|
||||||
# "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
|
|
||||||
#
|
|
||||||
# if(PDFLATEX_COMPILER)
|
|
||||||
# set(DOXYFILE_PDFLATEX TRUE)
|
|
||||||
# endif()
|
|
||||||
# if(DOXYGEN_DOT_EXECUTABLE)
|
|
||||||
# set(DOXYFILE_DOT TRUE)
|
|
||||||
# endif()
|
|
||||||
#
|
|
||||||
# add_custom_command(TARGET doxygen
|
|
||||||
# POST_BUILD
|
|
||||||
# COMMAND ${CMAKE_MAKE_PROGRAM}
|
|
||||||
# WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
|
|
||||||
#endif()
|
|
||||||
|
|
||||||
configure_file(${DOXYFILE_IN} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config ESCAPE_QUOTES IMMEDIATE @ONLY)
|
add_custom_target(doxygen
|
||||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in)
|
COMMAND "${DOXYGEN_EXECUTABLE}"
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in ${CMAKE_CURRENT_BINARY_DIR}/doxy.trac ESCAPE_QUOTES IMMEDIATE @ONLY)
|
"${DOXYFILE}"
|
||||||
add_custom_target(doxygen-trac ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.trac)
|
COMMENT "Writing documentation to ${DOXYFILE_OUTPUT_DIR}..."
|
||||||
endif()
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
get_target_property(DOC_TARGET doc TYPE)
|
set(DOXYFILE_DOT "NO")
|
||||||
if(NOT DOC_TARGET)
|
if(DOXYGEN_DOT_EXECUTABLE)
|
||||||
add_custom_target(doc)
|
set(DOXYFILE_DOT "YES")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_dependencies(doc doxygen)
|
## LaTeX
|
||||||
|
set(DOXYFILE_PDFLATEX "NO")
|
||||||
|
|
||||||
|
set_property(DIRECTORY APPEND PROPERTY
|
||||||
|
ADDITIONAL_MAKE_CLEAN_FILES
|
||||||
|
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
|
||||||
|
|
||||||
|
if(DOXYFILE_LATEX STREQUAL "ON")
|
||||||
|
set(DOXYFILE_GENERATE_LATEX "YES")
|
||||||
|
find_package(LATEX)
|
||||||
|
find_program(DOXYFILE_MAKE make)
|
||||||
|
mark_as_advanced(DOXYFILE_MAKE)
|
||||||
|
if(LATEX_COMPILER AND MAKEINDEX_COMPILER AND DOXYFILE_MAKE)
|
||||||
|
if(PDFLATEX_COMPILER)
|
||||||
|
set(DOXYFILE_PDFLATEX "YES")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_command(TARGET doxygen
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND "${DOXYFILE_MAKE}"
|
||||||
|
COMMENT "Running LaTeX for Doxygen documentation in ${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}..."
|
||||||
|
WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
|
||||||
|
else()
|
||||||
|
set(DOXYGEN_LATEX "NO")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(DOXYFILE_GENERATE_LATEX "NO")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
configure_file("${DOXYFILE_IN}" "${DOXYFILE}" @ONLY)
|
||||||
|
|
||||||
|
add_custom_target(doc)
|
||||||
|
add_dependencies(doc doxygen)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -17,9 +17,24 @@
|
|||||||
/* Define to 1 if you have the <argp.h> header file. */
|
/* Define to 1 if you have the <argp.h> header file. */
|
||||||
#cmakedefine HAVE_ARGP_H 1
|
#cmakedefine HAVE_ARGP_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <aprpa/inet.h> header file. */
|
||||||
|
#cmakedefine HAVE_ARPA_INET_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <pty.h> header file. */
|
/* Define to 1 if you have the <pty.h> header file. */
|
||||||
#cmakedefine HAVE_PTY_H 1
|
#cmakedefine HAVE_PTY_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <utmp.h> header file. */
|
||||||
|
#cmakedefine HAVE_UTMP_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <util.h> header file. */
|
||||||
|
#cmakedefine HAVE_UTIL_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <libutil.h> header file. */
|
||||||
|
#cmakedefine HAVE_LIBUTIL_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_TIME_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <termios.h> header file. */
|
/* Define to 1 if you have the <termios.h> header file. */
|
||||||
#cmakedefine HAVE_TERMIOS_H 1
|
#cmakedefine HAVE_TERMIOS_H 1
|
||||||
|
|
||||||
@@ -61,6 +76,9 @@
|
|||||||
|
|
||||||
/*************************** FUNCTIONS ***************************/
|
/*************************** FUNCTIONS ***************************/
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `CRYPTO_ctr128_encrypt' function. */
|
||||||
|
#cmakedefine HAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `snprintf' function. */
|
/* Define to 1 if you have the `snprintf' function. */
|
||||||
#cmakedefine HAVE_SNPRINTF 1
|
#cmakedefine HAVE_SNPRINTF 1
|
||||||
|
|
||||||
@@ -79,9 +97,15 @@
|
|||||||
/* Define to 1 if you have the `_vsnprintf_s' function. */
|
/* Define to 1 if you have the `_vsnprintf_s' function. */
|
||||||
#cmakedefine HAVE__VSNPRINTF_S 1
|
#cmakedefine HAVE__VSNPRINTF_S 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `isblank' function. */
|
||||||
|
#cmakedefine HAVE_ISBLANK 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `strncpy' function. */
|
/* Define to 1 if you have the `strncpy' function. */
|
||||||
#cmakedefine HAVE_STRNCPY 1
|
#cmakedefine HAVE_STRNCPY 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strndup' function. */
|
||||||
|
#cmakedefine HAVE_STRNDUP 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `cfmakeraw' function. */
|
/* Define to 1 if you have the `cfmakeraw' function. */
|
||||||
#cmakedefine HAVE_CFMAKERAW 1
|
#cmakedefine HAVE_CFMAKERAW 1
|
||||||
|
|
||||||
@@ -123,13 +147,16 @@
|
|||||||
/* Define to 1 if you have the `pthread' library (-lpthread). */
|
/* Define to 1 if you have the `pthread' library (-lpthread). */
|
||||||
#cmakedefine HAVE_PTHREAD 1
|
#cmakedefine HAVE_PTHREAD 1
|
||||||
|
|
||||||
|
|
||||||
/**************************** OPTIONS ****************************/
|
/**************************** OPTIONS ****************************/
|
||||||
|
|
||||||
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
|
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
|
||||||
#cmakedefine HAVE_MSC_THREAD_LOCAL_STORAGE 1
|
#cmakedefine HAVE_MSC_THREAD_LOCAL_STORAGE 1
|
||||||
|
|
||||||
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
|
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
|
||||||
|
#cmakedefine HAVE_GCC_NARG_MACRO 1
|
||||||
|
|
||||||
|
#cmakedefine HAVE_COMPILER__FUNC__ 1
|
||||||
|
#cmakedefine HAVE_COMPILER__FUNCTION__ 1
|
||||||
|
|
||||||
/* Define to 1 if you want to enable GSSAPI */
|
/* Define to 1 if you want to enable GSSAPI */
|
||||||
#cmakedefine WITH_GSSAPI 1
|
#cmakedefine WITH_GSSAPI 1
|
||||||
@@ -155,6 +182,9 @@
|
|||||||
/* Define to 1 if you want to enable calltrace debug output */
|
/* Define to 1 if you want to enable calltrace debug output */
|
||||||
#cmakedefine DEBUG_CALLTRACE 1
|
#cmakedefine DEBUG_CALLTRACE 1
|
||||||
|
|
||||||
|
/* Define to 1 if you want to enable NaCl support */
|
||||||
|
#cmakedefine WITH_NACL 1
|
||||||
|
|
||||||
/*************************** ENDIAN *****************************/
|
/*************************** ENDIAN *****************************/
|
||||||
|
|
||||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||||
|
|||||||
@@ -721,7 +721,7 @@ EXCLUDE_SYMLINKS = NO
|
|||||||
EXCLUDE_PATTERNS = */.git/* \
|
EXCLUDE_PATTERNS = */.git/* \
|
||||||
*/.svn/* \
|
*/.svn/* \
|
||||||
*/cmake/* \
|
*/cmake/* \
|
||||||
*/build/*
|
*/obj/*
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
@@ -1628,7 +1628,7 @@ INCLUDE_FILE_PATTERNS =
|
|||||||
# undefined via #undef or recursively expanded use the := operator
|
# undefined via #undef or recursively expanded use the := operator
|
||||||
# instead of the = operator.
|
# instead of the = operator.
|
||||||
|
|
||||||
PREDEFINED =
|
PREDEFINED = WITH_SERVER WITH_SFTP WITH_PCAP
|
||||||
|
|
||||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
||||||
# this tag can be used to specify a list of macro names that should be expanded.
|
# this tag can be used to specify a list of macro names that should be expanded.
|
||||||
@@ -285,7 +285,7 @@ int authenticate_kbdint(ssh_session session)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ssh_userauth_none(session, NULL, NULL);
|
rc = ssh_userauth_none(session, NULL);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@endcode
|
@endcode
|
||||||
@@ -304,7 +304,7 @@ int test_several_auth_methods(ssh_session session)
|
|||||||
{
|
{
|
||||||
int method, rc;
|
int method, rc;
|
||||||
|
|
||||||
rc = ssh_userauth_none(session, NULL, NULL);
|
rc = ssh_userauth_none(session, NULL);
|
||||||
if (rc != SSH_AUTH_SUCCESS) {
|
if (rc != SSH_AUTH_SUCCESS) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ If an error has been encountered, it returns a negative value:
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
unsigned int nbytes;
|
int nbytes;
|
||||||
|
|
||||||
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
|
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
|
||||||
while (nbytes > 0)
|
while (nbytes > 0)
|
||||||
|
|||||||
119
doc/curve25519-sha256@libssh.org.txt
Normal file
119
doc/curve25519-sha256@libssh.org.txt
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
curve25519-sha256@libssh.org.txt Aris Adamantiadis <aris@badcode.be>
|
||||||
|
21/9/2013
|
||||||
|
|
||||||
|
1. Introduction
|
||||||
|
|
||||||
|
This document describes the key exchange methode curve25519-sha256@libssh.org
|
||||||
|
for SSH version 2 protocol. It is provided as an alternative to the existing
|
||||||
|
key exchange mechanisms based on either Diffie-Hellman or Elliptic Curve Diffie-
|
||||||
|
Hellman [RFC5656].
|
||||||
|
The reason is the following : During summer of 2013, revelations from ex-
|
||||||
|
consultant at NSA Edward Snowden gave proof that NSA willingly inserts backdoors
|
||||||
|
into softwares, hardware components and published standards. While it is still
|
||||||
|
believed that the mathematics behind ECC cryptography are still sound and solid,
|
||||||
|
some people (including Bruce Schneier [SCHNEIER]), showed their lack of confidence
|
||||||
|
in NIST-published curves such as nistp256, nistp384, nistp521, for which constant
|
||||||
|
parameters (including the generator point) are defined without explanation. It
|
||||||
|
is also believed that NSA had a word to say in their definition. These curves
|
||||||
|
are not the most secure or fastest possible for their key sizes [DJB], and
|
||||||
|
researchers think it is possible that NSA have ways of cracking NIST curves.
|
||||||
|
It is also interesting to note that SSH belongs to the list of protocols the NSA
|
||||||
|
claims to be able to eavesdrop. Having a secure replacement would make passive
|
||||||
|
attacks much harder if such a backdoor exists.
|
||||||
|
|
||||||
|
However an alternative exists in the form of Curve25519. This algorithm has been
|
||||||
|
proposed in 2006 by DJB [Curve25519]. Its main strengths are its speed, its
|
||||||
|
constant-time run time (and resistance against side-channel attacks), and its
|
||||||
|
lack of nebulous hard-coded constants.
|
||||||
|
|
||||||
|
The reference version being used in this document is the one described in
|
||||||
|
[Curve25519] as implemented in the library NaCl [NaCl].
|
||||||
|
This document does not attempt to provide alternatives to the ecdsa-sha1-*
|
||||||
|
authentication keys.
|
||||||
|
|
||||||
|
2. Key exchange
|
||||||
|
|
||||||
|
The key exchange procedure is very similar to the one described chapter 4 of
|
||||||
|
[RFC5656]. Public ephemeral keys are transmitted over SSH encapsulated into
|
||||||
|
standard SSH strings.
|
||||||
|
|
||||||
|
The following is an overview of the key exchange process:
|
||||||
|
|
||||||
|
Client Server
|
||||||
|
------ ------
|
||||||
|
Generate ephemeral key pair.
|
||||||
|
SSH_MSG_KEX_ECDH_INIT -------->
|
||||||
|
Verify that client public key
|
||||||
|
length is 32 bytes.
|
||||||
|
Generate ephemeral key pair.
|
||||||
|
Compute shared secret.
|
||||||
|
Generate and sign exchange hash.
|
||||||
|
<-------- SSH_MSG_KEX_ECDH_REPLY
|
||||||
|
Verify that server public key length is 32 bytes.
|
||||||
|
* Verify host keys belong to server.
|
||||||
|
Compute shared secret.
|
||||||
|
Generate exchange hash.
|
||||||
|
Verify server's signature.
|
||||||
|
|
||||||
|
* Optional but strongly recommanded as this protects against MITM attacks.
|
||||||
|
|
||||||
|
This is implemented using the same messages as described in RFC5656 chapter 4
|
||||||
|
|
||||||
|
3. Method Name
|
||||||
|
|
||||||
|
The name of this key exchange method is "curve25519-sha256@libssh.org".
|
||||||
|
|
||||||
|
4. Implementation considerations
|
||||||
|
|
||||||
|
The whole method is based on the curve25519 scalar multiplication. In this
|
||||||
|
method, a private key is a scalar of 256 bits, and a public key is a point
|
||||||
|
of 256 bits.
|
||||||
|
|
||||||
|
4.1. Private key generation
|
||||||
|
|
||||||
|
A 32 bytes private key should be generated for each new connection,
|
||||||
|
using a secure PRNG. The following actions must be done on the private key:
|
||||||
|
mysecret[0] &= 248;
|
||||||
|
mysecret[31] &= 127;
|
||||||
|
mysecret[31] |= 64;
|
||||||
|
In order to keep the key valid. However, many cryptographic libraries will do
|
||||||
|
this automatically.
|
||||||
|
It should be noted that, in opposition to NIST curves, no special validation
|
||||||
|
should be done to ensure the result is a valid and secure private key.
|
||||||
|
|
||||||
|
4.2 Public key generation
|
||||||
|
|
||||||
|
The 32 bytes public key of either a client or a server must be generated using
|
||||||
|
the 32 bytes private key and a common generator base. This base is defined as 9
|
||||||
|
followed by all zeroes:
|
||||||
|
const unsigned char basepoint[32] = {9};
|
||||||
|
|
||||||
|
The public key is calculated using the cryptographic scalar multiplication:
|
||||||
|
const unsigned char privkey[32];
|
||||||
|
unsigned char pubkey[32];
|
||||||
|
crypto_scalarmult (pubkey, privkey, basepoint);
|
||||||
|
However some cryptographic libraries may provide a combined function:
|
||||||
|
crypto_scalarmult_base (pubkey, privkey);
|
||||||
|
|
||||||
|
It should be noted that, in opposition to NIST curves, no special validation
|
||||||
|
should be done to ensure the received public keys are valid curves point. The
|
||||||
|
Curve25519 algorithm ensure that every possible public key maps to a valid
|
||||||
|
ECC Point.
|
||||||
|
|
||||||
|
4.3 Shared secret generation
|
||||||
|
|
||||||
|
The shared secret, k, is defined in SSH specifications to be a big integer.
|
||||||
|
This number is calculated using the following procedure:
|
||||||
|
|
||||||
|
X is the 32 bytes point obtained by the scalar multiplication of the other
|
||||||
|
side's public key and the local private key scalar.
|
||||||
|
|
||||||
|
The whole 32 bytes of the number X are then converted into a big integer k.
|
||||||
|
This conversion follows the network byte order. This step differs from
|
||||||
|
RFC5656.
|
||||||
|
|
||||||
|
[RFC5656] http://tools.ietf.org/html/rfc5656
|
||||||
|
[SCHNEIER] https://www.schneier.com/blog/archives/2013/09/the_nsa_is_brea.html#c1675929
|
||||||
|
[DJB] http://cr.yp.to/talks/2013.05.31/slides-dan+tanja-20130531-4x3.pdf
|
||||||
|
[Curve25519] "Curve25519: new Diffie-Hellman speed records."
|
||||||
|
http://cr.yp.to/ecdh/curve25519-20060209.pdf
|
||||||
1546
doc/doxy.trac.in
1546
doc/doxy.trac.in
File diff suppressed because it is too large
Load Diff
@@ -144,10 +144,10 @@ or whatever use you have for it.
|
|||||||
|
|
||||||
@subsection libssh_reverse Doing reverse port forwarding with libssh
|
@subsection libssh_reverse Doing reverse port forwarding with libssh
|
||||||
|
|
||||||
To do reverse port forwarding, call ssh_forward_listen(),
|
To do reverse port forwarding, call ssh_channel_listen_forward(),
|
||||||
then ssh_forward_accept().
|
then ssh_channel_accept_forward().
|
||||||
|
|
||||||
When you call ssh_forward_listen(), you can let the remote server
|
When you call ssh_channel_listen_forward(), you can let the remote server
|
||||||
chose the non-priviledged port it should listen to. Otherwise, you can chose
|
chose the non-priviledged port it should listen to. Otherwise, you can chose
|
||||||
your own priviledged or non-priviledged port. Beware that you should have
|
your own priviledged or non-priviledged port. Beware that you should have
|
||||||
administrative priviledges on the remote server to open a priviledged port
|
administrative priviledges on the remote server to open a priviledged port
|
||||||
@@ -164,6 +164,7 @@ int web_server(ssh_session session)
|
|||||||
ssh_channel channel;
|
ssh_channel channel;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int nbytes, nwritten;
|
int nbytes, nwritten;
|
||||||
|
int port = 0;
|
||||||
char *helloworld = ""
|
char *helloworld = ""
|
||||||
"HTTP/1.1 200 OK\n"
|
"HTTP/1.1 200 OK\n"
|
||||||
"Content-Type: text/html\n"
|
"Content-Type: text/html\n"
|
||||||
@@ -178,7 +179,7 @@ int web_server(ssh_session session)
|
|||||||
" </body>\n"
|
" </body>\n"
|
||||||
"</html>\n";
|
"</html>\n";
|
||||||
|
|
||||||
rc = ssh_forward_listen(session, NULL, 8080, NULL);
|
rc = ssh_channel_listen_forward(session, NULL, 8080, NULL);
|
||||||
if (rc != SSH_OK)
|
if (rc != SSH_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error opening remote port: %s\n",
|
fprintf(stderr, "Error opening remote port: %s\n",
|
||||||
@@ -186,7 +187,7 @@ int web_server(ssh_session session)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = ssh_forward_accept(session, 60000);
|
channel = ssh_channel_accept_forward(session, 60000, &port);
|
||||||
if (channel == NULL)
|
if (channel == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error waiting for incoming connection: %s\n",
|
fprintf(stderr, "Error waiting for incoming connection: %s\n",
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ int show_remote_processes(ssh_session session)
|
|||||||
ssh_channel channel;
|
ssh_channel channel;
|
||||||
int rc;
|
int rc;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
unsigned int nbytes;
|
int nbytes;
|
||||||
|
|
||||||
channel = ssh_channel_new(session);
|
channel = ssh_channel_new(session);
|
||||||
if (channel == NULL)
|
if (channel == NULL)
|
||||||
@@ -391,7 +391,7 @@ int show_remote_processes(ssh_session session)
|
|||||||
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
|
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
|
||||||
while (nbytes > 0)
|
while (nbytes > 0)
|
||||||
{
|
{
|
||||||
if (write(1, buffer, nbytes) != nbytes)
|
if (write(1, buffer, nbytes) != (unsigned int) nbytes)
|
||||||
{
|
{
|
||||||
ssh_channel_close(channel);
|
ssh_channel_close(channel);
|
||||||
ssh_channel_free(channel);
|
ssh_channel_free(channel);
|
||||||
@@ -443,11 +443,10 @@ Most of time, the error returned are SSH_FATAL, but some functions
|
|||||||
(generaly the ssh_request_xxx ones) may fail because of server denying request.
|
(generaly the ssh_request_xxx ones) may fail because of server denying request.
|
||||||
In these cases, SSH_REQUEST_DENIED is returned.
|
In these cases, SSH_REQUEST_DENIED is returned.
|
||||||
|
|
||||||
ssh_get_error() and ssh_get_error_code() take a ssh_session as a parameter.
|
For thread safety, errors are bound to ssh_session objects.
|
||||||
That's for thread safety, error messages that can be attached to a session
|
As long as your ssh_session object is not NULL, you can retrieve the last error
|
||||||
aren't static anymore. Any error that happens during ssh_options_xxx()
|
message and error code from the ssh_session using ssh_get_error() and
|
||||||
or ssh_connect() (i.e., outside of any session) can be retrieved by
|
ssh_get_error_code() respectively.
|
||||||
giving NULL as argument.
|
|
||||||
|
|
||||||
The SFTP subsystem has its own error codes, in addition to libssh ones.
|
The SFTP subsystem has its own error codes, in addition to libssh ones.
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ the interesting functions as you go.
|
|||||||
|
|
||||||
The libssh library provides:
|
The libssh library provides:
|
||||||
|
|
||||||
- <strong>Key Exchange Methods</strong>: <i>ecdh-sha2-nistp256</i>, diffie-hellman-group1-sha1, diffie-hellman-group14-sha1
|
- <strong>Key Exchange Methods</strong>: <i>curve25519-sha256@libssh.org, ecdh-sha2-nistp256</i>, diffie-hellman-group1-sha1, diffie-hellman-group14-sha1
|
||||||
- <strong>Hostkey Types</strong>: <i>ecdsa-sha2-nistp256</i>, ssh-dss, ssh-rsa
|
- <strong>Hostkey Types</strong>: <i>ecdsa-sha2-nistp256</i>, ssh-dss, ssh-rsa
|
||||||
- <strong>Ciphers</strong>: <i>aes256-ctr, aes192-ctr, aes128-ctr</i>, aes256-cbc (rijndael-cbc@lysator.liu.se), aes192-cbc, aes128-cbc, 3des-cbc, des-cbc-ssh1, blowfish-cbc, none
|
- <strong>Ciphers</strong>: <i>aes256-ctr, aes192-ctr, aes128-ctr</i>, aes256-cbc (rijndael-cbc@lysator.liu.se), aes192-cbc, aes128-cbc, 3des-cbc, des-cbc-ssh1, blowfish-cbc, none
|
||||||
- <strong>Compression Schemes</strong>: zlib, <i>zlib@openssh.com</i>, none
|
- <strong>Compression Schemes</strong>: zlib, <i>zlib@openssh.com</i>, none
|
||||||
@@ -184,6 +184,8 @@ It was later modified and expanded by the following RFCs.
|
|||||||
Authentication and Key Exchange for the Secure Shell (SSH) Protocol
|
Authentication and Key Exchange for the Secure Shell (SSH) Protocol
|
||||||
- <a href="http://tools.ietf.org/html/rfc4716" target="_blank">RFC 4716</a>,
|
- <a href="http://tools.ietf.org/html/rfc4716" target="_blank">RFC 4716</a>,
|
||||||
The Secure Shell (SSH) Public Key File Format
|
The Secure Shell (SSH) Public Key File Format
|
||||||
|
- <a href="http://tools.ietf.org/html/rfc5647" target="_blank">RFC 5647</a>,
|
||||||
|
AES Galois Counter Mode for the Secure Shell Transport Layer Protocol
|
||||||
- <a href="http://tools.ietf.org/html/rfc5656" target="_blank">RFC 5656</a>,
|
- <a href="http://tools.ietf.org/html/rfc5656" target="_blank">RFC 5656</a>,
|
||||||
Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer
|
Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer
|
||||||
|
|
||||||
@@ -203,6 +205,12 @@ do the same in libssh.
|
|||||||
|
|
||||||
@subsection main-rfc-extensions Secure Shell Extensions
|
@subsection main-rfc-extensions Secure Shell Extensions
|
||||||
|
|
||||||
|
The libssh project has an extension to support Curve25519 which is also supported by
|
||||||
|
the OpenSSH project.
|
||||||
|
|
||||||
|
- <a href="http://git.libssh.org/projects/libssh.git/tree/doc/curve25519-sha256@libssh.org.txt" target="_blank">curve25519-sha256@libssh.org</a>,
|
||||||
|
Curve25519-SHA256 for ECDH KEX
|
||||||
|
|
||||||
The OpenSSH project has defined some extensions to the protocol. We support some of
|
The OpenSSH project has defined some extensions to the protocol. We support some of
|
||||||
them like the statvfs calls in SFTP or the ssh-agent.
|
them like the statvfs calls in SFTP or the ssh-agent.
|
||||||
|
|
||||||
|
|||||||
122
doc/sftp.dox
122
doc/sftp.dox
@@ -210,52 +210,63 @@ results to come.
|
|||||||
|
|
||||||
Synchronous read is done with sftp_read().
|
Synchronous read is done with sftp_read().
|
||||||
|
|
||||||
The following example prints the contents of remote file "/etc/profile". For
|
Files are normally transferred in chunks. A good chunk size is 16 KB. The following
|
||||||
each 1024 bytes of information read, it waits until the end of the read operation:
|
example transfers the remote file "/etc/profile" in 16 KB chunks. For each chunk we
|
||||||
|
request, sftp_read blocks till the data has been received:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
|
// Good chunk size
|
||||||
|
#define MAX_XFER_BUF_SIZE 16384
|
||||||
|
|
||||||
int sftp_read_sync(ssh_session session, sftp_session sftp)
|
int sftp_read_sync(ssh_session session, sftp_session sftp)
|
||||||
{
|
{
|
||||||
int access_type;
|
int access_type;
|
||||||
sftp_file file;
|
sftp_file file;
|
||||||
char buffer[1024];
|
char buffer[MAX_XFER_BUF_SIZE];
|
||||||
int nbytes, rc;
|
int nbytes, nwritten, rc;
|
||||||
|
int fd;
|
||||||
|
|
||||||
access_type = O_RDONLY;
|
access_type = O_RDONLY;
|
||||||
file = sftp_open(sftp, "/etc/profile",
|
file = sftp_open(sftp, "/etc/profile",
|
||||||
access_type, 0);
|
access_type, 0);
|
||||||
if (file == NULL)
|
if (file == NULL) {
|
||||||
{
|
fprintf(stderr, "Can't open file for reading: %s\n",
|
||||||
fprintf(stderr, "Can't open file for reading: %s\n",
|
ssh_get_error(session));
|
||||||
ssh_get_error(session));
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbytes = sftp_read(file, buffer, sizeof(buffer));
|
|
||||||
while (nbytes > 0)
|
|
||||||
{
|
|
||||||
if (write(1, buffer, nbytes) != nbytes)
|
|
||||||
{
|
|
||||||
sftp_close(file);
|
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
|
||||||
nbytes = sftp_read(file, buffer, sizeof(buffer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbytes < 0)
|
fd = open("/path/to/profile", O_CREAT);
|
||||||
{
|
if (fd < 0) {
|
||||||
fprintf(stderr, "Error while reading file: %s\n",
|
fprintf(stderr, "Can't open file for writing: %s\n",
|
||||||
ssh_get_error(session));
|
strerror(errno));
|
||||||
sftp_close(file);
|
return SSH_ERROR;
|
||||||
return SSH_ERROR;
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
nbytes = sftp_read(file, buffer, sizeof(buffer));
|
||||||
|
if (nbytes == 0) {
|
||||||
|
break; // EOF
|
||||||
|
} else if (nbytes < 0) {
|
||||||
|
fprintf(stderr, "Error while reading file: %s\n",
|
||||||
|
ssh_get_error(session));
|
||||||
|
sftp_close(file);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
nwritten = write(fd, buffer, nbytes);
|
||||||
|
if (nwritten != nbytes) {
|
||||||
|
fprintf(stderr, "Error writing: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
sftp_close(file);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sftp_close(file);
|
rc = sftp_close(file);
|
||||||
if (rc != SSH_OK)
|
if (rc != SSH_OK) {
|
||||||
{
|
fprintf(stderr, "Can't close the read file: %s\n",
|
||||||
fprintf(stderr, "Can't close the read file: %s\n",
|
ssh_get_error(session));
|
||||||
ssh_get_error(session));
|
return rc;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
@@ -271,14 +282,17 @@ sftp_async_read() waits for the data to come. To open a file in nonblocking mode
|
|||||||
call sftp_file_set_nonblocking() right after you opened it. Default is blocking mode.
|
call sftp_file_set_nonblocking() right after you opened it. Default is blocking mode.
|
||||||
|
|
||||||
The example below reads a very big file in asynchronous, nonblocking, mode. Each
|
The example below reads a very big file in asynchronous, nonblocking, mode. Each
|
||||||
time the data are not ready yet, a counter is incrementer.
|
time the data is not ready yet, a counter is incremented.
|
||||||
|
|
||||||
@code
|
@code
|
||||||
|
// Good chunk size
|
||||||
|
#define MAX_XFER_BUF_SIZE 16384
|
||||||
|
|
||||||
int sftp_read_async(ssh_session session, sftp_session sftp)
|
int sftp_read_async(ssh_session session, sftp_session sftp)
|
||||||
{
|
{
|
||||||
int access_type;
|
int access_type;
|
||||||
sftp_file file;
|
sftp_file file;
|
||||||
char buffer[1024];
|
char buffer[MAX_XFER_BUF_SIZE];
|
||||||
int async_request;
|
int async_request;
|
||||||
int nbytes;
|
int nbytes;
|
||||||
long counter;
|
long counter;
|
||||||
@@ -287,8 +301,7 @@ int sftp_read_async(ssh_session session, sftp_session sftp)
|
|||||||
access_type = O_RDONLY;
|
access_type = O_RDONLY;
|
||||||
file = sftp_open(sftp, "some_very_big_file",
|
file = sftp_open(sftp, "some_very_big_file",
|
||||||
access_type, 0);
|
access_type, 0);
|
||||||
if (file == NULL)
|
if (file == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Can't open file for reading: %s\n",
|
fprintf(stderr, "Can't open file for reading: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
@@ -298,27 +311,31 @@ int sftp_read_async(ssh_session session, sftp_session sftp)
|
|||||||
async_request = sftp_async_read_begin(file, sizeof(buffer));
|
async_request = sftp_async_read_begin(file, sizeof(buffer));
|
||||||
counter = 0L;
|
counter = 0L;
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
if (async_request >= 0)
|
if (async_request >= 0) {
|
||||||
nbytes = sftp_async_read(file, buffer, sizeof(buffer),
|
nbytes = sftp_async_read(file, buffer, sizeof(buffer),
|
||||||
async_request);
|
async_request);
|
||||||
else nbytes = -1;
|
} else {
|
||||||
while (nbytes > 0 || nbytes == SSH_AGAIN)
|
nbytes = -1;
|
||||||
{
|
|
||||||
if (nbytes > 0)
|
|
||||||
{
|
|
||||||
write(1, buffer, nbytes);
|
|
||||||
async_request = sftp_async_read_begin(file, sizeof(buffer));
|
|
||||||
}
|
|
||||||
else counter++;
|
|
||||||
usleep(10000);
|
|
||||||
if (async_request >= 0)
|
|
||||||
nbytes = sftp_async_read(file, buffer, sizeof(buffer),
|
|
||||||
async_request);
|
|
||||||
else nbytes = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbytes < 0)
|
while (nbytes > 0 || nbytes == SSH_AGAIN) {
|
||||||
{
|
if (nbytes > 0) {
|
||||||
|
write(1, buffer, nbytes);
|
||||||
|
async_request = sftp_async_read_begin(file, sizeof(buffer));
|
||||||
|
} else {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
usleep(10000);
|
||||||
|
|
||||||
|
if (async_request >= 0) {
|
||||||
|
nbytes = sftp_async_read(file, buffer, sizeof(buffer),
|
||||||
|
async_request);
|
||||||
|
} else {
|
||||||
|
nbytes = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbytes < 0) {
|
||||||
fprintf(stderr, "Error while reading file: %s\n",
|
fprintf(stderr, "Error while reading file: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
sftp_close(file);
|
sftp_close(file);
|
||||||
@@ -328,8 +345,7 @@ int sftp_read_async(ssh_session session, sftp_session sftp)
|
|||||||
printf("The counter has reached value: %ld\n", counter);
|
printf("The counter has reached value: %ld\n", counter);
|
||||||
|
|
||||||
rc = sftp_close(file);
|
rc = sftp_close(file);
|
||||||
if (rc != SSH_OK)
|
if (rc != SSH_OK) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Can't close the read file: %s\n",
|
fprintf(stderr, "Can't close the read file: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -61,5 +61,6 @@ implement the following methods :
|
|||||||
- mutex_destroy
|
- mutex_destroy
|
||||||
- thread_id
|
- thread_id
|
||||||
|
|
||||||
|
libgcrypt 1.6 and bigger backend does not support custom callback. Using anything else than pthreads (ssh_threads_get_pthread()) here will fail.
|
||||||
Good luck !
|
Good luck !
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ include_directories(
|
|||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (BSD OR SOLARIS)
|
if (BSD OR SOLARIS OR OSX)
|
||||||
find_package(Argp)
|
find_package(Argp)
|
||||||
endif (BSD OR SOLARIS)
|
endif (BSD OR SOLARIS OR OSX)
|
||||||
|
|
||||||
if (UNIX AND NOT WIN32)
|
if (UNIX AND NOT WIN32)
|
||||||
add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
|
add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
|
||||||
@@ -25,13 +25,6 @@ if (UNIX AND NOT WIN32)
|
|||||||
add_executable(sshnetcat sshnetcat.c ${examples_SRCS})
|
add_executable(sshnetcat sshnetcat.c ${examples_SRCS})
|
||||||
target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY})
|
||||||
|
|
||||||
if (WITH_SERVER)
|
|
||||||
if (HAVE_LIBUTIL)
|
|
||||||
add_executable(samplesshd-tty samplesshd-tty.c)
|
|
||||||
target_link_libraries(samplesshd-tty ${LIBSSH_SHARED_LIBRARY} util)
|
|
||||||
endif (HAVE_LIBUTIL)
|
|
||||||
endif (WITH_SERVER)
|
|
||||||
|
|
||||||
if (WITH_SFTP)
|
if (WITH_SFTP)
|
||||||
add_executable(samplesftp samplesftp.c ${examples_SRCS})
|
add_executable(samplesftp samplesftp.c ${examples_SRCS})
|
||||||
target_link_libraries(samplesftp ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(samplesftp ${LIBSSH_SHARED_LIBRARY})
|
||||||
@@ -41,8 +34,10 @@ if (UNIX AND NOT WIN32)
|
|||||||
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
|
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
|
||||||
|
|
||||||
if (WITH_SERVER)
|
if (WITH_SERVER)
|
||||||
add_executable(samplesshd samplesshd.c)
|
if (HAVE_LIBUTIL)
|
||||||
target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES})
|
add_executable(ssh_server_fork ssh_server_fork.c)
|
||||||
|
target_link_libraries(ssh_server_fork ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES} util)
|
||||||
|
endif (HAVE_LIBUTIL)
|
||||||
|
|
||||||
if (WITH_GSSAPI AND GSSAPI_FOUND)
|
if (WITH_GSSAPI AND GSSAPI_FOUND)
|
||||||
add_executable(samplesshd-cb samplesshd-cb.c)
|
add_executable(samplesshd-cb samplesshd-cb.c)
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ int authenticate_console(ssh_session session){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
method = ssh_auth_list(session);
|
method = ssh_userauth_list(session, NULL);
|
||||||
while (rc != SSH_AUTH_SUCCESS) {
|
while (rc != SSH_AUTH_SUCCESS) {
|
||||||
if (method & SSH_AUTH_METHOD_GSSAPI_MIC){
|
if (method & SSH_AUTH_METHOD_GSSAPI_MIC){
|
||||||
rc = ssh_userauth_gssapi(session);
|
rc = ssh_userauth_gssapi(session);
|
||||||
@@ -129,10 +129,10 @@ int authenticate_console(ssh_session session){
|
|||||||
}
|
}
|
||||||
// Try to authenticate with public key first
|
// Try to authenticate with public key first
|
||||||
if (method & SSH_AUTH_METHOD_PUBLICKEY) {
|
if (method & SSH_AUTH_METHOD_PUBLICKEY) {
|
||||||
rc = ssh_userauth_autopubkey(session, NULL);
|
rc = ssh_userauth_publickey_auto(session, NULL, NULL);
|
||||||
if (rc == SSH_AUTH_ERROR) {
|
if (rc == SSH_AUTH_ERROR) {
|
||||||
error(session);
|
error(session);
|
||||||
return rc;
|
return rc;
|
||||||
} else if (rc == SSH_AUTH_SUCCESS) {
|
} else if (rc == SSH_AUTH_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,26 @@ int verify_knownhost(ssh_session session){
|
|||||||
int state;
|
int state;
|
||||||
char buf[10];
|
char buf[10];
|
||||||
unsigned char *hash = NULL;
|
unsigned char *hash = NULL;
|
||||||
int hlen;
|
size_t hlen;
|
||||||
|
ssh_key srv_pubkey;
|
||||||
|
int rc;
|
||||||
|
|
||||||
state=ssh_is_server_known(session);
|
state=ssh_is_server_known(session);
|
||||||
|
|
||||||
hlen = ssh_get_pubkey_hash(session, &hash);
|
rc = ssh_get_publickey(session, &srv_pubkey);
|
||||||
if (hlen < 0) {
|
if (rc < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = ssh_get_publickey_hash(srv_pubkey,
|
||||||
|
SSH_PUBLICKEY_HASH_SHA1,
|
||||||
|
&hash,
|
||||||
|
&hlen);
|
||||||
|
ssh_key_free(srv_pubkey);
|
||||||
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
switch(state){
|
switch(state){
|
||||||
case SSH_SERVER_KNOWN_OK:
|
case SSH_SERVER_KNOWN_OK:
|
||||||
break; /* ok */
|
break; /* ok */
|
||||||
|
|||||||
@@ -229,6 +229,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
|
|||||||
fprintf(stderr,"error: %s\n",ssh_get_error(dest->session));
|
fprintf(stderr,"error: %s\n",ssh_get_error(dest->session));
|
||||||
ssh_string_free_char(filename);
|
ssh_string_free_char(filename);
|
||||||
ssh_scp_free(dest->scp);
|
ssh_scp_free(dest->scp);
|
||||||
|
dest->scp = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -298,13 +298,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
|||||||
int ret;
|
int ret;
|
||||||
while(channel){
|
while(channel){
|
||||||
do{
|
do{
|
||||||
|
int fd;
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
if(!eof)
|
if(!eof)
|
||||||
FD_SET(0,&fds);
|
FD_SET(0,&fds);
|
||||||
timeout.tv_sec=30;
|
timeout.tv_sec=30;
|
||||||
timeout.tv_usec=0;
|
timeout.tv_usec=0;
|
||||||
FD_SET(ssh_get_fd(session),&fds);
|
|
||||||
maxfd=ssh_get_fd(session)+1;
|
fd = ssh_get_fd(session);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, "Error getting fd\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FD_SET(fd, &fds);
|
||||||
|
maxfd = fd + 1;
|
||||||
|
|
||||||
channels[0]=channel; // set the first channel we want to read from
|
channels[0]=channel; // set the first channel we want to read from
|
||||||
channels[1]=NULL;
|
channels[1]=NULL;
|
||||||
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
|
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ clients must be made or how a client should react.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define SSHD_USER "libssh"
|
#define SSHD_USER "libssh"
|
||||||
#define SSHD_PASSWORD "libssh"
|
#define SSHD_PASSWORD "libssh"
|
||||||
@@ -36,6 +37,7 @@ clients must be made or how a client should react.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int port = 22;
|
static int port = 22;
|
||||||
|
static bool authenticated = false;
|
||||||
|
|
||||||
#ifdef WITH_PCAP
|
#ifdef WITH_PCAP
|
||||||
static const char *pcap_file = "debug.server.pcap";
|
static const char *pcap_file = "debug.server.pcap";
|
||||||
@@ -61,11 +63,20 @@ static void cleanup_pcap(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int auth_password(const char *user, const char *password){
|
static int auth_password(const char *user, const char *password)
|
||||||
if(strcmp(user, SSHD_USER))
|
{
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
cmp = strcmp(user, SSHD_USER);
|
||||||
|
if (cmp != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
if(strcmp(password, SSHD_PASSWORD))
|
}
|
||||||
|
cmp = strcmp(password, SSHD_PASSWORD);
|
||||||
|
if (cmp != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticated = true;
|
||||||
return 1; // authenticated
|
return 1; // authenticated
|
||||||
}
|
}
|
||||||
#ifdef HAVE_ARGP_H
|
#ifdef HAVE_ARGP_H
|
||||||
@@ -200,6 +211,7 @@ static int kbdint_check_response(ssh_session session) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authenticated = true;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +340,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
/* proceed to authentication */
|
/* proceed to authentication */
|
||||||
auth = authenticate(session);
|
auth = authenticate(session);
|
||||||
if(!auth){
|
if (!auth || !authenticated) {
|
||||||
printf("Authentication error: %s\n", ssh_get_error(session));
|
printf("Authentication error: %s\n", ssh_get_error(session));
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -1,462 +0,0 @@
|
|||||||
/* This is a sample implementation of a libssh based SSH server */
|
|
||||||
/*
|
|
||||||
Copyright 2003-2011 Aris Adamantiadis
|
|
||||||
|
|
||||||
This file is part of the SSH Library
|
|
||||||
|
|
||||||
You are free to copy this file, modify it in any way, consider it being public
|
|
||||||
domain. This does not apply to the rest of the library though, but it is
|
|
||||||
allowed to cut-and-paste working code from this file to any license of
|
|
||||||
program.
|
|
||||||
The goal is to show the API in action. It's not a reference on how terminal
|
|
||||||
clients must be made or how a client should react.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <libssh/libssh.h>
|
|
||||||
#include <libssh/server.h>
|
|
||||||
#include <libssh/callbacks.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_ARGP_H
|
|
||||||
#include <argp.h>
|
|
||||||
#endif
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <poll.h>
|
|
||||||
#include <pty.h>
|
|
||||||
|
|
||||||
#define SSHD_USER "libssh"
|
|
||||||
#define SSHD_PASSWORD "libssh"
|
|
||||||
|
|
||||||
#ifndef KEYS_FOLDER
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define KEYS_FOLDER
|
|
||||||
#else
|
|
||||||
#define KEYS_FOLDER "/etc/ssh/"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WITH_PCAP
|
|
||||||
const char *pcap_file="debug.server.pcap";
|
|
||||||
ssh_pcap_file pcap;
|
|
||||||
|
|
||||||
static void set_pcap(ssh_session session){
|
|
||||||
if(!pcap_file)
|
|
||||||
return;
|
|
||||||
pcap=ssh_pcap_file_new();
|
|
||||||
if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
|
|
||||||
printf("Error opening pcap file\n");
|
|
||||||
ssh_pcap_file_free(pcap);
|
|
||||||
pcap=NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ssh_set_pcap_file(session,pcap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup_pcap(){
|
|
||||||
ssh_pcap_file_free(pcap);
|
|
||||||
pcap=NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static int auth_password(const char *user, const char *password){
|
|
||||||
if(strcmp(user, SSHD_USER))
|
|
||||||
return 0;
|
|
||||||
if(strcmp(password, SSHD_PASSWORD))
|
|
||||||
return 0;
|
|
||||||
return 1; // authenticated
|
|
||||||
}
|
|
||||||
#ifdef HAVE_ARGP_H
|
|
||||||
const char *argp_program_version = "libssh server example "
|
|
||||||
SSH_STRINGIFY(LIBSSH_VERSION);
|
|
||||||
const char *argp_program_bug_address = "<libssh@libssh.org>";
|
|
||||||
|
|
||||||
/* Program documentation. */
|
|
||||||
static char doc[] = "libssh -- a Secure Shell protocol implementation";
|
|
||||||
|
|
||||||
/* A description of the arguments we accept. */
|
|
||||||
static char args_doc[] = "BINDADDR";
|
|
||||||
|
|
||||||
static int port = 22;
|
|
||||||
|
|
||||||
/* The options we understand. */
|
|
||||||
static struct argp_option options[] = {
|
|
||||||
{
|
|
||||||
.name = "port",
|
|
||||||
.key = 'p',
|
|
||||||
.arg = "PORT",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the port to bind.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "hostkey",
|
|
||||||
.key = 'k',
|
|
||||||
.arg = "FILE",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the host key.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "dsakey",
|
|
||||||
.key = 'd',
|
|
||||||
.arg = "FILE",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the dsa key.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "rsakey",
|
|
||||||
.key = 'r',
|
|
||||||
.arg = "FILE",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the rsa key.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "verbose",
|
|
||||||
.key = 'v',
|
|
||||||
.arg = NULL,
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Get verbose output.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{NULL, 0, 0, 0, NULL, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Parse a single option. */
|
|
||||||
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
|
||||||
/* Get the input argument from argp_parse, which we
|
|
||||||
* know is a pointer to our arguments structure.
|
|
||||||
*/
|
|
||||||
ssh_bind sshbind = state->input;
|
|
||||||
|
|
||||||
switch (key) {
|
|
||||||
case 'p':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
|
|
||||||
port = atoi(arg);
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
|
|
||||||
break;
|
|
||||||
case 'k':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
|
|
||||||
break;
|
|
||||||
case ARGP_KEY_ARG:
|
|
||||||
if (state->arg_num >= 1) {
|
|
||||||
/* Too many arguments. */
|
|
||||||
argp_usage (state);
|
|
||||||
}
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
|
|
||||||
break;
|
|
||||||
case ARGP_KEY_END:
|
|
||||||
if (state->arg_num < 1) {
|
|
||||||
/* Not enough arguments. */
|
|
||||||
argp_usage (state);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return ARGP_ERR_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Our argp parser. */
|
|
||||||
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
|
|
||||||
#endif /* HAVE_ARGP_H */
|
|
||||||
|
|
||||||
static int authenticate(ssh_session session) {
|
|
||||||
ssh_message message;
|
|
||||||
|
|
||||||
do {
|
|
||||||
message=ssh_message_get(session);
|
|
||||||
if(!message)
|
|
||||||
break;
|
|
||||||
switch(ssh_message_type(message)){
|
|
||||||
case SSH_REQUEST_AUTH:
|
|
||||||
switch(ssh_message_subtype(message)){
|
|
||||||
case SSH_AUTH_METHOD_PASSWORD:
|
|
||||||
printf("User %s wants to auth with pass %s\n",
|
|
||||||
ssh_message_auth_user(message),
|
|
||||||
ssh_message_auth_password(message));
|
|
||||||
if(auth_password(ssh_message_auth_user(message),
|
|
||||||
ssh_message_auth_password(message))){
|
|
||||||
ssh_message_auth_reply_success(message,0);
|
|
||||||
ssh_message_free(message);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ssh_message_auth_set_methods(message,
|
|
||||||
SSH_AUTH_METHOD_PASSWORD |
|
|
||||||
SSH_AUTH_METHOD_INTERACTIVE);
|
|
||||||
// not authenticated, send default message
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SSH_AUTH_METHOD_NONE:
|
|
||||||
default:
|
|
||||||
printf("User %s wants to auth with unknown auth %d\n",
|
|
||||||
ssh_message_auth_user(message),
|
|
||||||
ssh_message_subtype(message));
|
|
||||||
ssh_message_auth_set_methods(message,
|
|
||||||
SSH_AUTH_METHOD_PASSWORD |
|
|
||||||
SSH_AUTH_METHOD_INTERACTIVE);
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ssh_message_auth_set_methods(message,
|
|
||||||
SSH_AUTH_METHOD_PASSWORD |
|
|
||||||
SSH_AUTH_METHOD_INTERACTIVE);
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
}
|
|
||||||
ssh_message_free(message);
|
|
||||||
} while (1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int copy_fd_to_chan(socket_t fd, int revents, void *userdata) {
|
|
||||||
ssh_channel chan = (ssh_channel)userdata;
|
|
||||||
char buf[2048];
|
|
||||||
int sz = 0;
|
|
||||||
|
|
||||||
if(!chan) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(revents & POLLIN) {
|
|
||||||
sz = read(fd, buf, 2048);
|
|
||||||
if(sz > 0) {
|
|
||||||
ssh_channel_write(chan, buf, sz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(revents & POLLHUP) {
|
|
||||||
ssh_channel_close(chan);
|
|
||||||
sz = -1;
|
|
||||||
}
|
|
||||||
return sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int copy_chan_to_fd(ssh_session session,
|
|
||||||
ssh_channel channel,
|
|
||||||
void *data,
|
|
||||||
uint32_t len,
|
|
||||||
int is_stderr,
|
|
||||||
void *userdata) {
|
|
||||||
int fd = *(int*)userdata;
|
|
||||||
int sz;
|
|
||||||
(void)session;
|
|
||||||
(void)channel;
|
|
||||||
(void)is_stderr;
|
|
||||||
|
|
||||||
sz = write(fd, data, len);
|
|
||||||
return sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void chan_close(ssh_session session, ssh_channel channel, void *userdata) {
|
|
||||||
int fd = *(int*)userdata;
|
|
||||||
(void)session;
|
|
||||||
(void)channel;
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ssh_channel_callbacks_struct cb = {
|
|
||||||
.channel_data_function = copy_chan_to_fd,
|
|
||||||
.channel_eof_function = chan_close,
|
|
||||||
.channel_close_function = chan_close,
|
|
||||||
.userdata = NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
static int main_loop(ssh_channel chan) {
|
|
||||||
ssh_session session = ssh_channel_get_session(chan);
|
|
||||||
socket_t fd;
|
|
||||||
struct termios *term = NULL;
|
|
||||||
struct winsize *win = NULL;
|
|
||||||
pid_t childpid;
|
|
||||||
ssh_event event;
|
|
||||||
short events;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
childpid = forkpty(&fd, NULL, term, win);
|
|
||||||
if(childpid == 0) {
|
|
||||||
execl("/bin/bash", "/bin/bash", (char *)NULL);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
cb.userdata = &fd;
|
|
||||||
ssh_callbacks_init(&cb);
|
|
||||||
ssh_set_channel_callbacks(chan, &cb);
|
|
||||||
|
|
||||||
events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL;
|
|
||||||
|
|
||||||
event = ssh_event_new();
|
|
||||||
if(event == NULL) {
|
|
||||||
printf("Couldn't get a event\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(ssh_event_add_fd(event, fd, events, copy_fd_to_chan, chan) != SSH_OK) {
|
|
||||||
printf("Couldn't add an fd to the event\n");
|
|
||||||
ssh_event_free(event);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(ssh_event_add_session(event, session) != SSH_OK) {
|
|
||||||
printf("Couldn't add the session to the event\n");
|
|
||||||
ssh_event_remove_fd(event, fd);
|
|
||||||
ssh_event_free(event);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
rc = ssh_event_dopoll(event, 1000);
|
|
||||||
if (rc == SSH_ERROR){
|
|
||||||
fprintf(stderr, "Error : %s\n", ssh_get_error(session));
|
|
||||||
ssh_event_free(event);
|
|
||||||
ssh_disconnect(session);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} while(!ssh_channel_is_closed(chan));
|
|
||||||
|
|
||||||
ssh_event_remove_fd(event, fd);
|
|
||||||
|
|
||||||
ssh_event_remove_session(event, session);
|
|
||||||
|
|
||||||
ssh_event_free(event);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
|
||||||
ssh_session session;
|
|
||||||
ssh_bind sshbind;
|
|
||||||
ssh_message message;
|
|
||||||
ssh_channel chan=0;
|
|
||||||
int auth=0;
|
|
||||||
int shell=0;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
sshbind=ssh_bind_new();
|
|
||||||
session=ssh_new();
|
|
||||||
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
|
|
||||||
KEYS_FOLDER "ssh_host_dsa_key");
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
|
|
||||||
KEYS_FOLDER "ssh_host_rsa_key");
|
|
||||||
|
|
||||||
#ifdef HAVE_ARGP_H
|
|
||||||
/*
|
|
||||||
* Parse our arguments; every option seen by parse_opt will
|
|
||||||
* be reflected in arguments.
|
|
||||||
*/
|
|
||||||
argp_parse (&argp, argc, argv, 0, 0, sshbind);
|
|
||||||
#else
|
|
||||||
(void) argc;
|
|
||||||
(void) argv;
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_PCAP
|
|
||||||
set_pcap(session);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(ssh_bind_listen(sshbind)<0){
|
|
||||||
printf("Error listening to socket: %s\n", ssh_get_error(sshbind));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
printf("Started sample libssh sshd on port %d\n", port);
|
|
||||||
printf("You can login as the user %s with the password %s\n", SSHD_USER,
|
|
||||||
SSHD_PASSWORD);
|
|
||||||
r = ssh_bind_accept(sshbind, session);
|
|
||||||
if(r==SSH_ERROR){
|
|
||||||
printf("Error accepting a connection: %s\n", ssh_get_error(sshbind));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ssh_handle_key_exchange(session)) {
|
|
||||||
printf("ssh_handle_key_exchange: %s\n", ssh_get_error(session));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* proceed to authentication */
|
|
||||||
auth = authenticate(session);
|
|
||||||
if(!auth){
|
|
||||||
printf("Authentication error: %s\n", ssh_get_error(session));
|
|
||||||
ssh_disconnect(session);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* wait for a channel session */
|
|
||||||
do {
|
|
||||||
message = ssh_message_get(session);
|
|
||||||
if(message){
|
|
||||||
if(ssh_message_type(message) == SSH_REQUEST_CHANNEL_OPEN &&
|
|
||||||
ssh_message_subtype(message) == SSH_CHANNEL_SESSION) {
|
|
||||||
chan = ssh_message_channel_request_open_reply_accept(message);
|
|
||||||
ssh_message_free(message);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
ssh_message_free(message);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(!chan);
|
|
||||||
|
|
||||||
if(!chan) {
|
|
||||||
printf("Error: cleint did not ask for a channel session (%s)\n",
|
|
||||||
ssh_get_error(session));
|
|
||||||
ssh_finalize();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* wait for a shell */
|
|
||||||
do {
|
|
||||||
message = ssh_message_get(session);
|
|
||||||
if(message != NULL) {
|
|
||||||
if(ssh_message_type(message) == SSH_REQUEST_CHANNEL) {
|
|
||||||
if(ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) {
|
|
||||||
shell = 1;
|
|
||||||
ssh_message_channel_request_reply_success(message);
|
|
||||||
ssh_message_free(message);
|
|
||||||
break;
|
|
||||||
} else if(ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_PTY) {
|
|
||||||
ssh_message_channel_request_reply_success(message);
|
|
||||||
ssh_message_free(message);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
ssh_message_free(message);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(!shell);
|
|
||||||
|
|
||||||
if(!shell) {
|
|
||||||
printf("Error: No shell requested (%s)\n", ssh_get_error(session));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("it works !\n");
|
|
||||||
|
|
||||||
main_loop(chan);
|
|
||||||
|
|
||||||
ssh_disconnect(session);
|
|
||||||
ssh_bind_free(sshbind);
|
|
||||||
#ifdef WITH_PCAP
|
|
||||||
cleanup_pcap();
|
|
||||||
#endif
|
|
||||||
ssh_finalize();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,314 +0,0 @@
|
|||||||
/* This is a sample implementation of a libssh based SSH server */
|
|
||||||
/*
|
|
||||||
Copyright 2003-2009 Aris Adamantiadis
|
|
||||||
|
|
||||||
This file is part of the SSH Library
|
|
||||||
|
|
||||||
You are free to copy this file, modify it in any way, consider it being public
|
|
||||||
domain. This does not apply to the rest of the library though, but it is
|
|
||||||
allowed to cut-and-paste working code from this file to any license of
|
|
||||||
program.
|
|
||||||
The goal is to show the API in action. It's not a reference on how terminal
|
|
||||||
clients must be made or how a client should react.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <libssh/libssh.h>
|
|
||||||
#include <libssh/server.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_ARGP_H
|
|
||||||
#include <argp.h>
|
|
||||||
#endif
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifndef KEYS_FOLDER
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define KEYS_FOLDER
|
|
||||||
#else
|
|
||||||
#define KEYS_FOLDER "/etc/ssh/"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WITH_PCAP
|
|
||||||
static const char *pcap_file="debug.server.pcap";
|
|
||||||
static ssh_pcap_file pcap;
|
|
||||||
|
|
||||||
static void set_pcap(ssh_session session) {
|
|
||||||
if(!pcap_file)
|
|
||||||
return;
|
|
||||||
pcap=ssh_pcap_file_new();
|
|
||||||
if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
|
|
||||||
printf("Error opening pcap file\n");
|
|
||||||
ssh_pcap_file_free(pcap);
|
|
||||||
pcap=NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ssh_set_pcap_file(session,pcap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup_pcap(void) {
|
|
||||||
ssh_pcap_file_free(pcap);
|
|
||||||
pcap=NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static int auth_password(const char *user, const char *password){
|
|
||||||
if(strcmp(user,"aris"))
|
|
||||||
return 0;
|
|
||||||
if(strcmp(password,"lala"))
|
|
||||||
return 0;
|
|
||||||
return 1; // authenticated
|
|
||||||
}
|
|
||||||
#ifdef HAVE_ARGP_H
|
|
||||||
const char *argp_program_version = "libssh server example "
|
|
||||||
SSH_STRINGIFY(LIBSSH_VERSION);
|
|
||||||
const char *argp_program_bug_address = "<libssh@libssh.org>";
|
|
||||||
|
|
||||||
/* Program documentation. */
|
|
||||||
static char doc[] = "libssh -- a Secure Shell protocol implementation";
|
|
||||||
|
|
||||||
/* A description of the arguments we accept. */
|
|
||||||
static char args_doc[] = "BINDADDR";
|
|
||||||
|
|
||||||
/* The options we understand. */
|
|
||||||
static struct argp_option options[] = {
|
|
||||||
{
|
|
||||||
.name = "port",
|
|
||||||
.key = 'p',
|
|
||||||
.arg = "PORT",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the port to bind.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "hostkey",
|
|
||||||
.key = 'k',
|
|
||||||
.arg = "FILE",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the host key.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "dsakey",
|
|
||||||
.key = 'd',
|
|
||||||
.arg = "FILE",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the dsa key.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "rsakey",
|
|
||||||
.key = 'r',
|
|
||||||
.arg = "FILE",
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Set the rsa key.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "verbose",
|
|
||||||
.key = 'v',
|
|
||||||
.arg = NULL,
|
|
||||||
.flags = 0,
|
|
||||||
.doc = "Get verbose output.",
|
|
||||||
.group = 0
|
|
||||||
},
|
|
||||||
{NULL, 0, NULL, 0, NULL, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Parse a single option. */
|
|
||||||
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
|
||||||
/* Get the input argument from argp_parse, which we
|
|
||||||
* know is a pointer to our arguments structure.
|
|
||||||
*/
|
|
||||||
ssh_bind sshbind = state->input;
|
|
||||||
|
|
||||||
switch (key) {
|
|
||||||
case 'p':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
|
|
||||||
break;
|
|
||||||
case 'k':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
|
|
||||||
break;
|
|
||||||
case ARGP_KEY_ARG:
|
|
||||||
if (state->arg_num >= 1) {
|
|
||||||
/* Too many arguments. */
|
|
||||||
argp_usage (state);
|
|
||||||
}
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
|
|
||||||
break;
|
|
||||||
case ARGP_KEY_END:
|
|
||||||
if (state->arg_num < 1) {
|
|
||||||
/* Not enough arguments. */
|
|
||||||
argp_usage (state);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return ARGP_ERR_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Our argp parser. */
|
|
||||||
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
|
|
||||||
#endif /* HAVE_ARGP_H */
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
|
||||||
ssh_session session;
|
|
||||||
ssh_bind sshbind;
|
|
||||||
ssh_message message;
|
|
||||||
ssh_channel chan=0;
|
|
||||||
char buf[2048];
|
|
||||||
int auth=0;
|
|
||||||
int sftp=0;
|
|
||||||
int i;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
sshbind=ssh_bind_new();
|
|
||||||
session=ssh_new();
|
|
||||||
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key");
|
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key");
|
|
||||||
|
|
||||||
#ifdef HAVE_ARGP_H
|
|
||||||
/*
|
|
||||||
* Parse our arguments; every option seen by parse_opt will
|
|
||||||
* be reflected in arguments.
|
|
||||||
*/
|
|
||||||
argp_parse (&argp, argc, argv, 0, 0, sshbind);
|
|
||||||
#else
|
|
||||||
(void) argc;
|
|
||||||
(void) argv;
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_PCAP
|
|
||||||
set_pcap(session);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(ssh_bind_listen(sshbind)<0){
|
|
||||||
printf("Error listening to socket: %s\n",ssh_get_error(sshbind));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
r=ssh_bind_accept(sshbind,session);
|
|
||||||
if(r==SSH_ERROR){
|
|
||||||
printf("error accepting a connection : %s\n",ssh_get_error(sshbind));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ssh_handle_key_exchange(session)) {
|
|
||||||
printf("ssh_handle_key_exchange: %s\n", ssh_get_error(session));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
message=ssh_message_get(session);
|
|
||||||
if(!message)
|
|
||||||
break;
|
|
||||||
switch(ssh_message_type(message)){
|
|
||||||
case SSH_REQUEST_AUTH:
|
|
||||||
switch(ssh_message_subtype(message)){
|
|
||||||
case SSH_AUTH_METHOD_PASSWORD:
|
|
||||||
printf("User %s wants to auth with pass %s\n",
|
|
||||||
ssh_message_auth_user(message),
|
|
||||||
ssh_message_auth_password(message));
|
|
||||||
if(auth_password(ssh_message_auth_user(message),
|
|
||||||
ssh_message_auth_password(message))){
|
|
||||||
auth=1;
|
|
||||||
ssh_message_auth_reply_success(message,0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// not authenticated, send default message
|
|
||||||
case SSH_AUTH_METHOD_NONE:
|
|
||||||
default:
|
|
||||||
ssh_message_auth_set_methods(message,SSH_AUTH_METHOD_PASSWORD);
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
}
|
|
||||||
ssh_message_free(message);
|
|
||||||
} while (!auth);
|
|
||||||
if(!auth){
|
|
||||||
printf("auth error: %s\n",ssh_get_error(session));
|
|
||||||
ssh_disconnect(session);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
message=ssh_message_get(session);
|
|
||||||
if(message){
|
|
||||||
switch(ssh_message_type(message)){
|
|
||||||
case SSH_REQUEST_CHANNEL_OPEN:
|
|
||||||
if(ssh_message_subtype(message)==SSH_CHANNEL_SESSION){
|
|
||||||
chan=ssh_message_channel_request_open_reply_accept(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
}
|
|
||||||
ssh_message_free(message);
|
|
||||||
}
|
|
||||||
} while(message && !chan);
|
|
||||||
if(!chan){
|
|
||||||
printf("error : %s\n",ssh_get_error(session));
|
|
||||||
ssh_finalize();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
message=ssh_message_get(session);
|
|
||||||
if(message && ssh_message_type(message)==SSH_REQUEST_CHANNEL &&
|
|
||||||
(ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL ||
|
|
||||||
ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_PTY)) {
|
|
||||||
// if(!strcmp(ssh_message_channel_request_subsystem(message),"sftp")){
|
|
||||||
sftp=1;
|
|
||||||
ssh_message_channel_request_reply_success(message);
|
|
||||||
break;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
if(!sftp){
|
|
||||||
ssh_message_reply_default(message);
|
|
||||||
}
|
|
||||||
ssh_message_free(message);
|
|
||||||
} while (message && !sftp);
|
|
||||||
if(!sftp){
|
|
||||||
printf("error : %s\n",ssh_get_error(session));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
printf("it works !\n");
|
|
||||||
do{
|
|
||||||
i=ssh_channel_read(chan,buf, 2048, 0);
|
|
||||||
if(i>0) {
|
|
||||||
ssh_channel_write(chan, buf, i);
|
|
||||||
if (write(1,buf,i) < 0) {
|
|
||||||
printf("error writing to buffer\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (buf[0] == '\x0d') {
|
|
||||||
if (write(1, "\n", 1) < 0) {
|
|
||||||
printf("error writing to buffer\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ssh_channel_write(chan, "\n", 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (i>0);
|
|
||||||
ssh_disconnect(session);
|
|
||||||
ssh_bind_free(sshbind);
|
|
||||||
#ifdef WITH_PCAP
|
|
||||||
cleanup_pcap();
|
|
||||||
#endif
|
|
||||||
ssh_finalize();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
697
examples/ssh_server_fork.c
Normal file
697
examples/ssh_server_fork.c
Normal file
@@ -0,0 +1,697 @@
|
|||||||
|
/* This is a sample implementation of a libssh based SSH server */
|
||||||
|
/*
|
||||||
|
Copyright 2014 Audrius Butkevicius
|
||||||
|
|
||||||
|
This file is part of the SSH Library
|
||||||
|
|
||||||
|
You are free to copy this file, modify it in any way, consider it being public
|
||||||
|
domain. This does not apply to the rest of the library though, but it is
|
||||||
|
allowed to cut-and-paste working code from this file to any license of
|
||||||
|
program.
|
||||||
|
The goal is to show the API in action.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <libssh/callbacks.h>
|
||||||
|
#include <libssh/poll.h>
|
||||||
|
#include <libssh/server.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_ARGP_H
|
||||||
|
#include <argp.h>
|
||||||
|
#endif
|
||||||
|
#include <fcntl.h>
|
||||||
|
#ifdef HAVE_LIBUTIL_H
|
||||||
|
#include <libutil.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_PTY_H
|
||||||
|
#include <pty.h>
|
||||||
|
#endif
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifdef HAVE_UTMP_H
|
||||||
|
#include <utmp.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_UTIL_H
|
||||||
|
#include <util.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef KEYS_FOLDER
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define KEYS_FOLDER
|
||||||
|
#else
|
||||||
|
#define KEYS_FOLDER "/etc/ssh/"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define USER "myuser"
|
||||||
|
#define PASS "mypassword"
|
||||||
|
#define BUF_SIZE 1048576
|
||||||
|
#define SESSION_END (SSH_CLOSED | SSH_CLOSED_ERROR)
|
||||||
|
#define SFTP_SERVER_PATH "/usr/lib/sftp-server"
|
||||||
|
|
||||||
|
static void set_default_keys(ssh_bind sshbind,
|
||||||
|
int rsa_already_set,
|
||||||
|
int dsa_already_set,
|
||||||
|
int ecdsa_already_set) {
|
||||||
|
if (!rsa_already_set) {
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
|
||||||
|
KEYS_FOLDER "ssh_host_rsa_key");
|
||||||
|
}
|
||||||
|
if (!dsa_already_set) {
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
|
||||||
|
KEYS_FOLDER "ssh_host_dsa_key");
|
||||||
|
}
|
||||||
|
if (!ecdsa_already_set) {
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY,
|
||||||
|
KEYS_FOLDER "ssh_host_ecdsa_key");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_ARGP_H
|
||||||
|
const char *argp_program_version = "libssh server example "
|
||||||
|
SSH_STRINGIFY(LIBSSH_VERSION);
|
||||||
|
const char *argp_program_bug_address = "<libssh@libssh.org>";
|
||||||
|
|
||||||
|
/* Program documentation. */
|
||||||
|
static char doc[] = "libssh -- a Secure Shell protocol implementation";
|
||||||
|
|
||||||
|
/* A description of the arguments we accept. */
|
||||||
|
static char args_doc[] = "BINDADDR";
|
||||||
|
|
||||||
|
/* The options we understand. */
|
||||||
|
static struct argp_option options[] = {
|
||||||
|
{
|
||||||
|
.name = "port",
|
||||||
|
.key = 'p',
|
||||||
|
.arg = "PORT",
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Set the port to bind.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "hostkey",
|
||||||
|
.key = 'k',
|
||||||
|
.arg = "FILE",
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Set a host key. Can be used multiple times. "
|
||||||
|
"Implies no default keys.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "dsakey",
|
||||||
|
.key = 'd',
|
||||||
|
.arg = "FILE",
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Set the dsa key.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "rsakey",
|
||||||
|
.key = 'r',
|
||||||
|
.arg = "FILE",
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Set the rsa key.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "ecdsakey",
|
||||||
|
.key = 'e',
|
||||||
|
.arg = "FILE",
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Set the ecdsa key.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "no-default-keys",
|
||||||
|
.key = 'n',
|
||||||
|
.arg = NULL,
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Do not set default key locations.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "verbose",
|
||||||
|
.key = 'v',
|
||||||
|
.arg = NULL,
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Get verbose output.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
|
{NULL, 0, NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Parse a single option. */
|
||||||
|
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
* know is a pointer to our arguments structure. */
|
||||||
|
ssh_bind sshbind = state->input;
|
||||||
|
static int no_default_keys = 0;
|
||||||
|
static int rsa_already_set = 0, dsa_already_set = 0, ecdsa_already_set = 0;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case 'n':
|
||||||
|
no_default_keys = 1;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
|
||||||
|
dsa_already_set = 1;
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
|
||||||
|
/* We can't track the types of keys being added with this
|
||||||
|
option, so let's ensure we keep the keys we're adding
|
||||||
|
by just not setting the default keys */
|
||||||
|
no_default_keys = 1;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
|
||||||
|
rsa_already_set = 1;
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY, arg);
|
||||||
|
ecdsa_already_set = 1;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR,
|
||||||
|
"3");
|
||||||
|
break;
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
if (state->arg_num >= 1) {
|
||||||
|
/* Too many arguments. */
|
||||||
|
argp_usage (state);
|
||||||
|
}
|
||||||
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
|
||||||
|
break;
|
||||||
|
case ARGP_KEY_END:
|
||||||
|
if (state->arg_num < 1) {
|
||||||
|
/* Not enough arguments. */
|
||||||
|
argp_usage (state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!no_default_keys) {
|
||||||
|
set_default_keys(sshbind,
|
||||||
|
rsa_already_set,
|
||||||
|
dsa_already_set,
|
||||||
|
ecdsa_already_set);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Our argp parser. */
|
||||||
|
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
|
||||||
|
#endif /* HAVE_ARGP_H */
|
||||||
|
|
||||||
|
/* A userdata struct for channel. */
|
||||||
|
struct channel_data_struct {
|
||||||
|
/* pid of the child process the channel will spawn. */
|
||||||
|
pid_t pid;
|
||||||
|
/* For PTY allocation */
|
||||||
|
socket_t pty_master;
|
||||||
|
socket_t pty_slave;
|
||||||
|
/* For communication with the child process. */
|
||||||
|
socket_t child_stdin;
|
||||||
|
socket_t child_stdout;
|
||||||
|
/* Only used for subsystem and exec requests. */
|
||||||
|
socket_t child_stderr;
|
||||||
|
/* Event which is used to poll the above descriptors. */
|
||||||
|
ssh_event event;
|
||||||
|
/* Terminal size struct. */
|
||||||
|
struct winsize *winsize;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* A userdata struct for session. */
|
||||||
|
struct session_data_struct {
|
||||||
|
/* Pointer to the channel the session will allocate. */
|
||||||
|
ssh_channel channel;
|
||||||
|
int auth_attempts;
|
||||||
|
int authenticated;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int data_function(ssh_session session, ssh_channel channel, void *data,
|
||||||
|
uint32_t len, int is_stderr, void *userdata) {
|
||||||
|
struct channel_data_struct *cdata = (struct channel_data_struct *) userdata;
|
||||||
|
|
||||||
|
(void) session;
|
||||||
|
(void) channel;
|
||||||
|
(void) is_stderr;
|
||||||
|
|
||||||
|
if (len == 0 || cdata->pid < 1 || kill(cdata->pid, 0) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return write(cdata->child_stdin, (char *) data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pty_request(ssh_session session, ssh_channel channel,
|
||||||
|
const char *term, int cols, int rows, int py, int px,
|
||||||
|
void *userdata) {
|
||||||
|
struct channel_data_struct *cdata = (struct channel_data_struct *)userdata;
|
||||||
|
|
||||||
|
(void) session;
|
||||||
|
(void) channel;
|
||||||
|
(void) term;
|
||||||
|
|
||||||
|
cdata->winsize->ws_row = rows;
|
||||||
|
cdata->winsize->ws_col = cols;
|
||||||
|
cdata->winsize->ws_xpixel = px;
|
||||||
|
cdata->winsize->ws_ypixel = py;
|
||||||
|
|
||||||
|
if (openpty(&cdata->pty_master, &cdata->pty_slave, NULL, NULL,
|
||||||
|
cdata->winsize) != 0) {
|
||||||
|
fprintf(stderr, "Failed to open pty\n");
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pty_resize(ssh_session session, ssh_channel channel, int cols,
|
||||||
|
int rows, int py, int px, void *userdata) {
|
||||||
|
struct channel_data_struct *cdata = (struct channel_data_struct *)userdata;
|
||||||
|
|
||||||
|
(void) session;
|
||||||
|
(void) channel;
|
||||||
|
|
||||||
|
cdata->winsize->ws_row = rows;
|
||||||
|
cdata->winsize->ws_col = cols;
|
||||||
|
cdata->winsize->ws_xpixel = px;
|
||||||
|
cdata->winsize->ws_ypixel = py;
|
||||||
|
|
||||||
|
if (cdata->pty_master != -1) {
|
||||||
|
return ioctl(cdata->pty_master, TIOCSWINSZ, cdata->winsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int exec_pty(const char *mode, const char *command,
|
||||||
|
struct channel_data_struct *cdata) {
|
||||||
|
switch(cdata->pid = fork()) {
|
||||||
|
case -1:
|
||||||
|
close(cdata->pty_master);
|
||||||
|
close(cdata->pty_slave);
|
||||||
|
fprintf(stderr, "Failed to fork\n");
|
||||||
|
return SSH_ERROR;
|
||||||
|
case 0:
|
||||||
|
close(cdata->pty_master);
|
||||||
|
if (login_tty(cdata->pty_slave) != 0) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
execl("/bin/sh", "sh", mode, command, NULL);
|
||||||
|
exit(0);
|
||||||
|
default:
|
||||||
|
close(cdata->pty_slave);
|
||||||
|
/* pty fd is bi-directional */
|
||||||
|
cdata->child_stdout = cdata->child_stdin = cdata->pty_master;
|
||||||
|
}
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int exec_nopty(const char *command, struct channel_data_struct *cdata) {
|
||||||
|
int in[2], out[2], err[2];
|
||||||
|
|
||||||
|
/* Do the plumbing to be able to talk with the child process. */
|
||||||
|
if (pipe(in) != 0) {
|
||||||
|
goto stdin_failed;
|
||||||
|
}
|
||||||
|
if (pipe(out) != 0) {
|
||||||
|
goto stdout_failed;
|
||||||
|
}
|
||||||
|
if (pipe(err) != 0) {
|
||||||
|
goto stderr_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(cdata->pid = fork()) {
|
||||||
|
case -1:
|
||||||
|
goto fork_failed;
|
||||||
|
case 0:
|
||||||
|
/* Finish the plumbing in the child process. */
|
||||||
|
close(in[1]);
|
||||||
|
close(out[0]);
|
||||||
|
close(err[0]);
|
||||||
|
dup2(in[0], STDIN_FILENO);
|
||||||
|
dup2(out[1], STDOUT_FILENO);
|
||||||
|
dup2(err[1], STDERR_FILENO);
|
||||||
|
close(in[0]);
|
||||||
|
close(out[1]);
|
||||||
|
close(err[1]);
|
||||||
|
/* exec the requested command. */
|
||||||
|
execl("/bin/sh", "sh", "-c", command, NULL);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(in[0]);
|
||||||
|
close(out[1]);
|
||||||
|
close(err[1]);
|
||||||
|
|
||||||
|
cdata->child_stdin = in[1];
|
||||||
|
cdata->child_stdout = out[0];
|
||||||
|
cdata->child_stderr = err[0];
|
||||||
|
|
||||||
|
return SSH_OK;
|
||||||
|
|
||||||
|
fork_failed:
|
||||||
|
close(err[0]);
|
||||||
|
close(err[1]);
|
||||||
|
stderr_failed:
|
||||||
|
close(out[0]);
|
||||||
|
close(out[1]);
|
||||||
|
stdout_failed:
|
||||||
|
close(in[0]);
|
||||||
|
close(in[1]);
|
||||||
|
stdin_failed:
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int exec_request(ssh_session session, ssh_channel channel,
|
||||||
|
const char *command, void *userdata) {
|
||||||
|
struct channel_data_struct *cdata = (struct channel_data_struct *) userdata;
|
||||||
|
|
||||||
|
|
||||||
|
(void) session;
|
||||||
|
(void) channel;
|
||||||
|
|
||||||
|
if(cdata->pid > 0) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cdata->pty_master != -1 && cdata->pty_slave != -1) {
|
||||||
|
return exec_pty("-c", command, cdata);
|
||||||
|
}
|
||||||
|
return exec_nopty(command, cdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int shell_request(ssh_session session, ssh_channel channel,
|
||||||
|
void *userdata) {
|
||||||
|
struct channel_data_struct *cdata = (struct channel_data_struct *) userdata;
|
||||||
|
|
||||||
|
(void) session;
|
||||||
|
(void) channel;
|
||||||
|
|
||||||
|
if(cdata->pid > 0) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cdata->pty_master != -1 && cdata->pty_slave != -1) {
|
||||||
|
return exec_pty("-l", NULL, cdata);
|
||||||
|
}
|
||||||
|
/* Client requested a shell without a pty, let's pretend we allow that */
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int subsystem_request(ssh_session session, ssh_channel channel,
|
||||||
|
const char *subsystem, void *userdata) {
|
||||||
|
/* subsystem requests behave simillarly to exec requests. */
|
||||||
|
if (strcmp(subsystem, "sftp") == 0) {
|
||||||
|
return exec_request(session, channel, SFTP_SERVER_PATH, userdata);
|
||||||
|
}
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int auth_password(ssh_session session, const char *user,
|
||||||
|
const char *pass, void *userdata) {
|
||||||
|
struct session_data_struct *sdata = (struct session_data_struct *) userdata;
|
||||||
|
|
||||||
|
(void) session;
|
||||||
|
|
||||||
|
if (strcmp(user, USER) == 0 && strcmp(pass, PASS) == 0) {
|
||||||
|
sdata->authenticated = 1;
|
||||||
|
return SSH_AUTH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdata->auth_attempts++;
|
||||||
|
return SSH_AUTH_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssh_channel channel_open(ssh_session session, void *userdata) {
|
||||||
|
struct session_data_struct *sdata = (struct session_data_struct *) userdata;
|
||||||
|
|
||||||
|
sdata->channel = ssh_channel_new(session);
|
||||||
|
return sdata->channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process_stdout(socket_t fd, int revents, void *userdata) {
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
int n = -1;
|
||||||
|
ssh_channel channel = (ssh_channel) userdata;
|
||||||
|
|
||||||
|
if (channel != NULL && (revents & POLLIN) != 0) {
|
||||||
|
n = read(fd, buf, BUF_SIZE);
|
||||||
|
if (n > 0) {
|
||||||
|
ssh_channel_write(channel, buf, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process_stderr(socket_t fd, int revents, void *userdata) {
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
int n = -1;
|
||||||
|
ssh_channel channel = (ssh_channel) userdata;
|
||||||
|
|
||||||
|
if (channel != NULL && (revents & POLLIN) != 0) {
|
||||||
|
n = read(fd, buf, BUF_SIZE);
|
||||||
|
if (n > 0) {
|
||||||
|
ssh_channel_write_stderr(channel, buf, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_session(ssh_event event, ssh_session session) {
|
||||||
|
int n, rc;
|
||||||
|
|
||||||
|
/* Structure for storing the pty size. */
|
||||||
|
struct winsize wsize = {
|
||||||
|
.ws_row = 0,
|
||||||
|
.ws_col = 0,
|
||||||
|
.ws_xpixel = 0,
|
||||||
|
.ws_ypixel = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Our struct holding information about the channel. */
|
||||||
|
struct channel_data_struct cdata = {
|
||||||
|
.pid = 0,
|
||||||
|
.pty_master = -1,
|
||||||
|
.pty_slave = -1,
|
||||||
|
.child_stdin = -1,
|
||||||
|
.child_stdout = -1,
|
||||||
|
.child_stderr = -1,
|
||||||
|
.event = NULL,
|
||||||
|
.winsize = &wsize
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Our struct holding information about the session. */
|
||||||
|
struct session_data_struct sdata = {
|
||||||
|
.channel = NULL,
|
||||||
|
.auth_attempts = 0,
|
||||||
|
.authenticated = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ssh_channel_callbacks_struct channel_cb = {
|
||||||
|
.userdata = &cdata,
|
||||||
|
.channel_pty_request_function = pty_request,
|
||||||
|
.channel_pty_window_change_function = pty_resize,
|
||||||
|
.channel_shell_request_function = shell_request,
|
||||||
|
.channel_exec_request_function = exec_request,
|
||||||
|
.channel_data_function = data_function,
|
||||||
|
.channel_subsystem_request_function = subsystem_request
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ssh_server_callbacks_struct server_cb = {
|
||||||
|
.userdata = &sdata,
|
||||||
|
.auth_password_function = auth_password,
|
||||||
|
.channel_open_request_session_function = channel_open,
|
||||||
|
};
|
||||||
|
|
||||||
|
ssh_callbacks_init(&server_cb);
|
||||||
|
ssh_callbacks_init(&channel_cb);
|
||||||
|
|
||||||
|
ssh_set_server_callbacks(session, &server_cb);
|
||||||
|
|
||||||
|
if (ssh_handle_key_exchange(session) != SSH_OK) {
|
||||||
|
fprintf(stderr, "%s\n", ssh_get_error(session));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_set_auth_methods(session, SSH_AUTH_METHOD_PASSWORD);
|
||||||
|
ssh_event_add_session(event, session);
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
while (sdata.authenticated == 0 || sdata.channel == NULL) {
|
||||||
|
/* If the user has used up all attempts, or if he hasn't been able to
|
||||||
|
* authenticate in 10 seconds (n * 100ms), disconnect. */
|
||||||
|
if (sdata.auth_attempts >= 3 || n >= 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ssh_event_dopoll(event, 100) == SSH_ERROR) {
|
||||||
|
fprintf(stderr, "%s\n", ssh_get_error(session));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_set_channel_callbacks(sdata.channel, &channel_cb);
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* Poll the main event which takes care of the session, the channel and
|
||||||
|
* even our child process's stdout/stderr (once it's started). */
|
||||||
|
if (ssh_event_dopoll(event, -1) == SSH_ERROR) {
|
||||||
|
ssh_channel_close(sdata.channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If child process's stdout/stderr has been registered with the event,
|
||||||
|
* or the child process hasn't started yet, continue. */
|
||||||
|
if (cdata.event != NULL || cdata.pid == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* Executed only once, once the child process starts. */
|
||||||
|
cdata.event = event;
|
||||||
|
/* If stdout valid, add stdout to be monitored by the poll event. */
|
||||||
|
if (cdata.child_stdout != -1) {
|
||||||
|
if (ssh_event_add_fd(event, cdata.child_stdout, POLLIN, process_stdout,
|
||||||
|
sdata.channel) != SSH_OK) {
|
||||||
|
fprintf(stderr, "Failed to register stdout to poll context\n");
|
||||||
|
ssh_channel_close(sdata.channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If stderr valid, add stderr to be monitored by the poll event. */
|
||||||
|
if (cdata.child_stderr != -1){
|
||||||
|
if (ssh_event_add_fd(event, cdata.child_stderr, POLLIN, process_stderr,
|
||||||
|
sdata.channel) != SSH_OK) {
|
||||||
|
fprintf(stderr, "Failed to register stderr to poll context\n");
|
||||||
|
ssh_channel_close(sdata.channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while(ssh_channel_is_open(sdata.channel) &&
|
||||||
|
(cdata.pid == 0 || waitpid(cdata.pid, &rc, WNOHANG) == 0));
|
||||||
|
|
||||||
|
close(cdata.pty_master);
|
||||||
|
close(cdata.child_stdin);
|
||||||
|
close(cdata.child_stdout);
|
||||||
|
close(cdata.child_stderr);
|
||||||
|
|
||||||
|
/* Remove the descriptors from the polling context, since they are now
|
||||||
|
* closed, they will always trigger during the poll calls. */
|
||||||
|
ssh_event_remove_fd(event, cdata.child_stdout);
|
||||||
|
ssh_event_remove_fd(event, cdata.child_stderr);
|
||||||
|
|
||||||
|
/* If the child process exited. */
|
||||||
|
if (kill(cdata.pid, 0) < 0 && WIFEXITED(rc)) {
|
||||||
|
rc = WEXITSTATUS(rc);
|
||||||
|
ssh_channel_request_send_exit_status(sdata.channel, rc);
|
||||||
|
/* If client terminated the channel or the process did not exit nicely,
|
||||||
|
* but only if something has been forked. */
|
||||||
|
} else if (cdata.pid > 0) {
|
||||||
|
kill(cdata.pid, SIGKILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_channel_send_eof(sdata.channel);
|
||||||
|
ssh_channel_close(sdata.channel);
|
||||||
|
|
||||||
|
/* Wait up to 5 seconds for the client to terminate the session. */
|
||||||
|
for (n = 0; n < 50 && (ssh_get_status(session) & SESSION_END) == 0; n++) {
|
||||||
|
ssh_event_dopoll(event, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SIGCHLD handler for cleaning up dead children. */
|
||||||
|
static void sigchld_handler(int signo) {
|
||||||
|
(void) signo;
|
||||||
|
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
ssh_bind sshbind;
|
||||||
|
ssh_session session;
|
||||||
|
ssh_event event;
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
/* Set up SIGCHLD handler. */
|
||||||
|
sa.sa_handler = sigchld_handler;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
|
||||||
|
if (sigaction(SIGCHLD, &sa, NULL) != 0) {
|
||||||
|
fprintf(stderr, "Failed to register SIGCHLD handler\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_init();
|
||||||
|
sshbind = ssh_bind_new();
|
||||||
|
|
||||||
|
#ifdef HAVE_ARGP_H
|
||||||
|
argp_parse(&argp, argc, argv, 0, 0, sshbind);
|
||||||
|
#else
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
|
||||||
|
set_default_keys(sshbind, 0, 0, 0);
|
||||||
|
#endif /* HAVE_ARGP_H */
|
||||||
|
|
||||||
|
if(ssh_bind_listen(sshbind) < 0) {
|
||||||
|
fprintf(stderr, "%s\n", ssh_get_error(sshbind));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
session = ssh_new();
|
||||||
|
if (session == NULL) {
|
||||||
|
fprintf(stderr, "Failed to allocate session\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Blocks until there is a new incoming connection. */
|
||||||
|
if(ssh_bind_accept(sshbind, session) != SSH_ERROR) {
|
||||||
|
switch(fork()) {
|
||||||
|
case 0:
|
||||||
|
/* Remove the SIGCHLD handler inherited from parent. */
|
||||||
|
sa.sa_handler = SIG_DFL;
|
||||||
|
sigaction(SIGCHLD, &sa, NULL);
|
||||||
|
/* Remove socket binding, which allows us to restart the
|
||||||
|
* parent process, without terminating existing sessions. */
|
||||||
|
ssh_bind_free(sshbind);
|
||||||
|
|
||||||
|
event = ssh_event_new();
|
||||||
|
if (event != NULL) {
|
||||||
|
/* Blocks until the SSH session ends by either
|
||||||
|
* child process exiting, or client disconnecting. */
|
||||||
|
handle_session(event, session);
|
||||||
|
ssh_event_free(event);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Could not create polling context\n");
|
||||||
|
}
|
||||||
|
ssh_disconnect(session);
|
||||||
|
ssh_free(session);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
case -1:
|
||||||
|
fprintf(stderr, "Failed to fork\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "%s\n", ssh_get_error(sshbind));
|
||||||
|
}
|
||||||
|
/* Since the session has been passed to a child fork, do some cleaning
|
||||||
|
* up at the parent process. */
|
||||||
|
ssh_disconnect(session);
|
||||||
|
ssh_free(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_bind_free(sshbind);
|
||||||
|
ssh_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -87,13 +87,23 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
|||||||
int ret;
|
int ret;
|
||||||
while(channel){
|
while(channel){
|
||||||
do{
|
do{
|
||||||
|
int fd;
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
if(!eof)
|
if(!eof)
|
||||||
FD_SET(0,&fds);
|
FD_SET(0,&fds);
|
||||||
timeout.tv_sec=30;
|
timeout.tv_sec=30;
|
||||||
timeout.tv_usec=0;
|
timeout.tv_usec=0;
|
||||||
FD_SET(ssh_get_fd(session),&fds);
|
|
||||||
maxfd=ssh_get_fd(session)+1;
|
fd = ssh_get_fd(session);
|
||||||
|
if (fd == -1) {
|
||||||
|
fprintf(stderr, "Error getting the session file descriptor: %s\n",
|
||||||
|
ssh_get_error(session));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FD_SET(fd, &fds);
|
||||||
|
maxfd = fd + 1;
|
||||||
|
|
||||||
channels[0]=channel; // set the first channel we want to read from
|
channels[0]=channel; // set the first channel we want to read from
|
||||||
channels[1]=NULL;
|
channels[1]=NULL;
|
||||||
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
|
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
|
||||||
@@ -102,27 +112,27 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
|||||||
if(FD_ISSET(0,&fds)){
|
if(FD_ISSET(0,&fds)){
|
||||||
lus=read(0,buffer,sizeof(buffer));
|
lus=read(0,buffer,sizeof(buffer));
|
||||||
if(lus)
|
if(lus)
|
||||||
channel_write(channel,buffer,lus);
|
ssh_channel_write(channel,buffer,lus);
|
||||||
else {
|
else {
|
||||||
eof=1;
|
eof=1;
|
||||||
channel_send_eof(channel);
|
ssh_channel_send_eof(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(channel && channel_is_closed(channel)){
|
if(channel && ssh_channel_is_closed(channel)){
|
||||||
channel_free(channel);
|
ssh_channel_free(channel);
|
||||||
channel=NULL;
|
channel=NULL;
|
||||||
channels[0]=NULL;
|
channels[0]=NULL;
|
||||||
}
|
}
|
||||||
if(outchannels[0]){
|
if(outchannels[0]){
|
||||||
while(channel && channel_is_open(channel) && channel_poll(channel,0)){
|
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)){
|
||||||
lus=channel_read(channel,buffer,sizeof(buffer),0);
|
lus = ssh_channel_read(channel,buffer,sizeof(buffer),0);
|
||||||
if(lus==-1){
|
if(lus==-1){
|
||||||
fprintf(stderr, "Error reading channel: %s\n",
|
fprintf(stderr, "Error reading channel: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(lus==0){
|
if(lus==0){
|
||||||
channel_free(channel);
|
ssh_channel_free(channel);
|
||||||
channel=channels[0]=NULL;
|
channel=channels[0]=NULL;
|
||||||
} else {
|
} else {
|
||||||
ret = write(1, buffer, lus);
|
ret = write(1, buffer, lus);
|
||||||
@@ -133,27 +143,28 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(channel && channel_is_open(channel) && channel_poll(channel,1)){ /* stderr */
|
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)){ /* stderr */
|
||||||
lus=channel_read(channel,buffer,sizeof(buffer),1);
|
lus = ssh_channel_read(channel, buffer, sizeof(buffer), 1);
|
||||||
if(lus==-1){
|
if(lus==-1){
|
||||||
fprintf(stderr, "Error reading channel: %s\n",
|
fprintf(stderr, "Error reading channel: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(lus==0){
|
if(lus==0){
|
||||||
channel_free(channel);
|
ssh_channel_free(channel);
|
||||||
channel=channels[0]=NULL;
|
channel=channels[0]=NULL;
|
||||||
} else
|
} else {
|
||||||
ret = write(2, buffer, lus);
|
ret = write(2, buffer, lus);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error writing to stderr: %s",
|
fprintf(stderr, "Error writing to stderr: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(channel && channel_is_closed(channel)){
|
if(channel && ssh_channel_is_closed(channel)){
|
||||||
channel_free(channel);
|
ssh_channel_free(channel);
|
||||||
channel=NULL;
|
channel=NULL;
|
||||||
}
|
}
|
||||||
} while (ret==EINTR || ret==SSH_EINTR);
|
} while (ret==EINTR || ret==SSH_EINTR);
|
||||||
@@ -164,8 +175,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
|||||||
static void forwarding(ssh_session session){
|
static void forwarding(ssh_session session){
|
||||||
ssh_channel channel;
|
ssh_channel channel;
|
||||||
int r;
|
int r;
|
||||||
channel=channel_new(session);
|
channel = ssh_channel_new(session);
|
||||||
r=channel_open_forward(channel,desthost,atoi(port),"localhost",22);
|
r = ssh_channel_open_forward(channel, desthost, atoi(port), "localhost", 22);
|
||||||
if(r<0) {
|
if(r<0) {
|
||||||
printf("error forwarding port : %s\n",ssh_get_error(session));
|
printf("error forwarding port : %s\n",ssh_get_error(session));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
project(headers C)
|
project(libssh-headers-x C)
|
||||||
|
|
||||||
add_subdirectory(libssh)
|
add_subdirectory(libssh)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ set(libssh_HDRS
|
|||||||
libssh.h
|
libssh.h
|
||||||
ssh2.h
|
ssh2.h
|
||||||
legacy.h
|
legacy.h
|
||||||
|
libsshpp.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (WITH_SFTP)
|
if (WITH_SFTP)
|
||||||
|
|||||||
@@ -90,6 +90,14 @@ enum ssh_auth_state_e {
|
|||||||
SSH_AUTH_STATE_GSSAPI_TOKEN,
|
SSH_AUTH_STATE_GSSAPI_TOKEN,
|
||||||
/** We have sent the MIC and expecting to be authenticated */
|
/** We have sent the MIC and expecting to be authenticated */
|
||||||
SSH_AUTH_STATE_GSSAPI_MIC_SENT,
|
SSH_AUTH_STATE_GSSAPI_MIC_SENT,
|
||||||
|
/** We have offered a pubkey to check if it is supported */
|
||||||
|
SSH_AUTH_STATE_PUBKEY_OFFER_SENT,
|
||||||
|
/** We have sent pubkey and signature expecting to be authenticated */
|
||||||
|
SSH_AUTH_STATE_PUBKEY_AUTH_SENT,
|
||||||
|
/** We have sent a password expecting to be authenticated */
|
||||||
|
SSH_AUTH_STATE_PASSWORD_AUTH_SENT,
|
||||||
|
/** We have sent a request without auth information (method 'none') */
|
||||||
|
SSH_AUTH_STATE_AUTH_NONE_SENT,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
|
|||||||
33
include/libssh/bignum.h
Normal file
33
include/libssh/bignum.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the SSH Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 by Aris Adamantiadis <aris@badcode.be>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BIGNUM_H_
|
||||||
|
#define BIGNUM_H_
|
||||||
|
|
||||||
|
#include "libssh/libcrypto.h"
|
||||||
|
#include "libssh/libgcrypt.h"
|
||||||
|
|
||||||
|
bignum make_string_bn(ssh_string string);
|
||||||
|
void make_string_bn_inplace(ssh_string string, bignum bnout);
|
||||||
|
ssh_string make_bignum_string(bignum num);
|
||||||
|
void ssh_print_bignum(const char *which,bignum num);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BIGNUM_H_ */
|
||||||
@@ -36,9 +36,11 @@ struct ssh_bind_struct {
|
|||||||
char *ecdsakey;
|
char *ecdsakey;
|
||||||
char *dsakey;
|
char *dsakey;
|
||||||
char *rsakey;
|
char *rsakey;
|
||||||
|
char *ed25519key;
|
||||||
ssh_key ecdsa;
|
ssh_key ecdsa;
|
||||||
ssh_key dsa;
|
ssh_key dsa;
|
||||||
ssh_key rsa;
|
ssh_key rsa;
|
||||||
|
ssh_key ed25519;
|
||||||
char *bindaddr;
|
char *bindaddr;
|
||||||
socket_t bindfd;
|
socket_t bindfd;
|
||||||
unsigned int bindport;
|
unsigned int bindport;
|
||||||
|
|||||||
87
include/libssh/blf.h
Normal file
87
include/libssh/blf.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/* $OpenBSD: blf.h,v 1.7 2007/03/14 17:59:41 grunk Exp $ */
|
||||||
|
/*
|
||||||
|
* Blowfish - a fast block cipher designed by Bruce Schneier
|
||||||
|
*
|
||||||
|
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Niels Provos.
|
||||||
|
* 4. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BLF_H_
|
||||||
|
#define _BLF_H_
|
||||||
|
|
||||||
|
//#include "includes.h"
|
||||||
|
|
||||||
|
#if !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H)
|
||||||
|
|
||||||
|
/* Schneier specifies a maximum key length of 56 bytes.
|
||||||
|
* This ensures that every key bit affects every cipher
|
||||||
|
* bit. However, the subkeys can hold up to 72 bytes.
|
||||||
|
* Warning: For normal blowfish encryption only 56 bytes
|
||||||
|
* of the key affect all cipherbits.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BLF_N 16 /* Number of Subkeys */
|
||||||
|
#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
|
||||||
|
#define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */
|
||||||
|
|
||||||
|
/* Blowfish context */
|
||||||
|
typedef struct BlowfishContext {
|
||||||
|
uint32_t S[4][256]; /* S-Boxes */
|
||||||
|
uint32_t P[BLF_N + 2]; /* Subkeys */
|
||||||
|
} blf_ctx;
|
||||||
|
|
||||||
|
/* Raw access to customized Blowfish
|
||||||
|
* blf_key is just:
|
||||||
|
* Blowfish_initstate( state )
|
||||||
|
* Blowfish_expand0state( state, key, keylen )
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *);
|
||||||
|
void Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *);
|
||||||
|
void Blowfish_initstate(blf_ctx *);
|
||||||
|
void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t);
|
||||||
|
void Blowfish_expandstate
|
||||||
|
(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
|
||||||
|
|
||||||
|
/* Standard Blowfish */
|
||||||
|
|
||||||
|
void blf_key(blf_ctx *, const uint8_t *, uint16_t);
|
||||||
|
void blf_enc(blf_ctx *, uint32_t *, uint16_t);
|
||||||
|
void blf_dec(blf_ctx *, uint32_t *, uint16_t);
|
||||||
|
|
||||||
|
void blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t);
|
||||||
|
void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t);
|
||||||
|
|
||||||
|
void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
|
||||||
|
void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
|
||||||
|
|
||||||
|
/* Converts uint8_t to uint32_t */
|
||||||
|
uint32_t Blowfish_stream2word(const uint8_t *, uint16_t , uint16_t *);
|
||||||
|
|
||||||
|
#endif /* !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) */
|
||||||
|
#endif /* _BLF_H */
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef BUFFER_H_
|
#ifndef BUFFER_H_
|
||||||
#define BUFFER_H_
|
#define BUFFER_H_
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "libssh/libssh.h"
|
#include "libssh/libssh.h"
|
||||||
/*
|
/*
|
||||||
* Describes a buffer state
|
* Describes a buffer state
|
||||||
@@ -34,21 +36,49 @@ struct ssh_buffer_struct {
|
|||||||
uint32_t used;
|
uint32_t used;
|
||||||
uint32_t allocated;
|
uint32_t allocated;
|
||||||
uint32_t pos;
|
uint32_t pos;
|
||||||
|
int secure;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
|
||||||
|
|
||||||
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
|
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
|
||||||
LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
|
LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
|
||||||
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
|
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
|
||||||
LIBSSH_API ssh_buffer ssh_buffer_new(void);
|
LIBSSH_API ssh_buffer ssh_buffer_new(void);
|
||||||
|
void ssh_buffer_set_secure(ssh_buffer buffer);
|
||||||
int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
|
int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
|
||||||
int buffer_add_u8(ssh_buffer buffer, uint8_t data);
|
int buffer_add_u8(ssh_buffer buffer, uint8_t data);
|
||||||
int buffer_add_u16(ssh_buffer buffer, uint16_t data);
|
int buffer_add_u16(ssh_buffer buffer, uint16_t data);
|
||||||
int buffer_add_u32(ssh_buffer buffer, uint32_t data);
|
int buffer_add_u32(ssh_buffer buffer, uint32_t data);
|
||||||
int buffer_add_u64(ssh_buffer buffer, uint64_t data);
|
int buffer_add_u64(ssh_buffer buffer, uint64_t data);
|
||||||
int buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
|
int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
|
||||||
|
|
||||||
|
int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len);
|
||||||
|
|
||||||
|
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
va_list ap);
|
||||||
|
int _ssh_buffer_pack(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
...);
|
||||||
|
#define ssh_buffer_pack(buffer, format, ...) \
|
||||||
|
_ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
|
||||||
|
|
||||||
|
int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format, int argc,
|
||||||
|
va_list ap);
|
||||||
|
int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
...);
|
||||||
|
#define ssh_buffer_unpack(buffer, format, ...) \
|
||||||
|
_ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
|
||||||
|
|
||||||
int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
|
int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
|
||||||
int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
|
int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
|
||||||
int buffer_reinit(ssh_buffer buffer);
|
int ssh_buffer_reinit(ssh_buffer buffer);
|
||||||
|
|
||||||
/* buffer_get_rest returns a pointer to the current position into the buffer */
|
/* buffer_get_rest returns a pointer to the current position into the buffer */
|
||||||
void *buffer_get_rest(ssh_buffer buffer);
|
void *buffer_get_rest(ssh_buffer buffer);
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ typedef struct ssh_callbacks_struct *ssh_callbacks;
|
|||||||
* @param user User that wants to authenticate
|
* @param user User that wants to authenticate
|
||||||
* @param password Password used for authentication
|
* @param password Password used for authentication
|
||||||
* @param userdata Userdata to be passed to the callback function.
|
* @param userdata Userdata to be passed to the callback function.
|
||||||
* @returns SSH_AUTH_OK Authentication is accepted.
|
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
|
||||||
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
||||||
* @returns SSH_AUTH_DENIED Authentication failed.
|
* @returns SSH_AUTH_DENIED Authentication failed.
|
||||||
*/
|
*/
|
||||||
@@ -179,7 +179,7 @@ typedef int (*ssh_auth_password_callback) (ssh_session session, const char *user
|
|||||||
* @param session Current session handler
|
* @param session Current session handler
|
||||||
* @param user User that wants to authenticate
|
* @param user User that wants to authenticate
|
||||||
* @param userdata Userdata to be passed to the callback function.
|
* @param userdata Userdata to be passed to the callback function.
|
||||||
* @returns SSH_AUTH_OK Authentication is accepted.
|
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
|
||||||
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
||||||
* @returns SSH_AUTH_DENIED Authentication failed.
|
* @returns SSH_AUTH_DENIED Authentication failed.
|
||||||
*/
|
*/
|
||||||
@@ -191,7 +191,7 @@ typedef int (*ssh_auth_none_callback) (ssh_session session, const char *user, vo
|
|||||||
* @param user Username of the user (can be spoofed)
|
* @param user Username of the user (can be spoofed)
|
||||||
* @param principal Authenticated principal of the user, including realm.
|
* @param principal Authenticated principal of the user, including realm.
|
||||||
* @param userdata Userdata to be passed to the callback function.
|
* @param userdata Userdata to be passed to the callback function.
|
||||||
* @returns SSH_AUTH_OK Authentication is accepted.
|
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
|
||||||
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
||||||
* @returns SSH_AUTH_DENIED Authentication failed.
|
* @returns SSH_AUTH_DENIED Authentication failed.
|
||||||
* @warning Implementations should verify that parameter user matches in some way the principal.
|
* @warning Implementations should verify that parameter user matches in some way the principal.
|
||||||
@@ -209,7 +209,7 @@ typedef int (*ssh_auth_gssapi_mic_callback) (ssh_session session, const char *us
|
|||||||
* SSH_PUBLICKEY_STATE_VALID if the signature is valid. Others values should be
|
* SSH_PUBLICKEY_STATE_VALID if the signature is valid. Others values should be
|
||||||
* replied with a SSH_AUTH_DENIED.
|
* replied with a SSH_AUTH_DENIED.
|
||||||
* @param userdata Userdata to be passed to the callback function.
|
* @param userdata Userdata to be passed to the callback function.
|
||||||
* @returns SSH_AUTH_OK Authentication is accepted.
|
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
|
||||||
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
|
||||||
* @returns SSH_AUTH_DENIED Authentication failed.
|
* @returns SSH_AUTH_DENIED Authentication failed.
|
||||||
*/
|
*/
|
||||||
@@ -495,6 +495,8 @@ LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
|
|||||||
* @param len the length of the data
|
* @param len the length of the data
|
||||||
* @param is_stderr is 0 for stdout or 1 for stderr
|
* @param is_stderr is 0 for stdout or 1 for stderr
|
||||||
* @param userdata Userdata to be passed to the callback function.
|
* @param userdata Userdata to be passed to the callback function.
|
||||||
|
* @returns number of bytes processed by the callee. The remaining bytes will
|
||||||
|
* be sent in the next callback message, when more data is available.
|
||||||
*/
|
*/
|
||||||
typedef int (*ssh_channel_data_callback) (ssh_session session,
|
typedef int (*ssh_channel_data_callback) (ssh_session session,
|
||||||
ssh_channel channel,
|
ssh_channel channel,
|
||||||
@@ -788,14 +790,21 @@ struct ssh_threads_callbacks_struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief sets the thread callbacks necessary if your program is using
|
* @brief Set the thread callbacks structure.
|
||||||
* libssh in a multithreaded fashion. This function must be called first,
|
*
|
||||||
* outside of any threading context (in your main() for instance), before
|
* This is necessary if your program is using libssh in a multithreaded fashion.
|
||||||
* ssh_init().
|
* This function must be called first, outside of any threading context (in your
|
||||||
* @param cb pointer to a ssh_threads_callbacks_struct structure, which contains
|
* main() function for instance), before you call ssh_init().
|
||||||
* the different callbacks to be set.
|
*
|
||||||
|
* @param[in] cb A pointer to a ssh_threads_callbacks_struct structure, which
|
||||||
|
* contains the different callbacks to be set.
|
||||||
|
*
|
||||||
|
* @returns Always returns SSH_OK.
|
||||||
|
*
|
||||||
* @see ssh_threads_callbacks_struct
|
* @see ssh_threads_callbacks_struct
|
||||||
* @see SSH_THREADS_PTHREAD
|
* @see SSH_THREADS_PTHREAD
|
||||||
|
* @bug libgcrypt 1.6 and bigger backend does not support custom callback.
|
||||||
|
* Using anything else than pthreads here will fail.
|
||||||
*/
|
*/
|
||||||
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
|
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
|
||||||
*cb);
|
*cb);
|
||||||
@@ -809,9 +818,13 @@ LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
|
|||||||
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
|
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief returns a pointer on the noop threads callbacks, to be used with
|
* @brief Get the noop threads callbacks structure
|
||||||
* ssh_threads_set_callbacks. These callbacks do nothing and are being used by
|
*
|
||||||
* default.
|
* This can be used with ssh_threads_set_callbacks. These callbacks do nothing
|
||||||
|
* and are being used by default.
|
||||||
|
*
|
||||||
|
* @return Always returns a valid pointer to the noop callbacks structure.
|
||||||
|
*
|
||||||
* @see ssh_threads_set_callbacks
|
* @see ssh_threads_set_callbacks
|
||||||
*/
|
*/
|
||||||
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
|
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ struct ssh_channel_struct {
|
|||||||
int exit_status;
|
int exit_status;
|
||||||
enum ssh_channel_request_state_e request_state;
|
enum ssh_channel_request_state_e request_state;
|
||||||
ssh_channel_callbacks callbacks;
|
ssh_channel_callbacks callbacks;
|
||||||
|
/* counters */
|
||||||
|
ssh_counter counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf);
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf);
|
||||||
@@ -96,8 +98,6 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
|||||||
int ssh_channel_flush(ssh_channel channel);
|
int ssh_channel_flush(ssh_channel channel);
|
||||||
uint32_t ssh_channel_new_id(ssh_session session);
|
uint32_t ssh_channel_new_id(ssh_session session);
|
||||||
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
|
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
|
||||||
int channel_write_common(ssh_channel channel, const void *data,
|
|
||||||
uint32_t len, int is_stderr);
|
|
||||||
void ssh_channel_do_free(ssh_channel channel);
|
void ssh_channel_do_free(ssh_channel channel);
|
||||||
#ifdef WITH_SSH1
|
#ifdef WITH_SSH1
|
||||||
SSH_PACKET_CALLBACK(ssh_packet_data1);
|
SSH_PACKET_CALLBACK(ssh_packet_data1);
|
||||||
|
|||||||
@@ -44,6 +44,9 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "libssh/ecdh.h"
|
#include "libssh/ecdh.h"
|
||||||
#include "libssh/kex.h"
|
#include "libssh/kex.h"
|
||||||
|
#include "libssh/curve25519.h"
|
||||||
|
|
||||||
|
#define DIGEST_MAX_LEN 64
|
||||||
|
|
||||||
enum ssh_key_exchange_e {
|
enum ssh_key_exchange_e {
|
||||||
/* diffie-hellman-group1-sha1 */
|
/* diffie-hellman-group1-sha1 */
|
||||||
@@ -51,7 +54,9 @@ enum ssh_key_exchange_e {
|
|||||||
/* diffie-hellman-group14-sha1 */
|
/* diffie-hellman-group14-sha1 */
|
||||||
SSH_KEX_DH_GROUP14_SHA1,
|
SSH_KEX_DH_GROUP14_SHA1,
|
||||||
/* ecdh-sha2-nistp256 */
|
/* ecdh-sha2-nistp256 */
|
||||||
SSH_KEX_ECDH_SHA2_NISTP256
|
SSH_KEX_ECDH_SHA2_NISTP256,
|
||||||
|
/* curve25519-sha256@libssh.org */
|
||||||
|
SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ssh_crypto_struct {
|
struct ssh_crypto_struct {
|
||||||
@@ -60,6 +65,11 @@ struct ssh_crypto_struct {
|
|||||||
EC_KEY *ecdh_privkey;
|
EC_KEY *ecdh_privkey;
|
||||||
ssh_string ecdh_client_pubkey;
|
ssh_string ecdh_client_pubkey;
|
||||||
ssh_string ecdh_server_pubkey;
|
ssh_string ecdh_server_pubkey;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_CURVE25519
|
||||||
|
ssh_curve25519_privkey curve25519_privkey;
|
||||||
|
ssh_curve25519_pubkey curve25519_client_pubkey;
|
||||||
|
ssh_curve25519_pubkey curve25519_server_pubkey;
|
||||||
#endif
|
#endif
|
||||||
ssh_string dh_server_signature; /* information used by dh_handshake. */
|
ssh_string dh_server_signature; /* information used by dh_handshake. */
|
||||||
size_t digest_len; /* len of all the fields below */
|
size_t digest_len; /* len of all the fields below */
|
||||||
@@ -71,8 +81,10 @@ struct ssh_crypto_struct {
|
|||||||
unsigned char *encryptkey;
|
unsigned char *encryptkey;
|
||||||
unsigned char *encryptMAC;
|
unsigned char *encryptMAC;
|
||||||
unsigned char *decryptMAC;
|
unsigned char *decryptMAC;
|
||||||
unsigned char hmacbuf[EVP_MAX_MD_SIZE];
|
unsigned char hmacbuf[DIGEST_MAX_LEN];
|
||||||
struct ssh_cipher_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
|
struct ssh_cipher_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
|
||||||
|
enum ssh_hmac_e in_hmac, out_hmac; /* the MAC algorithms used */
|
||||||
|
|
||||||
ssh_string server_pubkey;
|
ssh_string server_pubkey;
|
||||||
const char *server_pubkey_type;
|
const char *server_pubkey_type;
|
||||||
int do_compress_out; /* idem */
|
int do_compress_out; /* idem */
|
||||||
@@ -103,9 +115,9 @@ struct ssh_cipher_struct {
|
|||||||
/* sets the new key for immediate use */
|
/* sets the new key for immediate use */
|
||||||
int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
||||||
int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
||||||
void (*cbc_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
void (*encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
||||||
unsigned long len);
|
unsigned long len);
|
||||||
void (*cbc_decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
void (*decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
||||||
unsigned long len);
|
unsigned long len);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
57
include/libssh/curve25519.h
Normal file
57
include/libssh/curve25519.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the SSH Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 by Aris Adamantiadis <aris@badcode.be>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation,
|
||||||
|
* version 2.1 of the License.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CURVE25519_H_
|
||||||
|
#define CURVE25519_H_
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "libssh.h"
|
||||||
|
|
||||||
|
#ifdef WITH_NACL
|
||||||
|
|
||||||
|
#include <nacl/crypto_scalarmult_curve25519.h>
|
||||||
|
#define CURVE25519_PUBKEY_SIZE crypto_scalarmult_curve25519_BYTES
|
||||||
|
#define CURVE25519_PRIVKEY_SIZE crypto_scalarmult_curve25519_SCALARBYTES
|
||||||
|
#define crypto_scalarmult_base crypto_scalarmult_curve25519_base
|
||||||
|
#define crypto_scalarmult crypto_scalarmult_curve25519
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define CURVE25519_PUBKEY_SIZE 32
|
||||||
|
#define CURVE25519_PRIVKEY_SIZE 32
|
||||||
|
int crypto_scalarmult_base(unsigned char *q, const unsigned char *n);
|
||||||
|
int crypto_scalarmult(unsigned char *q, const unsigned char *n, const unsigned char *p);
|
||||||
|
#endif /* WITH_NACL */
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
#define HAVE_CURVE25519 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef unsigned char ssh_curve25519_pubkey[CURVE25519_PUBKEY_SIZE];
|
||||||
|
typedef unsigned char ssh_curve25519_privkey[CURVE25519_PRIVKEY_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
int ssh_client_curve25519_init(ssh_session session);
|
||||||
|
int ssh_client_curve25519_reply(ssh_session session, ssh_buffer packet);
|
||||||
|
|
||||||
|
#ifdef WITH_SERVER
|
||||||
|
int ssh_server_curve25519_init(ssh_session session, ssh_buffer packet);
|
||||||
|
#endif /* WITH_SERVER */
|
||||||
|
|
||||||
|
#endif /* CURVE25519_H_ */
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "libssh/crypto.h"
|
#include "libssh/crypto.h"
|
||||||
|
|
||||||
void ssh_print_bignum(const char *which,bignum num);
|
|
||||||
int dh_generate_e(ssh_session session);
|
int dh_generate_e(ssh_session session);
|
||||||
int dh_generate_f(ssh_session session);
|
int dh_generate_f(ssh_session session);
|
||||||
int dh_generate_x(ssh_session session);
|
int dh_generate_x(ssh_session session);
|
||||||
@@ -48,8 +47,5 @@ int make_sessionid(ssh_session session);
|
|||||||
int hashbufin_add_cookie(ssh_session session, unsigned char *cookie);
|
int hashbufin_add_cookie(ssh_session session, unsigned char *cookie);
|
||||||
int hashbufout_add_cookie(ssh_session session);
|
int hashbufout_add_cookie(ssh_session session);
|
||||||
int generate_session_keys(ssh_session session);
|
int generate_session_keys(ssh_session session);
|
||||||
bignum make_string_bn(ssh_string string);
|
|
||||||
ssh_string make_bignum_string(bignum num);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* DH_H_ */
|
#endif /* DH_H_ */
|
||||||
|
|||||||
@@ -26,7 +26,9 @@
|
|||||||
#ifdef HAVE_LIBCRYPTO
|
#ifdef HAVE_LIBCRYPTO
|
||||||
#ifdef HAVE_OPENSSL_ECDH_H
|
#ifdef HAVE_OPENSSL_ECDH_H
|
||||||
|
|
||||||
#define HAVE_ECDH
|
#ifdef HAVE_ECC
|
||||||
|
#define HAVE_ECDH 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* HAVE_OPENSSL_ECDH_H */
|
#endif /* HAVE_OPENSSL_ECDH_H */
|
||||||
#endif /* HAVE_LIBCRYPTO */
|
#endif /* HAVE_LIBCRYPTO */
|
||||||
|
|||||||
79
include/libssh/ed25519.h
Normal file
79
include/libssh/ed25519.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the SSH Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 by Aris Adamantiadis
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ED25519_H_
|
||||||
|
#define ED25519_H_
|
||||||
|
#include "libssh/priv.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup ed25519 ed25519 API
|
||||||
|
* @internal
|
||||||
|
* @brief API for DJB's ed25519
|
||||||
|
*
|
||||||
|
* @{ */
|
||||||
|
|
||||||
|
#define ED25519_PK_LEN 32
|
||||||
|
#define ED25519_SK_LEN 64
|
||||||
|
#define ED25519_SIG_LEN 64
|
||||||
|
|
||||||
|
typedef uint8_t ed25519_pubkey[ED25519_PK_LEN];
|
||||||
|
typedef uint8_t ed25519_privkey[ED25519_SK_LEN];
|
||||||
|
typedef uint8_t ed25519_signature[ED25519_SIG_LEN];
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief generate an ed25519 key pair
|
||||||
|
* @param[out] pk generated public key
|
||||||
|
* @param[out] sk generated secret key
|
||||||
|
* @return 0 on success, -1 on error.
|
||||||
|
* */
|
||||||
|
int crypto_sign_ed25519_keypair(ed25519_pubkey pk, ed25519_privkey sk);
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief sign a message with ed25519
|
||||||
|
* @param[out] sm location to store the signed message.
|
||||||
|
* Its length should be mlen + 64.
|
||||||
|
* @param[out] smlen pointer to the size of the signed message
|
||||||
|
* @param[in] m message to be signed
|
||||||
|
* @param[in] mlen length of the message to be signed
|
||||||
|
* @param[in] sk secret key to sign the message with
|
||||||
|
* @return 0 on success.
|
||||||
|
*/
|
||||||
|
int crypto_sign_ed25519(
|
||||||
|
unsigned char *sm,unsigned long long *smlen,
|
||||||
|
const unsigned char *m,unsigned long long mlen,
|
||||||
|
const ed25519_privkey sk);
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief "open" and verify the signature of a signed message
|
||||||
|
* @param[out] m location to store the verified message.
|
||||||
|
* Its length should be equal to smlen.
|
||||||
|
* @param[out] mlen pointer to the size of the verified message
|
||||||
|
* @param[in] sm signed message to verify
|
||||||
|
* @param[in] smlen length of the signed message to verify
|
||||||
|
* @param[in] pk public key used to sign the message
|
||||||
|
* @returns 0 on success (supposedly).
|
||||||
|
*/
|
||||||
|
int crypto_sign_ed25519_open(
|
||||||
|
unsigned char *m,unsigned long long *mlen,
|
||||||
|
const unsigned char *sm,unsigned long long smlen,
|
||||||
|
const ed25519_pubkey pk);
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
#endif /* ED25519_H_ */
|
||||||
68
include/libssh/fe25519.h
Normal file
68
include/libssh/fe25519.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* $OpenBSD: fe25519.h,v 1.3 2013/12/09 11:03:45 markus Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public Domain, Authors: Daniel J. Bernstein, Niels Duif, Tanja Lange,
|
||||||
|
* Peter Schwabe, Bo-Yin Yang.
|
||||||
|
* Copied from supercop-20130419/crypto_sign/ed25519/ref/fe25519.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FE25519_H
|
||||||
|
#define FE25519_H
|
||||||
|
|
||||||
|
#include "libssh/priv.h"
|
||||||
|
|
||||||
|
#define fe25519 crypto_sign_ed25519_ref_fe25519
|
||||||
|
#define fe25519_freeze crypto_sign_ed25519_ref_fe25519_freeze
|
||||||
|
#define fe25519_unpack crypto_sign_ed25519_ref_fe25519_unpack
|
||||||
|
#define fe25519_pack crypto_sign_ed25519_ref_fe25519_pack
|
||||||
|
#define fe25519_iszero crypto_sign_ed25519_ref_fe25519_iszero
|
||||||
|
#define fe25519_iseq_vartime crypto_sign_ed25519_ref_fe25519_iseq_vartime
|
||||||
|
#define fe25519_cmov crypto_sign_ed25519_ref_fe25519_cmov
|
||||||
|
#define fe25519_setone crypto_sign_ed25519_ref_fe25519_setone
|
||||||
|
#define fe25519_setzero crypto_sign_ed25519_ref_fe25519_setzero
|
||||||
|
#define fe25519_neg crypto_sign_ed25519_ref_fe25519_neg
|
||||||
|
#define fe25519_getparity crypto_sign_ed25519_ref_fe25519_getparity
|
||||||
|
#define fe25519_add crypto_sign_ed25519_ref_fe25519_add
|
||||||
|
#define fe25519_sub crypto_sign_ed25519_ref_fe25519_sub
|
||||||
|
#define fe25519_mul crypto_sign_ed25519_ref_fe25519_mul
|
||||||
|
#define fe25519_square crypto_sign_ed25519_ref_fe25519_square
|
||||||
|
#define fe25519_invert crypto_sign_ed25519_ref_fe25519_invert
|
||||||
|
#define fe25519_pow2523 crypto_sign_ed25519_ref_fe25519_pow2523
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t v[32];
|
||||||
|
} fe25519;
|
||||||
|
|
||||||
|
void fe25519_freeze(fe25519 *r);
|
||||||
|
|
||||||
|
void fe25519_unpack(fe25519 *r, const unsigned char x[32]);
|
||||||
|
|
||||||
|
void fe25519_pack(unsigned char r[32], const fe25519 *x);
|
||||||
|
|
||||||
|
int fe25519_iszero(const fe25519 *x);
|
||||||
|
|
||||||
|
int fe25519_iseq_vartime(const fe25519 *x, const fe25519 *y);
|
||||||
|
|
||||||
|
void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b);
|
||||||
|
|
||||||
|
void fe25519_setone(fe25519 *r);
|
||||||
|
|
||||||
|
void fe25519_setzero(fe25519 *r);
|
||||||
|
|
||||||
|
void fe25519_neg(fe25519 *r, const fe25519 *x);
|
||||||
|
|
||||||
|
unsigned char fe25519_getparity(const fe25519 *x);
|
||||||
|
|
||||||
|
void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y);
|
||||||
|
|
||||||
|
void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y);
|
||||||
|
|
||||||
|
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y);
|
||||||
|
|
||||||
|
void fe25519_square(fe25519 *r, const fe25519 *x);
|
||||||
|
|
||||||
|
void fe25519_invert(fe25519 *r, const fe25519 *x);
|
||||||
|
|
||||||
|
void fe25519_pow2523(fe25519 *r, const fe25519 *x);
|
||||||
|
|
||||||
|
#endif
|
||||||
43
include/libssh/ge25519.h
Normal file
43
include/libssh/ge25519.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/* $OpenBSD: ge25519.h,v 1.3 2013/12/09 11:03:45 markus Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public Domain, Authors: Daniel J. Bernstein, Niels Duif, Tanja Lange,
|
||||||
|
* Peter Schwabe, Bo-Yin Yang.
|
||||||
|
* Copied from supercop-20130419/crypto_sign/ed25519/ref/ge25519.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GE25519_H
|
||||||
|
#define GE25519_H
|
||||||
|
|
||||||
|
#include "fe25519.h"
|
||||||
|
#include "sc25519.h"
|
||||||
|
|
||||||
|
#define ge25519 crypto_sign_ed25519_ref_ge25519
|
||||||
|
#define ge25519_base crypto_sign_ed25519_ref_ge25519_base
|
||||||
|
#define ge25519_unpackneg_vartime crypto_sign_ed25519_ref_unpackneg_vartime
|
||||||
|
#define ge25519_pack crypto_sign_ed25519_ref_pack
|
||||||
|
#define ge25519_isneutral_vartime crypto_sign_ed25519_ref_isneutral_vartime
|
||||||
|
#define ge25519_double_scalarmult_vartime crypto_sign_ed25519_ref_double_scalarmult_vartime
|
||||||
|
#define ge25519_scalarmult_base crypto_sign_ed25519_ref_scalarmult_base
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
fe25519 x;
|
||||||
|
fe25519 y;
|
||||||
|
fe25519 z;
|
||||||
|
fe25519 t;
|
||||||
|
} ge25519;
|
||||||
|
|
||||||
|
const ge25519 ge25519_base;
|
||||||
|
|
||||||
|
int ge25519_unpackneg_vartime(ge25519 *r, const unsigned char p[32]);
|
||||||
|
|
||||||
|
void ge25519_pack(unsigned char r[32], const ge25519 *p);
|
||||||
|
|
||||||
|
int ge25519_isneutral_vartime(const ge25519 *p);
|
||||||
|
|
||||||
|
void ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const sc25519 *s1, const ge25519 *p2, const sc25519 *s2);
|
||||||
|
|
||||||
|
void ge25519_scalarmult_base(ge25519 *r, const sc25519 *s);
|
||||||
|
|
||||||
|
#endif
|
||||||
27
include/libssh/knownhosts.h
Normal file
27
include/libssh/knownhosts.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the SSH Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 20014 by Aris Adamantiadis <aris@badcode.be>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef KNOWNHOSTS_H_
|
||||||
|
#define KNOWNHOSTS_H_
|
||||||
|
|
||||||
|
char **ssh_knownhosts_algorithms(ssh_session session);
|
||||||
|
|
||||||
|
#endif /* KNOWNHOSTS_H_ */
|
||||||
@@ -42,51 +42,51 @@ LIBSSH_API int ssh_userauth_autopubkey(ssh_session session, const char *passphra
|
|||||||
LIBSSH_API int ssh_userauth_privatekey_file(ssh_session session, const char *username,
|
LIBSSH_API int ssh_userauth_privatekey_file(ssh_session session, const char *username,
|
||||||
const char *filename, const char *passphrase);
|
const char *filename, const char *passphrase);
|
||||||
|
|
||||||
LIBSSH_API void buffer_free(ssh_buffer buffer);
|
SSH_DEPRECATED LIBSSH_API void buffer_free(ssh_buffer buffer);
|
||||||
LIBSSH_API void *buffer_get(ssh_buffer buffer);
|
SSH_DEPRECATED LIBSSH_API void *buffer_get(ssh_buffer buffer);
|
||||||
LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
|
SSH_DEPRECATED LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
|
||||||
LIBSSH_API ssh_buffer buffer_new(void);
|
SSH_DEPRECATED LIBSSH_API ssh_buffer buffer_new(void);
|
||||||
|
|
||||||
LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
|
SSH_DEPRECATED LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
|
||||||
LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
|
SSH_DEPRECATED LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
|
||||||
LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
|
SSH_DEPRECATED LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
|
||||||
LIBSSH_API int channel_close(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_close(ssh_channel channel);
|
||||||
LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
|
SSH_DEPRECATED LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
|
||||||
LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
SSH_DEPRECATED LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||||
LIBSSH_API void channel_free(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API void channel_free(ssh_channel channel);
|
||||||
LIBSSH_API int channel_get_exit_status(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_get_exit_status(ssh_channel channel);
|
||||||
LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
|
||||||
LIBSSH_API int channel_is_closed(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_is_closed(ssh_channel channel);
|
||||||
LIBSSH_API int channel_is_eof(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_is_eof(ssh_channel channel);
|
||||||
LIBSSH_API int channel_is_open(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_is_open(ssh_channel channel);
|
||||||
LIBSSH_API ssh_channel channel_new(ssh_session session);
|
SSH_DEPRECATED LIBSSH_API ssh_channel channel_new(ssh_session session);
|
||||||
LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
|
SSH_DEPRECATED LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||||
int remoteport, const char *sourcehost, int localport);
|
int remoteport, const char *sourcehost, int localport);
|
||||||
LIBSSH_API int channel_open_session(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_open_session(ssh_channel channel);
|
||||||
LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
|
SSH_DEPRECATED LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
|
||||||
LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
SSH_DEPRECATED LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||||
|
|
||||||
LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
SSH_DEPRECATED LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||||
int is_stderr);
|
int is_stderr);
|
||||||
|
|
||||||
LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
SSH_DEPRECATED LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||||
int is_stderr);
|
int is_stderr);
|
||||||
LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
|
SSH_DEPRECATED LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||||
LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
|
SSH_DEPRECATED LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
|
||||||
LIBSSH_API int channel_request_pty(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_request_pty(ssh_channel channel);
|
||||||
LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
|
SSH_DEPRECATED LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
|
||||||
int cols, int rows);
|
int cols, int rows);
|
||||||
LIBSSH_API int channel_request_shell(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_request_shell(ssh_channel channel);
|
||||||
LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
|
SSH_DEPRECATED LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
|
||||||
LIBSSH_API int channel_request_sftp(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_request_sftp(ssh_channel channel);
|
||||||
LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
|
SSH_DEPRECATED LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
|
||||||
LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
SSH_DEPRECATED LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||||
const char *cookie, int screen_number);
|
const char *cookie, int screen_number);
|
||||||
LIBSSH_API int channel_send_eof(ssh_channel channel);
|
SSH_DEPRECATED LIBSSH_API int channel_send_eof(ssh_channel channel);
|
||||||
LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
SSH_DEPRECATED LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||||
timeval * timeout);
|
timeval * timeout);
|
||||||
LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
|
SSH_DEPRECATED LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
|
||||||
LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
|
SSH_DEPRECATED LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
|
||||||
|
|
||||||
LIBSSH_API void privatekey_free(ssh_private_key prv);
|
LIBSSH_API void privatekey_free(ssh_private_key prv);
|
||||||
LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
||||||
@@ -107,14 +107,14 @@ LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
|
|||||||
LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype);
|
LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype);
|
||||||
LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);
|
LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);
|
||||||
|
|
||||||
LIBSSH_API void string_burn(ssh_string str);
|
SSH_DEPRECATED LIBSSH_API void string_burn(ssh_string str);
|
||||||
LIBSSH_API ssh_string string_copy(ssh_string str);
|
SSH_DEPRECATED LIBSSH_API ssh_string string_copy(ssh_string str);
|
||||||
LIBSSH_API void *string_data(ssh_string str);
|
SSH_DEPRECATED LIBSSH_API void *string_data(ssh_string str);
|
||||||
LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
|
SSH_DEPRECATED LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
|
||||||
LIBSSH_API void string_free(ssh_string str);
|
SSH_DEPRECATED LIBSSH_API void string_free(ssh_string str);
|
||||||
LIBSSH_API ssh_string string_from_char(const char *what);
|
SSH_DEPRECATED LIBSSH_API ssh_string string_from_char(const char *what);
|
||||||
LIBSSH_API size_t string_len(ssh_string str);
|
SSH_DEPRECATED LIBSSH_API size_t string_len(ssh_string str);
|
||||||
LIBSSH_API ssh_string string_new(size_t size);
|
SSH_DEPRECATED LIBSSH_API ssh_string string_new(size_t size);
|
||||||
LIBSSH_API char *string_to_char(ssh_string str);
|
SSH_DEPRECATED LIBSSH_API char *string_to_char(ssh_string str);
|
||||||
|
|
||||||
#endif /* LEGACY_H_ */
|
#endif /* LEGACY_H_ */
|
||||||
|
|||||||
@@ -36,10 +36,20 @@
|
|||||||
|
|
||||||
typedef SHA_CTX* SHACTX;
|
typedef SHA_CTX* SHACTX;
|
||||||
typedef SHA256_CTX* SHA256CTX;
|
typedef SHA256_CTX* SHA256CTX;
|
||||||
|
typedef SHA512_CTX* SHA384CTX;
|
||||||
|
typedef SHA512_CTX* SHA512CTX;
|
||||||
typedef MD5_CTX* MD5CTX;
|
typedef MD5_CTX* MD5CTX;
|
||||||
typedef HMAC_CTX* HMACCTX;
|
typedef HMAC_CTX* HMACCTX;
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
typedef EVP_MD_CTX *EVPCTX;
|
||||||
|
#else
|
||||||
|
typedef void *EVPCTX;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
|
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
|
||||||
|
#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
|
||||||
|
#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
|
||||||
|
#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
|
||||||
#ifdef MD5_DIGEST_LEN
|
#ifdef MD5_DIGEST_LEN
|
||||||
#undef MD5_DIGEST_LEN
|
#undef MD5_DIGEST_LEN
|
||||||
#endif
|
#endif
|
||||||
@@ -79,6 +89,14 @@ SHA256CTX sha256_init(void);
|
|||||||
void sha256_update(SHA256CTX c, const void *data, unsigned long len);
|
void sha256_update(SHA256CTX c, const void *data, unsigned long len);
|
||||||
void sha256_final(unsigned char *md, SHA256CTX c);
|
void sha256_final(unsigned char *md, SHA256CTX c);
|
||||||
|
|
||||||
|
SHA384CTX sha384_init(void);
|
||||||
|
void sha384_update(SHA384CTX c, const void *data, unsigned long len);
|
||||||
|
void sha384_final(unsigned char *md, SHA384CTX c);
|
||||||
|
|
||||||
|
SHA512CTX sha512_init(void);
|
||||||
|
void sha512_update(SHA512CTX c, const void *data, unsigned long len);
|
||||||
|
void sha512_final(unsigned char *md, SHA512CTX c);
|
||||||
|
|
||||||
struct ssh_cipher_struct *ssh_get_ciphertab(void);
|
struct ssh_cipher_struct *ssh_get_ciphertab(void);
|
||||||
|
|
||||||
#endif /* HAVE_LIBCRYPTO */
|
#endif /* HAVE_LIBCRYPTO */
|
||||||
|
|||||||
@@ -27,17 +27,24 @@
|
|||||||
|
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
typedef gcry_md_hd_t SHACTX;
|
typedef gcry_md_hd_t SHACTX;
|
||||||
|
typedef gcry_md_hd_t SHA256CTX;
|
||||||
|
typedef gcry_md_hd_t SHA384CTX;
|
||||||
|
typedef gcry_md_hd_t SHA512CTX;
|
||||||
typedef gcry_md_hd_t MD5CTX;
|
typedef gcry_md_hd_t MD5CTX;
|
||||||
typedef gcry_md_hd_t HMACCTX;
|
typedef gcry_md_hd_t HMACCTX;
|
||||||
|
typedef void *EVPCTX;
|
||||||
#define SHA_DIGEST_LENGTH 20
|
#define SHA_DIGEST_LENGTH 20
|
||||||
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
|
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
|
||||||
#define MD5_DIGEST_LEN 16
|
#define MD5_DIGEST_LEN 16
|
||||||
#define SHA256_DIGEST_LENGTH 32
|
#define SHA256_DIGEST_LENGTH 32
|
||||||
|
#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
|
||||||
#define SHA384_DIGEST_LENGTH 48
|
#define SHA384_DIGEST_LENGTH 48
|
||||||
|
#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
|
||||||
#define SHA512_DIGEST_LENGTH 64
|
#define SHA512_DIGEST_LENGTH 64
|
||||||
|
#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
|
||||||
|
|
||||||
#ifndef EVP_MAX_MD_SIZE
|
#ifndef EVP_MAX_MD_SIZE
|
||||||
#define EVP_MAX_MD_SIZE 36
|
#define EVP_MAX_MD_SIZE 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
|
#define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
#else /* _MSC_VER */
|
#else /* _MSC_VER */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -77,8 +78,8 @@
|
|||||||
|
|
||||||
/* libssh version */
|
/* libssh version */
|
||||||
#define LIBSSH_VERSION_MAJOR 0
|
#define LIBSSH_VERSION_MAJOR 0
|
||||||
#define LIBSSH_VERSION_MINOR 6
|
#define LIBSSH_VERSION_MINOR 7
|
||||||
#define LIBSSH_VERSION_MICRO 0
|
#define LIBSSH_VERSION_MICRO 7
|
||||||
|
|
||||||
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
|
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
|
||||||
LIBSSH_VERSION_MINOR, \
|
LIBSSH_VERSION_MINOR, \
|
||||||
@@ -104,6 +105,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct ssh_counter_struct {
|
||||||
|
uint64_t in_bytes;
|
||||||
|
uint64_t out_bytes;
|
||||||
|
uint64_t in_packets;
|
||||||
|
uint64_t out_packets;
|
||||||
|
};
|
||||||
|
typedef struct ssh_counter_struct *ssh_counter;
|
||||||
|
|
||||||
typedef struct ssh_agent_struct* ssh_agent;
|
typedef struct ssh_agent_struct* ssh_agent;
|
||||||
typedef struct ssh_buffer_struct* ssh_buffer;
|
typedef struct ssh_buffer_struct* ssh_buffer;
|
||||||
@@ -208,10 +216,14 @@ enum ssh_publickey_state_e {
|
|||||||
SSH_PUBLICKEY_STATE_WRONG=2
|
SSH_PUBLICKEY_STATE_WRONG=2
|
||||||
};
|
};
|
||||||
|
|
||||||
/* status flags */
|
/* Status flags */
|
||||||
|
/** Socket is closed */
|
||||||
#define SSH_CLOSED 0x01
|
#define SSH_CLOSED 0x01
|
||||||
|
/** Reading to socket won't block */
|
||||||
#define SSH_READ_PENDING 0x02
|
#define SSH_READ_PENDING 0x02
|
||||||
|
/** Session was closed due to an error */
|
||||||
#define SSH_CLOSED_ERROR 0x04
|
#define SSH_CLOSED_ERROR 0x04
|
||||||
|
/** Output buffer not empty */
|
||||||
#define SSH_WRITE_PENDING 0x08
|
#define SSH_WRITE_PENDING 0x08
|
||||||
|
|
||||||
enum ssh_server_known_e {
|
enum ssh_server_known_e {
|
||||||
@@ -241,7 +253,8 @@ enum ssh_keytypes_e{
|
|||||||
SSH_KEYTYPE_DSS=1,
|
SSH_KEYTYPE_DSS=1,
|
||||||
SSH_KEYTYPE_RSA,
|
SSH_KEYTYPE_RSA,
|
||||||
SSH_KEYTYPE_RSA1,
|
SSH_KEYTYPE_RSA1,
|
||||||
SSH_KEYTYPE_ECDSA
|
SSH_KEYTYPE_ECDSA,
|
||||||
|
SSH_KEYTYPE_ED25519
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ssh_keycmp_e {
|
enum ssh_keycmp_e {
|
||||||
@@ -327,7 +340,12 @@ enum ssh_options_e {
|
|||||||
SSH_OPTIONS_COMPRESSION,
|
SSH_OPTIONS_COMPRESSION,
|
||||||
SSH_OPTIONS_COMPRESSION_LEVEL,
|
SSH_OPTIONS_COMPRESSION_LEVEL,
|
||||||
SSH_OPTIONS_KEY_EXCHANGE,
|
SSH_OPTIONS_KEY_EXCHANGE,
|
||||||
SSH_OPTIONS_HOSTKEYS
|
SSH_OPTIONS_HOSTKEYS,
|
||||||
|
SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
|
||||||
|
SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
|
||||||
|
SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
|
||||||
|
SSH_OPTIONS_HMAC_C_S,
|
||||||
|
SSH_OPTIONS_HMAC_S_C,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -370,6 +388,7 @@ LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr,
|
|||||||
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
|
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
|
||||||
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
|
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
|
||||||
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||||
|
LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms);
|
||||||
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||||
int is_stderr);
|
int is_stderr);
|
||||||
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
|
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||||
@@ -387,6 +406,8 @@ LIBSSH_API int ssh_channel_send_eof(ssh_channel channel);
|
|||||||
LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||||
timeval * timeout);
|
timeval * timeout);
|
||||||
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
|
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
|
||||||
|
LIBSSH_API void ssh_channel_set_counter(ssh_channel channel,
|
||||||
|
ssh_counter counter);
|
||||||
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
|
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
|
||||||
LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
|
LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
|
||||||
|
|
||||||
@@ -397,9 +418,19 @@ LIBSSH_API const char *ssh_copyright(void);
|
|||||||
LIBSSH_API void ssh_disconnect(ssh_session session);
|
LIBSSH_API void ssh_disconnect(ssh_session session);
|
||||||
LIBSSH_API char *ssh_dirname (const char *path);
|
LIBSSH_API char *ssh_dirname (const char *path);
|
||||||
LIBSSH_API int ssh_finalize(void);
|
LIBSSH_API int ssh_finalize(void);
|
||||||
LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
|
|
||||||
LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
|
/* REVERSE PORT FORWARDING */
|
||||||
LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session,
|
||||||
|
int timeout_ms,
|
||||||
|
int *destination_port);
|
||||||
|
LIBSSH_API int ssh_channel_cancel_forward(ssh_session session,
|
||||||
|
const char *address,
|
||||||
|
int port);
|
||||||
|
LIBSSH_API int ssh_channel_listen_forward(ssh_session session,
|
||||||
|
const char *address,
|
||||||
|
int port,
|
||||||
|
int *bound_port);
|
||||||
|
|
||||||
LIBSSH_API void ssh_free(ssh_session session);
|
LIBSSH_API void ssh_free(ssh_session session);
|
||||||
LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
|
LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
|
||||||
LIBSSH_API const char *ssh_get_error(void *error);
|
LIBSSH_API const char *ssh_get_error(void *error);
|
||||||
@@ -408,11 +439,30 @@ LIBSSH_API socket_t ssh_get_fd(ssh_session session);
|
|||||||
LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
|
LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
|
||||||
LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
|
LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
|
||||||
LIBSSH_API int ssh_get_openssh_version(ssh_session session);
|
LIBSSH_API int ssh_get_openssh_version(ssh_session session);
|
||||||
|
|
||||||
LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
|
LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
|
||||||
LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
|
|
||||||
|
enum ssh_publickey_hash_type {
|
||||||
|
SSH_PUBLICKEY_HASH_SHA1,
|
||||||
|
SSH_PUBLICKEY_HASH_MD5,
|
||||||
|
SSH_PUBLICKEY_HASH_SHA256
|
||||||
|
};
|
||||||
|
LIBSSH_API int ssh_get_publickey_hash(const ssh_key key,
|
||||||
|
enum ssh_publickey_hash_type type,
|
||||||
|
unsigned char **hash,
|
||||||
|
size_t *hlen);
|
||||||
|
|
||||||
|
/* DEPRECATED FUNCTIONS */
|
||||||
|
SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
|
||||||
|
SSH_DEPRECATED LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
|
||||||
|
SSH_DEPRECATED LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
|
||||||
|
SSH_DEPRECATED LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||||
|
|
||||||
|
|
||||||
LIBSSH_API int ssh_get_random(void *where,int len,int strong);
|
LIBSSH_API int ssh_get_random(void *where,int len,int strong);
|
||||||
LIBSSH_API int ssh_get_version(ssh_session session);
|
LIBSSH_API int ssh_get_version(ssh_session session);
|
||||||
LIBSSH_API int ssh_get_status(ssh_session session);
|
LIBSSH_API int ssh_get_status(ssh_session session);
|
||||||
|
LIBSSH_API int ssh_get_poll_flags(ssh_session session);
|
||||||
LIBSSH_API int ssh_init(void);
|
LIBSSH_API int ssh_init(void);
|
||||||
LIBSSH_API int ssh_is_blocking(ssh_session session);
|
LIBSSH_API int ssh_is_blocking(ssh_session session);
|
||||||
LIBSSH_API int ssh_is_connected(ssh_session session);
|
LIBSSH_API int ssh_is_connected(ssh_session session);
|
||||||
@@ -493,6 +543,11 @@ LIBSSH_API int ssh_pki_import_privkey_file(const char *filename,
|
|||||||
ssh_auth_callback auth_fn,
|
ssh_auth_callback auth_fn,
|
||||||
void *auth_data,
|
void *auth_data,
|
||||||
ssh_key *pkey);
|
ssh_key *pkey);
|
||||||
|
LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey,
|
||||||
|
const char *passphrase,
|
||||||
|
ssh_auth_callback auth_fn,
|
||||||
|
void *auth_data,
|
||||||
|
const char *filename);
|
||||||
|
|
||||||
LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key,
|
LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key,
|
||||||
enum ssh_keytypes_e type,
|
enum ssh_keytypes_e type,
|
||||||
@@ -507,6 +562,12 @@ LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key,
|
|||||||
LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
|
LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
|
||||||
const char *filename);
|
const char *filename);
|
||||||
|
|
||||||
|
LIBSSH_API const char *ssh_pki_key_ecdsa_name(const ssh_key key);
|
||||||
|
|
||||||
|
LIBSSH_API char *ssh_get_fingerprint_hash(enum ssh_publickey_hash_type type,
|
||||||
|
unsigned char *hash,
|
||||||
|
size_t len);
|
||||||
|
LIBSSH_API void ssh_print_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len);
|
||||||
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
|
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
|
||||||
LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
|
LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
|
||||||
LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
|
LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
|
||||||
@@ -533,7 +594,10 @@ LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socke
|
|||||||
fd_set *readfds, struct timeval *timeout);
|
fd_set *readfds, struct timeval *timeout);
|
||||||
LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
|
LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
|
||||||
LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
|
LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
|
||||||
|
LIBSSH_API int ssh_set_agent_socket(ssh_session session, socket_t fd);
|
||||||
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
|
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
|
||||||
|
LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter,
|
||||||
|
ssh_counter rcounter);
|
||||||
LIBSSH_API void ssh_set_fd_except(ssh_session session);
|
LIBSSH_API void ssh_set_fd_except(ssh_session session);
|
||||||
LIBSSH_API void ssh_set_fd_toread(ssh_session session);
|
LIBSSH_API void ssh_set_fd_toread(ssh_session session);
|
||||||
LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
|
LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
|
||||||
@@ -599,7 +663,13 @@ LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout);
|
|||||||
LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd);
|
LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd);
|
||||||
LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
|
LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
|
||||||
LIBSSH_API void ssh_event_free(ssh_event event);
|
LIBSSH_API void ssh_event_free(ssh_event event);
|
||||||
|
LIBSSH_API const char* ssh_get_clientbanner(ssh_session session);
|
||||||
LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
|
LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
|
||||||
|
LIBSSH_API const char* ssh_get_kex_algo(ssh_session session);
|
||||||
|
LIBSSH_API const char* ssh_get_cipher_in(ssh_session session);
|
||||||
|
LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
|
||||||
|
LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
|
||||||
|
LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
|
||||||
|
|
||||||
#ifndef LIBSSH_LEGACY_0_4
|
#ifndef LIBSSH_LEGACY_0_4
|
||||||
#include "libssh/legacy.h"
|
#include "libssh/legacy.h"
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace ssh {
|
namespace ssh {
|
||||||
|
|
||||||
@@ -361,18 +362,18 @@ public:
|
|||||||
* @see ssh_channel_forward_accept
|
* @see ssh_channel_forward_accept
|
||||||
* @see Session::listenForward
|
* @see Session::listenForward
|
||||||
*/
|
*/
|
||||||
Channel *acceptForward(int timeout_ms);
|
inline Channel *acceptForward(int timeout_ms);
|
||||||
/* acceptForward is implemented later in this file */
|
/* implemented outside the class due Channel references */
|
||||||
|
|
||||||
void_throwable cancelForward(const char *address, int port){
|
void_throwable cancelForward(const char *address, int port){
|
||||||
int err=ssh_forward_cancel(c_session, address, port);
|
int err=ssh_channel_cancel_forward(c_session, address, port);
|
||||||
ssh_throw(err);
|
ssh_throw(err);
|
||||||
return_throwable;
|
return_throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void_throwable listenForward(const char *address, int port,
|
void_throwable listenForward(const char *address, int port,
|
||||||
int &boundport){
|
int &boundport){
|
||||||
int err=ssh_forward_listen(c_session, address, port, &boundport);
|
int err=ssh_channel_listen_forward(c_session, address, port, &boundport);
|
||||||
ssh_throw(err);
|
ssh_throw(err);
|
||||||
return_throwable;
|
return_throwable;
|
||||||
}
|
}
|
||||||
@@ -480,12 +481,30 @@ public:
|
|||||||
ssh_throw(err);
|
ssh_throw(err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
int read(void *dest, size_t count, bool is_stderr=false){
|
int read(void *dest, size_t count, bool is_stderr){
|
||||||
int err;
|
int err;
|
||||||
/* handle int overflow */
|
/* handle int overflow */
|
||||||
if(count > 0x7fffffff)
|
if(count > 0x7fffffff)
|
||||||
count = 0x7fffffff;
|
count = 0x7fffffff;
|
||||||
err=ssh_channel_read(channel,dest,count,is_stderr);
|
err=ssh_channel_read_timeout(channel,dest,count,is_stderr,-1);
|
||||||
|
ssh_throw(err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
int read(void *dest, size_t count, int timeout){
|
||||||
|
int err;
|
||||||
|
/* handle int overflow */
|
||||||
|
if(count > 0x7fffffff)
|
||||||
|
count = 0x7fffffff;
|
||||||
|
err=ssh_channel_read_timeout(channel,dest,count,false,timeout);
|
||||||
|
ssh_throw(err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
int read(void *dest, size_t count, bool is_stderr=false, int timeout=-1){
|
||||||
|
int err;
|
||||||
|
/* handle int overflow */
|
||||||
|
if(count > 0x7fffffff)
|
||||||
|
count = 0x7fffffff;
|
||||||
|
err=ssh_channel_read_timeout(channel,dest,count,is_stderr,timeout);
|
||||||
ssh_throw(err);
|
ssh_throw(err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -581,10 +600,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* This code cannot be put inline due to references to Channel */
|
inline Channel *Session::acceptForward(int timeout_ms){
|
||||||
Channel *Session::acceptForward(int timeout_ms){
|
ssh_channel forward =
|
||||||
ssh_channel forward = ssh_forward_accept(c_session,
|
ssh_channel_accept_forward(c_session, timeout_ms, NULL);
|
||||||
timeout_ms);
|
|
||||||
ssh_throw_null(c_session,forward);
|
ssh_throw_null(c_session,forward);
|
||||||
Channel *newchan = new Channel(*this,forward);
|
Channel *newchan = new Channel(*this,forward);
|
||||||
return newchan;
|
return newchan;
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ struct ssh_channel_request {
|
|||||||
|
|
||||||
/* X11 */
|
/* X11 */
|
||||||
uint8_t x11_single_connection;
|
uint8_t x11_single_connection;
|
||||||
const char *x11_auth_protocol;
|
char *x11_auth_protocol;
|
||||||
const char *x11_auth_cookie;
|
char *x11_auth_cookie;
|
||||||
uint32_t x11_screen_number;
|
uint32_t x11_screen_number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,15 +33,6 @@ int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2);
|
|||||||
int ssh_is_ipaddr_v4(const char *str);
|
int ssh_is_ipaddr_v4(const char *str);
|
||||||
int ssh_is_ipaddr(const char *str);
|
int ssh_is_ipaddr(const char *str);
|
||||||
|
|
||||||
#ifndef HAVE_NTOHLL
|
|
||||||
/* macro for byte ordering */
|
|
||||||
uint64_t ntohll(uint64_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAVE_HTONLL
|
|
||||||
#define htonll(x) ntohll((x))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* list processing */
|
/* list processing */
|
||||||
|
|
||||||
struct ssh_list {
|
struct ssh_list {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef PACKET_H_
|
#ifndef PACKET_H_
|
||||||
#define PACKET_H_
|
#define PACKET_H_
|
||||||
|
|
||||||
|
#include "libssh/wrapper.h"
|
||||||
|
|
||||||
struct ssh_socket_struct;
|
struct ssh_socket_struct;
|
||||||
|
|
||||||
/* this structure should go someday */
|
/* this structure should go someday */
|
||||||
@@ -41,6 +43,12 @@ enum ssh_packet_state_e {
|
|||||||
PACKET_STATE_PROCESSING
|
PACKET_STATE_PROCESSING
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ssh_packet_filter_result_e {
|
||||||
|
SSH_PACKET_UNKNOWN,
|
||||||
|
SSH_PACKET_ALLOWED,
|
||||||
|
SSH_PACKET_DENIED
|
||||||
|
};
|
||||||
|
|
||||||
int packet_send(ssh_session session);
|
int packet_send(ssh_session session);
|
||||||
|
|
||||||
#ifdef WITH_SSH1
|
#ifdef WITH_SSH1
|
||||||
@@ -82,6 +90,6 @@ unsigned char *packet_encrypt(ssh_session session,
|
|||||||
void *packet,
|
void *packet,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,
|
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,
|
||||||
unsigned char *mac);
|
unsigned char *mac, enum ssh_hmac_e type);
|
||||||
|
|
||||||
#endif /* PACKET_H_ */
|
#endif /* PACKET_H_ */
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#ifndef PKI_H_
|
#ifndef PKI_H_
|
||||||
#define PKI_H_
|
#define PKI_H_
|
||||||
|
|
||||||
|
#include "libssh/priv.h"
|
||||||
#ifdef HAVE_OPENSSL_EC_H
|
#ifdef HAVE_OPENSSL_EC_H
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "libssh/crypto.h"
|
#include "libssh/crypto.h"
|
||||||
|
#include "libssh/ed25519.h"
|
||||||
|
|
||||||
#define MAX_PUBKEY_SIZE 0x100000 /* 1M */
|
#define MAX_PUBKEY_SIZE 0x100000 /* 1M */
|
||||||
#define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
|
#define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
|
||||||
@@ -55,11 +57,14 @@ struct ssh_key_struct {
|
|||||||
void *ecdsa;
|
void *ecdsa;
|
||||||
#endif /* HAVE_OPENSSL_EC_H */
|
#endif /* HAVE_OPENSSL_EC_H */
|
||||||
#endif
|
#endif
|
||||||
|
ed25519_pubkey *ed25519_pubkey;
|
||||||
|
ed25519_privkey *ed25519_privkey;
|
||||||
void *cert;
|
void *cert;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ssh_signature_struct {
|
struct ssh_signature_struct {
|
||||||
enum ssh_keytypes_e type;
|
enum ssh_keytypes_e type;
|
||||||
|
const char *type_c;
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
gcry_sexp_t dsa_sig;
|
gcry_sexp_t dsa_sig;
|
||||||
gcry_sexp_t rsa_sig;
|
gcry_sexp_t rsa_sig;
|
||||||
@@ -73,6 +78,7 @@ struct ssh_signature_struct {
|
|||||||
void *ecdsa_sig;
|
void *ecdsa_sig;
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
ed25519_signature *ed25519_sig;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ssh_signature_struct *ssh_signature;
|
typedef struct ssh_signature_struct *ssh_signature;
|
||||||
|
|||||||
@@ -21,25 +21,43 @@
|
|||||||
#ifndef PKI_PRIV_H_
|
#ifndef PKI_PRIV_H_
|
||||||
#define PKI_PRIV_H_
|
#define PKI_PRIV_H_
|
||||||
|
|
||||||
|
#include "libssh/pki.h"
|
||||||
|
|
||||||
|
/* defined in bcrypt_pbkdf.c */
|
||||||
|
int bcrypt_pbkdf(const char *pass,
|
||||||
|
size_t passlen,
|
||||||
|
const uint8_t *salt,
|
||||||
|
size_t saltlen,
|
||||||
|
uint8_t *key,
|
||||||
|
size_t keylen,
|
||||||
|
unsigned int rounds);
|
||||||
|
|
||||||
#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
|
#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
|
||||||
#define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
|
#define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
|
||||||
#define DSA_HEADER_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
|
#define DSA_HEADER_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
|
||||||
#define DSA_HEADER_END "-----END DSA PRIVATE KEY-----"
|
#define DSA_HEADER_END "-----END DSA PRIVATE KEY-----"
|
||||||
#define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
|
#define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
|
||||||
#define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
|
#define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
|
||||||
|
#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
|
||||||
|
#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
|
||||||
|
/* Magic defined in OpenSSH/PROTOCOL.key */
|
||||||
|
#define OPENSSH_AUTH_MAGIC "openssh-key-v1"
|
||||||
|
|
||||||
#define ssh_pki_log(...) \
|
#define ssh_pki_log(...) \
|
||||||
_ssh_pki_log(__FUNCTION__, __VA_ARGS__)
|
_ssh_log(SSH_LOG_FUNCTIONS, __func__, __VA_ARGS__)
|
||||||
void _ssh_pki_log(const char *function,
|
void _ssh_pki_log(const char *function,
|
||||||
const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
|
const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
|
||||||
|
|
||||||
int pki_key_ecdsa_nid_from_name(const char *name);
|
int pki_key_ecdsa_nid_from_name(const char *name);
|
||||||
|
const char *pki_key_ecdsa_nid_to_name(int nid);
|
||||||
|
|
||||||
/* SSH Key Functions */
|
/* SSH Key Functions */
|
||||||
ssh_key pki_key_dup(const ssh_key key, int demote);
|
ssh_key pki_key_dup(const ssh_key key, int demote);
|
||||||
int pki_key_generate_rsa(ssh_key key, int parameter);
|
int pki_key_generate_rsa(ssh_key key, int parameter);
|
||||||
int pki_key_generate_dss(ssh_key key, int parameter);
|
int pki_key_generate_dss(ssh_key key, int parameter);
|
||||||
int pki_key_generate_ecdsa(ssh_key key, int parameter);
|
int pki_key_generate_ecdsa(ssh_key key, int parameter);
|
||||||
|
int pki_key_generate_ed25519(ssh_key key);
|
||||||
|
|
||||||
int pki_key_compare(const ssh_key k1,
|
int pki_key_compare(const ssh_key k1,
|
||||||
const ssh_key k2,
|
const ssh_key k2,
|
||||||
enum ssh_keycmp_e what);
|
enum ssh_keycmp_e what);
|
||||||
@@ -51,6 +69,11 @@ ssh_key pki_private_key_from_base64(const char *b64_key,
|
|||||||
ssh_auth_callback auth_fn,
|
ssh_auth_callback auth_fn,
|
||||||
void *auth_data);
|
void *auth_data);
|
||||||
|
|
||||||
|
ssh_string pki_private_key_to_pem(const ssh_key key,
|
||||||
|
const char *passphrase,
|
||||||
|
ssh_auth_callback auth_fn,
|
||||||
|
void *auth_data);
|
||||||
|
|
||||||
/* SSH Public Key Functions */
|
/* SSH Public Key Functions */
|
||||||
int pki_pubkey_build_dss(ssh_key key,
|
int pki_pubkey_build_dss(ssh_key key,
|
||||||
ssh_string p,
|
ssh_string p,
|
||||||
@@ -85,4 +108,22 @@ ssh_signature pki_do_sign(const ssh_key privkey,
|
|||||||
ssh_signature pki_do_sign_sessionid(const ssh_key key,
|
ssh_signature pki_do_sign_sessionid(const ssh_key key,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
size_t hlen);
|
size_t hlen);
|
||||||
|
int pki_ed25519_sign(const ssh_key privkey, ssh_signature sig,
|
||||||
|
const unsigned char *hash, size_t hlen);
|
||||||
|
int pki_ed25519_verify(const ssh_key pubkey, ssh_signature sig,
|
||||||
|
const unsigned char *hash, size_t hlen);
|
||||||
|
int pki_ed25519_key_cmp(const ssh_key k1,
|
||||||
|
const ssh_key k2,
|
||||||
|
enum ssh_keycmp_e what);
|
||||||
|
int pki_ed25519_key_dup(ssh_key new, const ssh_key key);
|
||||||
|
int pki_ed25519_public_key_to_blob(ssh_buffer buffer, ssh_key key);
|
||||||
|
ssh_string pki_ed25519_sig_to_blob(ssh_signature sig);
|
||||||
|
int pki_ed25519_sig_from_blob(ssh_signature sig, ssh_string sig_blob);
|
||||||
|
|
||||||
|
/* PKI Container OpenSSH */
|
||||||
|
ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
|
||||||
|
const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
|
||||||
|
ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
|
||||||
|
const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
|
||||||
|
|
||||||
#endif /* PKI_PRIV_H_ */
|
#endif /* PKI_PRIV_H_ */
|
||||||
|
|||||||
@@ -43,6 +43,20 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif /* !defined(HAVE_STRTOULL) */
|
#endif /* !defined(HAVE_STRTOULL) */
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRNDUP)
|
||||||
|
char *strndup(const char *s, size_t n);
|
||||||
|
#endif /* ! HAVE_STRNDUP */
|
||||||
|
|
||||||
|
#ifdef HAVE_BYTESWAP_H
|
||||||
|
#include <byteswap.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef bswap_32
|
||||||
|
#define bswap_32(x) \
|
||||||
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
||||||
|
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
/* Imitate define of inttypes.h */
|
/* Imitate define of inttypes.h */
|
||||||
@@ -60,14 +74,21 @@
|
|||||||
|
|
||||||
# ifdef _MSC_VER
|
# ifdef _MSC_VER
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
|
# include <stdarg.h> /* va_copy define check */
|
||||||
|
|
||||||
/* On Microsoft compilers define inline to __inline on all others use inline */
|
/* On Microsoft compilers define inline to __inline on all others use inline */
|
||||||
# undef inline
|
# undef inline
|
||||||
# define inline __inline
|
# define inline __inline
|
||||||
|
|
||||||
|
# ifndef va_copy
|
||||||
|
# define va_copy(dest, src) (dest = src)
|
||||||
|
# endif
|
||||||
|
|
||||||
# define strcasecmp _stricmp
|
# define strcasecmp _stricmp
|
||||||
# define strncasecmp _strnicmp
|
# define strncasecmp _strnicmp
|
||||||
# define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
|
# if ! defined(HAVE_ISBLANK)
|
||||||
|
# define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
|
||||||
|
# endif
|
||||||
|
|
||||||
# define usleep(X) Sleep(((X)+1000)/1000)
|
# define usleep(X) Sleep(((X)+1000)/1000)
|
||||||
|
|
||||||
@@ -107,27 +128,46 @@
|
|||||||
struct timeval;
|
struct timeval;
|
||||||
int gettimeofday(struct timeval *__p, void *__t);
|
int gettimeofday(struct timeval *__p, void *__t);
|
||||||
|
|
||||||
|
#define _XCLOSESOCKET closesocket
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#define PRIdS "zd"
|
#define PRIdS "zd"
|
||||||
|
|
||||||
|
#define _XCLOSESOCKET close
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#include "libssh/libssh.h"
|
#include "libssh/libssh.h"
|
||||||
#include "libssh/callbacks.h"
|
#include "libssh/callbacks.h"
|
||||||
|
|
||||||
/* some constants */
|
/* some constants */
|
||||||
|
#ifndef MAX_PACKAT_LEN
|
||||||
#define MAX_PACKET_LEN 262144
|
#define MAX_PACKET_LEN 262144
|
||||||
#define ERROR_BUFFERLEN 1024
|
|
||||||
#define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
|
|
||||||
#define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
|
|
||||||
#define KBDINT_MAX_PROMPT 256 /* more than openssh's :) */
|
|
||||||
|
|
||||||
#ifndef __FUNCTION__
|
|
||||||
#if defined(__SUNPRO_C)
|
|
||||||
#define __FUNCTION__ __func__
|
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ERROR_BUFFERLEN
|
||||||
|
#define ERROR_BUFFERLEN 1024
|
||||||
|
#endif
|
||||||
|
#ifndef CLIENTBANNER1
|
||||||
|
#define CLIENTBANNER1 "SSH-1.5-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
|
||||||
|
#endif
|
||||||
|
#ifndef CLIENTBANNER2
|
||||||
|
#define CLIENTBANNER2 "SSH-2.0-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
|
||||||
|
#endif
|
||||||
|
#ifndef KBDINT_MAX_PROMPT
|
||||||
|
#define KBDINT_MAX_PROMPT 256 /* more than openssh's :) */
|
||||||
|
#endif
|
||||||
|
#ifndef MAX_BUF_SIZE
|
||||||
|
#define MAX_BUF_SIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_COMPILER__FUNC__
|
||||||
|
# ifdef HAVE_COMPILER__FUNCTION__
|
||||||
|
# define __func__ __FUNCTION__
|
||||||
|
# else
|
||||||
|
# error "Your system must provide a __func__ macro"
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
|
#if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
|
||||||
@@ -164,7 +204,7 @@ void ssh_log_function(int verbosity,
|
|||||||
const char *function,
|
const char *function,
|
||||||
const char *buffer);
|
const char *buffer);
|
||||||
#define SSH_LOG(priority, ...) \
|
#define SSH_LOG(priority, ...) \
|
||||||
_ssh_log(priority, __FUNCTION__, __VA_ARGS__)
|
_ssh_log(priority, __func__, __VA_ARGS__)
|
||||||
|
|
||||||
/* LEGACY */
|
/* LEGACY */
|
||||||
void ssh_log_common(struct ssh_common_struct *common,
|
void ssh_log_common(struct ssh_common_struct *common,
|
||||||
@@ -182,18 +222,18 @@ struct error_struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define ssh_set_error(error, code, ...) \
|
#define ssh_set_error(error, code, ...) \
|
||||||
_ssh_set_error(error, code, __FUNCTION__, __VA_ARGS__)
|
_ssh_set_error(error, code, __func__, __VA_ARGS__)
|
||||||
void _ssh_set_error(void *error,
|
void _ssh_set_error(void *error,
|
||||||
int code,
|
int code,
|
||||||
const char *function,
|
const char *function,
|
||||||
const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
|
const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
|
||||||
|
|
||||||
#define ssh_set_error_oom(error) \
|
#define ssh_set_error_oom(error) \
|
||||||
_ssh_set_error_oom(error, __FUNCTION__)
|
_ssh_set_error_oom(error, __func__)
|
||||||
void _ssh_set_error_oom(void *error, const char *function);
|
void _ssh_set_error_oom(void *error, const char *function);
|
||||||
|
|
||||||
#define ssh_set_error_invalid(error) \
|
#define ssh_set_error_invalid(error) \
|
||||||
_ssh_set_error_invalid(error, __FUNCTION__)
|
_ssh_set_error_invalid(error, __func__)
|
||||||
void _ssh_set_error_invalid(void *error, const char *function);
|
void _ssh_set_error_invalid(void *error, const char *function);
|
||||||
|
|
||||||
|
|
||||||
@@ -223,8 +263,9 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
|
|||||||
/* match.c */
|
/* match.c */
|
||||||
int match_hostname(const char *host, const char *pattern, unsigned int len);
|
int match_hostname(const char *host, const char *pattern, unsigned int len);
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Free memory space */
|
/** Free memory space */
|
||||||
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
|
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
|
||||||
@@ -251,7 +292,7 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
|
|||||||
/** Overwrite the buffer with '\0' */
|
/** Overwrite the buffer with '\0' */
|
||||||
# define BURN_BUFFER(x, size) do { \
|
# define BURN_BUFFER(x, size) do { \
|
||||||
if ((x) != NULL) \
|
if ((x) != NULL) \
|
||||||
memset((x), '\0', (size))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
|
memset((x), '\0', (size)); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#else /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
|
#else /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
|
||||||
/** Overwrite a string with '\0' */
|
/** Overwrite a string with '\0' */
|
||||||
@@ -262,7 +303,7 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
|
|||||||
/** Overwrite the buffer with '\0' */
|
/** Overwrite the buffer with '\0' */
|
||||||
# define BURN_BUFFER(x, size) do { \
|
# define BURN_BUFFER(x, size) do { \
|
||||||
if ((x) != NULL) \
|
if ((x) != NULL) \
|
||||||
memset((x), '\0', (size))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
|
memset((x), '\0', (size)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#endif /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
|
#endif /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
|
||||||
|
|
||||||
@@ -285,5 +326,64 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
|
|||||||
*/
|
*/
|
||||||
#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
|
#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the argument cound of variadic arguments
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_GCC_NARG_MACRO
|
||||||
|
/*
|
||||||
|
* Since MSVC 2010 there is a bug in passing __VA_ARGS__ to subsequent
|
||||||
|
* macros as a single token, which results in:
|
||||||
|
* warning C4003: not enough actual parameters for macro '_VA_ARG_N'
|
||||||
|
* and incorrect behavior. This fixes issue.
|
||||||
|
*/
|
||||||
|
#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
|
||||||
|
|
||||||
|
#define __VA_NARG__(...) \
|
||||||
|
(__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
|
||||||
|
#define __VA_NARG_(...) \
|
||||||
|
VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
|
||||||
|
#define __VA_ARG_N( \
|
||||||
|
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
|
||||||
|
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
|
||||||
|
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
|
||||||
|
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
|
||||||
|
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
|
||||||
|
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
|
||||||
|
_61,_62,_63,N,...) N
|
||||||
|
#define __RSEQ_N() \
|
||||||
|
63, 62, 61, 60, \
|
||||||
|
59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
|
||||||
|
49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
|
||||||
|
39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
|
||||||
|
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
|
||||||
|
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
|
||||||
|
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||||
|
#else
|
||||||
|
/* clang does not support the above construction */
|
||||||
|
#define __VA_NARG__(...) (-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
|
||||||
|
|
||||||
|
#ifndef HAVE_HTONLL
|
||||||
|
# ifdef WORDS_BIGENDIAN
|
||||||
|
# define htonll(x) (x)
|
||||||
|
# else
|
||||||
|
# define htonll(x) \
|
||||||
|
(((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_NTOHLL
|
||||||
|
# ifdef WORDS_BIGENDIAN
|
||||||
|
# define ntohll(x) (x)
|
||||||
|
# else
|
||||||
|
# define ntohll(x) \
|
||||||
|
(((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ssh_agent_state_free(void *data);
|
||||||
|
|
||||||
#endif /* _LIBSSH_PRIV_H */
|
#endif /* _LIBSSH_PRIV_H */
|
||||||
/* vim: set ts=4 sw=4 et cindent: */
|
/* vim: set ts=4 sw=4 et cindent: */
|
||||||
|
|||||||
74
include/libssh/sc25519.h
Normal file
74
include/libssh/sc25519.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/* $OpenBSD: sc25519.h,v 1.3 2013/12/09 11:03:45 markus Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public Domain, Authors: Daniel J. Bernstein, Niels Duif, Tanja Lange,
|
||||||
|
* Peter Schwabe, Bo-Yin Yang.
|
||||||
|
* Copied from supercop-20130419/crypto_sign/ed25519/ref/sc25519.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SC25519_H
|
||||||
|
#define SC25519_H
|
||||||
|
|
||||||
|
#define sc25519 crypto_sign_ed25519_ref_sc25519
|
||||||
|
#define shortsc25519 crypto_sign_ed25519_ref_shortsc25519
|
||||||
|
#define sc25519_from32bytes crypto_sign_ed25519_ref_sc25519_from32bytes
|
||||||
|
#define shortsc25519_from16bytes crypto_sign_ed25519_ref_shortsc25519_from16bytes
|
||||||
|
#define sc25519_from64bytes crypto_sign_ed25519_ref_sc25519_from64bytes
|
||||||
|
#define sc25519_from_shortsc crypto_sign_ed25519_ref_sc25519_from_shortsc
|
||||||
|
#define sc25519_to32bytes crypto_sign_ed25519_ref_sc25519_to32bytes
|
||||||
|
#define sc25519_iszero_vartime crypto_sign_ed25519_ref_sc25519_iszero_vartime
|
||||||
|
#define sc25519_isshort_vartime crypto_sign_ed25519_ref_sc25519_isshort_vartime
|
||||||
|
#define sc25519_lt_vartime crypto_sign_ed25519_ref_sc25519_lt_vartime
|
||||||
|
#define sc25519_add crypto_sign_ed25519_ref_sc25519_add
|
||||||
|
#define sc25519_sub_nored crypto_sign_ed25519_ref_sc25519_sub_nored
|
||||||
|
#define sc25519_mul crypto_sign_ed25519_ref_sc25519_mul
|
||||||
|
#define sc25519_mul_shortsc crypto_sign_ed25519_ref_sc25519_mul_shortsc
|
||||||
|
#define sc25519_window3 crypto_sign_ed25519_ref_sc25519_window3
|
||||||
|
#define sc25519_window5 crypto_sign_ed25519_ref_sc25519_window5
|
||||||
|
#define sc25519_2interleave2 crypto_sign_ed25519_ref_sc25519_2interleave2
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t v[32];
|
||||||
|
} sc25519;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t v[16];
|
||||||
|
} shortsc25519;
|
||||||
|
|
||||||
|
void sc25519_from32bytes(sc25519 *r, const unsigned char x[32]);
|
||||||
|
|
||||||
|
void shortsc25519_from16bytes(shortsc25519 *r, const unsigned char x[16]);
|
||||||
|
|
||||||
|
void sc25519_from64bytes(sc25519 *r, const unsigned char x[64]);
|
||||||
|
|
||||||
|
void sc25519_from_shortsc(sc25519 *r, const shortsc25519 *x);
|
||||||
|
|
||||||
|
void sc25519_to32bytes(unsigned char r[32], const sc25519 *x);
|
||||||
|
|
||||||
|
int sc25519_iszero_vartime(const sc25519 *x);
|
||||||
|
|
||||||
|
int sc25519_isshort_vartime(const sc25519 *x);
|
||||||
|
|
||||||
|
int sc25519_lt_vartime(const sc25519 *x, const sc25519 *y);
|
||||||
|
|
||||||
|
void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y);
|
||||||
|
|
||||||
|
void sc25519_sub_nored(sc25519 *r, const sc25519 *x, const sc25519 *y);
|
||||||
|
|
||||||
|
void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y);
|
||||||
|
|
||||||
|
void sc25519_mul_shortsc(sc25519 *r, const sc25519 *x, const shortsc25519 *y);
|
||||||
|
|
||||||
|
/* Convert s into a representation of the form \sum_{i=0}^{84}r[i]2^3
|
||||||
|
* with r[i] in {-4,...,3}
|
||||||
|
*/
|
||||||
|
void sc25519_window3(signed char r[85], const sc25519 *s);
|
||||||
|
|
||||||
|
/* Convert s into a representation of the form \sum_{i=0}^{50}r[i]2^5
|
||||||
|
* with r[i] in {-16,...,15}
|
||||||
|
*/
|
||||||
|
void sc25519_window5(signed char r[51], const sc25519 *s);
|
||||||
|
|
||||||
|
void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -44,7 +44,8 @@ enum ssh_bind_options_e {
|
|||||||
SSH_BIND_OPTIONS_RSAKEY,
|
SSH_BIND_OPTIONS_RSAKEY,
|
||||||
SSH_BIND_OPTIONS_BANNER,
|
SSH_BIND_OPTIONS_BANNER,
|
||||||
SSH_BIND_OPTIONS_LOG_VERBOSITY,
|
SSH_BIND_OPTIONS_LOG_VERBOSITY,
|
||||||
SSH_BIND_OPTIONS_LOG_VERBOSITY_STR
|
SSH_BIND_OPTIONS_LOG_VERBOSITY_STR,
|
||||||
|
SSH_BIND_OPTIONS_ECDSAKEY
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ssh_bind_struct* ssh_bind;
|
typedef struct ssh_bind_struct* ssh_bind;
|
||||||
@@ -80,69 +81,6 @@ typedef struct ssh_bind_callbacks_struct *ssh_bind_callbacks;
|
|||||||
*/
|
*/
|
||||||
LIBSSH_API ssh_bind ssh_bind_new(void);
|
LIBSSH_API ssh_bind ssh_bind_new(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the options for the current SSH server bind.
|
|
||||||
*
|
|
||||||
* @param sshbind The ssh server bind to configure.
|
|
||||||
*
|
|
||||||
* @param type The option type to set. This could be one of the
|
|
||||||
* following:
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_BINDADDR
|
|
||||||
* The ip address to bind (const char *).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_BINDPORT
|
|
||||||
* The port to bind (unsigned int).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_BINDPORT_STR
|
|
||||||
* The port to bind (const char *).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_HOSTKEY
|
|
||||||
* This specifies the file containing the private host key used
|
|
||||||
* by SSHv1. (const char *).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_DSAKEY
|
|
||||||
* This specifies the file containing the private host dsa key
|
|
||||||
* used by SSHv2. (const char *).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_RSAKEY
|
|
||||||
* This specifies the file containing the private host dsa key
|
|
||||||
* used by SSHv2. (const char *).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_BANNER
|
|
||||||
* That the server banner (version string) for SSH.
|
|
||||||
* (const char *).
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_LOG_VERBOSITY
|
|
||||||
* Set the session logging verbosity (int).\n
|
|
||||||
* \n
|
|
||||||
* The verbosity of the messages. Every log smaller or
|
|
||||||
* equal to verbosity will be shown.
|
|
||||||
* - SSH_LOG_NOLOG: No logging
|
|
||||||
* - SSH_LOG_RARE: Rare conditions or warnings
|
|
||||||
* - SSH_LOG_ENTRY: API-accessible entrypoints
|
|
||||||
* - SSH_LOG_PACKET: Packet id and size
|
|
||||||
* - SSH_LOG_FUNCTIONS: Function entering and leaving
|
|
||||||
*
|
|
||||||
* - SSH_BIND_OPTIONS_LOG_VERBOSITY_STR
|
|
||||||
* Set the session logging verbosity (const char *).\n
|
|
||||||
* \n
|
|
||||||
* The verbosity of the messages. Every log smaller or
|
|
||||||
* equal to verbosity will be shown.
|
|
||||||
* - SSH_LOG_NOLOG: No logging
|
|
||||||
* - SSH_LOG_RARE: Rare conditions or warnings
|
|
||||||
* - SSH_LOG_ENTRY: API-accessible entrypoints
|
|
||||||
* - SSH_LOG_PACKET: Packet id and size
|
|
||||||
* - SSH_LOG_FUNCTIONS: Function entering and leaving
|
|
||||||
* \n
|
|
||||||
* See the corresponding numbers in libssh.h.
|
|
||||||
*
|
|
||||||
* @param value The value to set. This is a generic pointer and the
|
|
||||||
* datatype which is used should be set according to the
|
|
||||||
* type set.
|
|
||||||
*
|
|
||||||
* @returns SSH_OK on success, SSH_ERROR on invalid option or parameter.
|
|
||||||
*/
|
|
||||||
LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind,
|
LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind,
|
||||||
enum ssh_bind_options_e type, const void *value);
|
enum ssh_bind_options_e type, const void *value);
|
||||||
|
|
||||||
@@ -382,6 +320,8 @@ LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel,
|
|||||||
const void *data,
|
const void *data,
|
||||||
uint32_t len);
|
uint32_t len);
|
||||||
|
|
||||||
|
LIBSSH_API int ssh_send_keepalive(ssh_session session);
|
||||||
|
|
||||||
/* deprecated functions */
|
/* deprecated functions */
|
||||||
SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session);
|
SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session);
|
||||||
SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel,
|
SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel,
|
||||||
|
|||||||
@@ -97,9 +97,6 @@ struct ssh_session_struct {
|
|||||||
int openssh;
|
int openssh;
|
||||||
uint32_t send_seq;
|
uint32_t send_seq;
|
||||||
uint32_t recv_seq;
|
uint32_t recv_seq;
|
||||||
/* status flags */
|
|
||||||
int closed;
|
|
||||||
int closed_by_except;
|
|
||||||
|
|
||||||
int connected;
|
int connected;
|
||||||
/* !=0 when the user got a session handle */
|
/* !=0 when the user got a session handle */
|
||||||
@@ -130,6 +127,15 @@ struct ssh_session_struct {
|
|||||||
struct ssh_agent_state_struct *agent_state;
|
struct ssh_agent_state_struct *agent_state;
|
||||||
struct ssh_auth_auto_state_struct *auth_auto_state;
|
struct ssh_auth_auto_state_struct *auth_auto_state;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RFC 4253, 7.1: if the first_kex_packet_follows flag was set in
|
||||||
|
* the received SSH_MSG_KEXINIT, but the guess was wrong, this
|
||||||
|
* field will be set such that the following guessed packet will
|
||||||
|
* be ignored. Once that packet has been received and ignored,
|
||||||
|
* this field is cleared.
|
||||||
|
*/
|
||||||
|
int first_kex_follows_guess_wrong;
|
||||||
|
|
||||||
ssh_buffer in_hashbuf;
|
ssh_buffer in_hashbuf;
|
||||||
ssh_buffer out_hashbuf;
|
ssh_buffer out_hashbuf;
|
||||||
struct ssh_crypto_struct *current_crypto;
|
struct ssh_crypto_struct *current_crypto;
|
||||||
@@ -150,7 +156,7 @@ struct ssh_session_struct {
|
|||||||
ssh_key rsa_key;
|
ssh_key rsa_key;
|
||||||
ssh_key dsa_key;
|
ssh_key dsa_key;
|
||||||
ssh_key ecdsa_key;
|
ssh_key ecdsa_key;
|
||||||
|
ssh_key ed25519_key;
|
||||||
/* The type of host key wanted by client */
|
/* The type of host key wanted by client */
|
||||||
enum ssh_keytypes_e hostkey;
|
enum ssh_keytypes_e hostkey;
|
||||||
} srv;
|
} srv;
|
||||||
@@ -178,6 +184,7 @@ struct ssh_session_struct {
|
|||||||
char *knownhosts;
|
char *knownhosts;
|
||||||
char *wanted_methods[10];
|
char *wanted_methods[10];
|
||||||
char *ProxyCommand;
|
char *ProxyCommand;
|
||||||
|
char *custombanner;
|
||||||
unsigned long timeout; /* seconds */
|
unsigned long timeout; /* seconds */
|
||||||
unsigned long timeout_usec;
|
unsigned long timeout_usec;
|
||||||
unsigned int port;
|
unsigned int port;
|
||||||
@@ -186,7 +193,13 @@ struct ssh_session_struct {
|
|||||||
int ssh2;
|
int ssh2;
|
||||||
int ssh1;
|
int ssh1;
|
||||||
char compressionlevel;
|
char compressionlevel;
|
||||||
|
char *gss_server_identity;
|
||||||
|
char *gss_client_identity;
|
||||||
|
int gss_delegate_creds;
|
||||||
} opts;
|
} opts;
|
||||||
|
/* counters */
|
||||||
|
ssh_counter socket_counter;
|
||||||
|
ssh_counter raw_counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
|
|||||||
@@ -143,10 +143,10 @@ struct sftp_request_queue_struct {
|
|||||||
|
|
||||||
/* SSH_FXP_MESSAGE described into .7 page 26 */
|
/* SSH_FXP_MESSAGE described into .7 page 26 */
|
||||||
struct sftp_status_message_struct {
|
struct sftp_status_message_struct {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
ssh_string error;
|
ssh_string error_unused; /* not used anymore */
|
||||||
ssh_string lang;
|
ssh_string lang_unused; /* not used anymore */
|
||||||
char *errormsg;
|
char *errormsg;
|
||||||
char *langmsg;
|
char *langmsg;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ void ssh_socket_set_write_wontblock(ssh_socket s);
|
|||||||
void ssh_socket_set_read_wontblock(ssh_socket s);
|
void ssh_socket_set_read_wontblock(ssh_socket s);
|
||||||
void ssh_socket_set_except(ssh_socket s);
|
void ssh_socket_set_except(ssh_socket s);
|
||||||
int ssh_socket_get_status(ssh_socket s);
|
int ssh_socket_get_status(ssh_socket s);
|
||||||
|
int ssh_socket_get_poll_flags(ssh_socket s);
|
||||||
int ssh_socket_buffered_write_bytes(ssh_socket s);
|
int ssh_socket_buffered_write_bytes(ssh_socket s);
|
||||||
int ssh_socket_data_available(ssh_socket s);
|
int ssh_socket_data_available(ssh_socket s);
|
||||||
int ssh_socket_data_writable(ssh_socket s);
|
int ssh_socket_data_writable(ssh_socket s);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define WRAPPER_H_
|
#define WRAPPER_H_
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "libssh/libssh.h"
|
||||||
#include "libssh/libcrypto.h"
|
#include "libssh/libcrypto.h"
|
||||||
#include "libssh/libgcrypt.h"
|
#include "libssh/libgcrypt.h"
|
||||||
|
|
||||||
@@ -34,6 +35,9 @@ enum ssh_mac_e {
|
|||||||
|
|
||||||
enum ssh_hmac_e {
|
enum ssh_hmac_e {
|
||||||
SSH_HMAC_SHA1 = 1,
|
SSH_HMAC_SHA1 = 1,
|
||||||
|
SSH_HMAC_SHA256,
|
||||||
|
SSH_HMAC_SHA384,
|
||||||
|
SSH_HMAC_SHA512,
|
||||||
SSH_HMAC_MD5
|
SSH_HMAC_MD5
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,17 +46,40 @@ enum ssh_des_e {
|
|||||||
SSH_DES
|
SSH_DES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ssh_hmac_struct {
|
||||||
|
const char* name;
|
||||||
|
enum ssh_hmac_e hmac_type;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
|
typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
|
||||||
MD5CTX md5_init(void);
|
MD5CTX md5_init(void);
|
||||||
void md5_update(MD5CTX c, const void *data, unsigned long len);
|
void md5_update(MD5CTX c, const void *data, unsigned long len);
|
||||||
void md5_final(unsigned char *md,MD5CTX c);
|
void md5_final(unsigned char *md,MD5CTX c);
|
||||||
|
|
||||||
SHACTX sha1_init(void);
|
SHACTX sha1_init(void);
|
||||||
void sha1_update(SHACTX c, const void *data, unsigned long len);
|
void sha1_update(SHACTX c, const void *data, unsigned long len);
|
||||||
void sha1_final(unsigned char *md,SHACTX c);
|
void sha1_final(unsigned char *md,SHACTX c);
|
||||||
void sha1(unsigned char *digest,int len,unsigned char *hash);
|
void sha1(unsigned char *digest,int len,unsigned char *hash);
|
||||||
|
|
||||||
|
SHA256CTX sha256_init(void);
|
||||||
|
void sha256_update(SHA256CTX c, const void *data, unsigned long len);
|
||||||
|
void sha256_final(unsigned char *md,SHA256CTX c);
|
||||||
void sha256(unsigned char *digest, int len, unsigned char *hash);
|
void sha256(unsigned char *digest, int len, unsigned char *hash);
|
||||||
|
|
||||||
|
SHA384CTX sha384_init(void);
|
||||||
|
void sha384_update(SHA384CTX c, const void *data, unsigned long len);
|
||||||
|
void sha384_final(unsigned char *md,SHA384CTX c);
|
||||||
|
void sha384(unsigned char *digest, int len, unsigned char *hash);
|
||||||
|
|
||||||
|
SHA512CTX sha512_init(void);
|
||||||
|
void sha512_update(SHA512CTX c, const void *data, unsigned long len);
|
||||||
|
void sha512_final(unsigned char *md,SHA512CTX c);
|
||||||
|
void sha512(unsigned char *digest, int len, unsigned char *hash);
|
||||||
|
|
||||||
void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen);
|
void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen);
|
||||||
|
EVPCTX evp_init(int nid);
|
||||||
|
void evp_update(EVPCTX ctx, const void *data, unsigned long len);
|
||||||
|
void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen);
|
||||||
|
|
||||||
ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type);
|
ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type);
|
||||||
void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len);
|
void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len);
|
||||||
@@ -61,11 +88,17 @@ void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx);
|
|||||||
HMACCTX hmac_init(const void *key,int len, enum ssh_hmac_e type);
|
HMACCTX hmac_init(const void *key,int len, enum ssh_hmac_e type);
|
||||||
void hmac_update(HMACCTX c, const void *data, unsigned long len);
|
void hmac_update(HMACCTX c, const void *data, unsigned long len);
|
||||||
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
|
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
|
||||||
|
size_t hmac_digest_len(enum ssh_hmac_e type);
|
||||||
|
|
||||||
int crypt_set_algorithms(ssh_session session, enum ssh_des_e des_type);
|
int crypt_set_algorithms(ssh_session session, enum ssh_des_e des_type);
|
||||||
int crypt_set_algorithms_server(ssh_session session);
|
int crypt_set_algorithms_server(ssh_session session);
|
||||||
struct ssh_crypto_struct *crypto_new(void);
|
struct ssh_crypto_struct *crypto_new(void);
|
||||||
void crypto_free(struct ssh_crypto_struct *crypto);
|
void crypto_free(struct ssh_crypto_struct *crypto);
|
||||||
|
|
||||||
|
void ssh_reseed(void);
|
||||||
|
|
||||||
|
void ssh_cipher_clear(struct ssh_cipher_struct *cipher);
|
||||||
|
struct ssh_hmac_struct *ssh_get_hmactab(void);
|
||||||
|
const char *ssh_hmac_type_to_string(enum ssh_hmac_e hmac_type);
|
||||||
|
|
||||||
#endif /* WRAPPER_H_ */
|
#endif /* WRAPPER_H_ */
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ else()
|
|||||||
set(LIBSSH_INCLUDE_DIR @INCLUDE_INSTALL_DIR@)
|
set(LIBSSH_INCLUDE_DIR @INCLUDE_INSTALL_DIR@)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(LIBSSH_LIRBARY @LIB_INSTALL_DIR@/libssh.so)
|
set(LIBSSH_LIBRARY @LIB_INSTALL_DIR@/@LIBSSH_LIBRARY_NAME@)
|
||||||
set(LIBSSH_LIRBARIES @LIB_INSTALL_DIR@/libssh.so)
|
set(LIBSSH_LIBRARIES @LIB_INSTALL_DIR@/@LIBSSH_LIBRARY_NAME@)
|
||||||
|
|
||||||
|
set(LIBSSH_THREADS_LIBRARY @LIB_INSTALL_DIR@/@LIBSSH_THREADS_LIBRARY_NAME@)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Script to build libssh on UNIX.
|
# Script to build libssh on UNIX.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2006-2007 Andreas Schneider <mail@cynapses.org>
|
# Copyright (c) 2006-2007 Andreas Schneider <asn@cryptomilk.org>
|
||||||
#
|
#
|
||||||
|
|
||||||
SOURCE_DIR=".."
|
SOURCE_DIR=".."
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
project(libssh-library C)
|
project(libssh-library C)
|
||||||
|
|
||||||
set(LIBSSH_PUBLIC_INCLUDE_DIRS
|
set(LIBSSH_PUBLIC_INCLUDE_DIRS
|
||||||
${CMAKE_SOURCE_DIR}/include
|
${libssh_SOURCE_DIR}/include
|
||||||
CACHE INTERNAL "libssh public include directories"
|
CACHE INTERNAL "libssh public include directories"
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||||
${CMAKE_BINARY_DIR}
|
${libssh_BINARY_DIR}
|
||||||
${OPENSSL_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBSSH_LINK_LIBRARIES
|
set(LIBSSH_LINK_LIBRARIES
|
||||||
@@ -28,17 +27,17 @@ if (HAVE_LIBSOCKET)
|
|||||||
)
|
)
|
||||||
endif (HAVE_LIBSOCKET)
|
endif (HAVE_LIBSOCKET)
|
||||||
|
|
||||||
if (OPENSSL_LIBRARIES)
|
if (OPENSSL_CRYPTO_LIBRARY)
|
||||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||||
${OPENSSL_INCLUDE_DIRS}
|
${OPENSSL_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBSSH_LINK_LIBRARIES
|
set(LIBSSH_LINK_LIBRARIES
|
||||||
${LIBSSH_LINK_LIBRARIES}
|
${LIBSSH_LINK_LIBRARIES}
|
||||||
${OPENSSL_LIBRARIES}
|
${OPENSSL_CRYPTO_LIBRARY}
|
||||||
)
|
)
|
||||||
endif (OPENSSL_LIBRARIES)
|
endif (OPENSSL_CRYPTO_LIBRARY)
|
||||||
|
|
||||||
if (GCRYPT_LIBRARY)
|
if (GCRYPT_LIBRARY)
|
||||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||||
@@ -55,7 +54,7 @@ endif (GCRYPT_LIBRARY)
|
|||||||
if (WITH_ZLIB)
|
if (WITH_ZLIB)
|
||||||
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||||
${ZLIB_INCLUDE_DIRS}
|
${ZLIB_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBSSH_LINK_LIBRARIES
|
set(LIBSSH_LINK_LIBRARIES
|
||||||
@@ -76,6 +75,18 @@ if (WITH_GSSAPI AND GSSAPI_FOUND)
|
|||||||
)
|
)
|
||||||
endif (WITH_GSSAPI AND GSSAPI_FOUND)
|
endif (WITH_GSSAPI AND GSSAPI_FOUND)
|
||||||
|
|
||||||
|
if (WITH_NACL AND NACL_FOUND)
|
||||||
|
set(LIBSSH_PRIVATE_INCLUDE_DIRS
|
||||||
|
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||||
|
${NACL_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBSSH_LINK_LIBRARIES
|
||||||
|
${LIBSSH_LINK_LIBRARIES}
|
||||||
|
${NACL_LIBRARY}
|
||||||
|
)
|
||||||
|
endif (WITH_NACL AND NACL_FOUND)
|
||||||
|
|
||||||
set(LIBSSH_LINK_LIBRARIES
|
set(LIBSSH_LINK_LIBRARIES
|
||||||
${LIBSSH_LINK_LIBRARIES}
|
${LIBSSH_LINK_LIBRARIES}
|
||||||
CACHE INTERNAL "libssh link libraries"
|
CACHE INTERNAL "libssh link libraries"
|
||||||
@@ -97,12 +108,14 @@ set(libssh_SRCS
|
|||||||
agent.c
|
agent.c
|
||||||
auth.c
|
auth.c
|
||||||
base64.c
|
base64.c
|
||||||
|
bignum.c
|
||||||
buffer.c
|
buffer.c
|
||||||
callbacks.c
|
callbacks.c
|
||||||
channels.c
|
channels.c
|
||||||
client.c
|
client.c
|
||||||
config.c
|
config.c
|
||||||
connect.c
|
connect.c
|
||||||
|
curve25519.c
|
||||||
dh.c
|
dh.c
|
||||||
ecdh.c
|
ecdh.c
|
||||||
error.c
|
error.c
|
||||||
@@ -111,7 +124,6 @@ set(libssh_SRCS
|
|||||||
kex.c
|
kex.c
|
||||||
known_hosts.c
|
known_hosts.c
|
||||||
legacy.c
|
legacy.c
|
||||||
libcrypto.c
|
|
||||||
log.c
|
log.c
|
||||||
match.c
|
match.c
|
||||||
messages.c
|
messages.c
|
||||||
@@ -122,6 +134,8 @@ set(libssh_SRCS
|
|||||||
packet_crypt.c
|
packet_crypt.c
|
||||||
pcap.c
|
pcap.c
|
||||||
pki.c
|
pki.c
|
||||||
|
pki_container_openssh.c
|
||||||
|
pki_ed25519.c
|
||||||
poll.c
|
poll.c
|
||||||
session.c
|
session.c
|
||||||
scp.c
|
scp.c
|
||||||
@@ -129,6 +143,12 @@ set(libssh_SRCS
|
|||||||
string.c
|
string.c
|
||||||
threads.c
|
threads.c
|
||||||
wrapper.c
|
wrapper.c
|
||||||
|
external/bcrypt_pbkdf.c
|
||||||
|
external/blowfish.c
|
||||||
|
external/ed25519.c
|
||||||
|
external/fe25519.c
|
||||||
|
external/ge25519.c
|
||||||
|
external/sc25519.c
|
||||||
)
|
)
|
||||||
|
|
||||||
if (WITH_GCRYPT)
|
if (WITH_GCRYPT)
|
||||||
@@ -142,7 +162,11 @@ else (WITH_GCRYPT)
|
|||||||
set(libssh_SRCS
|
set(libssh_SRCS
|
||||||
${libssh_SRCS}
|
${libssh_SRCS}
|
||||||
pki_crypto.c
|
pki_crypto.c
|
||||||
|
libcrypto.c
|
||||||
)
|
)
|
||||||
|
if(OPENSSL_VERSION VERSION_LESS "1.1.0")
|
||||||
|
set(libssh_SRCS ${libssh_SRCS} libcrypto-compat.c)
|
||||||
|
endif()
|
||||||
endif (WITH_GCRYPT)
|
endif (WITH_GCRYPT)
|
||||||
|
|
||||||
if (WITH_SFTP)
|
if (WITH_SFTP)
|
||||||
@@ -192,6 +216,13 @@ if (WITH_GSSAPI AND GSSAPI_FOUND)
|
|||||||
)
|
)
|
||||||
endif (WITH_GSSAPI AND GSSAPI_FOUND)
|
endif (WITH_GSSAPI AND GSSAPI_FOUND)
|
||||||
|
|
||||||
|
if (NOT WITH_NACL)
|
||||||
|
set(libssh_SRCS
|
||||||
|
${libssh_SRCS}
|
||||||
|
external/curve25519_ref.c
|
||||||
|
)
|
||||||
|
endif (NOT WITH_NACL)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${LIBSSH_PUBLIC_INCLUDE_DIRS}
|
${LIBSSH_PUBLIC_INCLUDE_DIRS}
|
||||||
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
${LIBSSH_PRIVATE_INCLUDE_DIRS}
|
||||||
@@ -218,6 +249,10 @@ if (WITH_VISIBILITY_HIDDEN)
|
|||||||
set_target_properties(${LIBSSH_SHARED_LIBRARY} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
set_target_properties(${LIBSSH_SHARED_LIBRARY} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
|
||||||
endif (WITH_VISIBILITY_HIDDEN)
|
endif (WITH_VISIBILITY_HIDDEN)
|
||||||
|
|
||||||
|
if (MINGW)
|
||||||
|
set_target_properties(${LIBSSH_SHARED_LIBRARY} PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS
|
TARGETS
|
||||||
@@ -268,6 +303,7 @@ if (WITH_STATIC_LIB)
|
|||||||
)
|
)
|
||||||
endif (WITH_STATIC_LIB)
|
endif (WITH_STATIC_LIB)
|
||||||
|
|
||||||
if (CMAKE_HAVE_THREADS_LIBRARY)
|
message(STATUS "Threads_FOUND=${Threads_FOUND}")
|
||||||
|
if (Threads_FOUND)
|
||||||
add_subdirectory(threads)
|
add_subdirectory(threads)
|
||||||
endif (CMAKE_HAVE_THREADS_LIBRARY)
|
endif (Threads_FOUND)
|
||||||
|
|||||||
48
src/agent.c
48
src/agent.c
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2009 by Andreas Schneider <asn@cryptomilk.org>
|
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@@ -185,15 +185,32 @@ int ssh_set_agent_channel(ssh_session session, ssh_channel channel){
|
|||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief sets the SSH agent socket.
|
||||||
|
* The SSH agent will be used to authenticate this client using
|
||||||
|
* the given socket to communicate with the ssh-agent. The caller
|
||||||
|
* is responsible for connecting to the socket prior to calling
|
||||||
|
* this function.
|
||||||
|
* @returns SSH_OK in case of success
|
||||||
|
* SSH_ERROR in case of an error
|
||||||
|
*/
|
||||||
|
int ssh_set_agent_socket(ssh_session session, socket_t fd){
|
||||||
|
if (!session)
|
||||||
|
return SSH_ERROR;
|
||||||
|
if (!session->agent){
|
||||||
|
ssh_set_error(session, SSH_REQUEST_DENIED, "Session has no active agent");
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_socket_set_fd(session->agent->sock, fd);
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
void agent_close(struct ssh_agent_struct *agent) {
|
void agent_close(struct ssh_agent_struct *agent) {
|
||||||
if (agent == NULL) {
|
if (agent == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv("SSH_AUTH_SOCK")) {
|
ssh_socket_close(agent->sock);
|
||||||
ssh_socket_close(agent->sock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void agent_free(ssh_agent agent) {
|
void agent_free(ssh_agent agent) {
|
||||||
@@ -300,7 +317,7 @@ static int agent_talk(struct ssh_session_struct *session,
|
|||||||
"Error reading response from authentication socket.");
|
"Error reading response from authentication socket.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (buffer_add_data(reply, payload, n) < 0) {
|
if (ssh_buffer_add_data(reply, payload, n) < 0) {
|
||||||
SSH_LOG(SSH_LOG_WARN, "Not enough space");
|
SSH_LOG(SSH_LOG_WARN, "Not enough space");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -365,6 +382,9 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
|
|||||||
ssh_buffer_free(reply);
|
ssh_buffer_free(reply);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
type = bswap_32(type);
|
||||||
|
#endif
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_WARN,
|
SSH_LOG(SSH_LOG_WARN,
|
||||||
"Answer type: %d, expected answer: %d",
|
"Answer type: %d, expected answer: %d",
|
||||||
@@ -375,7 +395,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (type != c2) {
|
} else if (type != c2) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Bad authentication reply message type: %d", type);
|
"Bad authentication reply message type: %u", type);
|
||||||
ssh_buffer_free(reply);
|
ssh_buffer_free(reply);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -393,7 +413,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->agent->ident) {
|
if (session->agent->ident) {
|
||||||
buffer_reinit(session->agent->ident);
|
ssh_buffer_reinit(session->agent->ident);
|
||||||
}
|
}
|
||||||
session->agent->ident = reply;
|
session->agent->ident = reply;
|
||||||
|
|
||||||
@@ -490,8 +510,8 @@ ssh_string ssh_agent_sign_data(ssh_session session,
|
|||||||
ssh_buffer reply;
|
ssh_buffer reply;
|
||||||
ssh_string key_blob;
|
ssh_string key_blob;
|
||||||
ssh_string sig_blob;
|
ssh_string sig_blob;
|
||||||
int type = SSH2_AGENT_FAILURE;
|
unsigned int type = 0;
|
||||||
int flags = 0;
|
unsigned int flags = 0;
|
||||||
uint32_t dlen;
|
uint32_t dlen;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -526,7 +546,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
|
|||||||
ssh_buffer_free(request);
|
ssh_buffer_free(request);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (buffer_add_data(request, buffer_get_rest(data), dlen) < 0) {
|
if (ssh_buffer_add_data(request, buffer_get_rest(data), dlen) < 0) {
|
||||||
ssh_buffer_free(request);
|
ssh_buffer_free(request);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -555,13 +575,19 @@ ssh_string ssh_agent_sign_data(ssh_session session,
|
|||||||
ssh_buffer_free(reply);
|
ssh_buffer_free(reply);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
type = bswap_32(type);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (agent_failed(type)) {
|
if (agent_failed(type)) {
|
||||||
SSH_LOG(SSH_LOG_WARN, "Agent reports failure in signing the key");
|
SSH_LOG(SSH_LOG_WARN, "Agent reports failure in signing the key");
|
||||||
ssh_buffer_free(reply);
|
ssh_buffer_free(reply);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (type != SSH2_AGENT_SIGN_RESPONSE) {
|
} else if (type != SSH2_AGENT_SIGN_RESPONSE) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Bad authentication response: %d", type);
|
ssh_set_error(session,
|
||||||
|
SSH_FATAL,
|
||||||
|
"Bad authentication response: %u",
|
||||||
|
type);
|
||||||
ssh_buffer_free(reply);
|
ssh_buffer_free(reply);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
671
src/auth.c
Normal file → Executable file
671
src/auth.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
15
src/auth1.c
15
src/auth1.c
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ static int send_username(ssh_session session, const char *username) {
|
|||||||
if (packet_send(session) == SSH_ERROR) {
|
if (packet_send(session) == SSH_ERROR) {
|
||||||
return SSH_AUTH_ERROR;
|
return SSH_AUTH_ERROR;
|
||||||
}
|
}
|
||||||
|
return SSH_AUTH_AGAIN;
|
||||||
pending:
|
pending:
|
||||||
rc = wait_auth1_status(session);
|
rc = wait_auth1_status(session);
|
||||||
switch (rc){
|
switch (rc){
|
||||||
@@ -161,12 +163,14 @@ int ssh_userauth1_password(ssh_session session, const char *username,
|
|||||||
ssh_string pwd = NULL;
|
ssh_string pwd = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
if (session->pending_call_state == SSH_PENDING_CALL_AUTH_PASSWORD) {
|
||||||
|
goto pending;
|
||||||
|
}
|
||||||
|
|
||||||
rc = send_username(session, username);
|
rc = send_username(session, username);
|
||||||
if (rc != SSH_AUTH_DENIED) {
|
if (rc != SSH_AUTH_DENIED) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
if (session->pending_call_state == SSH_PENDING_CALL_AUTH_PASSWORD)
|
|
||||||
goto pending;
|
|
||||||
/* we trick a bit here. A known flaw in SSH1 protocol is that it's
|
/* we trick a bit here. A known flaw in SSH1 protocol is that it's
|
||||||
* easy to guess password sizes.
|
* easy to guess password sizes.
|
||||||
* not that sure ...
|
* not that sure ...
|
||||||
@@ -219,8 +223,11 @@ int ssh_userauth1_password(ssh_session session, const char *username,
|
|||||||
}
|
}
|
||||||
pending:
|
pending:
|
||||||
rc = wait_auth1_status(session);
|
rc = wait_auth1_status(session);
|
||||||
if (rc != SSH_AUTH_AGAIN)
|
if (rc == SSH_AUTH_ERROR && errno == EAGAIN) {
|
||||||
session->pending_call_state = SSH_PENDING_CALL_NONE;
|
/* Nothing to do */
|
||||||
|
} else if (rc != SSH_AUTH_AGAIN) {
|
||||||
|
session->pending_call_state = SSH_PENDING_CALL_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/base64.c
13
src/base64.c
@@ -82,13 +82,18 @@ ssh_buffer base64_to_bin(const char *source) {
|
|||||||
SAFE_FREE(base64);
|
SAFE_FREE(base64);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* The base64 buffer often contains sensitive data. Make sure we don't leak
|
||||||
|
* sensitive data
|
||||||
|
*/
|
||||||
|
ssh_buffer_set_secure(buffer);
|
||||||
|
|
||||||
len = strlen(ptr);
|
len = strlen(ptr);
|
||||||
while (len > 4) {
|
while (len > 4) {
|
||||||
if (_base64_to_bin(block, ptr, 3) < 0) {
|
if (_base64_to_bin(block, ptr, 3) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (buffer_add_data(buffer, block, 3) < 0) {
|
if (ssh_buffer_add_data(buffer, block, 3) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
len -= 4;
|
len -= 4;
|
||||||
@@ -112,7 +117,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
|||||||
if (_base64_to_bin(block, ptr, 3) < 0) {
|
if (_base64_to_bin(block, ptr, 3) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (buffer_add_data(buffer, block, 3) < 0) {
|
if (ssh_buffer_add_data(buffer, block, 3) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
SAFE_FREE(base64);
|
SAFE_FREE(base64);
|
||||||
@@ -131,7 +136,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
|||||||
if (_base64_to_bin(block, ptr, 1) < 0) {
|
if (_base64_to_bin(block, ptr, 1) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (buffer_add_data(buffer, block, 1) < 0) {
|
if (ssh_buffer_add_data(buffer, block, 1) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
SAFE_FREE(base64);
|
SAFE_FREE(base64);
|
||||||
@@ -149,7 +154,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
|||||||
if (_base64_to_bin(block, ptr, 2) < 0) {
|
if (_base64_to_bin(block, ptr, 2) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (buffer_add_data(buffer,block,2) < 0) {
|
if (ssh_buffer_add_data(buffer,block,2) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
SAFE_FREE(base64);
|
SAFE_FREE(base64);
|
||||||
|
|||||||
111
src/bignum.c
Normal file
111
src/bignum.c
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the SSH Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 by Aris Adamantiadis <aris@badcode.be>
|
||||||
|
*
|
||||||
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* The SSH Library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with the SSH Library; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||||
|
* MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "libssh/priv.h"
|
||||||
|
#include "libssh/bignum.h"
|
||||||
|
#include "libssh/string.h"
|
||||||
|
|
||||||
|
ssh_string make_bignum_string(bignum num) {
|
||||||
|
ssh_string ptr = NULL;
|
||||||
|
int pad = 0;
|
||||||
|
unsigned int len = bignum_num_bytes(num);
|
||||||
|
unsigned int bits = bignum_num_bits(num);
|
||||||
|
|
||||||
|
if (len == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the first bit is set we have a negative number */
|
||||||
|
if (!(bits % 8) && bignum_is_bit_set(num, bits - 1)) {
|
||||||
|
pad++;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_CRYPTO
|
||||||
|
fprintf(stderr, "%d bits, %d bytes, %d padding\n", bits, len, pad);
|
||||||
|
#endif /* DEBUG_CRYPTO */
|
||||||
|
|
||||||
|
ptr = ssh_string_new(len + pad);
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We have a negative number so we need a leading zero */
|
||||||
|
if (pad) {
|
||||||
|
ptr->data[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
bignum_bn2bin(num, len, ptr->data + pad);
|
||||||
|
#elif HAVE_LIBCRYPTO
|
||||||
|
bignum_bn2bin(num, ptr->data + pad);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bignum make_string_bn(ssh_string string){
|
||||||
|
bignum bn = NULL;
|
||||||
|
unsigned int len = ssh_string_len(string);
|
||||||
|
|
||||||
|
#ifdef DEBUG_CRYPTO
|
||||||
|
fprintf(stderr, "Importing a %d bits, %d bytes object ...\n",
|
||||||
|
len * 8, len);
|
||||||
|
#endif /* DEBUG_CRYPTO */
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
bignum_bin2bn(string->data, len, &bn);
|
||||||
|
#elif defined HAVE_LIBCRYPTO
|
||||||
|
bn = bignum_bin2bn(string->data, len, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return bn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void make_string_bn_inplace(ssh_string string, bignum bnout) {
|
||||||
|
unsigned int len = ssh_string_len(string);
|
||||||
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
/* XXX: FIXME as needed for LIBGCRYPT ECDSA codepaths. */
|
||||||
|
(void) len;
|
||||||
|
(void) bnout;
|
||||||
|
#elif defined HAVE_LIBCRYPTO
|
||||||
|
bignum_bin2bn(string->data, len, bnout);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prints the bignum on stderr */
|
||||||
|
void ssh_print_bignum(const char *which, bignum num) {
|
||||||
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
unsigned char *hex = NULL;
|
||||||
|
bignum_bn2hex(num, &hex);
|
||||||
|
#elif defined HAVE_LIBCRYPTO
|
||||||
|
char *hex = NULL;
|
||||||
|
hex = bignum_bn2hex(num);
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, "%s value: ", which);
|
||||||
|
fprintf(stderr, "%s\n", (hex == NULL) ? "(null)" : (char *) hex);
|
||||||
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
SAFE_FREE(hex);
|
||||||
|
#elif defined HAVE_LIBCRYPTO
|
||||||
|
OPENSSL_free(hex);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
109
src/bind.c
109
src/bind.c
@@ -109,7 +109,7 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname,
|
|||||||
"Setting socket options failed: %s",
|
"Setting socket options failed: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
freeaddrinfo (ai);
|
freeaddrinfo (ai);
|
||||||
close(s);
|
CLOSE_SOCKET(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname,
|
|||||||
port,
|
port,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
freeaddrinfo (ai);
|
freeaddrinfo (ai);
|
||||||
close(s);
|
CLOSE_SOCKET(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,26 +144,19 @@ ssh_bind ssh_bind_new(void) {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_bind_listen(ssh_bind sshbind) {
|
static int ssh_bind_import_keys(ssh_bind sshbind) {
|
||||||
const char *host;
|
|
||||||
socket_t fd;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (ssh_init() < 0) {
|
|
||||||
ssh_set_error(sshbind, SSH_FATAL, "ssh_init() failed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sshbind->ecdsakey == NULL &&
|
if (sshbind->ecdsakey == NULL &&
|
||||||
sshbind->dsakey == NULL &&
|
sshbind->dsakey == NULL &&
|
||||||
sshbind->rsakey == NULL) {
|
sshbind->rsakey == NULL) {
|
||||||
ssh_set_error(sshbind, SSH_FATAL,
|
ssh_set_error(sshbind, SSH_FATAL,
|
||||||
"DSA or RSA host key file must be set before listen()");
|
"ECDSA, DSA, or RSA host key file must be set");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
if (sshbind->ecdsakey) {
|
if (sshbind->ecdsa == NULL && sshbind->ecdsakey != NULL) {
|
||||||
rc = ssh_pki_import_privkey_file(sshbind->ecdsakey,
|
rc = ssh_pki_import_privkey_file(sshbind->ecdsakey,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -179,12 +172,13 @@ int ssh_bind_listen(ssh_bind sshbind) {
|
|||||||
ssh_set_error(sshbind, SSH_FATAL,
|
ssh_set_error(sshbind, SSH_FATAL,
|
||||||
"The ECDSA host key has the wrong type");
|
"The ECDSA host key has the wrong type");
|
||||||
ssh_key_free(sshbind->ecdsa);
|
ssh_key_free(sshbind->ecdsa);
|
||||||
|
sshbind->ecdsa = NULL;
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sshbind->dsakey) {
|
if (sshbind->dsa == NULL && sshbind->dsakey != NULL) {
|
||||||
rc = ssh_pki_import_privkey_file(sshbind->dsakey,
|
rc = ssh_pki_import_privkey_file(sshbind->dsakey,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -201,11 +195,12 @@ int ssh_bind_listen(ssh_bind sshbind) {
|
|||||||
"The DSA host key has the wrong type: %d",
|
"The DSA host key has the wrong type: %d",
|
||||||
ssh_key_type(sshbind->dsa));
|
ssh_key_type(sshbind->dsa));
|
||||||
ssh_key_free(sshbind->dsa);
|
ssh_key_free(sshbind->dsa);
|
||||||
|
sshbind->dsa = NULL;
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sshbind->rsakey) {
|
if (sshbind->rsa == NULL && sshbind->rsakey != NULL) {
|
||||||
rc = ssh_pki_import_privkey_file(sshbind->rsakey,
|
rc = ssh_pki_import_privkey_file(sshbind->rsakey,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -222,10 +217,29 @@ int ssh_bind_listen(ssh_bind sshbind) {
|
|||||||
ssh_set_error(sshbind, SSH_FATAL,
|
ssh_set_error(sshbind, SSH_FATAL,
|
||||||
"The RSA host key has the wrong type");
|
"The RSA host key has the wrong type");
|
||||||
ssh_key_free(sshbind->rsa);
|
ssh_key_free(sshbind->rsa);
|
||||||
|
sshbind->rsa = NULL;
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ssh_bind_listen(ssh_bind sshbind) {
|
||||||
|
const char *host;
|
||||||
|
socket_t fd;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (ssh_init() < 0) {
|
||||||
|
ssh_set_error(sshbind, SSH_FATAL, "ssh_init() failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ssh_bind_import_keys(sshbind);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (sshbind->bindfd == SSH_INVALID_SOCKET) {
|
if (sshbind->bindfd == SSH_INVALID_SOCKET) {
|
||||||
host = sshbind->bindaddr;
|
host = sshbind->bindaddr;
|
||||||
if (host == NULL) {
|
if (host == NULL) {
|
||||||
@@ -235,20 +249,25 @@ int ssh_bind_listen(ssh_bind sshbind) {
|
|||||||
fd = bind_socket(sshbind, host, sshbind->bindport);
|
fd = bind_socket(sshbind, host, sshbind->bindport);
|
||||||
if (fd == SSH_INVALID_SOCKET) {
|
if (fd == SSH_INVALID_SOCKET) {
|
||||||
ssh_key_free(sshbind->dsa);
|
ssh_key_free(sshbind->dsa);
|
||||||
|
sshbind->dsa = NULL;
|
||||||
ssh_key_free(sshbind->rsa);
|
ssh_key_free(sshbind->rsa);
|
||||||
|
sshbind->rsa = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sshbind->bindfd = fd;
|
|
||||||
|
|
||||||
if (listen(fd, 10) < 0) {
|
if (listen(fd, 10) < 0) {
|
||||||
ssh_set_error(sshbind, SSH_FATAL,
|
ssh_set_error(sshbind, SSH_FATAL,
|
||||||
"Listening to socket %d: %s",
|
"Listening to socket %d: %s",
|
||||||
fd, strerror(errno));
|
fd, strerror(errno));
|
||||||
close(fd);
|
CLOSE_SOCKET(fd);
|
||||||
ssh_key_free(sshbind->dsa);
|
ssh_key_free(sshbind->dsa);
|
||||||
|
sshbind->dsa = NULL;
|
||||||
ssh_key_free(sshbind->rsa);
|
ssh_key_free(sshbind->rsa);
|
||||||
|
sshbind->rsa = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sshbind->bindfd = fd;
|
||||||
} else {
|
} else {
|
||||||
SSH_LOG(SSH_LOG_INFO, "Using app-provided bind socket");
|
SSH_LOG(SSH_LOG_INFO, "Using app-provided bind socket");
|
||||||
}
|
}
|
||||||
@@ -331,21 +350,27 @@ void ssh_bind_free(ssh_bind sshbind){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sshbind->bindfd >= 0) {
|
if (sshbind->bindfd >= 0) {
|
||||||
#ifdef _WIN32
|
CLOSE_SOCKET(sshbind->bindfd);
|
||||||
closesocket(sshbind->bindfd);
|
|
||||||
#else
|
|
||||||
close(sshbind->bindfd);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
sshbind->bindfd = SSH_INVALID_SOCKET;
|
sshbind->bindfd = SSH_INVALID_SOCKET;
|
||||||
|
|
||||||
/* options */
|
/* options */
|
||||||
SAFE_FREE(sshbind->banner);
|
SAFE_FREE(sshbind->banner);
|
||||||
|
SAFE_FREE(sshbind->bindaddr);
|
||||||
|
|
||||||
SAFE_FREE(sshbind->dsakey);
|
SAFE_FREE(sshbind->dsakey);
|
||||||
SAFE_FREE(sshbind->rsakey);
|
SAFE_FREE(sshbind->rsakey);
|
||||||
SAFE_FREE(sshbind->dsa);
|
SAFE_FREE(sshbind->ecdsakey);
|
||||||
SAFE_FREE(sshbind->rsa);
|
SAFE_FREE(sshbind->ed25519key);
|
||||||
SAFE_FREE(sshbind->bindaddr);
|
|
||||||
|
ssh_key_free(sshbind->dsa);
|
||||||
|
sshbind->dsa = NULL;
|
||||||
|
ssh_key_free(sshbind->rsa);
|
||||||
|
sshbind->rsa = NULL;
|
||||||
|
ssh_key_free(sshbind->ecdsa);
|
||||||
|
sshbind->ecdsa = NULL;
|
||||||
|
ssh_key_free(sshbind->ed25519);
|
||||||
|
sshbind->ed25519 = NULL;
|
||||||
|
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
if (sshbind->wanted_methods[i]) {
|
if (sshbind->wanted_methods[i]) {
|
||||||
@@ -357,7 +382,7 @@ void ssh_bind_free(ssh_bind sshbind){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
|
int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
|
||||||
int i;
|
int i, rc;
|
||||||
|
|
||||||
if (session == NULL){
|
if (session == NULL){
|
||||||
ssh_set_error(sshbind, SSH_FATAL,"session is null");
|
ssh_set_error(sshbind, SSH_FATAL,"session is null");
|
||||||
@@ -368,7 +393,7 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
|
|||||||
session->version = 2;
|
session->version = 2;
|
||||||
|
|
||||||
/* copy options */
|
/* copy options */
|
||||||
for (i = 0; i < 10; ++i) {
|
for (i = 0; i < 10; i++) {
|
||||||
if (sshbind->wanted_methods[i]) {
|
if (sshbind->wanted_methods[i]) {
|
||||||
session->opts.wanted_methods[i] = strdup(sshbind->wanted_methods[i]);
|
session->opts.wanted_methods[i] = strdup(sshbind->wanted_methods[i]);
|
||||||
if (session->opts.wanted_methods[i] == NULL) {
|
if (session->opts.wanted_methods[i] == NULL) {
|
||||||
@@ -388,7 +413,8 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
|
|||||||
}
|
}
|
||||||
|
|
||||||
session->common.log_verbosity = sshbind->common.log_verbosity;
|
session->common.log_verbosity = sshbind->common.log_verbosity;
|
||||||
|
if(sshbind->banner != NULL)
|
||||||
|
session->opts.custombanner = strdup(sshbind->banner);
|
||||||
ssh_socket_free(session->socket);
|
ssh_socket_free(session->socket);
|
||||||
session->socket = ssh_socket_new(session);
|
session->socket = ssh_socket_new(session);
|
||||||
if (session->socket == NULL) {
|
if (session->socket == NULL) {
|
||||||
@@ -399,6 +425,16 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
|
|||||||
ssh_socket_set_fd(session->socket, fd);
|
ssh_socket_set_fd(session->socket, fd);
|
||||||
ssh_socket_get_poll_handle_out(session->socket);
|
ssh_socket_get_poll_handle_out(session->socket);
|
||||||
|
|
||||||
|
/* We must try to import any keys that could be imported in case
|
||||||
|
* we are not using ssh_bind_listen (which is the other place
|
||||||
|
* where keys can be imported) on this ssh_bind and are instead
|
||||||
|
* only using ssh_bind_accept_fd to manage sockets ourselves.
|
||||||
|
*/
|
||||||
|
rc = ssh_bind_import_keys(sshbind);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
if (sshbind->ecdsa) {
|
if (sshbind->ecdsa) {
|
||||||
session->srv.ecdsa_key = ssh_key_dup(sshbind->ecdsa);
|
session->srv.ecdsa_key = ssh_key_dup(sshbind->ecdsa);
|
||||||
@@ -422,6 +458,16 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
|
|||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sshbind->ed25519 != NULL) {
|
||||||
|
session->srv.ed25519_key = ssh_key_dup(sshbind->ed25519);
|
||||||
|
if (session->srv.ed25519_key == NULL){
|
||||||
|
ssh_set_error_oom(sshbind);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* force PRNG to change state in case we fork after ssh_bind_accept */
|
||||||
|
ssh_reseed();
|
||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,13 +495,8 @@ int ssh_bind_accept(ssh_bind sshbind, ssh_session session) {
|
|||||||
rc = ssh_bind_accept_fd(sshbind, session, fd);
|
rc = ssh_bind_accept_fd(sshbind, session, fd);
|
||||||
|
|
||||||
if(rc == SSH_ERROR){
|
if(rc == SSH_ERROR){
|
||||||
#ifdef _WIN32
|
CLOSE_SOCKET(fd);
|
||||||
closesocket(fd);
|
ssh_socket_free(session->socket);
|
||||||
#else
|
|
||||||
close(fd);
|
|
||||||
#endif
|
|
||||||
if (session->socket)
|
|
||||||
ssh_socket_close(session->socket);
|
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
545
src/buffer.c
545
src/buffer.c
@@ -24,6 +24,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -32,6 +33,8 @@
|
|||||||
|
|
||||||
#include "libssh/priv.h"
|
#include "libssh/priv.h"
|
||||||
#include "libssh/buffer.h"
|
#include "libssh/buffer.h"
|
||||||
|
#include "libssh/misc.h"
|
||||||
|
#include "libssh/bignum.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup libssh_buffer The SSH buffer functions.
|
* @defgroup libssh_buffer The SSH buffer functions.
|
||||||
@@ -104,13 +107,25 @@ void ssh_buffer_free(struct ssh_buffer_struct *buffer) {
|
|||||||
|
|
||||||
if (buffer->data) {
|
if (buffer->data) {
|
||||||
/* burn the data */
|
/* burn the data */
|
||||||
memset(buffer->data, 0, buffer->allocated);
|
BURN_BUFFER(buffer->data, buffer->allocated);
|
||||||
SAFE_FREE(buffer->data);
|
SAFE_FREE(buffer->data);
|
||||||
}
|
}
|
||||||
memset(buffer, 'X', sizeof(*buffer));
|
BURN_BUFFER(buffer, sizeof(struct ssh_buffer_struct));
|
||||||
SAFE_FREE(buffer);
|
SAFE_FREE(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the buffer as secure.
|
||||||
|
*
|
||||||
|
* A secure buffer will never leave cleartext data in the heap
|
||||||
|
* after being reallocated or freed.
|
||||||
|
*
|
||||||
|
* @param[in] buffer buffer to set secure.
|
||||||
|
*/
|
||||||
|
void ssh_buffer_set_secure(ssh_buffer buffer){
|
||||||
|
buffer->secure = 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
|
static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
|
||||||
size_t smallest = 1;
|
size_t smallest = 1;
|
||||||
char *new;
|
char *new;
|
||||||
@@ -125,9 +140,20 @@ static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
|
|||||||
smallest <<= 1;
|
smallest <<= 1;
|
||||||
}
|
}
|
||||||
needed = smallest;
|
needed = smallest;
|
||||||
new = realloc(buffer->data, needed);
|
if (buffer->secure){
|
||||||
if (new == NULL) {
|
new = malloc(needed);
|
||||||
return -1;
|
if (new == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(new, buffer->data,buffer->used);
|
||||||
|
BURN_BUFFER(buffer->data, buffer->used);
|
||||||
|
SAFE_FREE(buffer->data);
|
||||||
|
} else {
|
||||||
|
new = realloc(buffer->data, needed);
|
||||||
|
if (new == NULL) {
|
||||||
|
buffer->data = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buffer->data = new;
|
buffer->data = new;
|
||||||
buffer->allocated = needed;
|
buffer->allocated = needed;
|
||||||
@@ -140,12 +166,20 @@ static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
|
|||||||
* @param buffer SSH buffer
|
* @param buffer SSH buffer
|
||||||
*/
|
*/
|
||||||
static void buffer_shift(ssh_buffer buffer){
|
static void buffer_shift(ssh_buffer buffer){
|
||||||
|
uint32_t burn_pos = buffer->pos;
|
||||||
|
|
||||||
buffer_verify(buffer);
|
buffer_verify(buffer);
|
||||||
if(buffer->pos==0)
|
if(buffer->pos==0)
|
||||||
return;
|
return;
|
||||||
memmove(buffer->data, buffer->data + buffer->pos, buffer->used - buffer->pos);
|
memmove(buffer->data, buffer->data + buffer->pos, buffer->used - buffer->pos);
|
||||||
buffer->used -= buffer->pos;
|
buffer->used -= buffer->pos;
|
||||||
buffer->pos=0;
|
buffer->pos=0;
|
||||||
|
|
||||||
|
if (buffer->secure){
|
||||||
|
void *ptr = buffer->data + buffer->used;
|
||||||
|
BURN_BUFFER(ptr, burn_pos);
|
||||||
|
}
|
||||||
|
|
||||||
buffer_verify(buffer);
|
buffer_verify(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,9 +192,10 @@ static void buffer_shift(ssh_buffer buffer){
|
|||||||
*
|
*
|
||||||
* @return 0 on success, < 0 on error.
|
* @return 0 on success, < 0 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_reinit(struct ssh_buffer_struct *buffer) {
|
int ssh_buffer_reinit(struct ssh_buffer_struct *buffer)
|
||||||
|
{
|
||||||
buffer_verify(buffer);
|
buffer_verify(buffer);
|
||||||
memset(buffer->data, 0, buffer->used);
|
BURN_BUFFER(buffer->data, buffer->used);
|
||||||
buffer->used = 0;
|
buffer->used = 0;
|
||||||
buffer->pos = 0;
|
buffer->pos = 0;
|
||||||
if(buffer->allocated > 127) {
|
if(buffer->allocated > 127) {
|
||||||
@@ -185,9 +220,14 @@ int buffer_reinit(struct ssh_buffer_struct *buffer) {
|
|||||||
*
|
*
|
||||||
* @return 0 on success, < 0 on error.
|
* @return 0 on success, < 0 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len) {
|
int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len)
|
||||||
|
{
|
||||||
buffer_verify(buffer);
|
buffer_verify(buffer);
|
||||||
|
|
||||||
|
if (data == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (buffer->used + len < len) {
|
if (buffer->used + len < len) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -221,8 +261,12 @@ int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
|
|||||||
struct ssh_string_struct *string) {
|
struct ssh_string_struct *string) {
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
|
|
||||||
|
if (string == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
len = ssh_string_len(string);
|
len = ssh_string_len(string);
|
||||||
if (buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) {
|
if (ssh_buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,12 +284,16 @@ int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
|
|||||||
*
|
*
|
||||||
* @return 0 on success, -1 on error.
|
* @return 0 on success, -1 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data){
|
int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
|
||||||
if (buffer_add_data(buffer, &data, sizeof(data)) < 0) {
|
{
|
||||||
return -1;
|
int rc;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
rc = ssh_buffer_add_data(buffer, &data, sizeof(data));
|
||||||
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,12 +307,16 @@ int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data){
|
|||||||
*
|
*
|
||||||
* @return 0 on success, -1 on error.
|
* @return 0 on success, -1 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data){
|
int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
|
||||||
if (buffer_add_data(buffer, &data, sizeof(data)) < 0) {
|
{
|
||||||
return -1;
|
int rc;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
rc = ssh_buffer_add_data(buffer, &data, sizeof(data));
|
||||||
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,12 +330,16 @@ int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data){
|
|||||||
*
|
*
|
||||||
* @return 0 on success, -1 on error.
|
* @return 0 on success, -1 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data){
|
int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
|
||||||
if (buffer_add_data(buffer, &data, sizeof(data)) < 0) {
|
{
|
||||||
return -1;
|
int rc;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
rc = ssh_buffer_add_data(buffer, &data, sizeof(data));
|
||||||
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,12 +353,16 @@ int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data){
|
|||||||
*
|
*
|
||||||
* @return 0 on success, -1 on error.
|
* @return 0 on success, -1 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data){
|
int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
|
||||||
if (buffer_add_data(buffer, &data, sizeof(uint8_t)) < 0) {
|
{
|
||||||
return -1;
|
int rc;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
rc = ssh_buffer_add_data(buffer, &data, sizeof(uint8_t));
|
||||||
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,12 +420,18 @@ int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
|
|||||||
* @return 0 on success, -1 on error.
|
* @return 0 on success, -1 on error.
|
||||||
*/
|
*/
|
||||||
int buffer_add_buffer(struct ssh_buffer_struct *buffer,
|
int buffer_add_buffer(struct ssh_buffer_struct *buffer,
|
||||||
struct ssh_buffer_struct *source) {
|
struct ssh_buffer_struct *source)
|
||||||
if (buffer_add_data(buffer, buffer_get_rest(source), buffer_get_rest_len(source)) < 0) {
|
{
|
||||||
return -1;
|
int rc;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
rc = ssh_buffer_add_data(buffer,
|
||||||
|
buffer_get_rest(source),
|
||||||
|
buffer_get_rest_len(source));
|
||||||
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -497,12 +563,15 @@ uint32_t buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
|
|||||||
* @returns 0 if there is not enough data in buffer, len otherwise.
|
* @returns 0 if there is not enough data in buffer, len otherwise.
|
||||||
*/
|
*/
|
||||||
uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
|
uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
|
||||||
|
int rc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for a integer overflow first, then check if not enough data is in
|
* Check for a integer overflow first, then check if not enough data is in
|
||||||
* the buffer.
|
* the buffer.
|
||||||
*/
|
*/
|
||||||
if (buffer->pos + len < len || buffer->pos + len > buffer->used) {
|
rc = ssh_buffer_validate_length(buffer, len);
|
||||||
return 0;
|
if (rc != SSH_OK) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(data,buffer->data+buffer->pos,len);
|
memcpy(data,buffer->data+buffer->pos,len);
|
||||||
buffer->pos+=len;
|
buffer->pos+=len;
|
||||||
@@ -551,6 +620,24 @@ int buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
|
|||||||
return buffer_get_data(buffer,data,sizeof(uint64_t));
|
return buffer_get_data(buffer,data,sizeof(uint64_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Valdiates that the given length can be obtained from the buffer.
|
||||||
|
*
|
||||||
|
* @param[in] buffer The buffer to read from.
|
||||||
|
*
|
||||||
|
* @param[in] len The length to be checked.
|
||||||
|
*
|
||||||
|
* @return SSH_OK if the length is valid, SSH_ERROR otherwise.
|
||||||
|
*/
|
||||||
|
int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len)
|
||||||
|
{
|
||||||
|
if (buffer->pos + len < len || buffer->pos + len > buffer->used) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
@@ -564,13 +651,15 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
|
|||||||
uint32_t stringlen;
|
uint32_t stringlen;
|
||||||
uint32_t hostlen;
|
uint32_t hostlen;
|
||||||
struct ssh_string_struct *str = NULL;
|
struct ssh_string_struct *str = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (buffer_get_u32(buffer, &stringlen) == 0) {
|
if (buffer_get_u32(buffer, &stringlen) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
hostlen = ntohl(stringlen);
|
hostlen = ntohl(stringlen);
|
||||||
/* verify if there is enough space in buffer to get it */
|
/* verify if there is enough space in buffer to get it */
|
||||||
if (buffer->pos + hostlen < hostlen || buffer->pos + hostlen > buffer->used) {
|
rc = ssh_buffer_validate_length(buffer, hostlen);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
return NULL; /* it is indeed */
|
return NULL; /* it is indeed */
|
||||||
}
|
}
|
||||||
str = ssh_string_new(hostlen);
|
str = ssh_string_new(hostlen);
|
||||||
@@ -621,6 +710,388 @@ struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief Add multiple values in a buffer on a single function call
|
||||||
|
* @param[in] buffer The buffer to add to
|
||||||
|
* @param[in] format A format string of arguments.
|
||||||
|
* @param[in] ap A va_list of arguments.
|
||||||
|
* @returns SSH_OK on success
|
||||||
|
* SSH_ERROR on error
|
||||||
|
* @see ssh_buffer_add_format() for format list values.
|
||||||
|
*/
|
||||||
|
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
va_list ap)
|
||||||
|
{
|
||||||
|
int rc = SSH_ERROR;
|
||||||
|
const char *p;
|
||||||
|
union {
|
||||||
|
uint8_t byte;
|
||||||
|
uint16_t word;
|
||||||
|
uint32_t dword;
|
||||||
|
uint64_t qword;
|
||||||
|
ssh_string string;
|
||||||
|
void *data;
|
||||||
|
} o;
|
||||||
|
char *cstring;
|
||||||
|
bignum b;
|
||||||
|
size_t len;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
for (p = format, count = 0; *p != '\0'; p++, count++) {
|
||||||
|
/* Invalid number of arguments passed */
|
||||||
|
if (argc != -1 && count > argc) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(*p) {
|
||||||
|
case 'b':
|
||||||
|
o.byte = (uint8_t)va_arg(ap, unsigned int);
|
||||||
|
rc = buffer_add_u8(buffer, o.byte);
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
o.word = (uint16_t)va_arg(ap, unsigned int);
|
||||||
|
o.word = htons(o.word);
|
||||||
|
rc = buffer_add_u16(buffer, o.word);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
o.dword = va_arg(ap, uint32_t);
|
||||||
|
o.dword = htonl(o.dword);
|
||||||
|
rc = buffer_add_u32(buffer, o.dword);
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
o.qword = va_arg(ap, uint64_t);
|
||||||
|
o.qword = htonll(o.qword);
|
||||||
|
rc = buffer_add_u64(buffer, o.qword);
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
o.string = va_arg(ap, ssh_string);
|
||||||
|
rc = buffer_add_ssh_string(buffer, o.string);
|
||||||
|
o.string = NULL;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
cstring = va_arg(ap, char *);
|
||||||
|
len = strlen(cstring);
|
||||||
|
rc = buffer_add_u32(buffer, htonl(len));
|
||||||
|
if (rc == SSH_OK){
|
||||||
|
rc = ssh_buffer_add_data(buffer, cstring, len);
|
||||||
|
}
|
||||||
|
cstring = NULL;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
len = va_arg(ap, size_t);
|
||||||
|
|
||||||
|
o.data = va_arg(ap, void *);
|
||||||
|
count++; /* increase argument count */
|
||||||
|
|
||||||
|
rc = ssh_buffer_add_data(buffer, o.data, len);
|
||||||
|
o.data = NULL;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
b = va_arg(ap, bignum);
|
||||||
|
o.string = make_bignum_string(b);
|
||||||
|
if(o.string == NULL){
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rc = buffer_add_ssh_string(buffer, o.string);
|
||||||
|
SAFE_FREE(o.string);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
cstring = va_arg(ap, char *);
|
||||||
|
len = strlen(cstring);
|
||||||
|
rc = ssh_buffer_add_data(buffer, cstring, len);
|
||||||
|
cstring = NULL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SSH_LOG(SSH_LOG_WARN, "Invalid buffer format %c", *p);
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
}
|
||||||
|
if (rc != SSH_OK){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != -1 && argc != count) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc != SSH_ERROR){
|
||||||
|
/* Check if our canary is intact, if not somthing really bad happened */
|
||||||
|
uint32_t canary = va_arg(ap, uint32_t);
|
||||||
|
if (canary != SSH_BUFFER_PACK_END) {
|
||||||
|
if (argc == -1){
|
||||||
|
return SSH_ERROR;
|
||||||
|
} else {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief Add multiple values in a buffer on a single function call
|
||||||
|
* @param[in] buffer The buffer to add to
|
||||||
|
* @param[in] format A format string of arguments. This string contains single
|
||||||
|
* letters describing the order and type of arguments:
|
||||||
|
* 'b': uint8_t (pushed in network byte order)
|
||||||
|
* 'w': uint16_t (pushed in network byte order)
|
||||||
|
* 'd': uint32_t (pushed in network byte order)
|
||||||
|
* 'q': uint64_t (pushed in network byte order)
|
||||||
|
* 'S': ssh_string
|
||||||
|
* 's': char * (C string, pushed as SSH string)
|
||||||
|
* 't': char * (C string, pushed as free text)
|
||||||
|
* 'P': size_t, void * (len of data, pointer to data)
|
||||||
|
* only pushes data.
|
||||||
|
* 'B': bignum (pushed as SSH string)
|
||||||
|
* @returns SSH_OK on success
|
||||||
|
* SSH_ERROR on error
|
||||||
|
* @warning when using 'P' with a constant size (e.g. 8), do not
|
||||||
|
* forget to cast to (size_t).
|
||||||
|
*/
|
||||||
|
int _ssh_buffer_pack(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
va_start(ap, argc);
|
||||||
|
rc = ssh_buffer_pack_va(buffer, format, argc, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief Get multiple values from a buffer on a single function call
|
||||||
|
* @param[in] buffer The buffer to get from
|
||||||
|
* @param[in] format A format string of arguments.
|
||||||
|
* @param[in] ap A va_list of arguments.
|
||||||
|
* @returns SSH_OK on success
|
||||||
|
* SSH_ERROR on error
|
||||||
|
* @see ssh_buffer_get_format() for format list values.
|
||||||
|
*/
|
||||||
|
int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
va_list ap)
|
||||||
|
{
|
||||||
|
int rc = SSH_ERROR;
|
||||||
|
const char *p, *last;
|
||||||
|
union {
|
||||||
|
uint8_t *byte;
|
||||||
|
uint16_t *word;
|
||||||
|
uint32_t *dword;
|
||||||
|
uint64_t *qword;
|
||||||
|
ssh_string *string;
|
||||||
|
char **cstring;
|
||||||
|
void **data;
|
||||||
|
} o;
|
||||||
|
size_t len, rlen, max_len;
|
||||||
|
uint32_t u32len;
|
||||||
|
va_list ap_copy;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
max_len = ssh_buffer_get_len(buffer);
|
||||||
|
|
||||||
|
/* copy the argument list in case a rollback is needed */
|
||||||
|
va_copy(ap_copy, ap);
|
||||||
|
|
||||||
|
for (p = format, count = 0; *p != '\0'; p++, count++) {
|
||||||
|
/* Invalid number of arguments passed */
|
||||||
|
if (argc != -1 && count > argc) {
|
||||||
|
va_end(ap_copy);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (*p) {
|
||||||
|
case 'b':
|
||||||
|
o.byte = va_arg(ap, uint8_t *);
|
||||||
|
rlen = buffer_get_u8(buffer, o.byte);
|
||||||
|
rc = rlen==1 ? SSH_OK : SSH_ERROR;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
o.word = va_arg(ap, uint16_t *);
|
||||||
|
rlen = buffer_get_data(buffer, o.word, sizeof(uint16_t));
|
||||||
|
*o.word = ntohs(*o.word);
|
||||||
|
rc = rlen==2 ? SSH_OK : SSH_ERROR;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
o.dword = va_arg(ap, uint32_t *);
|
||||||
|
rlen = buffer_get_u32(buffer, o.dword);
|
||||||
|
*o.dword = ntohl(*o.dword);
|
||||||
|
rc = rlen==4 ? SSH_OK : SSH_ERROR;
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
o.qword = va_arg(ap, uint64_t*);
|
||||||
|
rlen = buffer_get_u64(buffer, o.qword);
|
||||||
|
*o.qword = ntohll(*o.qword);
|
||||||
|
rc = rlen==8 ? SSH_OK : SSH_ERROR;
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
o.string = va_arg(ap, ssh_string *);
|
||||||
|
*o.string = buffer_get_ssh_string(buffer);
|
||||||
|
rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
|
||||||
|
o.string = NULL;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
o.cstring = va_arg(ap, char **);
|
||||||
|
*o.cstring = NULL;
|
||||||
|
rc = buffer_get_u32(buffer, &u32len);
|
||||||
|
if (rc != 4){
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len = ntohl(u32len);
|
||||||
|
if (len > max_len - 1) {
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ssh_buffer_validate_length(buffer, len);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*o.cstring = malloc(len + 1);
|
||||||
|
if (*o.cstring == NULL){
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rlen = buffer_get_data(buffer, *o.cstring, len);
|
||||||
|
if (rlen != len){
|
||||||
|
SAFE_FREE(*o.cstring);
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
(*o.cstring)[len] = '\0';
|
||||||
|
o.cstring = NULL;
|
||||||
|
rc = SSH_OK;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
len = va_arg(ap, size_t);
|
||||||
|
if (len > max_len - 1) {
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ssh_buffer_validate_length(buffer, len);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
o.data = va_arg(ap, void **);
|
||||||
|
count++;
|
||||||
|
|
||||||
|
*o.data = malloc(len);
|
||||||
|
if(*o.data == NULL){
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rlen = buffer_get_data(buffer, *o.data, len);
|
||||||
|
if (rlen != len){
|
||||||
|
SAFE_FREE(*o.data);
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
o.data = NULL;
|
||||||
|
rc = SSH_OK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SSH_LOG(SSH_LOG_WARN, "Invalid buffer format %c", *p);
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
}
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != -1 && argc != count) {
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc != SSH_ERROR){
|
||||||
|
/* Check if our canary is intact, if not somthing really bad happened */
|
||||||
|
uint32_t canary = va_arg(ap, uint32_t);
|
||||||
|
if (canary != SSH_BUFFER_PACK_END){
|
||||||
|
if (argc == -1){
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
} else {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc != SSH_OK){
|
||||||
|
/* Reset the format string and erase everything that was allocated */
|
||||||
|
last = p;
|
||||||
|
for(p=format;p<last;++p){
|
||||||
|
switch(*p){
|
||||||
|
case 'b':
|
||||||
|
case 'w':
|
||||||
|
case 'd':
|
||||||
|
case 'q':
|
||||||
|
(void)va_arg(ap_copy, void *);
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
o.string=va_arg(ap_copy, ssh_string *);
|
||||||
|
SAFE_FREE(*o.string);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
o.cstring=va_arg(ap_copy, char **);
|
||||||
|
SAFE_FREE(*o.cstring);
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
(void)va_arg(ap_copy, size_t);
|
||||||
|
o.data = va_arg(ap_copy, void **);
|
||||||
|
SAFE_FREE(*o.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
(void)va_arg(ap_copy, void *);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(ap_copy);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief Get multiple values from a buffer on a single function call
|
||||||
|
* @param[in] buffer The buffer to get from
|
||||||
|
* @param[in] format A format string of arguments. This string contains single
|
||||||
|
* letters describing the order and type of arguments:
|
||||||
|
* 'b': uint8_t * (pulled in network byte order)
|
||||||
|
* 'w': uint16_t * (pulled in network byte order)
|
||||||
|
* 'd': uint32_t * (pulled in network byte order)
|
||||||
|
* 'q': uint64_t * (pulled in network byte order)
|
||||||
|
* 'S': ssh_string *
|
||||||
|
* 's': char ** (C string, pulled as SSH string)
|
||||||
|
* 'P': size_t, void ** (len of data, pointer to data)
|
||||||
|
* only pulls data.
|
||||||
|
* @returns SSH_OK on success
|
||||||
|
* SSH_ERROR on error
|
||||||
|
* @warning when using 'P' with a constant size (e.g. 8), do not
|
||||||
|
* forget to cast to (size_t).
|
||||||
|
*/
|
||||||
|
int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
|
||||||
|
const char *format,
|
||||||
|
int argc,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
va_start(ap, argc);
|
||||||
|
rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/* vim: set ts=4 sw=4 et cindent: */
|
/* vim: set ts=4 sw=4 et cindent: */
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009 by Andreas Schneider <mail@cynapses.org>
|
* Copyright (c) 2009-2013 by Andreas Schneider <asn@cryptomilk.org>
|
||||||
*
|
*
|
||||||
* The SSH Library is free software; you can redistribute it and/or modify
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
|||||||
1021
src/channels.c
1021
src/channels.c
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@
|
|||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003-2008 by Aris Adamantiadis
|
* Copyright (c) 2003-2008 by Aris Adamantiadis
|
||||||
* Copyright (c) 2009 by Andreas Schneider <mail@cynapses.org>
|
* Copyright (c) 2009 by Andreas Schneider <asn@cryptomilk.org>
|
||||||
*
|
*
|
||||||
* The SSH Library is free software; you can redistribute it and/or modify
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -101,7 +101,8 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
|
|||||||
}
|
}
|
||||||
session = channel->session;
|
session = channel->session;
|
||||||
|
|
||||||
if(channel->request_state != SSH_CHANNEL_REQ_STATE_NONE){
|
if(channel->request_state != SSH_CHANNEL_REQ_STATE_NONE &&
|
||||||
|
channel->request_state != SSH_CHANNEL_REQ_STATE_ACCEPTED){
|
||||||
ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
|
ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
@@ -356,7 +357,7 @@ int channel_write1(ssh_channel channel, const void *data, int len) {
|
|||||||
effectivelen = len > 32000 ? 32000 : len;
|
effectivelen = len > 32000 ? 32000 : len;
|
||||||
|
|
||||||
if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
|
if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
|
||||||
buffer_add_data(session->out_buffer, ptr, effectivelen) < 0) {
|
ssh_buffer_add_data(session->out_buffer, ptr, effectivelen) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,6 +368,9 @@ int channel_write1(ssh_channel channel, const void *data, int len) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ssh_handle_packets(session, SSH_TIMEOUT_NONBLOCKING);
|
ssh_handle_packets(session, SSH_TIMEOUT_NONBLOCKING);
|
||||||
|
if (channel->counter != NULL) {
|
||||||
|
channel->counter->out_bytes += effectivelen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ssh_blocking_flush(session,SSH_TIMEOUT_USER) == SSH_ERROR)
|
if (ssh_blocking_flush(session,SSH_TIMEOUT_USER) == SSH_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
298
src/client.c
298
src/client.c
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003-2008 by Aris Adamantiadis
|
* Copyright (c) 2003-2013 by Aris Adamantiadis
|
||||||
*
|
*
|
||||||
* The SSH Library is free software; you can redistribute it and/or modify
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -60,12 +60,15 @@
|
|||||||
static void socket_callback_connected(int code, int errno_code, void *user){
|
static void socket_callback_connected(int code, int errno_code, void *user){
|
||||||
ssh_session session=(ssh_session)user;
|
ssh_session session=(ssh_session)user;
|
||||||
|
|
||||||
if(session->session_state != SSH_SESSION_STATE_CONNECTING){
|
if (session->session_state != SSH_SESSION_STATE_CONNECTING &&
|
||||||
|
session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED)
|
||||||
|
{
|
||||||
ssh_set_error(session,SSH_FATAL, "Wrong state in socket_callback_connected : %d",
|
ssh_set_error(session,SSH_FATAL, "Wrong state in socket_callback_connected : %d",
|
||||||
session->session_state);
|
session->session_state);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_RARE,"Socket connection callback: %d (%d)",code, errno_code);
|
SSH_LOG(SSH_LOG_RARE,"Socket connection callback: %d (%d)",code, errno_code);
|
||||||
if(code == SSH_SOCKET_CONNECTED_OK)
|
if(code == SSH_SOCKET_CONNECTED_OK)
|
||||||
session->session_state=SSH_SESSION_STATE_SOCKET_CONNECTED;
|
session->session_state=SSH_SESSION_STATE_SOCKET_CONNECTED;
|
||||||
@@ -87,48 +90,74 @@ static void socket_callback_connected(int code, int errno_code, void *user){
|
|||||||
* @param user is a pointer to session
|
* @param user is a pointer to session
|
||||||
* @returns Number of bytes processed, or zero if the banner is not complete.
|
* @returns Number of bytes processed, or zero if the banner is not complete.
|
||||||
*/
|
*/
|
||||||
static int callback_receive_banner(const void *data, size_t len, void *user) {
|
static int callback_receive_banner(const void *data, size_t len, void *user)
|
||||||
char *buffer = (char *)data;
|
{
|
||||||
ssh_session session=(ssh_session) user;
|
char *buffer = (char *)data;
|
||||||
char *str = NULL;
|
ssh_session session=(ssh_session) user;
|
||||||
size_t i;
|
char *str = NULL;
|
||||||
int ret=0;
|
size_t i;
|
||||||
|
int ret=0;
|
||||||
|
|
||||||
if(session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED){
|
if (session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED) {
|
||||||
ssh_set_error(session,SSH_FATAL,"Wrong state in callback_receive_banner : %d",session->session_state);
|
ssh_set_error(session,SSH_FATAL,
|
||||||
|
"Wrong state in callback_receive_banner : %d",
|
||||||
|
session->session_state);
|
||||||
|
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
for(i=0;i<len;++i){
|
for (i = 0; i < len; ++i) {
|
||||||
#ifdef WITH_PCAP
|
#ifdef WITH_PCAP
|
||||||
if(session->pcap_ctx && buffer[i] == '\n'){
|
if (session->pcap_ctx && buffer[i] == '\n') {
|
||||||
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_IN,buffer,i+1,i+1);
|
ssh_pcap_context_write(session->pcap_ctx,
|
||||||
}
|
SSH_PCAP_DIR_IN,
|
||||||
|
buffer,i+1,
|
||||||
|
i+1);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if(buffer[i]=='\r')
|
if (buffer[i] == '\r') {
|
||||||
buffer[i]='\0';
|
buffer[i] = '\0';
|
||||||
if(buffer[i]=='\n'){
|
}
|
||||||
buffer[i]='\0';
|
if (buffer[i] == '\n') {
|
||||||
str=strdup(buffer);
|
int cmp;
|
||||||
/* number of bytes read */
|
|
||||||
ret=i+1;
|
|
||||||
session->serverbanner=str;
|
|
||||||
session->session_state=SSH_SESSION_STATE_BANNER_RECEIVED;
|
|
||||||
SSH_LOG(SSH_LOG_PACKET,"Received banner: %s",str);
|
|
||||||
session->ssh_connection_callback(session);
|
|
||||||
|
|
||||||
return ret;
|
buffer[i] = '\0';
|
||||||
}
|
|
||||||
if(i>127){
|
|
||||||
/* Too big banner */
|
|
||||||
session->session_state=SSH_SESSION_STATE_ERROR;
|
|
||||||
ssh_set_error(session,SSH_FATAL,"Receiving banner: too large banner");
|
|
||||||
|
|
||||||
return 0;
|
/* The server MAY send other lines of data... */
|
||||||
}
|
cmp = strncmp(buffer, "SSH-", 4);
|
||||||
}
|
if (cmp == 0) {
|
||||||
|
str = strdup(buffer);
|
||||||
|
if (str == NULL) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
/* number of bytes read */
|
||||||
|
ret = i + 1;
|
||||||
|
session->serverbanner = str;
|
||||||
|
session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
|
||||||
|
SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
|
||||||
|
session->ssh_connection_callback(session);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
} else {
|
||||||
|
SSH_LOG(SSH_LOG_DEBUG,
|
||||||
|
"ssh_protocol_version_exchange: %s",
|
||||||
|
buffer);
|
||||||
|
ret = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* According to RFC 4253 the max banner length is 255 */
|
||||||
|
if (i > 255) {
|
||||||
|
/* Too big banner */
|
||||||
|
session->session_state=SSH_SESSION_STATE_ERROR;
|
||||||
|
ssh_set_error(session,
|
||||||
|
SSH_FATAL,
|
||||||
|
"Receiving banner: too large banner");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
@@ -140,38 +169,75 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
|
|||||||
*
|
*
|
||||||
* @return 0 on success, < 0 on error.
|
* @return 0 on success, < 0 on error.
|
||||||
*/
|
*/
|
||||||
int ssh_send_banner(ssh_session session, int server) {
|
int ssh_send_banner(ssh_session session, int server)
|
||||||
const char *banner = NULL;
|
{
|
||||||
char buffer[128] = {0};
|
const char *banner = NULL;
|
||||||
int err=SSH_ERROR;
|
const char *terminator = NULL;
|
||||||
|
/* The maximum banner length is 255 for SSH2 */
|
||||||
|
char buffer[256] = {0};
|
||||||
|
size_t len;
|
||||||
|
int rc = SSH_ERROR;
|
||||||
|
|
||||||
banner = session->version == 1 ? CLIENTBANNER1 : CLIENTBANNER2;
|
banner = session->version == 1 ? CLIENTBANNER1 : CLIENTBANNER2;
|
||||||
|
terminator = session->version == 1 ? "\n" : "\r\n";
|
||||||
|
|
||||||
if (server) {
|
if (server == 1) {
|
||||||
session->serverbanner = strdup(banner);
|
if (session->opts.custombanner == NULL){
|
||||||
if (session->serverbanner == NULL) {
|
len = strlen(banner);
|
||||||
goto end;
|
session->serverbanner = strdup(banner);
|
||||||
|
if (session->serverbanner == NULL) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
len = strlen(session->opts.custombanner);
|
||||||
|
session->serverbanner = malloc(len + 8 + 1);
|
||||||
|
if(session->serverbanner == NULL) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
snprintf(session->serverbanner,
|
||||||
|
len + 8 + 1,
|
||||||
|
"SSH-2.0-%s",
|
||||||
|
session->opts.custombanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buffer,
|
||||||
|
sizeof(buffer),
|
||||||
|
"%s%s",
|
||||||
|
session->serverbanner,
|
||||||
|
terminator);
|
||||||
|
} else {
|
||||||
|
session->clientbanner = strdup(banner);
|
||||||
|
if (session->clientbanner == NULL) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SSH version 1 has a banner length of 128 only */
|
||||||
|
len = session->version == 1 ? 128 : 0;
|
||||||
|
|
||||||
|
snprintf(buffer,
|
||||||
|
sizeof(buffer) - len,
|
||||||
|
"%s%s",
|
||||||
|
session->clientbanner,
|
||||||
|
terminator);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
session->clientbanner = strdup(banner);
|
rc = ssh_socket_write(session->socket, buffer, strlen(buffer));
|
||||||
if (session->clientbanner == NULL) {
|
if (rc == SSH_ERROR) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(buffer, 128, "%s\n", banner);
|
|
||||||
|
|
||||||
if (ssh_socket_write(session->socket, buffer, strlen(buffer)) == SSH_ERROR) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
#ifdef WITH_PCAP
|
#ifdef WITH_PCAP
|
||||||
if(session->pcap_ctx)
|
if (session->pcap_ctx != NULL) {
|
||||||
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,buffer,strlen(buffer),strlen(buffer));
|
ssh_pcap_context_write(session->pcap_ctx,
|
||||||
|
SSH_PCAP_DIR_OUT,
|
||||||
|
buffer,
|
||||||
|
strlen(buffer),
|
||||||
|
strlen(buffer));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
err=SSH_OK;
|
|
||||||
end:
|
|
||||||
|
|
||||||
return err;
|
rc = SSH_OK;
|
||||||
|
end:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
@@ -196,6 +262,11 @@ static int dh_handshake(ssh_session session) {
|
|||||||
case SSH_KEX_ECDH_SHA2_NISTP256:
|
case SSH_KEX_ECDH_SHA2_NISTP256:
|
||||||
rc = ssh_client_ecdh_init(session);
|
rc = ssh_client_ecdh_init(session);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_CURVE25519
|
||||||
|
case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
|
||||||
|
rc = ssh_client_curve25519_init(session);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
rc = SSH_ERROR;
|
rc = SSH_ERROR;
|
||||||
@@ -249,24 +320,19 @@ static int ssh_service_request_termination(void *s){
|
|||||||
* @bug actually only works with ssh-userauth
|
* @bug actually only works with ssh-userauth
|
||||||
*/
|
*/
|
||||||
int ssh_service_request(ssh_session session, const char *service) {
|
int ssh_service_request(ssh_session session, const char *service) {
|
||||||
ssh_string service_s = NULL;
|
|
||||||
int rc=SSH_ERROR;
|
int rc=SSH_ERROR;
|
||||||
|
|
||||||
if(session->auth_service_state != SSH_AUTH_SERVICE_NONE)
|
if(session->auth_service_state != SSH_AUTH_SERVICE_NONE)
|
||||||
goto pending;
|
goto pending;
|
||||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_SERVICE_REQUEST) < 0) {
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
service_s = ssh_string_from_char(service);
|
|
||||||
if (service_s == NULL) {
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer,service_s) < 0) {
|
rc = ssh_buffer_pack(session->out_buffer,
|
||||||
ssh_string_free(service_s);
|
"bs",
|
||||||
|
SSH2_MSG_SERVICE_REQUEST,
|
||||||
|
service);
|
||||||
|
if (rc != SSH_OK){
|
||||||
|
ssh_set_error_oom(session);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
ssh_string_free(service_s);
|
|
||||||
session->auth_service_state=SSH_AUTH_SERVICE_SENT;
|
session->auth_service_state=SSH_AUTH_SERVICE_SENT;
|
||||||
if (packet_send(session) == SSH_ERROR) {
|
if (packet_send(session) == SSH_ERROR) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
@@ -320,7 +386,13 @@ static void ssh_client_connection_callback(ssh_session session){
|
|||||||
switch(session->session_state){
|
switch(session->session_state){
|
||||||
case SSH_SESSION_STATE_NONE:
|
case SSH_SESSION_STATE_NONE:
|
||||||
case SSH_SESSION_STATE_CONNECTING:
|
case SSH_SESSION_STATE_CONNECTING:
|
||||||
|
break;
|
||||||
case SSH_SESSION_STATE_SOCKET_CONNECTED:
|
case SSH_SESSION_STATE_SOCKET_CONNECTED:
|
||||||
|
/* If SSHv1 is disabled, we can send the banner immedietly */
|
||||||
|
if (session->opts.ssh1 == 0) {
|
||||||
|
ssh_set_fd_towrite(session);
|
||||||
|
ssh_send_banner(session, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SSH_SESSION_STATE_BANNER_RECEIVED:
|
case SSH_SESSION_STATE_BANNER_RECEIVED:
|
||||||
if (session->serverbanner == NULL) {
|
if (session->serverbanner == NULL) {
|
||||||
@@ -366,7 +438,9 @@ static void ssh_client_connection_callback(ssh_session session){
|
|||||||
#endif
|
#endif
|
||||||
ssh_packet_set_default_callbacks(session);
|
ssh_packet_set_default_callbacks(session);
|
||||||
session->session_state=SSH_SESSION_STATE_INITIAL_KEX;
|
session->session_state=SSH_SESSION_STATE_INITIAL_KEX;
|
||||||
ssh_send_banner(session, 0);
|
if (session->opts.ssh1 == 1) {
|
||||||
|
ssh_send_banner(session, 0);
|
||||||
|
}
|
||||||
set_status(session, 0.5f);
|
set_status(session, 0.5f);
|
||||||
break;
|
break;
|
||||||
case SSH_SESSION_STATE_INITIAL_KEX:
|
case SSH_SESSION_STATE_INITIAL_KEX:
|
||||||
@@ -486,7 +560,12 @@ int ssh_connect(ssh_session session) {
|
|||||||
ssh_set_error(session, SSH_FATAL, "Couldn't apply options");
|
ssh_set_error(session, SSH_FATAL, "Couldn't apply options");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
SSH_LOG(SSH_LOG_RARE,"libssh %s, using threading %s", ssh_copyright(), ssh_threads_get_type());
|
|
||||||
|
SSH_LOG(SSH_LOG_PROTOCOL,
|
||||||
|
"libssh %s, using threading %s",
|
||||||
|
ssh_copyright(),
|
||||||
|
ssh_threads_get_type());
|
||||||
|
|
||||||
session->ssh_connection_callback = ssh_client_connection_callback;
|
session->ssh_connection_callback = ssh_client_connection_callback;
|
||||||
session->session_state=SSH_SESSION_STATE_CONNECTING;
|
session->session_state=SSH_SESSION_STATE_CONNECTING;
|
||||||
ssh_socket_set_callbacks(session->socket,&session->socket_callbacks);
|
ssh_socket_set_callbacks(session->socket,&session->socket_callbacks);
|
||||||
@@ -495,6 +574,7 @@ int ssh_connect(ssh_session session) {
|
|||||||
session->socket_callbacks.exception=ssh_socket_exception_callback;
|
session->socket_callbacks.exception=ssh_socket_exception_callback;
|
||||||
session->socket_callbacks.userdata=session;
|
session->socket_callbacks.userdata=session;
|
||||||
if (session->opts.fd != SSH_INVALID_SOCKET) {
|
if (session->opts.fd != SSH_INVALID_SOCKET) {
|
||||||
|
session->session_state=SSH_SESSION_STATE_SOCKET_CONNECTED;
|
||||||
ssh_socket_set_fd(session->socket, session->opts.fd);
|
ssh_socket_set_fd(session->socket, session->opts.fd);
|
||||||
ret=SSH_OK;
|
ret=SSH_OK;
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@@ -505,7 +585,7 @@ int ssh_connect(ssh_session session) {
|
|||||||
} else {
|
} else {
|
||||||
ret=ssh_socket_connect(session->socket,
|
ret=ssh_socket_connect(session->socket,
|
||||||
session->opts.host,
|
session->opts.host,
|
||||||
session->opts.port,
|
session->opts.port > 0 ? session->opts.port : 22,
|
||||||
session->opts.bindaddr);
|
session->opts.bindaddr);
|
||||||
}
|
}
|
||||||
if (ret == SSH_ERROR) {
|
if (ret == SSH_ERROR) {
|
||||||
@@ -524,9 +604,10 @@ pending:
|
|||||||
if (timeout == 0) {
|
if (timeout == 0) {
|
||||||
timeout = 10 * 1000;
|
timeout = 10 * 1000;
|
||||||
}
|
}
|
||||||
SSH_LOG(SSH_LOG_PACKET,"ssh_connect: Actual timeout : %d", timeout);
|
SSH_LOG(SSH_LOG_PACKET,"Actual timeout : %d", timeout);
|
||||||
ret = ssh_handle_packets_termination(session, timeout, ssh_connect_termination, session);
|
ret = ssh_handle_packets_termination(session, timeout, ssh_connect_termination, session);
|
||||||
if (ret == SSH_ERROR || !ssh_connect_termination(session)) {
|
if (session->session_state != SSH_SESSION_STATE_ERROR &&
|
||||||
|
(ret == SSH_ERROR || !ssh_connect_termination(session))) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Timeout connecting to %s", session->opts.host);
|
"Timeout connecting to %s", session->opts.host);
|
||||||
session->session_state = SSH_SESSION_STATE_ERROR;
|
session->session_state = SSH_SESSION_STATE_ERROR;
|
||||||
@@ -541,7 +622,7 @@ pending:
|
|||||||
session->session_state = SSH_SESSION_STATE_ERROR;
|
session->session_state = SSH_SESSION_STATE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SSH_LOG(SSH_LOG_PACKET,"ssh_connect: Actual state : %d",session->session_state);
|
SSH_LOG(SSH_LOG_PACKET,"current state : %d",session->session_state);
|
||||||
if(!ssh_is_blocking(session) && !ssh_connect_termination(session)){
|
if(!ssh_is_blocking(session) && !ssh_connect_termination(session)){
|
||||||
return SSH_AGAIN;
|
return SSH_AGAIN;
|
||||||
}
|
}
|
||||||
@@ -579,6 +660,14 @@ char *ssh_get_issue_banner(ssh_session session) {
|
|||||||
* @param[in] session The SSH session to use.
|
* @param[in] session The SSH session to use.
|
||||||
*
|
*
|
||||||
* @return The version number if available, 0 otherwise.
|
* @return The version number if available, 0 otherwise.
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* int openssh = ssh_get_openssh_version();
|
||||||
|
*
|
||||||
|
* if (openssh == SSH_INT_VERSION(6, 1, 0)) {
|
||||||
|
* printf("Version match!\m");
|
||||||
|
* }
|
||||||
|
* @endcode
|
||||||
*/
|
*/
|
||||||
int ssh_get_openssh_version(ssh_session session) {
|
int ssh_get_openssh_version(ssh_session session) {
|
||||||
if (session == NULL) {
|
if (session == NULL) {
|
||||||
@@ -595,32 +684,23 @@ int ssh_get_openssh_version(ssh_session session) {
|
|||||||
* @param[in] session The SSH session to use.
|
* @param[in] session The SSH session to use.
|
||||||
*/
|
*/
|
||||||
void ssh_disconnect(ssh_session session) {
|
void ssh_disconnect(ssh_session session) {
|
||||||
ssh_string str = NULL;
|
|
||||||
struct ssh_iterator *it;
|
struct ssh_iterator *it;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (session == NULL) {
|
if (session == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
|
if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
|
||||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_DISCONNECT) < 0) {
|
rc = ssh_buffer_pack(session->out_buffer,
|
||||||
|
"bds",
|
||||||
|
SSH2_MSG_DISCONNECT,
|
||||||
|
SSH2_DISCONNECT_BY_APPLICATION,
|
||||||
|
"Bye Bye");
|
||||||
|
if (rc != SSH_OK){
|
||||||
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (buffer_add_u32(session->out_buffer,
|
|
||||||
htonl(SSH2_DISCONNECT_BY_APPLICATION)) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = ssh_string_from_char("Bye Bye");
|
|
||||||
if (str == NULL) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer,str) < 0) {
|
|
||||||
ssh_string_free(str);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
ssh_string_free(str);
|
|
||||||
|
|
||||||
packet_send(session);
|
packet_send(session);
|
||||||
ssh_socket_close(session->socket);
|
ssh_socket_close(session->socket);
|
||||||
@@ -634,21 +714,25 @@ error:
|
|||||||
session->session_state=SSH_SESSION_STATE_DISCONNECTED;
|
session->session_state=SSH_SESSION_STATE_DISCONNECTED;
|
||||||
|
|
||||||
while ((it=ssh_list_get_iterator(session->channels)) != NULL) {
|
while ((it=ssh_list_get_iterator(session->channels)) != NULL) {
|
||||||
ssh_channel_free(ssh_iterator_value(ssh_channel,it));
|
ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
|
||||||
ssh_list_remove(session->channels, it);
|
ssh_list_remove(session->channels, it);
|
||||||
}
|
}
|
||||||
if(session->current_crypto){
|
if(session->current_crypto){
|
||||||
crypto_free(session->current_crypto);
|
crypto_free(session->current_crypto);
|
||||||
session->current_crypto=NULL;
|
session->current_crypto=NULL;
|
||||||
}
|
}
|
||||||
if(session->in_buffer)
|
if (session->in_buffer) {
|
||||||
buffer_reinit(session->in_buffer);
|
ssh_buffer_reinit(session->in_buffer);
|
||||||
if(session->out_buffer)
|
}
|
||||||
buffer_reinit(session->out_buffer);
|
if (session->out_buffer) {
|
||||||
if(session->in_hashbuf)
|
ssh_buffer_reinit(session->out_buffer);
|
||||||
buffer_reinit(session->in_hashbuf);
|
}
|
||||||
if(session->out_hashbuf)
|
if (session->in_hashbuf) {
|
||||||
buffer_reinit(session->out_hashbuf);
|
ssh_buffer_reinit(session->in_hashbuf);
|
||||||
|
}
|
||||||
|
if (session->out_hashbuf) {
|
||||||
|
ssh_buffer_reinit(session->out_hashbuf);
|
||||||
|
}
|
||||||
session->auth_methods = 0;
|
session->auth_methods = 0;
|
||||||
SAFE_FREE(session->serverbanner);
|
SAFE_FREE(session->serverbanner);
|
||||||
SAFE_FREE(session->clientbanner);
|
SAFE_FREE(session->clientbanner);
|
||||||
@@ -670,8 +754,8 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *ssh_copyright(void) {
|
const char *ssh_copyright(void) {
|
||||||
return SSH_STRINGIFY(LIBSSH_VERSION) " (c) 2003-2010 Aris Adamantiadis "
|
return SSH_STRINGIFY(LIBSSH_VERSION) " (c) 2003-2014 Aris Adamantiadis, Andreas Schneider, "
|
||||||
"(aris@0xbadc0de.be) Distributed under the LGPL, please refer to COPYING "
|
"and libssh contributors. Distributed under the LGPL, please refer to COPYING "
|
||||||
"file for information about your rights";
|
"file for information about your rights";
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
83
src/config.c
83
src/config.c
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009 by Andreas Schneider <mail@cynapses.org>
|
* Copyright (c) 2009-2013 by Andreas Schneider <asn@cryptomilk.org>
|
||||||
*
|
*
|
||||||
* The SSH Library is free software; you can redistribute it and/or modify
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -46,7 +46,12 @@ enum ssh_config_opcode_e {
|
|||||||
SOC_PROTOCOL,
|
SOC_PROTOCOL,
|
||||||
SOC_STRICTHOSTKEYCHECK,
|
SOC_STRICTHOSTKEYCHECK,
|
||||||
SOC_KNOWNHOSTS,
|
SOC_KNOWNHOSTS,
|
||||||
SOC_PROXYCOMMAND
|
SOC_PROXYCOMMAND,
|
||||||
|
SOC_GSSAPISERVERIDENTITY,
|
||||||
|
SOC_GSSAPICLIENTIDENTITY,
|
||||||
|
SOC_GSSAPIDELEGATECREDENTIALS,
|
||||||
|
|
||||||
|
SOC_END /* Keep this one last in the list */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ssh_config_keyword_table_s {
|
struct ssh_config_keyword_table_s {
|
||||||
@@ -67,6 +72,9 @@ static struct ssh_config_keyword_table_s ssh_config_keyword_table[] = {
|
|||||||
{ "stricthostkeychecking", SOC_STRICTHOSTKEYCHECK },
|
{ "stricthostkeychecking", SOC_STRICTHOSTKEYCHECK },
|
||||||
{ "userknownhostsfile", SOC_KNOWNHOSTS },
|
{ "userknownhostsfile", SOC_KNOWNHOSTS },
|
||||||
{ "proxycommand", SOC_PROXYCOMMAND },
|
{ "proxycommand", SOC_PROXYCOMMAND },
|
||||||
|
{ "gssapiserveridentity", SOC_GSSAPISERVERIDENTITY },
|
||||||
|
{ "gssapiserveridentity", SOC_GSSAPICLIENTIDENTITY },
|
||||||
|
{ "gssapidelegatecredentials", SOC_GSSAPIDELEGATECREDENTIALS },
|
||||||
{ NULL, SOC_UNSUPPORTED }
|
{ NULL, SOC_UNSUPPORTED }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,7 +130,7 @@ static char *ssh_config_get_token(char **str) {
|
|||||||
c = ssh_config_get_cmd(str);
|
c = ssh_config_get_cmd(str);
|
||||||
|
|
||||||
for (r = c; *c; c++) {
|
for (r = c; *c; c++) {
|
||||||
if (isblank(*c)) {
|
if (isblank(*c) || *c == '=') {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -179,7 +187,7 @@ static int ssh_config_get_yesno(char **str, int notfound) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int ssh_config_parse_line(ssh_session session, const char *line,
|
static int ssh_config_parse_line(ssh_session session, const char *line,
|
||||||
unsigned int count, int *parsing) {
|
unsigned int count, int *parsing, int seen[]) {
|
||||||
enum ssh_config_opcode_e opcode;
|
enum ssh_config_opcode_e opcode;
|
||||||
const char *p;
|
const char *p;
|
||||||
char *s, *x;
|
char *s, *x;
|
||||||
@@ -210,27 +218,47 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
|
|||||||
}
|
}
|
||||||
|
|
||||||
opcode = ssh_config_get_opcode(keyword);
|
opcode = ssh_config_get_opcode(keyword);
|
||||||
|
if (*parsing == 1 && opcode != SOC_HOST) {
|
||||||
|
if (seen[opcode] != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
seen[opcode] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case SOC_HOST:
|
case SOC_HOST: {
|
||||||
*parsing = 0;
|
int ok = 0;
|
||||||
lowerhost = (session->opts.host) ? ssh_lowercase(session->opts.host) : NULL;
|
|
||||||
for (p = ssh_config_get_str_tok(&s, NULL); p && *p;
|
*parsing = 0;
|
||||||
p = ssh_config_get_str_tok(&s, NULL)) {
|
lowerhost = (session->opts.host) ? ssh_lowercase(session->opts.host) : NULL;
|
||||||
if (match_hostname(lowerhost, p, strlen(p))) {
|
for (p = ssh_config_get_str_tok(&s, NULL);
|
||||||
*parsing = 1;
|
p != NULL && p[0] != '\0';
|
||||||
|
p = ssh_config_get_str_tok(&s, NULL)) {
|
||||||
|
if (ok >= 0) {
|
||||||
|
ok = match_hostname(lowerhost, p, strlen(p));
|
||||||
|
if (ok < 0) {
|
||||||
|
*parsing = 0;
|
||||||
|
} else if (ok > 0) {
|
||||||
|
*parsing = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
SAFE_FREE(lowerhost);
|
||||||
SAFE_FREE(lowerhost);
|
break;
|
||||||
break;
|
}
|
||||||
case SOC_HOSTNAME:
|
case SOC_HOSTNAME:
|
||||||
p = ssh_config_get_str_tok(&s, NULL);
|
p = ssh_config_get_str_tok(&s, NULL);
|
||||||
if (p && *parsing) {
|
if (p && *parsing) {
|
||||||
ssh_options_set(session, SSH_OPTIONS_HOST, p);
|
char *z = ssh_path_expand_escape(session, p);
|
||||||
|
if (z == NULL) {
|
||||||
|
z = strdup(p);
|
||||||
|
}
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_HOST, z);
|
||||||
|
free(z);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOC_PORT:
|
case SOC_PORT:
|
||||||
if (session->opts.port == 22) {
|
if (session->opts.port == 0) {
|
||||||
p = ssh_config_get_str_tok(&s, NULL);
|
p = ssh_config_get_str_tok(&s, NULL);
|
||||||
if (p && *parsing) {
|
if (p && *parsing) {
|
||||||
ssh_options_set(session, SSH_OPTIONS_PORT_STR, p);
|
ssh_options_set(session, SSH_OPTIONS_PORT_STR, p);
|
||||||
@@ -323,6 +351,24 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
|
|||||||
ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, p);
|
ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, p);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SOC_GSSAPISERVERIDENTITY:
|
||||||
|
p = ssh_config_get_str_tok(&s, NULL);
|
||||||
|
if (p && *parsing) {
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_GSSAPI_SERVER_IDENTITY, p);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SOC_GSSAPICLIENTIDENTITY:
|
||||||
|
p = ssh_config_get_str_tok(&s, NULL);
|
||||||
|
if (p && *parsing) {
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY, p);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SOC_GSSAPIDELEGATECREDENTIALS:
|
||||||
|
i = ssh_config_get_yesno(&s, -1);
|
||||||
|
if (i >=0 && *parsing) {
|
||||||
|
ssh_options_set(session, SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS, &i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SOC_UNSUPPORTED:
|
case SOC_UNSUPPORTED:
|
||||||
SSH_LOG(SSH_LOG_RARE, "Unsupported option: %s, line: %d\n",
|
SSH_LOG(SSH_LOG_RARE, "Unsupported option: %s, line: %d\n",
|
||||||
keyword, count);
|
keyword, count);
|
||||||
@@ -345,17 +391,18 @@ int ssh_config_parse_file(ssh_session session, const char *filename) {
|
|||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int parsing;
|
int parsing;
|
||||||
|
int seen[SOC_END - SOC_UNSUPPORTED] = {0};
|
||||||
|
|
||||||
if ((f = fopen(filename, "r")) == NULL) {
|
if ((f = fopen(filename, "r")) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_RARE, "Reading configuration data from %s", filename);
|
SSH_LOG(SSH_LOG_PACKET, "Reading configuration data from %s", filename);
|
||||||
|
|
||||||
parsing = 1;
|
parsing = 1;
|
||||||
while (fgets(line, sizeof(line), f)) {
|
while (fgets(line, sizeof(line), f)) {
|
||||||
count++;
|
count++;
|
||||||
if (ssh_config_parse_line(session, line, count, &parsing) < 0) {
|
if (ssh_config_parse_line(session, line, count, &parsing, seen) < 0) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003-2009 by Aris Adamantiadis
|
* Copyright (c) 2003-2013 by Aris Adamantiadis
|
||||||
*
|
*
|
||||||
* The SSH Library is free software; you can redistribute it and/or modify
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -64,6 +64,10 @@
|
|||||||
#include <wspiapi.h>
|
#include <wspiapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef EINPROGRESS
|
||||||
|
#define EINPROGRESS WSAEINPROGRESS
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
@@ -285,6 +289,7 @@ socket_t ssh_connect_host(ssh_session session, const char *host,
|
|||||||
socket_t ret = ssh_connect_ai_timeout(session, host, port, itr,
|
socket_t ret = ssh_connect_ai_timeout(session, host, port, itr,
|
||||||
timeout, usec, s);
|
timeout, usec, s);
|
||||||
|
|
||||||
|
freeaddrinfo(ai);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +387,16 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(s, itr->ai_addr, itr->ai_addrlen);
|
errno = 0;
|
||||||
|
rc = connect(s, itr->ai_addr, itr->ai_addrlen);
|
||||||
|
if (rc == -1 && (errno != 0) && (errno != EINPROGRESS)) {
|
||||||
|
ssh_set_error(session, SSH_FATAL,
|
||||||
|
"Failed to connect: %s", strerror(errno));
|
||||||
|
ssh_connect_socket_close(s);
|
||||||
|
s = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +435,7 @@ static int ssh_select_cb (socket_t fd, int revents, void *userdata){
|
|||||||
* @param[in] readfds A fd_set of file descriptors to be select'ed for
|
* @param[in] readfds A fd_set of file descriptors to be select'ed for
|
||||||
* reading.
|
* reading.
|
||||||
*
|
*
|
||||||
* @param[in] timeout A timeout for the select.
|
* @param[in] timeout The timeout in milliseconds.
|
||||||
*
|
*
|
||||||
* @return SSH_OK on success,
|
* @return SSH_OK on success,
|
||||||
* SSH_ERROR on error,
|
* SSH_ERROR on error,
|
||||||
@@ -436,6 +450,7 @@ static int ssh_select_cb (socket_t fd, int revents, void *userdata){
|
|||||||
*/
|
*/
|
||||||
int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
||||||
fd_set *readfds, struct timeval *timeout) {
|
fd_set *readfds, struct timeval *timeout) {
|
||||||
|
fd_set origfds;
|
||||||
socket_t fd;
|
socket_t fd;
|
||||||
int i,j;
|
int i,j;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -449,9 +464,11 @@ int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
|||||||
ssh_event_add_session(event, channels[i]->session);
|
ssh_event_add_session(event, channels[i]->session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FD_ZERO(&origfds);
|
||||||
for (fd = 0; fd < maxfd ; fd++) {
|
for (fd = 0; fd < maxfd ; fd++) {
|
||||||
if (FD_ISSET(fd, readfds)) {
|
if (FD_ISSET(fd, readfds)) {
|
||||||
ssh_event_add_fd(event, fd, POLLIN, ssh_select_cb, readfds);
|
ssh_event_add_fd(event, fd, POLLIN, ssh_select_cb, readfds);
|
||||||
|
FD_SET(fd, &origfds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outchannels[0] = NULL;
|
outchannels[0] = NULL;
|
||||||
@@ -485,13 +502,17 @@ int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
|||||||
/* since there's nothing, let's fire the polling */
|
/* since there's nothing, let's fire the polling */
|
||||||
rc = ssh_event_dopoll(event,tm);
|
rc = ssh_event_dopoll(event,tm);
|
||||||
if (rc == SSH_ERROR){
|
if (rc == SSH_ERROR){
|
||||||
ssh_event_free(event);
|
goto out;
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
}
|
||||||
tm = ssh_timeout_update(&ts, base_tm);
|
tm = ssh_timeout_update(&ts, base_tm);
|
||||||
firstround=0;
|
firstround=0;
|
||||||
} while (1);
|
} while (1);
|
||||||
out:
|
out:
|
||||||
|
for (fd = 0; fd < maxfd; fd++) {
|
||||||
|
if (FD_ISSET(fd, &origfds)) {
|
||||||
|
ssh_event_remove_fd(event, fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
ssh_event_free(event);
|
ssh_event_free(event);
|
||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
286
src/curve25519.c
Normal file
286
src/curve25519.c
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
/*
|
||||||
|
* curve25519.c - Curve25519 ECDH functions for key exchange
|
||||||
|
* curve25519-sha256@libssh.org
|
||||||
|
*
|
||||||
|
* This file is part of the SSH Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 by Aris Adamantiadis <aris@badcode.be>
|
||||||
|
*
|
||||||
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, version 2.1 of the License.
|
||||||
|
*
|
||||||
|
* The SSH Library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with the SSH Library; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||||
|
* MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "libssh/curve25519.h"
|
||||||
|
#ifdef HAVE_CURVE25519
|
||||||
|
|
||||||
|
#ifdef WITH_NACL
|
||||||
|
#include "nacl/crypto_scalarmult_curve25519.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "libssh/ssh2.h"
|
||||||
|
#include "libssh/buffer.h"
|
||||||
|
#include "libssh/priv.h"
|
||||||
|
#include "libssh/session.h"
|
||||||
|
#include "libssh/crypto.h"
|
||||||
|
#include "libssh/dh.h"
|
||||||
|
#include "libssh/pki.h"
|
||||||
|
#include "libssh/bignum.h"
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief Starts curve25519-sha256@libssh.org key exchange
|
||||||
|
*/
|
||||||
|
int ssh_client_curve25519_init(ssh_session session){
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = ssh_get_random(session->next_crypto->curve25519_privkey, CURVE25519_PRIVKEY_SIZE, 1);
|
||||||
|
if (rc == 0){
|
||||||
|
ssh_set_error(session, SSH_FATAL, "PRNG error");
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto_scalarmult_base(session->next_crypto->curve25519_client_pubkey,
|
||||||
|
session->next_crypto->curve25519_privkey);
|
||||||
|
|
||||||
|
rc = ssh_buffer_pack(session->out_buffer,
|
||||||
|
"bdP",
|
||||||
|
SSH2_MSG_KEX_ECDH_INIT,
|
||||||
|
CURVE25519_PUBKEY_SIZE,
|
||||||
|
(size_t)CURVE25519_PUBKEY_SIZE, session->next_crypto->curve25519_client_pubkey);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = packet_send(session);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ssh_curve25519_build_k(ssh_session session) {
|
||||||
|
ssh_curve25519_pubkey k;
|
||||||
|
session->next_crypto->k = bignum_new();
|
||||||
|
|
||||||
|
if (session->next_crypto->k == NULL) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session->server)
|
||||||
|
crypto_scalarmult(k, session->next_crypto->curve25519_privkey,
|
||||||
|
session->next_crypto->curve25519_client_pubkey);
|
||||||
|
else
|
||||||
|
crypto_scalarmult(k, session->next_crypto->curve25519_privkey,
|
||||||
|
session->next_crypto->curve25519_server_pubkey);
|
||||||
|
|
||||||
|
bignum_bin2bn(k, CURVE25519_PUBKEY_SIZE, session->next_crypto->k);
|
||||||
|
|
||||||
|
#ifdef DEBUG_CRYPTO
|
||||||
|
ssh_print_hexa("Session server cookie",
|
||||||
|
session->next_crypto->server_kex.cookie, 16);
|
||||||
|
ssh_print_hexa("Session client cookie",
|
||||||
|
session->next_crypto->client_kex.cookie, 16);
|
||||||
|
ssh_print_bignum("Shared secret key", session->next_crypto->k);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal
|
||||||
|
* @brief parses a SSH_MSG_KEX_ECDH_REPLY packet and sends back
|
||||||
|
* a SSH_MSG_NEWKEYS
|
||||||
|
*/
|
||||||
|
int ssh_client_curve25519_reply(ssh_session session, ssh_buffer packet){
|
||||||
|
ssh_string q_s_string = NULL;
|
||||||
|
ssh_string pubkey = NULL;
|
||||||
|
ssh_string signature = NULL;
|
||||||
|
int rc;
|
||||||
|
pubkey = buffer_get_ssh_string(packet);
|
||||||
|
if (pubkey == NULL){
|
||||||
|
ssh_set_error(session,SSH_FATAL, "No public key in packet");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
/* this is the server host key */
|
||||||
|
session->next_crypto->server_pubkey = pubkey;
|
||||||
|
pubkey = NULL;
|
||||||
|
|
||||||
|
q_s_string = buffer_get_ssh_string(packet);
|
||||||
|
if (q_s_string == NULL) {
|
||||||
|
ssh_set_error(session,SSH_FATAL, "No Q_S ECC point in packet");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (ssh_string_len(q_s_string) != CURVE25519_PUBKEY_SIZE){
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Incorrect size for server Curve25519 public key: %d",
|
||||||
|
(int)ssh_string_len(q_s_string));
|
||||||
|
ssh_string_free(q_s_string);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
memcpy(session->next_crypto->curve25519_server_pubkey, ssh_string_data(q_s_string), CURVE25519_PUBKEY_SIZE);
|
||||||
|
ssh_string_free(q_s_string);
|
||||||
|
|
||||||
|
signature = buffer_get_ssh_string(packet);
|
||||||
|
if (signature == NULL) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "No signature in packet");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
session->next_crypto->dh_server_signature = signature;
|
||||||
|
signature=NULL; /* ownership changed */
|
||||||
|
/* TODO: verify signature now instead of waiting for NEWKEYS */
|
||||||
|
if (ssh_curve25519_build_k(session) < 0) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Cannot build k number");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send the MSG_NEWKEYS */
|
||||||
|
if (buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc=packet_send(session);
|
||||||
|
SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent");
|
||||||
|
return rc;
|
||||||
|
error:
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_SERVER
|
||||||
|
|
||||||
|
/** @brief Parse a SSH_MSG_KEXDH_INIT packet (server) and send a
|
||||||
|
* SSH_MSG_KEXDH_REPLY
|
||||||
|
*/
|
||||||
|
int ssh_server_curve25519_init(ssh_session session, ssh_buffer packet){
|
||||||
|
/* ECDH keys */
|
||||||
|
ssh_string q_c_string;
|
||||||
|
ssh_string q_s_string;
|
||||||
|
|
||||||
|
/* SSH host keys (rsa,dsa,ecdsa) */
|
||||||
|
ssh_key privkey;
|
||||||
|
ssh_string sig_blob = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Extract the client pubkey from the init packet */
|
||||||
|
q_c_string = buffer_get_ssh_string(packet);
|
||||||
|
if (q_c_string == NULL) {
|
||||||
|
ssh_set_error(session,SSH_FATAL, "No Q_C ECC point in packet");
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
if (ssh_string_len(q_c_string) != CURVE25519_PUBKEY_SIZE){
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Incorrect size for server Curve25519 public key: %d",
|
||||||
|
(int)ssh_string_len(q_c_string));
|
||||||
|
ssh_string_free(q_c_string);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(session->next_crypto->curve25519_client_pubkey,
|
||||||
|
ssh_string_data(q_c_string), CURVE25519_PUBKEY_SIZE);
|
||||||
|
ssh_string_free(q_c_string);
|
||||||
|
/* Build server's keypair */
|
||||||
|
|
||||||
|
rc = ssh_get_random(session->next_crypto->curve25519_privkey, CURVE25519_PRIVKEY_SIZE, 1);
|
||||||
|
if (rc == 0){
|
||||||
|
ssh_set_error(session, SSH_FATAL, "PRNG error");
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto_scalarmult_base(session->next_crypto->curve25519_server_pubkey,
|
||||||
|
session->next_crypto->curve25519_privkey);
|
||||||
|
|
||||||
|
rc = buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_ECDH_REPLY);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build k and session_id */
|
||||||
|
rc = ssh_curve25519_build_k(session);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Cannot build k number");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* privkey is not allocated */
|
||||||
|
rc = ssh_get_key_params(session, &privkey);
|
||||||
|
if (rc == SSH_ERROR) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = make_sessionid(session);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Could not create a session id");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add host's public key */
|
||||||
|
rc = buffer_add_ssh_string(session->out_buffer,
|
||||||
|
session->next_crypto->server_pubkey);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add ecdh public key */
|
||||||
|
q_s_string = ssh_string_new(CURVE25519_PUBKEY_SIZE);
|
||||||
|
if (q_s_string == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_string_fill(q_s_string,
|
||||||
|
session->next_crypto->curve25519_server_pubkey,
|
||||||
|
CURVE25519_PUBKEY_SIZE);
|
||||||
|
|
||||||
|
rc = buffer_add_ssh_string(session->out_buffer, q_s_string);
|
||||||
|
ssh_string_free(q_s_string);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
/* add signature blob */
|
||||||
|
sig_blob = ssh_srv_pki_do_sign_sessionid(session, privkey);
|
||||||
|
if (sig_blob == NULL) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = buffer_add_ssh_string(session->out_buffer, sig_blob);
|
||||||
|
ssh_string_free(sig_blob);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_KEX_ECDH_REPLY sent");
|
||||||
|
rc = packet_send(session);
|
||||||
|
if (rc == SSH_ERROR) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send the MSG_NEWKEYS */
|
||||||
|
rc = buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
|
||||||
|
if (rc < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
|
||||||
|
rc = packet_send(session);
|
||||||
|
SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent");
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
error:
|
||||||
|
ssh_buffer_reinit(session->out_buffer);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WITH_SERVER */
|
||||||
|
|
||||||
|
#endif /* HAVE_CURVE25519 */
|
||||||
89
src/ecdh.c
89
src/ecdh.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the SSH Library
|
* This file is part of the SSH Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011 by Aris Adamantiadis
|
* Copyright (c) 2011-2013 by Aris Adamantiadis
|
||||||
*
|
*
|
||||||
* The SSH Library is free software; you can redistribute it and/or modify
|
* The SSH Library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "libssh/buffer.h"
|
#include "libssh/buffer.h"
|
||||||
#include "libssh/ssh2.h"
|
#include "libssh/ssh2.h"
|
||||||
#include "libssh/pki.h"
|
#include "libssh/pki.h"
|
||||||
|
#include "libssh/bignum.h"
|
||||||
|
|
||||||
#ifdef HAVE_ECDH
|
#ifdef HAVE_ECDH
|
||||||
#include <openssl/ecdh.h>
|
#include <openssl/ecdh.h>
|
||||||
@@ -99,6 +100,7 @@ static int ecdh_build_k(ssh_session session) {
|
|||||||
const EC_GROUP *group = EC_KEY_get0_group(session->next_crypto->ecdh_privkey);
|
const EC_GROUP *group = EC_KEY_get0_group(session->next_crypto->ecdh_privkey);
|
||||||
EC_POINT *pubkey;
|
EC_POINT *pubkey;
|
||||||
void *buffer;
|
void *buffer;
|
||||||
|
int rc;
|
||||||
int len = (EC_GROUP_get_degree(group) + 7) / 8;
|
int len = (EC_GROUP_get_degree(group) + 7) / 8;
|
||||||
bignum_CTX ctx = bignum_ctx_new();
|
bignum_CTX ctx = bignum_ctx_new();
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
@@ -117,19 +119,48 @@ static int ecdh_build_k(ssh_session session) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->server)
|
if (session->server) {
|
||||||
EC_POINT_oct2point(group,pubkey,ssh_string_data(session->next_crypto->ecdh_client_pubkey),
|
rc = EC_POINT_oct2point(group,
|
||||||
ssh_string_len(session->next_crypto->ecdh_client_pubkey),ctx);
|
pubkey,
|
||||||
else
|
ssh_string_data(session->next_crypto->ecdh_client_pubkey),
|
||||||
EC_POINT_oct2point(group,pubkey,ssh_string_data(session->next_crypto->ecdh_server_pubkey),
|
ssh_string_len(session->next_crypto->ecdh_client_pubkey),
|
||||||
ssh_string_len(session->next_crypto->ecdh_server_pubkey),ctx);
|
ctx);
|
||||||
|
} else {
|
||||||
|
rc = EC_POINT_oct2point(group,
|
||||||
|
pubkey,
|
||||||
|
ssh_string_data(session->next_crypto->ecdh_server_pubkey),
|
||||||
|
ssh_string_len(session->next_crypto->ecdh_server_pubkey),
|
||||||
|
ctx);
|
||||||
|
}
|
||||||
|
bignum_ctx_free(ctx);
|
||||||
|
if (rc <= 0) {
|
||||||
|
EC_POINT_clear_free(pubkey);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
buffer = malloc(len);
|
buffer = malloc(len);
|
||||||
ECDH_compute_key(buffer,len,pubkey,session->next_crypto->ecdh_privkey,NULL);
|
if (buffer == NULL) {
|
||||||
EC_POINT_free(pubkey);
|
EC_POINT_clear_free(pubkey);
|
||||||
BN_bin2bn(buffer,len,session->next_crypto->k);
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ECDH_compute_key(buffer,
|
||||||
|
len,
|
||||||
|
pubkey,
|
||||||
|
session->next_crypto->ecdh_privkey,
|
||||||
|
NULL);
|
||||||
|
EC_POINT_clear_free(pubkey);
|
||||||
|
if (rc <= 0) {
|
||||||
|
free(buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bignum_bin2bn(buffer, len, session->next_crypto->k);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
EC_KEY_free(session->next_crypto->ecdh_privkey);
|
EC_KEY_free(session->next_crypto->ecdh_privkey);
|
||||||
session->next_crypto->ecdh_privkey=NULL;
|
session->next_crypto->ecdh_privkey = NULL;
|
||||||
|
|
||||||
#ifdef DEBUG_CRYPTO
|
#ifdef DEBUG_CRYPTO
|
||||||
ssh_print_hexa("Session server cookie",
|
ssh_print_hexa("Session server cookie",
|
||||||
session->next_crypto->server_kex.cookie, 16);
|
session->next_crypto->server_kex.cookie, 16);
|
||||||
@@ -138,10 +169,6 @@ static int ecdh_build_k(ssh_session session) {
|
|||||||
ssh_print_bignum("Shared secret key", session->next_crypto->k);
|
ssh_print_bignum("Shared secret key", session->next_crypto->k);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBCRYPTO
|
|
||||||
bignum_ctx_free(ctx);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,12 +286,6 @@ int ssh_server_ecdh_init(ssh_session session, ssh_buffer packet){
|
|||||||
session->next_crypto->ecdh_privkey = ecdh_key;
|
session->next_crypto->ecdh_privkey = ecdh_key;
|
||||||
session->next_crypto->ecdh_server_pubkey = q_s_string;
|
session->next_crypto->ecdh_server_pubkey = q_s_string;
|
||||||
|
|
||||||
rc = buffer_add_u8(session->out_buffer, SSH2_MSG_KEXDH_REPLY);
|
|
||||||
if (rc < 0) {
|
|
||||||
ssh_set_error_oom(session);
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* build k and session_id */
|
/* build k and session_id */
|
||||||
rc = ecdh_build_k(session);
|
rc = ecdh_build_k(session);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
@@ -284,30 +305,22 @@ int ssh_server_ecdh_init(ssh_session session, ssh_buffer packet){
|
|||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add host's public key */
|
|
||||||
rc = buffer_add_ssh_string(session->out_buffer,
|
|
||||||
session->next_crypto->server_pubkey);
|
|
||||||
if (rc < 0) {
|
|
||||||
ssh_set_error_oom(session);
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add ecdh public key */
|
|
||||||
rc = buffer_add_ssh_string(session->out_buffer, q_s_string);
|
|
||||||
if (rc < 0) {
|
|
||||||
ssh_set_error_oom(session);
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
/* add signature blob */
|
|
||||||
sig_blob = ssh_srv_pki_do_sign_sessionid(session, privkey);
|
sig_blob = ssh_srv_pki_do_sign_sessionid(session, privkey);
|
||||||
if (sig_blob == NULL) {
|
if (sig_blob == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
|
ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = buffer_add_ssh_string(session->out_buffer, sig_blob);
|
rc = ssh_buffer_pack(session->out_buffer,
|
||||||
|
"bSSS",
|
||||||
|
SSH2_MSG_KEXDH_REPLY,
|
||||||
|
session->next_crypto->server_pubkey, /* host's pubkey */
|
||||||
|
q_s_string, /* ecdh public key */
|
||||||
|
sig_blob); /* signature blob */
|
||||||
|
|
||||||
ssh_string_free(sig_blob);
|
ssh_string_free(sig_blob);
|
||||||
if (rc < 0) {
|
|
||||||
|
if (rc != SSH_OK) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user