test.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. #!/bin/bash
  2. # =============================================================================
  3. # \brief Testing command-line interface
  4. # \project bee2evp/cmd
  5. # \created 2022.06.24
  6. # \version 2024.06.14
  7. # \pre The working directory contains zed.csr.
  8. # =============================================================================
  9. bee2cmd="${BEE2CMD:-./bee2cmd}"
  10. if [ ! -f "${bee2cmd}" ]; then
  11. bee2cmd=$(command -v bee2cmd)
  12. if [ ! -f "${bee2cmd}" ]; then
  13. echo "Set path to bee2cmd executable file to BEE2CMD environment \
  14. variable or run this script from containing folder."
  15. exit 1
  16. fi
  17. fi
  18. this=$(realpath $BASH_SOURCE)
  19. function pause() {
  20. read -s -n 1 -p "Press any key to continue..."
  21. echo ""
  22. }
  23. test_ver() {
  24. $bee2cmd ver \
  25. || return 1
  26. $bee2cmd ver ver \
  27. && return 1
  28. return 0
  29. }
  30. test_bsum() {
  31. rm -rf -- check32 check256 -c \
  32. || return 2
  33. $bee2cmd bsum -bash31 $bee2cmd \
  34. && return 1
  35. $bee2cmd bsum -bash32 $bee2cmd $this > check32 \
  36. || return 1
  37. $bee2cmd bsum -bash32 -c check32 \
  38. || return 1
  39. $bee2cmd bsum $bee2cmd $this > check256 \
  40. || return 1
  41. $bee2cmd bsum -belt-hash -c check256 \
  42. || return 1
  43. $bee2cmd bsum -c check32 \
  44. && return 1
  45. $bee2cmd bsum -bash-prg-hash2561 $bee2cmd $this > -c \
  46. || return 1
  47. $bee2cmd bsum -bash-prg-hash2561 -c \
  48. && return 1
  49. $bee2cmd bsum -bash-prg-hash2561 -- -c \
  50. || return 1
  51. $bee2cmd bsum -bash-prg-hash2561 -c -- -c \
  52. || return 1
  53. $bee2cmd bsum -bash-prg-hash2562 -c -- -c \
  54. && return 1
  55. $bee2cmd bsum -c -bash-prg-hash2561 -- -c \
  56. || return 1
  57. $bee2cmd bsum -c -bash-prg-hash2561 -c -- -c \
  58. && return 1
  59. $bee2cmd bsum -c -belt-hash -bash-prg-hash2561 -- -c \
  60. && return 1
  61. $bee2cmd bsum -b -c -- -c \
  62. && return 1
  63. return 0
  64. }
  65. test_pwd() {
  66. rm -rf s1 s2 s3 s4 s5 ss1 ss2 ss3 \
  67. || return 2
  68. # pass
  69. $bee2cmd pwd gen pass:zed \
  70. && return 1
  71. $bee2cmd pwd val pass:zed \
  72. || return 1
  73. $bee2cmd pwd val pass:"zed" \
  74. || return 1
  75. if [ $($bee2cmd pwd print pass:zed) != "zed" ]; then
  76. return 1
  77. fi
  78. # env
  79. $bee2cmd pwd gen env:BEE2_CMD_TEST \
  80. && return 1
  81. unset BEE2_CMD_TEST \
  82. || return 2
  83. $bee2cmd pwd val env:BEE2_CMD_TEST \
  84. && return 1
  85. export BEE2_CMD_TEST=zed \
  86. || return 2
  87. $bee2cmd pwd val env:BEE2_CMD_TEST \
  88. || return 1
  89. if [ $($bee2cmd pwd print env:BEE2_CMD_TEST) != "zed" ]; then
  90. return 1
  91. fi
  92. # share
  93. $bee2cmd pwd gen share:"-t2 -t3 -pass pass:zed s1 s2" \
  94. && return 1
  95. $bee2cmd pwd gen share:"-t3 -pass pass:zed s1 s2" \
  96. && return 1
  97. $bee2cmd pwd gen share:"-l -pass pass:zed s1 s2" \
  98. && return 1
  99. $bee2cmd pwd gen share:"-l12 -pass pass:zed s1 s2" \
  100. && return 1
  101. $bee2cmd pwd gen share:"-l128 -l -pass pass:zed s1 s2" \
  102. && return 1
  103. $bee2cmd pwd gen share:"-l128 -l256 -pass pass:zed s1 s2" \
  104. && return 1
  105. $bee2cmd pwd gen share:"-l128 -crc -t3 -pass pass:zed s1 s2 s3 s4 s5" \
  106. && return 1
  107. $bee2cmd pwd gen share:"-l256 -crc -t3 -pass pass:zed s1 s2 s3 s4 s5" \
  108. || return 1
  109. $bee2cmd pwd val share:"-t3 -pass pass:zed s1 s2" \
  110. && return 1
  111. $bee2cmd pwd val share:"-l -pass pass:zed s1 s2" \
  112. && return 1
  113. $bee2cmd pwd val share:"-l12 -pass pass:zed s1 s2" \
  114. && return 1
  115. $bee2cmd pwd val share:"-l128 -l -pass pass:zed s1 s2" \
  116. && return 1
  117. $bee2cmd pwd val share:"-l128 -l256 -pass pass:zed s1 s2" \
  118. && return 1
  119. $bee2cmd pwd val share:"-l128 -pass pass:zed s1 s2" \
  120. && return 1
  121. $bee2cmd pwd val share:"-l256 -pass pass:zed s1 s2 s3" \
  122. || return 1
  123. $bee2cmd pwd val share:"-l256 -crc -pass pass:zed s1 s2 s3" \
  124. || return 1
  125. $bee2cmd pwd val share:"-pass pass:zed s2 s3 s4 s5" \
  126. || return 1
  127. $bee2cmd pwd val share:"-pass pass:zed -crc s2 s3 s4 s5" \
  128. || return 1
  129. $bee2cmd pwd print share:"-l128 -pass pass:zed s5 s1 s3" \
  130. && return 1
  131. $bee2cmd pwd print share:"-l256 -pass pass:zed s2 s1 s5 s3" \
  132. || return 1
  133. $bee2cmd pwd print share:"-pass pass:zed s1 s2 s3 s4 s5" \
  134. || return 1
  135. $bee2cmd pwd gen \
  136. share:"-l192 -pass share:\"-pass pass:zed s1 s2 s3\" ss1 ss2 ss3" \
  137. || return 1
  138. $bee2cmd pwd val share:"-pass share:\"-pass pass:zed s1 s2 s2\" ss1 ss2" \
  139. && return 1
  140. $bee2cmd pwd val share:"-pass share:\"-pass pass:zed s1 s2 s3\" ss1 ss1" \
  141. && return 1
  142. $bee2cmd pwd val share:"-pass share:\"-pass pass:zed s2 s4 s1\" ss3 ss1" \
  143. || return 1
  144. $bee2cmd pwd print share:"-pass share:\"-pass pass:zed s2 s4 s1\" ss3 ss1" \
  145. || return 1
  146. $bee2cmd pwd print \
  147. share:"-pass share:\"-pass pass:zed s2 s4 s1\" -crc ss3 ss1" \
  148. && return 1
  149. return 0
  150. }
  151. test_kg() {
  152. rm -rf privkey0 privkey1 privkey2 privkey3 pubkey1 pubkey2 pubkey3 \
  153. || return 2
  154. $bee2cmd kg gen -l256 -pass share:"-pass pass:zed s2 s3 s4" \
  155. && return 1
  156. $bee2cmd kg gen -l256 -pass share:"-pass pass:zed s2 s3 s4" -pass pass:zed \
  157. && return 1
  158. $bee2cmd kg gen -l256 -l192 -pass share:"-pass pass:zed s2 s3 s4" privkey0 \
  159. && return 1
  160. $bee2cmd kg gen -l256 -pass share:"-pass pass:zed s2 s3 s4" privkey0 \
  161. || return 1
  162. $bee2cmd kg val -pass share:"-pass pass:zed s1 s2 s4" privkey0 \
  163. || return 1
  164. $bee2cmd kg chp -passin share:"-pass pass:zed s3 s1 s4" \
  165. -passout pass:"root" privkey0 \
  166. || return 1
  167. $bee2cmd kg print -pass pass:root privkey0 \
  168. || return 1
  169. $bee2cmd kg gen -pass pass:trent -l192 privkey1 \
  170. || return 1
  171. pubkey1="$($bee2cmd kg print -pass pass:"trent" privkey1)"
  172. if [ ${#pubkey1} != "192" ]; then
  173. return 1
  174. fi
  175. $bee2cmd kg gen -pass pass:alice privkey2 \
  176. || return 1
  177. $bee2cmd kg extr -pass pass:alice privkey2 pubkey2 \
  178. || return 1
  179. if [ "$(wc -c pubkey2 | awk '{print $1}')" != "64" ]; then
  180. return 1
  181. fi
  182. $bee2cmd kg gen -l96 -pass pass:bob privkey3 \
  183. || return 1
  184. $bee2cmd kg extr -pass pass:bob privkey3 pubkey3 \
  185. || return 1
  186. return 0
  187. }
  188. test_cvc() {
  189. rm -rf cert0 req1 cert1 pubkey1 req2 req21 cert2 req3 cert3 \
  190. || return 2
  191. $bee2cmd cvc root -authority BYCA0000 -from 220707 -until 990707 \
  192. -pass pass:root -eid EEEEEEEEEE -esign 7777 privkey0 cert0 \
  193. || return 1
  194. $bee2cmd cvc print cert0 \
  195. || return 1
  196. $bee2cmd cvc req -pass pass:trent -authority BYCA0000 -holder BYCA1000 \
  197. -from 220711 -until 221231 -eid FFFFFFFFFF -esign 7777 privkey1 req1 \
  198. || return 1
  199. $bee2cmd cvc print req1 \
  200. || return 1
  201. $bee2cmd cvc iss -authority BYCA0000 -pass pass:root privkey0 cert0 \
  202. req1 cert1 \
  203. && return 1
  204. $bee2cmd cvc iss -from 220712 -until 221130 -holder BYCA1023 \
  205. -eid DDDDDDDDDD -esign BBBB -pass pass:root privkey0 cert0 req1 cert1 \
  206. || return 1
  207. $bee2cmd cvc print cert1 \
  208. || return 1
  209. $bee2cmd cvc extr cert1 pubkey1 \
  210. || return 1
  211. if [ "$(wc -c pubkey1 | awk '{print $1}')" != "96" ]; then
  212. return 1
  213. fi
  214. $bee2cmd cvc req -authority BYCA1023 -from 220712 -until 391231 -esign 1111 \
  215. -holder "590082394654" -pass pass:alice -eid 8888888888 privkey2 req2 \
  216. || return 1
  217. $bee2cmd cvc req -authority BYCA1023 -from 000000 -until 000000 \
  218. -holder "590082394654" -pass pass:alice privkey2 req21 \
  219. || return 1
  220. $bee2cmd cvc iss -pass pass:trent privkey1 cert1 req2 cert2 \
  221. || return 1
  222. $bee2cmd cvc match -pass pass:alice privkey2 cert2 \
  223. || return 1
  224. $bee2cmd cvc match -pass pass:alisa privkey2 cert2 \
  225. && return 1
  226. $bee2cmd cvc print cert2 \
  227. || return 1
  228. if [ "$($bee2cmd cvc print -from cert1)" != "220712" ]; then
  229. return 1
  230. fi
  231. if [ "$($bee2cmd cvc print -until cert1)" != "221130" ]; then
  232. return 1
  233. fi
  234. if [ "$($bee2cmd cvc print -eid cert1)" != "DDDDDDDDDD" ]; then
  235. return 1
  236. fi
  237. if [ "$($bee2cmd cvc print -esign cert1)" != "3333" ]; then
  238. return 1
  239. fi
  240. $bee2cmd cvc val cert0 cert0 \
  241. || return 1
  242. $bee2cmd cvc val -date 220707 cert0 cert1 \
  243. && return 1
  244. $bee2cmd cvc val -date 220712 cert0 cert1 \
  245. || return 1
  246. $bee2cmd cvc val -date 220707 cert0 cert1 cert2 \
  247. && return 1
  248. $bee2cmd cvc val -date 220712 cert0 cert1 cert2 \
  249. || return 1
  250. $bee2cmd cvc val -date 220712 cert0 cert1 cert2 \
  251. || return 1
  252. $bee2cmd cvc val -date 221201 cert0 cert1 cert2 \
  253. || return 1
  254. $bee2cmd cvc val -date 400101 cert0 cert1 cert2 \
  255. && return 1
  256. $bee2cmd cvc val -date cert0 cert1 cert2 \
  257. && return 1
  258. $bee2cmd cvc val cert0 cert1 cert2 \
  259. || return 1
  260. $bee2cmd cvc shorten -pass pass:trent -until 391230 privkey1 cert1 cert2 \
  261. || return 1
  262. $bee2cmd cvc val cert0 cert1 cert2 \
  263. || return 1
  264. if [ "$($bee2cmd cvc print -until cert2)" != "391230" ]; then
  265. return 1
  266. fi
  267. $bee2cmd cvc req -authority BYCA1023 -from 221030 -until 391231 \
  268. -holder 590082394655 -pass pass:bob privkey3 req3 \
  269. || return 1
  270. $bee2cmd cvc print req3 \
  271. || return 1
  272. $bee2cmd cvc iss -pass pass:trent privkey1 cert1 req3 cert3 \
  273. || return 1
  274. return 0
  275. }
  276. test_sig(){
  277. rm -rf ss ff cert01 cert11 cert21 body sig\
  278. || return 2
  279. echo test> ff
  280. echo sig> ss
  281. $bee2cmd sig val -pubkey pubkey2 ff ss \
  282. && return 1
  283. $bee2cmd sig val -anchor cert0 ff ss \
  284. && return 1
  285. $bee2cmd sig val -anchor cert2 ff ss \
  286. && return 1
  287. $bee2cmd sig val -pubkey pubkey2 ff ff \
  288. && return 1
  289. $bee2cmd sig val -anchor cert0 ff ff \
  290. && return 1
  291. $bee2cmd sig val -anchor cert2 ff ff \
  292. && return 1
  293. rm -rf ss
  294. $bee2cmd sig sign -date 400101 -certs "cert1 cert2" -pass pass:alice \
  295. privkey2 ff ss \
  296. && return 1
  297. $bee2cmd sig sign -date 230526 -certs "cert1 cert2" -pass pass:alice \
  298. privkey2 ff ss \
  299. || return 1
  300. $bee2cmd sig val -pubkey pubkey2 ff ss \
  301. || return 1
  302. $bee2cmd sig val -anchor cert2 ff ss \
  303. || return 1
  304. $bee2cmd sig val -anchor cert1 ff ss \
  305. || return 1
  306. $bee2cmd sig val -anchor cert0 ff ss \
  307. && return 1
  308. $bee2cmd sig sign -certs "cert0 cert1 cert2" -pass pass:alice privkey2 ff ff \
  309. || return 1
  310. $bee2cmd sig extr -cert0 ff cert01 \
  311. || return 1
  312. diff cert0 cert01 \
  313. || return 1
  314. $bee2cmd sig extr -cert1 ff cert11 \
  315. || return 1
  316. diff cert1 cert11 \
  317. || return 1
  318. $bee2cmd sig extr -cert2 ff cert21 \
  319. || return 1
  320. diff cert2 cert21 \
  321. || return 1
  322. $bee2cmd sig extr -body ff body \
  323. || return 1
  324. if [ $(< body) != "test" ]; then
  325. return 1
  326. fi
  327. $bee2cmd sig extr -sig ff sig \
  328. || return 1
  329. $bee2cmd sig val -pubkey pubkey2 ff ff \
  330. || return 1
  331. $bee2cmd sig val -anchor cert2 ff ff \
  332. || return 1
  333. $bee2cmd sig val -anchor cert1 ff ff \
  334. || return 1
  335. $bee2cmd sig val -anchor cert0 ff ff \
  336. || return 1
  337. rm -rf ss body
  338. $bee2cmd sig sign -certs cert2 -pass pass:alice privkey2 ff ss \
  339. || return 1
  340. $bee2cmd sig print ss \
  341. || return 1
  342. $bee2cmd sig val -pubkey pubkey2 ff ss \
  343. || return 1
  344. $bee2cmd sig val -anchor cert2 ff ss \
  345. || return 1
  346. $bee2cmd sig val -anchor cert1 ff ss \
  347. && return 1
  348. $bee2cmd sig extr -body ss body \
  349. && return 1
  350. $bee2cmd sig sign -pass pass:alice -date 230526 privkey2 ff ff \
  351. || return 1
  352. $bee2cmd sig val -pubkey pubkey2 ff ff \
  353. || return 1
  354. $bee2cmd sig val -anchor cert2 ff ff \
  355. && return 1
  356. $bee2cmd sig print ff \
  357. || return 1
  358. $bee2cmd sig print ss \
  359. || return 1
  360. $bee2cmd sig print -date ss \
  361. && return 1
  362. if [ "$($bee2cmd sig print -certc ss)" != "1" ]; then
  363. return 1
  364. fi
  365. $bee2cmd sig sign -pass pass:bob -certs "cert1 cert3" privkey3 ff ff \
  366. || return 1
  367. $bee2cmd sig val -pubkey pubkey3 ff ff \
  368. || return 1
  369. $bee2cmd sig val -anchor cert1 ff ff \
  370. || return 1
  371. $bee2cmd sig val -anchor cert3 ff ff \
  372. || return 1
  373. return 0
  374. }
  375. test_cvr(){
  376. rm -rf ring2 cert21 cert31 \
  377. || return 2
  378. $bee2cmd cvr init -pass pass:alice privkey2 cert2 ring2 \
  379. || return 1
  380. $bee2cmd cvr add -pass pass:alice privkey2 cert2 cert3 ring2 \
  381. || return 1
  382. $bee2cmd cvr add -pass pass:alice privkey2 cert2 cert3 ring2 \
  383. && return 1
  384. $bee2cmd cvr val cert2 ring2 \
  385. || return 1
  386. $bee2cmd sig val -anchor cert2 ring2 ring2 \
  387. || return 1
  388. $bee2cmd cvr find ring2 cert3 \
  389. || return 1
  390. $bee2cmd cvr find ring2 cert2 \
  391. && return 1
  392. $bee2cmd cvr extr -cert0 ring2 cert31 \
  393. || return 1
  394. diff cert3 cert31 \
  395. || return 1
  396. $bee2cmd sig extr -cert0 ring2 cert21 \
  397. || return 1
  398. diff cert2 cert21 \
  399. || return 1
  400. $bee2cmd cvr print ring2 \
  401. || return 1
  402. $bee2cmd cvr print -certc ring2 \
  403. || return 1
  404. $bee2cmd sig print ring2 \
  405. || return 1
  406. $bee2cmd cvr add -pass pass:alice privkey2 cert2 cert0 ring2 \
  407. || return 1
  408. $bee2cmd cvr add -pass pass:alice privkey2 cert2 cert1 ring2 \
  409. || return 1
  410. if [ "$($bee2cmd cvr print -certc ring2)" != "3" ]; then
  411. return 1
  412. fi
  413. $bee2cmd cvr del -pass pass:alice privkey2 cert2 cert1 ring2 \
  414. || return 1
  415. $bee2cmd cvr del -pass pass:alice privkey2 cert2 cert0 ring2 \
  416. || return 1
  417. $bee2cmd cvr del -pass pass:alice privkey2 cert2 cert0 ring2 \
  418. return 0
  419. }
  420. test_csr(){
  421. rm -rf zed.sk1 zed.csr1 \
  422. || return 2
  423. $bee2cmd csr val zed.csr \
  424. || return 1
  425. $bee2cmd kg gen -pass pass:zed1 zed.sk1 \
  426. || return 1
  427. $bee2cmd csr rewrap -pass pass:zed1 zed.sk1 zed.csr zed.csr1 \
  428. || return 1
  429. $bee2cmd csr val zed.csr1 \
  430. || return 1
  431. return 0
  432. }
  433. test_es() {
  434. rm -rf dd\
  435. || return 2
  436. $bee2cmd es print \
  437. || return 1
  438. $bee2cmd es read sys 1 dd \
  439. || return 1
  440. if [ "$(wc -c dd | awk '{print $1}')" != "1024" ]; then
  441. return 1
  442. fi
  443. return 0
  444. }
  445. run_test() {
  446. echo -n "Testing $1... "
  447. (test_$1 > /dev/null 2>&1)
  448. if [ $? -eq 0 ]; then
  449. echo "Success"
  450. else
  451. echo "Failed"
  452. fi
  453. }
  454. run_test ver && run_test bsum && run_test pwd && run_test kg && run_test cvc \
  455. && run_test sig && run_test cvr && run_test csr && run_test es