hane 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/README.md +32 -32
  2. package/binding.gyp +50 -50
  3. package/deps/win-nodeapi/node_api.def +158 -158
  4. package/package.json +34 -34
  5. package/src/native/addon.cc +183 -183
  6. package/src/native/zsign_driver.cc +86 -86
  7. package/src/native/zsign_driver.h +38 -38
  8. package/vendor/zlib/.cmake-format.yaml +245 -245
  9. package/vendor/zlib/.github/workflows/c-std.yml +230 -230
  10. package/vendor/zlib/.github/workflows/cmake.yml +112 -112
  11. package/vendor/zlib/.github/workflows/configure.yml +136 -136
  12. package/vendor/zlib/.github/workflows/fuzz.yml +25 -25
  13. package/vendor/zlib/.github/workflows/msys-cygwin.yml +77 -77
  14. package/vendor/zlib/BUILD.bazel +134 -134
  15. package/vendor/zlib/CMakeLists.txt +330 -330
  16. package/vendor/zlib/ChangeLog +1621 -1621
  17. package/vendor/zlib/FAQ +367 -367
  18. package/vendor/zlib/INDEX +68 -68
  19. package/vendor/zlib/LICENSE +22 -22
  20. package/vendor/zlib/MODULE.bazel +9 -9
  21. package/vendor/zlib/Makefile.in +419 -419
  22. package/vendor/zlib/README +115 -115
  23. package/vendor/zlib/README-cmake.md +83 -83
  24. package/vendor/zlib/adler32.c +164 -164
  25. package/vendor/zlib/amiga/Makefile.pup +69 -69
  26. package/vendor/zlib/amiga/Makefile.sas +68 -68
  27. package/vendor/zlib/compress.c +75 -75
  28. package/vendor/zlib/configure +966 -966
  29. package/vendor/zlib/contrib/README.contrib +57 -57
  30. package/vendor/zlib/contrib/ada/buffer_demo.adb +106 -106
  31. package/vendor/zlib/contrib/ada/mtest.adb +156 -156
  32. package/vendor/zlib/contrib/ada/read.adb +156 -156
  33. package/vendor/zlib/contrib/ada/readme.txt +65 -65
  34. package/vendor/zlib/contrib/ada/test.adb +463 -463
  35. package/vendor/zlib/contrib/ada/zlib-streams.adb +225 -225
  36. package/vendor/zlib/contrib/ada/zlib-streams.ads +114 -114
  37. package/vendor/zlib/contrib/ada/zlib-thin.adb +142 -142
  38. package/vendor/zlib/contrib/ada/zlib-thin.ads +450 -450
  39. package/vendor/zlib/contrib/ada/zlib.adb +701 -701
  40. package/vendor/zlib/contrib/ada/zlib.ads +328 -328
  41. package/vendor/zlib/contrib/ada/zlib.gpr +20 -20
  42. package/vendor/zlib/contrib/blast/Makefile +8 -8
  43. package/vendor/zlib/contrib/blast/README +4 -4
  44. package/vendor/zlib/contrib/blast/blast.c +466 -466
  45. package/vendor/zlib/contrib/blast/blast.h +83 -83
  46. package/vendor/zlib/contrib/delphi/ZLib.pas +557 -557
  47. package/vendor/zlib/contrib/delphi/ZLibConst.pas +11 -11
  48. package/vendor/zlib/contrib/delphi/readme.txt +76 -76
  49. package/vendor/zlib/contrib/delphi/zlibd32.mak +99 -99
  50. package/vendor/zlib/contrib/gcc_gvmat64/gvmat64.S +574 -574
  51. package/vendor/zlib/contrib/infback9/README +1 -1
  52. package/vendor/zlib/contrib/infback9/infback9.c +603 -603
  53. package/vendor/zlib/contrib/infback9/infback9.h +37 -37
  54. package/vendor/zlib/contrib/infback9/inffix9.h +107 -107
  55. package/vendor/zlib/contrib/infback9/inflate9.h +47 -47
  56. package/vendor/zlib/contrib/infback9/inftree9.c +319 -319
  57. package/vendor/zlib/contrib/infback9/inftree9.h +61 -61
  58. package/vendor/zlib/contrib/iostream/test.cpp +24 -24
  59. package/vendor/zlib/contrib/iostream/zfstream.cpp +329 -329
  60. package/vendor/zlib/contrib/iostream/zfstream.h +128 -128
  61. package/vendor/zlib/contrib/iostream2/zstream.h +307 -307
  62. package/vendor/zlib/contrib/iostream2/zstream_test.cpp +25 -25
  63. package/vendor/zlib/contrib/iostream3/README +35 -35
  64. package/vendor/zlib/contrib/iostream3/TODO +17 -17
  65. package/vendor/zlib/contrib/iostream3/test.cc +50 -50
  66. package/vendor/zlib/contrib/iostream3/zfstream.cc +479 -479
  67. package/vendor/zlib/contrib/iostream3/zfstream.h +466 -466
  68. package/vendor/zlib/contrib/minizip/CMakeLists.txt +380 -380
  69. package/vendor/zlib/contrib/minizip/Makefile +37 -37
  70. package/vendor/zlib/contrib/minizip/Makefile.am +45 -45
  71. package/vendor/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -6
  72. package/vendor/zlib/contrib/minizip/MiniZip64_info.txt +74 -74
  73. package/vendor/zlib/contrib/minizip/configure.ac +32 -32
  74. package/vendor/zlib/contrib/minizip/crypt.h +128 -128
  75. package/vendor/zlib/contrib/minizip/ints.h +57 -57
  76. package/vendor/zlib/contrib/minizip/ioapi.c +231 -231
  77. package/vendor/zlib/contrib/minizip/ioapi.h +183 -183
  78. package/vendor/zlib/contrib/minizip/iowin32.c +448 -448
  79. package/vendor/zlib/contrib/minizip/iowin32.h +28 -28
  80. package/vendor/zlib/contrib/minizip/make_vms.com +25 -25
  81. package/vendor/zlib/contrib/minizip/miniunz.c +647 -647
  82. package/vendor/zlib/contrib/minizip/miniunzip.1 +63 -63
  83. package/vendor/zlib/contrib/minizip/minizip.1 +46 -46
  84. package/vendor/zlib/contrib/minizip/minizip.c +512 -512
  85. package/vendor/zlib/contrib/minizip/minizip.pc.in +12 -12
  86. package/vendor/zlib/contrib/minizip/minizip.pc.txt +13 -13
  87. package/vendor/zlib/contrib/minizip/minizipConfig.cmake.in +35 -35
  88. package/vendor/zlib/contrib/minizip/mztools.c +288 -288
  89. package/vendor/zlib/contrib/minizip/mztools.h +37 -37
  90. package/vendor/zlib/contrib/minizip/skipset.h +361 -361
  91. package/vendor/zlib/contrib/minizip/test/CMakeLists.txt +121 -121
  92. package/vendor/zlib/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in +29 -29
  93. package/vendor/zlib/contrib/minizip/test/add_subdirectory_test.cmake.in +28 -28
  94. package/vendor/zlib/contrib/minizip/test/find_package_test.cmake.in +25 -25
  95. package/vendor/zlib/contrib/minizip/test/test_helper.cm +32 -32
  96. package/vendor/zlib/contrib/minizip/unzip.c +1981 -1981
  97. package/vendor/zlib/contrib/minizip/unzip.h +441 -441
  98. package/vendor/zlib/contrib/minizip/zip.c +2199 -2199
  99. package/vendor/zlib/contrib/minizip/zip.h +370 -370
  100. package/vendor/zlib/contrib/nuget/nuget.csproj +43 -43
  101. package/vendor/zlib/contrib/nuget/nuget.sln +22 -22
  102. package/vendor/zlib/contrib/pascal/example.pas +599 -599
  103. package/vendor/zlib/contrib/pascal/readme.txt +76 -76
  104. package/vendor/zlib/contrib/pascal/zlibd32.mak +99 -99
  105. package/vendor/zlib/contrib/pascal/zlibpas.pas +276 -276
  106. package/vendor/zlib/contrib/puff/Makefile +42 -42
  107. package/vendor/zlib/contrib/puff/README +63 -63
  108. package/vendor/zlib/contrib/puff/puff.c +840 -840
  109. package/vendor/zlib/contrib/puff/puff.h +35 -35
  110. package/vendor/zlib/contrib/puff/pufftest.c +169 -169
  111. package/vendor/zlib/contrib/untgz/Makefile +14 -14
  112. package/vendor/zlib/contrib/untgz/Makefile.msc +17 -17
  113. package/vendor/zlib/contrib/untgz/untgz.c +667 -667
  114. package/vendor/zlib/contrib/vstudio/readme.txt +81 -81
  115. package/vendor/zlib/contrib/vstudio/vc12/miniunz.vcxproj +315 -315
  116. package/vendor/zlib/contrib/vstudio/vc12/minizip.vcxproj +312 -312
  117. package/vendor/zlib/contrib/vstudio/vc12/testzlib.vcxproj +421 -421
  118. package/vendor/zlib/contrib/vstudio/vc12/testzlibdll.vcxproj +315 -315
  119. package/vendor/zlib/contrib/vstudio/vc12/zlib.rc +32 -32
  120. package/vendor/zlib/contrib/vstudio/vc12/zlibstat.vcxproj +458 -458
  121. package/vendor/zlib/contrib/vstudio/vc12/zlibvc.sln +119 -119
  122. package/vendor/zlib/contrib/vstudio/vc12/zlibvc.vcxproj +667 -667
  123. package/vendor/zlib/contrib/vstudio/vc14/miniunz.vcxproj +315 -315
  124. package/vendor/zlib/contrib/vstudio/vc14/minizip.vcxproj +312 -312
  125. package/vendor/zlib/contrib/vstudio/vc14/testzlib.vcxproj +421 -421
  126. package/vendor/zlib/contrib/vstudio/vc14/testzlibdll.vcxproj +315 -315
  127. package/vendor/zlib/contrib/vstudio/vc14/zlib.rc +32 -32
  128. package/vendor/zlib/contrib/vstudio/vc14/zlibstat.vcxproj +458 -458
  129. package/vendor/zlib/contrib/vstudio/vc14/zlibvc.sln +119 -119
  130. package/vendor/zlib/contrib/vstudio/vc14/zlibvc.vcxproj +667 -667
  131. package/vendor/zlib/contrib/vstudio/vc17/miniunz.vcxproj +408 -408
  132. package/vendor/zlib/contrib/vstudio/vc17/minizip.vcxproj +404 -404
  133. package/vendor/zlib/contrib/vstudio/vc17/testzlib.vcxproj +472 -472
  134. package/vendor/zlib/contrib/vstudio/vc17/testzlibdll.vcxproj +408 -408
  135. package/vendor/zlib/contrib/vstudio/vc17/zlib.rc +32 -32
  136. package/vendor/zlib/contrib/vstudio/vc17/zlibstat.vcxproj +601 -601
  137. package/vendor/zlib/contrib/vstudio/vc17/zlibvc.sln +179 -179
  138. package/vendor/zlib/contrib/vstudio/vc17/zlibvc.vcxproj +874 -874
  139. package/vendor/zlib/crc32.c +1049 -1049
  140. package/vendor/zlib/crc32.h +9446 -9446
  141. package/vendor/zlib/deflate.c +2152 -2152
  142. package/vendor/zlib/deflate.h +380 -380
  143. package/vendor/zlib/doc/algorithm.txt +209 -209
  144. package/vendor/zlib/doc/rfc1950.txt +619 -619
  145. package/vendor/zlib/doc/rfc1951.txt +955 -955
  146. package/vendor/zlib/doc/rfc1952.txt +675 -675
  147. package/vendor/zlib/doc/txtvsbin.txt +107 -107
  148. package/vendor/zlib/examples/README.examples +54 -54
  149. package/vendor/zlib/examples/enough.c +597 -597
  150. package/vendor/zlib/examples/fitblk.c +233 -233
  151. package/vendor/zlib/examples/gun.c +702 -702
  152. package/vendor/zlib/examples/gzappend.c +504 -504
  153. package/vendor/zlib/examples/gzjoin.c +449 -449
  154. package/vendor/zlib/examples/gzlog.c +1061 -1061
  155. package/vendor/zlib/examples/gzlog.h +91 -91
  156. package/vendor/zlib/examples/gznorm.c +474 -474
  157. package/vendor/zlib/examples/zlib_how.html +549 -549
  158. package/vendor/zlib/examples/zpipe.c +209 -209
  159. package/vendor/zlib/examples/zran.c +550 -550
  160. package/vendor/zlib/examples/zran.h +53 -53
  161. package/vendor/zlib/gzclose.c +23 -23
  162. package/vendor/zlib/gzguts.h +215 -215
  163. package/vendor/zlib/gzlib.c +585 -585
  164. package/vendor/zlib/gzread.c +603 -603
  165. package/vendor/zlib/gzwrite.c +631 -631
  166. package/vendor/zlib/infback.c +628 -628
  167. package/vendor/zlib/inffast.c +320 -320
  168. package/vendor/zlib/inffast.h +11 -11
  169. package/vendor/zlib/inffixed.h +94 -94
  170. package/vendor/zlib/inflate.c +1526 -1526
  171. package/vendor/zlib/inflate.h +126 -126
  172. package/vendor/zlib/inftrees.c +299 -299
  173. package/vendor/zlib/inftrees.h +62 -62
  174. package/vendor/zlib/make_vms.com +867 -867
  175. package/vendor/zlib/msdos/Makefile.bor +115 -115
  176. package/vendor/zlib/msdos/Makefile.dj2 +104 -104
  177. package/vendor/zlib/msdos/Makefile.emx +69 -69
  178. package/vendor/zlib/msdos/Makefile.msc +112 -112
  179. package/vendor/zlib/msdos/Makefile.tc +100 -100
  180. package/vendor/zlib/nintendods/Makefile +126 -126
  181. package/vendor/zlib/nintendods/README +5 -5
  182. package/vendor/zlib/old/Makefile.emx +69 -69
  183. package/vendor/zlib/old/Makefile.riscos +151 -151
  184. package/vendor/zlib/old/README +3 -3
  185. package/vendor/zlib/old/descrip.mms +48 -48
  186. package/vendor/zlib/old/os2/Makefile.os2 +136 -136
  187. package/vendor/zlib/old/os2/zlib.def +51 -51
  188. package/vendor/zlib/old/visual-basic.txt +160 -160
  189. package/vendor/zlib/os400/README400 +48 -48
  190. package/vendor/zlib/os400/bndsrc +133 -133
  191. package/vendor/zlib/os400/make.sh +366 -366
  192. package/vendor/zlib/os400/zlib.inc +531 -531
  193. package/vendor/zlib/qnx/package.qpg +141 -141
  194. package/vendor/zlib/test/CMakeLists.txt +265 -265
  195. package/vendor/zlib/test/add_subdirectory_exclude_test.cmake.in +29 -29
  196. package/vendor/zlib/test/add_subdirectory_test.cmake.in +28 -28
  197. package/vendor/zlib/test/example.c +552 -552
  198. package/vendor/zlib/test/find_package_test.cmake.in +26 -26
  199. package/vendor/zlib/test/infcover.c +672 -672
  200. package/vendor/zlib/test/minigzip.c +590 -590
  201. package/vendor/zlib/treebuild.xml +116 -116
  202. package/vendor/zlib/trees.c +1119 -1119
  203. package/vendor/zlib/trees.h +128 -128
  204. package/vendor/zlib/uncompr.c +85 -85
  205. package/vendor/zlib/watcom/watcom_f.mak +43 -43
  206. package/vendor/zlib/watcom/watcom_l.mak +43 -43
  207. package/vendor/zlib/win32/DLL_FAQ.txt +381 -381
  208. package/vendor/zlib/win32/Makefile.bor +109 -109
  209. package/vendor/zlib/win32/Makefile.gcc +177 -177
  210. package/vendor/zlib/win32/Makefile.msc +159 -159
  211. package/vendor/zlib/win32/README-WIN32.txt +103 -103
  212. package/vendor/zlib/win32/VisualC.txt +3 -3
  213. package/vendor/zlib/win32/zlib1.rc +37 -37
  214. package/vendor/zlib/zconf.h.in +544 -544
  215. package/vendor/zlib/zlib.3 +149 -149
  216. package/vendor/zlib/zlib.h +1957 -1957
  217. package/vendor/zlib/zlib.map +103 -103
  218. package/vendor/zlib/zlib.pc.cmakein +13 -13
  219. package/vendor/zlib/zlib.pc.in +13 -13
  220. package/vendor/zlib/zlibConfig.cmake.in +26 -26
  221. package/vendor/zlib/zutil.c +299 -299
  222. package/vendor/zlib/zutil.h +257 -257
  223. package/vendor/zsign/.gitattributes +3 -3
  224. package/vendor/zsign/LICENSE +20 -20
  225. package/vendor/zsign/README.md +142 -142
  226. package/vendor/zsign/build/linux/Makefile +43 -43
  227. package/vendor/zsign/build/macos/Makefile +43 -43
  228. package/vendor/zsign/build/windows/vs2022/include/minizip/crypt.h +128 -128
  229. package/vendor/zsign/build/windows/vs2022/include/minizip/ioapi.h +216 -216
  230. package/vendor/zsign/build/windows/vs2022/include/minizip/iowin32.h +28 -28
  231. package/vendor/zsign/build/windows/vs2022/include/minizip/mztools.h +37 -37
  232. package/vendor/zsign/build/windows/vs2022/include/minizip/unzip.h +437 -437
  233. package/vendor/zsign/build/windows/vs2022/include/minizip/zip.h +364 -364
  234. package/vendor/zsign/build/windows/vs2022/include/openssl/__DECC_INCLUDE_EPILOGUE.H +22 -22
  235. package/vendor/zsign/build/windows/vs2022/include/openssl/__DECC_INCLUDE_PROLOGUE.H +26 -26
  236. package/vendor/zsign/build/windows/vs2022/include/openssl/aes.h +111 -111
  237. package/vendor/zsign/build/windows/vs2022/include/openssl/applink.c +153 -153
  238. package/vendor/zsign/build/windows/vs2022/include/openssl/asn1_mac.h +10 -10
  239. package/vendor/zsign/build/windows/vs2022/include/openssl/asn1err.h +142 -142
  240. package/vendor/zsign/build/windows/vs2022/include/openssl/async.h +104 -104
  241. package/vendor/zsign/build/windows/vs2022/include/openssl/asyncerr.h +29 -29
  242. package/vendor/zsign/build/windows/vs2022/include/openssl/bioerr.h +72 -72
  243. package/vendor/zsign/build/windows/vs2022/include/openssl/blowfish.h +78 -78
  244. package/vendor/zsign/build/windows/vs2022/include/openssl/bn.h +590 -590
  245. package/vendor/zsign/build/windows/vs2022/include/openssl/bnerr.h +47 -47
  246. package/vendor/zsign/build/windows/vs2022/include/openssl/buffer.h +62 -62
  247. package/vendor/zsign/build/windows/vs2022/include/openssl/buffererr.h +25 -25
  248. package/vendor/zsign/build/windows/vs2022/include/openssl/camellia.h +117 -117
  249. package/vendor/zsign/build/windows/vs2022/include/openssl/cast.h +71 -71
  250. package/vendor/zsign/build/windows/vs2022/include/openssl/cmac.h +52 -52
  251. package/vendor/zsign/build/windows/vs2022/include/openssl/cmp_util.h +56 -56
  252. package/vendor/zsign/build/windows/vs2022/include/openssl/cmperr.h +131 -131
  253. package/vendor/zsign/build/windows/vs2022/include/openssl/cmserr.h +125 -125
  254. package/vendor/zsign/build/windows/vs2022/include/openssl/comperr.h +38 -38
  255. package/vendor/zsign/build/windows/vs2022/include/openssl/conf_api.h +46 -46
  256. package/vendor/zsign/build/windows/vs2022/include/openssl/conferr.h +52 -52
  257. package/vendor/zsign/build/windows/vs2022/include/openssl/conftypes.h +44 -44
  258. package/vendor/zsign/build/windows/vs2022/include/openssl/core.h +236 -236
  259. package/vendor/zsign/build/windows/vs2022/include/openssl/core_dispatch.h +1022 -1022
  260. package/vendor/zsign/build/windows/vs2022/include/openssl/core_object.h +41 -41
  261. package/vendor/zsign/build/windows/vs2022/include/openssl/crmferr.h +50 -50
  262. package/vendor/zsign/build/windows/vs2022/include/openssl/cryptoerr.h +56 -56
  263. package/vendor/zsign/build/windows/vs2022/include/openssl/cryptoerr_legacy.h +1466 -1466
  264. package/vendor/zsign/build/windows/vs2022/include/openssl/cterr.h +45 -45
  265. package/vendor/zsign/build/windows/vs2022/include/openssl/decoder.h +133 -133
  266. package/vendor/zsign/build/windows/vs2022/include/openssl/decodererr.h +28 -28
  267. package/vendor/zsign/build/windows/vs2022/include/openssl/des.h +211 -211
  268. package/vendor/zsign/build/windows/vs2022/include/openssl/dh.h +339 -339
  269. package/vendor/zsign/build/windows/vs2022/include/openssl/dherr.h +59 -59
  270. package/vendor/zsign/build/windows/vs2022/include/openssl/dsa.h +280 -280
  271. package/vendor/zsign/build/windows/vs2022/include/openssl/dsaerr.h +44 -44
  272. package/vendor/zsign/build/windows/vs2022/include/openssl/dtls1.h +57 -57
  273. package/vendor/zsign/build/windows/vs2022/include/openssl/e_os2.h +310 -310
  274. package/vendor/zsign/build/windows/vs2022/include/openssl/e_ostime.h +38 -38
  275. package/vendor/zsign/build/windows/vs2022/include/openssl/ebcdic.h +39 -39
  276. package/vendor/zsign/build/windows/vs2022/include/openssl/ec.h +1588 -1588
  277. package/vendor/zsign/build/windows/vs2022/include/openssl/ecdh.h +10 -10
  278. package/vendor/zsign/build/windows/vs2022/include/openssl/ecdsa.h +10 -10
  279. package/vendor/zsign/build/windows/vs2022/include/openssl/ecerr.h +104 -104
  280. package/vendor/zsign/build/windows/vs2022/include/openssl/encoder.h +124 -124
  281. package/vendor/zsign/build/windows/vs2022/include/openssl/encodererr.h +28 -28
  282. package/vendor/zsign/build/windows/vs2022/include/openssl/engine.h +833 -833
  283. package/vendor/zsign/build/windows/vs2022/include/openssl/engineerr.h +63 -63
  284. package/vendor/zsign/build/windows/vs2022/include/openssl/esserr.h +32 -32
  285. package/vendor/zsign/build/windows/vs2022/include/openssl/evp.h +2231 -2231
  286. package/vendor/zsign/build/windows/vs2022/include/openssl/evperr.h +140 -140
  287. package/vendor/zsign/build/windows/vs2022/include/openssl/fips_names.h +50 -50
  288. package/vendor/zsign/build/windows/vs2022/include/openssl/hmac.h +62 -62
  289. package/vendor/zsign/build/windows/vs2022/include/openssl/hpke.h +169 -169
  290. package/vendor/zsign/build/windows/vs2022/include/openssl/http.h +118 -118
  291. package/vendor/zsign/build/windows/vs2022/include/openssl/httperr.h +56 -56
  292. package/vendor/zsign/build/windows/vs2022/include/openssl/idea.h +82 -82
  293. package/vendor/zsign/build/windows/vs2022/include/openssl/indicator.h +31 -31
  294. package/vendor/zsign/build/windows/vs2022/include/openssl/kdf.h +138 -138
  295. package/vendor/zsign/build/windows/vs2022/include/openssl/kdferr.h +16 -16
  296. package/vendor/zsign/build/windows/vs2022/include/openssl/macros.h +338 -338
  297. package/vendor/zsign/build/windows/vs2022/include/openssl/md2.h +56 -56
  298. package/vendor/zsign/build/windows/vs2022/include/openssl/md4.h +63 -63
  299. package/vendor/zsign/build/windows/vs2022/include/openssl/md5.h +62 -62
  300. package/vendor/zsign/build/windows/vs2022/include/openssl/mdc2.h +55 -55
  301. package/vendor/zsign/build/windows/vs2022/include/openssl/modes.h +219 -219
  302. package/vendor/zsign/build/windows/vs2022/include/openssl/obj_mac.h +5820 -5820
  303. package/vendor/zsign/build/windows/vs2022/include/openssl/objects.h +184 -184
  304. package/vendor/zsign/build/windows/vs2022/include/openssl/objectserr.h +28 -28
  305. package/vendor/zsign/build/windows/vs2022/include/openssl/ocsperr.h +53 -53
  306. package/vendor/zsign/build/windows/vs2022/include/openssl/opensslconf.h +17 -17
  307. package/vendor/zsign/build/windows/vs2022/include/openssl/ossl_typ.h +16 -16
  308. package/vendor/zsign/build/windows/vs2022/include/openssl/param_build.h +63 -63
  309. package/vendor/zsign/build/windows/vs2022/include/openssl/params.h +160 -160
  310. package/vendor/zsign/build/windows/vs2022/include/openssl/pem.h +543 -543
  311. package/vendor/zsign/build/windows/vs2022/include/openssl/pem2.h +19 -19
  312. package/vendor/zsign/build/windows/vs2022/include/openssl/pemerr.h +58 -58
  313. package/vendor/zsign/build/windows/vs2022/include/openssl/pkcs12err.h +46 -46
  314. package/vendor/zsign/build/windows/vs2022/include/openssl/pkcs7err.h +63 -63
  315. package/vendor/zsign/build/windows/vs2022/include/openssl/prov_ssl.h +38 -38
  316. package/vendor/zsign/build/windows/vs2022/include/openssl/proverr.h +162 -162
  317. package/vendor/zsign/build/windows/vs2022/include/openssl/provider.h +66 -66
  318. package/vendor/zsign/build/windows/vs2022/include/openssl/quic.h +70 -70
  319. package/vendor/zsign/build/windows/vs2022/include/openssl/rand.h +125 -125
  320. package/vendor/zsign/build/windows/vs2022/include/openssl/randerr.h +69 -69
  321. package/vendor/zsign/build/windows/vs2022/include/openssl/rc2.h +68 -68
  322. package/vendor/zsign/build/windows/vs2022/include/openssl/rc4.h +47 -47
  323. package/vendor/zsign/build/windows/vs2022/include/openssl/rc5.h +79 -79
  324. package/vendor/zsign/build/windows/vs2022/include/openssl/ripemd.h +59 -59
  325. package/vendor/zsign/build/windows/vs2022/include/openssl/rsa.h +615 -615
  326. package/vendor/zsign/build/windows/vs2022/include/openssl/rsaerr.h +107 -107
  327. package/vendor/zsign/build/windows/vs2022/include/openssl/seed.h +113 -113
  328. package/vendor/zsign/build/windows/vs2022/include/openssl/self_test.h +98 -98
  329. package/vendor/zsign/build/windows/vs2022/include/openssl/sha.h +139 -139
  330. package/vendor/zsign/build/windows/vs2022/include/openssl/srtp.h +68 -68
  331. package/vendor/zsign/build/windows/vs2022/include/openssl/ssl2.h +30 -30
  332. package/vendor/zsign/build/windows/vs2022/include/openssl/ssl3.h +357 -357
  333. package/vendor/zsign/build/windows/vs2022/include/openssl/sslerr.h +379 -379
  334. package/vendor/zsign/build/windows/vs2022/include/openssl/sslerr_legacy.h +467 -467
  335. package/vendor/zsign/build/windows/vs2022/include/openssl/stack.h +90 -90
  336. package/vendor/zsign/build/windows/vs2022/include/openssl/store.h +377 -377
  337. package/vendor/zsign/build/windows/vs2022/include/openssl/storeerr.h +49 -49
  338. package/vendor/zsign/build/windows/vs2022/include/openssl/symhacks.h +39 -39
  339. package/vendor/zsign/build/windows/vs2022/include/openssl/thread.h +31 -31
  340. package/vendor/zsign/build/windows/vs2022/include/openssl/tls1.h +1220 -1220
  341. package/vendor/zsign/build/windows/vs2022/include/openssl/trace.h +320 -320
  342. package/vendor/zsign/build/windows/vs2022/include/openssl/ts.h +522 -522
  343. package/vendor/zsign/build/windows/vs2022/include/openssl/tserr.h +67 -67
  344. package/vendor/zsign/build/windows/vs2022/include/openssl/txt_db.h +63 -63
  345. package/vendor/zsign/build/windows/vs2022/include/openssl/types.h +245 -245
  346. package/vendor/zsign/build/windows/vs2022/include/openssl/uierr.h +38 -38
  347. package/vendor/zsign/build/windows/vs2022/include/openssl/whrlpool.h +62 -62
  348. package/vendor/zsign/build/windows/vs2022/include/openssl/x509err.h +70 -70
  349. package/vendor/zsign/build/windows/vs2022/include/openssl/x509v3err.h +96 -96
  350. package/vendor/zsign/src/archo.cpp +742 -742
  351. package/vendor/zsign/src/archo.h +61 -61
  352. package/vendor/zsign/src/bundle.cpp +589 -589
  353. package/vendor/zsign/src/bundle.h +46 -46
  354. package/vendor/zsign/src/common/archive.cpp +246 -246
  355. package/vendor/zsign/src/common/archive.h +22 -22
  356. package/vendor/zsign/src/common/common.h +56 -56
  357. package/vendor/zsign/src/common/fs.cpp +573 -573
  358. package/vendor/zsign/src/common/fs.h +50 -50
  359. package/vendor/zsign/src/common/log.cpp +145 -145
  360. package/vendor/zsign/src/common/log.h +37 -37
  361. package/vendor/zsign/src/common/mach-o.h +585 -585
  362. package/vendor/zsign/src/common/sha.cpp +133 -133
  363. package/vendor/zsign/src/common/sha.h +24 -24
  364. package/vendor/zsign/src/common/timer.cpp +28 -28
  365. package/vendor/zsign/src/common/timer.h +17 -17
  366. package/vendor/zsign/src/common/util.cpp +185 -185
  367. package/vendor/zsign/src/common/util.h +25 -25
  368. package/vendor/zsign/src/macho.cpp +273 -273
  369. package/vendor/zsign/src/macho.h +38 -38
  370. package/vendor/zsign/src/openssl.cpp +698 -698
  371. package/vendor/zsign/src/openssl.h +71 -71
  372. package/vendor/zsign/src/signing.cpp +745 -745
  373. package/vendor/zsign/src/signing.h +59 -59
  374. package/vendor/zsign/src/zsign.cpp +317 -317
  375. package/vendor/zsign/test/dylib/demo/Makefile +12 -12
  376. package/vendor/zsign/test/dylib/demo/control +9 -9
  377. package/vendor/zsign/test/dylib/demo/demo.m +21 -21
  378. package/vendor/zsign/test/linux/test.sh +19 -19
  379. package/vendor/zsign/test/macos/test.sh +19 -19
@@ -1,698 +1,698 @@
1
- #include "common.h"
2
- #include "base64.h"
3
- #include "openssl.h"
4
- #include <openssl/pem.h>
5
- #include <openssl/cms.h>
6
- #include <openssl/err.h>
7
- #include <openssl/provider.h>
8
- #include <openssl/pkcs12.h>
9
- #include <openssl/conf.h>
10
-
11
- const char* ZSignAsset::s_szAppleDevCACert = ""
12
- "-----BEGIN CERTIFICATE-----\n"
13
- "MIIEIjCCAwqgAwIBAgIIAd68xDltoBAwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UE\n"
14
- "BhMCVVMxEzARBgNVBAoTCkFwcGxlIEluYy4xJjAkBgNVBAsTHUFwcGxlIENlcnRp\n"
15
- "ZmljYXRpb24gQXV0aG9yaXR5MRYwFAYDVQQDEw1BcHBsZSBSb290IEN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ZptOllc34MBvbKuKmFysa/Nw0Uwj6OD\n"
31
- "Dc4dR7Txk4qjdJukw5hyhzs+r0ULklS5MruQGFNrCk4QttkdUGwhgAqJTleMa1s8\n"
32
- "Pab93vcNIx0LSiaHP7qRkkykGRIZbVf1eliHe2iK5IaMSuviSRSqpd1VAKmuu0sw\n"
33
- "ruGgsbwpgOYJd+W+NKIByn/c4grmO7i77LpilfMFY0GCzQ87HUyVpNur+cmV6U/k\n"
34
- "TecmmYHpvPm0KdIBembhLoz2IYrF+Hjhga6/05Cdqa3zr/04GpZnMBxRpVzscYqC\n"
35
- "tGwPDBUf\n"
36
- "-----END CERTIFICATE-----\n";
37
-
38
- const char* ZSignAsset::s_szAppleDevCACertG3 = ""
39
- "-----BEGIN CERTIFICATE-----\n"
40
- "MIIEUTCCAzmgAwIBAgIQfK9pCiW3Of57m0R6wXjF7jANBgkqhkiG9w0BAQsFADBi\n"
41
- "MQswCQYDVQQGEwJVUzETMBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBw\n"
42
- "bGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3Qg\n"
43
- "Q0EwHhcNMjAwMjE5MTgxMzQ3WhcNMzAwMjIwMDAwMDAwWjB1MUQwQgYDVQQDDDtB\n"
44
- "cHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9ucyBDZXJ0aWZpY2F0aW9u\n"
45
- "IEF1dGhvcml0eTELMAkGA1UECwwCRzMxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJ\n"
46
- "BgNVBAYTAlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2PWJ/KhZ\n"
47
- "C4fHTJEuLVaQ03gdpDDppUjvC0O/LYT7JF1FG+XrWTYSXFRknmxiLbTGl8rMPPbW\n"
48
- "BpH85QKmHGq0edVny6zpPwcR4YS8Rx1mjjmi6LRJ7TrS4RBgeo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ICATE-----\n";
65
-
66
- const char* ZSignAsset::s_szAppleRootCACert = ""
67
- "-----BEGIN CERTIFICATE-----\n"
68
- "MIIEuzCCA6OgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzET\n"
69
- "MBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlv\n"
70
- "biBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwHhcNMDYwNDI1MjE0\n"
71
- "MDM2WhcNMzUwMjA5MjE0MDM2WjBiMQswCQYDVQQGEwJVUzETMBEGA1UEChMKQXBw\n"
72
- "bGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkx\n"
73
- "FjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw\n"
74
- "ggEKAoIBAQDkkakJH5HbHkdQ6wXtXnmELes2oldMVeyLGYne+Uts9QerIjAC6Bg+\n"
75
- "+FAJ039BqJj50cpmnCRrEdCju+QbKsMflZ56DKRHi1vUFjczy8QPTc4UadHJGXL1\n"
76
- "XQ7Vf1+b8iUDulWPTV0N8WQ1IxVLFVkds5T39pyez1C6wVhQZ48ItCD3y6wsIG9w\n"
77
- "tj8BMIy3Q88PnT3zK0koGsj+zrW5DtleHNbLPbU6rfQPDgCSC7EhFi501TwN22IW\n"
78
- "q6NxkkdTVcGvL0Gz+PvjcM3mo0xFfh9Ma1CWQYnEdGILEINBhzOKgbEwWOxaBDKM\n"
79
- "aLOPHd5lc/9nXmW8Sdh2nzMUZaF3lMktAgMBAAGjggF6MIIBdjAOBgNVHQ8BAf8E\n"
80
- "BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUK9BpR5R2Cf70a40uQKb3\n"
81
- "R01/CF4wHwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wggERBgNVHSAE\n"
82
- "ggEIMIIBBDCCAQAGCSqGSIb3Y2QFATCB8jAqBggrBgEFBQcCARYeaHR0cHM6Ly93\n"
83
- "d3cuYXBwbGUuY29tL2FwcGxlY2EvMIHDBggrBgEFBQcCAjCBthqBs1JlbGlhbmNl\n"
84
- "IG9uIHRoaXMgY2VydGlmaWNhdGUgYnkgYW55IHBhcnR5IGFzc3VtZXMgYWNjZXB0\n"
85
- "YW5jZSBvZiB0aGUgdGhlbiBhcHBsaWNhYmxlIHN0YW5kYXJkIHRlcm1zIGFuZCBj\n"
86
- "b25kaXRpb25zIG9mIHVzZSwgY2VydGlmaWNhdGUgcG9saWN5IGFuZCBjZXJ0aWZp\n"
87
- "Y2F0aW9uIHByYWN0aWNlIHN0YXRlbWVudHMuMA0GCSqGSIb3DQEBBQUAA4IBAQBc\n"
88
- "NplMLXi37Yyb3PN3m/J20ncwT8EfhYOFG5k9RzfyqZtAjizUsZAS2L70c5vu0mQP\n"
89
- "y3lPNNiiPvl4/2vIB+x9OYOLUyDTOMSxv5pPCmv/K/xZpwUJfBdAVhEedNO3iyM7\n"
90
- "R6PVbyTi69G3cN8PReEnyvFteO3ntRcXqNx+IjXKJdXZD9Zr1KIkIxH3oayPc4Fg\n"
91
- "xhtbCS+SsvhESPBgOJ4V9T0mZyCKM2r3DYLP3uujL/lTaltkwGMzd/c6ByxW69oP\n"
92
- "IQ7aunMZT7XZNn/Bh1XZp5m5MkL72NVxnn6hUrcbvZNCJBIqxw8dtk2cXmPIS4AX\n"
93
- "UKqK1drk/NAJBzewdXUh\n"
94
- "-----END CERTIFICATE-----\n";
95
-
96
- ZSignAsset::OpenSSLInit::OpenSSLInit()
97
- {
98
- #if OPENSSL_VERSION_NUMBER < 0x10100000L
99
- OpenSSL_add_all_algorithms();
100
- ERR_load_crypto_strings();
101
- #endif
102
- }
103
-
104
- bool ZSignAsset::CMSError()
105
- {
106
- ERR_print_errors_fp(stdout);
107
- return false;
108
- }
109
-
110
- void* ZSignAsset::GenerateASN1Type(const string& value)
111
- {
112
- long errline = -1;
113
- char* genstr = NULL;
114
- BIO* ldapbio = BIO_new(BIO_s_mem());
115
- CONF* cnf = NCONF_new(NULL);
116
-
117
- if (cnf == NULL) {
118
- ZLog::Error(">>> NCONF_new failed\n");
119
- BIO_free(ldapbio);
120
- }
121
- string a = "asn1=SEQUENCE:A\n[A]\nC=OBJECT:sha256\nB=FORMAT:HEX,OCT:" + value + "\n";
122
- int code = BIO_puts(ldapbio, a.c_str());
123
- if (NCONF_load_bio(cnf, ldapbio, &errline) <= 0) {
124
- BIO_free(ldapbio);
125
- NCONF_free(cnf);
126
- ZLog::PrintV(">>> NCONF_load_bio failed %d\n", errline);
127
- }
128
- BIO_free(ldapbio);
129
- genstr = NCONF_get_string(cnf, "default", "asn1");
130
-
131
- if (genstr == NULL) {
132
- ZLog::Error(">>> NCONF_get_string failed\n");
133
- NCONF_free(cnf);
134
- }
135
- ASN1_TYPE* ret = ASN1_generate_nconf(genstr, cnf);
136
- NCONF_free(cnf);
137
- return ret;
138
- }
139
-
140
- bool ZSignAsset::GenerateCMS(void* pscert, void* pspkey, const string& strCDHashData, const string& strCDHashesPlist, const string& strCodeDirectorySlotSHA1, const string& strAltnateCodeDirectorySlot256, string& strCMSOutput)
141
- {
142
- if (!pscert || !pspkey) {
143
- return CMSError();
144
- }
145
-
146
- X509* scert = (X509*)pscert;
147
- EVP_PKEY* spkey = (EVP_PKEY*)pspkey;
148
-
149
- BIO* bother1;
150
- unsigned long issuerHash = X509_issuer_name_hash(scert);
151
- if (0x817d2f7a == issuerHash) {
152
- bother1 = BIO_new_mem_buf(s_szAppleDevCACert, (int)strlen(s_szAppleDevCACert));
153
- } else if (0x9b16b75c == issuerHash) {
154
- bother1 = BIO_new_mem_buf(s_szAppleDevCACertG3, (int)strlen(s_szAppleDevCACertG3));
155
- } else {
156
- ZLog::Error(">>> Unknown issuer hash!\n");
157
- return false;
158
- }
159
-
160
- BIO* bother2 = BIO_new_mem_buf(s_szAppleRootCACert, (int)strlen(s_szAppleRootCACert));
161
- if (!bother1 || !bother2) {
162
- return CMSError();
163
- }
164
-
165
- X509* ocert1 = PEM_read_bio_X509(bother1, NULL, 0, NULL);
166
- X509* ocert2 = PEM_read_bio_X509(bother2, NULL, 0, NULL);
167
- if (!ocert1 || !ocert2) {
168
- return CMSError();
169
- }
170
-
171
- STACK_OF(X509)* otherCerts = sk_X509_new_null();
172
- if (!otherCerts) {
173
- return CMSError();
174
- }
175
-
176
- if (!sk_X509_push(otherCerts, ocert1)) {
177
- return CMSError();
178
- }
179
-
180
- if (!sk_X509_push(otherCerts, ocert2)) {
181
- return CMSError();
182
- }
183
-
184
- BIO* in = BIO_new_mem_buf(strCDHashData.c_str(), (int)strCDHashData.size());
185
- if (!in) {
186
- return CMSError();
187
- }
188
-
189
- int nFlags = CMS_PARTIAL | CMS_DETACHED | CMS_NOSMIMECAP | CMS_BINARY;
190
- CMS_ContentInfo* cms = CMS_sign(NULL, NULL, otherCerts, NULL, nFlags);
191
- if (!cms) {
192
- return CMSError();
193
- }
194
-
195
- CMS_SignerInfo* si = CMS_add1_signer(cms, scert, spkey, EVP_sha256(), nFlags);
196
- // CMS_add1_signer(cms, NULL, NULL, EVP_sha1(), nFlags);
197
- if (!si) {
198
- return CMSError();
199
- }
200
-
201
- // add plist
202
- ASN1_OBJECT* obj = OBJ_txt2obj("1.2.840.113635.100.9.1", 1);
203
- if (!obj) {
204
- return CMSError();
205
- }
206
-
207
- int addHashPlist = CMS_signed_add1_attr_by_OBJ(si, obj, 0x4, strCDHashesPlist.c_str(), (int)strCDHashesPlist.size());
208
-
209
- if (!addHashPlist) {
210
- return CMSError();
211
- }
212
-
213
- // add CDHashes
214
- string sha256;
215
- char buf[16] = { 0 };
216
- for (size_t i = 0; i < strAltnateCodeDirectorySlot256.size(); i++) {
217
- snprintf(buf, sizeof(buf), "%02x", (uint8_t)strAltnateCodeDirectorySlot256[i]);
218
- sha256 += buf;
219
- }
220
- transform(sha256.begin(), sha256.end(), sha256.begin(), ::toupper);
221
-
222
- ASN1_OBJECT* obj2 = OBJ_txt2obj("1.2.840.113635.100.9.2", 1);
223
- if (!obj2) {
224
- return CMSError();
225
- }
226
-
227
- X509_ATTRIBUTE* attr = X509_ATTRIBUTE_new();
228
- X509_ATTRIBUTE_set1_object(attr, obj2);
229
-
230
- ASN1_TYPE* type_256 = (ASN1_TYPE*)GenerateASN1Type(sha256);
231
- X509_ATTRIBUTE_set1_data(attr, V_ASN1_SEQUENCE,
232
- type_256->value.asn1_string->data, type_256->value.asn1_string->length);
233
- int addHashSHA = CMS_signed_add1_attr(si, attr);
234
- if (!addHashSHA) {
235
- return CMSError();
236
- }
237
-
238
- if (!CMS_final(cms, in, NULL, nFlags)) {
239
- return CMSError();
240
- }
241
-
242
- BIO* out = BIO_new(BIO_s_mem());
243
- if (!out) {
244
- return CMSError();
245
- }
246
-
247
- //PEM_write_bio_CMS(out, cms);
248
- if (!i2d_CMS_bio(out, cms)) {
249
- return CMSError();
250
- }
251
-
252
- BUF_MEM* bptr = NULL;
253
- BIO_get_mem_ptr(out, &bptr);
254
- if (!bptr) {
255
- return CMSError();
256
- }
257
-
258
- strCMSOutput.clear();
259
- strCMSOutput.append(bptr->data, bptr->length);
260
- ASN1_TYPE_free(type_256);
261
- return (!strCMSOutput.empty());
262
- }
263
-
264
- bool ZSignAsset::GetCMSContent(const string& strCMSDataInput, string& strContentOutput)
265
- {
266
- if (strCMSDataInput.empty()) {
267
- return false;
268
- }
269
-
270
- BIO* in = BIO_new(BIO_s_mem());
271
- OPENSSL_assert((size_t)BIO_write(in, strCMSDataInput.data(), (int)strCMSDataInput.size()) == strCMSDataInput.size());
272
- CMS_ContentInfo* cms = d2i_CMS_bio(in, NULL);
273
- if (!cms) {
274
- return CMSError();
275
- }
276
-
277
- ASN1_OCTET_STRING** pos = CMS_get0_content(cms);
278
- if (!pos) {
279
- return CMSError();
280
- }
281
-
282
- if (!(*pos)) {
283
- return CMSError();
284
- }
285
-
286
- strContentOutput.clear();
287
- strContentOutput.append((const char*)(*pos)->data, (*pos)->length);
288
- return (!strContentOutput.empty());
289
- }
290
-
291
- bool ZSignAsset::GetCertSubjectCN(void* pcert, string& strSubjectCN)
292
- {
293
- if (!pcert) {
294
- return CMSError();
295
- }
296
-
297
- X509* cert = (X509*)pcert;
298
-
299
- X509_NAME* name = X509_get_subject_name(cert);
300
-
301
- int common_name_loc = X509_NAME_get_index_by_NID(name, NID_commonName, -1);
302
- if (common_name_loc < 0) {
303
- return CMSError();
304
- }
305
-
306
- X509_NAME_ENTRY* common_name_entry = X509_NAME_get_entry(name, common_name_loc);
307
- if (common_name_entry == NULL) {
308
- return CMSError();
309
- }
310
-
311
- ASN1_STRING* common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry);
312
- if (common_name_asn1 == NULL) {
313
- return CMSError();
314
- }
315
-
316
- strSubjectCN.clear();
317
- strSubjectCN.append((const char*)common_name_asn1->data, common_name_asn1->length);
318
- return (!strSubjectCN.empty());
319
- }
320
-
321
- bool ZSignAsset::GetCertSubjectCN(const string& strCertData, string& strSubjectCN)
322
- {
323
- if (strCertData.empty()) {
324
- return false;
325
- }
326
-
327
- BIO* bcert = BIO_new_mem_buf(strCertData.c_str(), (int)strCertData.size());
328
- if (!bcert) {
329
- return CMSError();
330
- }
331
-
332
- X509* cert = PEM_read_bio_X509(bcert, NULL, 0, NULL);
333
- if (!cert) {
334
- return CMSError();
335
- }
336
-
337
- return GetCertSubjectCN(cert, strSubjectCN);
338
- }
339
-
340
- void ZSignAsset::ParseCertSubject(const string& strSubject, jvalue& jvSubject)
341
- {
342
- vector<string> arrNodes;
343
- ZUtil::StringSplit(strSubject, "/", arrNodes);
344
- for (size_t i = 0; i < arrNodes.size(); i++) {
345
- vector<string> arrLines;
346
- ZUtil::StringSplit(arrNodes[i], "=", arrLines);
347
- if (2 == arrLines.size()) {
348
- jvSubject[arrLines[0]] = arrLines[1];
349
- }
350
- }
351
- }
352
-
353
- string ZSignAsset::ASN1_TIMEtoString(const void* time)
354
- {
355
- BIO* out = BIO_new(BIO_s_mem());
356
- if (!out) {
357
- CMSError();
358
- return "";
359
- }
360
-
361
- ASN1_TIME_print(out, (const ASN1_TIME*)time);
362
- BUF_MEM* bptr = NULL;
363
- BIO_get_mem_ptr(out, &bptr);
364
- if (!bptr) {
365
- CMSError();
366
- return "";
367
- }
368
- string strTime;
369
- strTime.append(bptr->data, bptr->length);
370
- return strTime;
371
- }
372
-
373
- bool ZSignAsset::GetCertInfo(void* pcert, jvalue & jvCertInfo)
374
- {
375
- if (!pcert) {
376
- return CMSError();
377
- }
378
-
379
- X509* cert = (X509*)pcert;
380
-
381
- jvCertInfo["Version"] = (int)X509_get_version(cert);
382
-
383
- ASN1_INTEGER* asn1_i = X509_get_serialNumber(cert);
384
- if (asn1_i) {
385
- BIGNUM* bignum = ASN1_INTEGER_to_BN(asn1_i, NULL);
386
- if (bignum) {
387
- jvCertInfo["SerialNumber"] = BN_bn2hex(bignum);
388
- }
389
- }
390
-
391
- jvCertInfo["SignatureAlgorithm"] = OBJ_nid2ln(X509_get_signature_nid(cert));
392
-
393
- EVP_PKEY* pubkey = X509_get_pubkey(cert);
394
- int type = EVP_PKEY_id(pubkey);
395
- jvCertInfo["PublicKey"]["Algorithm"] = OBJ_nid2ln(type);
396
-
397
- #if OPENSSL_VERSION_NUMBER < 0x10100000L
398
- jvCertInfo["Validity"]["NotBefore"] = ASN1_TIMEtoString(X509_get_notBefore(cert));
399
- jvCertInfo["Validity"]["NotAfter"] = ASN1_TIMEtoString(X509_get_notAfter(cert));
400
- #else
401
- jvCertInfo["Validity"]["NotBefore"] = ASN1_TIMEtoString(X509_get0_notBefore(cert));
402
- jvCertInfo["Validity"]["NotAfter"] = ASN1_TIMEtoString(X509_get0_notAfter(cert));
403
- #endif
404
-
405
- string strIssuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
406
- string strSubject = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
407
-
408
- ParseCertSubject(strIssuer, jvCertInfo["Issuer"]);
409
- ParseCertSubject(strSubject, jvCertInfo["Subject"]);
410
-
411
- return (!strIssuer.empty() && !strSubject.empty());
412
- }
413
-
414
- bool ZSignAsset::GetCMSInfo(uint8_t * pCMSData, uint32_t uCMSLength, jvalue & jvOutput)
415
- {
416
- BIO* in = BIO_new(BIO_s_mem());
417
- OPENSSL_assert((size_t)BIO_write(in, pCMSData, uCMSLength) == uCMSLength);
418
- CMS_ContentInfo* cms = d2i_CMS_bio(in, NULL);
419
- if (!cms) {
420
- return CMSError();
421
- }
422
-
423
- int detached = CMS_is_detached(cms);
424
- jvOutput["detached"] = detached;
425
-
426
- const ASN1_OBJECT* obj = CMS_get0_type(cms);
427
- const char* sn = OBJ_nid2ln(OBJ_obj2nid(obj));
428
- jvOutput["contentType"] = sn;
429
-
430
- ASN1_OCTET_STRING** pos = CMS_get0_content(cms);
431
- if (pos) {
432
- if ((*pos)) {
433
- jbase64 b64;
434
- jvOutput["content"] = b64.encode((const char*)(*pos)->data, (*pos)->length);
435
- }
436
- }
437
-
438
- STACK_OF(X509)* certs = CMS_get1_certs(cms);
439
- for (int i = 0; i < sk_X509_num(certs); i++) {
440
- jvalue jvCertInfo;
441
- if (GetCertInfo(sk_X509_value(certs, i), jvCertInfo)) {
442
- jvOutput["certs"].push_back(jvCertInfo);
443
- }
444
- }
445
-
446
- STACK_OF(CMS_SignerInfo)* sis = CMS_get0_SignerInfos(cms);
447
- for (int i = 0; i < sk_CMS_SignerInfo_num(sis); i++) {
448
- CMS_SignerInfo* si = sk_CMS_SignerInfo_value(sis, i);
449
- //int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, ASN1_OCTET_STRING **keyid, X509_NAME **issuer, ASN1_INTEGER **sno);
450
-
451
- int nSignedAttsCount = CMS_signed_get_attr_count(si);
452
- for (int j = 0; j < nSignedAttsCount; j++) {
453
- X509_ATTRIBUTE* attr = CMS_signed_get_attr(si, j);
454
- if (!attr) {
455
- continue;
456
- }
457
- int nCount = X509_ATTRIBUTE_count(attr);
458
- if (nCount <= 0) {
459
- continue;
460
- }
461
-
462
- ASN1_OBJECT* obj = X509_ATTRIBUTE_get0_object(attr);
463
- if (!obj) {
464
- continue;
465
- }
466
-
467
- char txtobj[128] = { 0 };
468
- OBJ_obj2txt(txtobj, 128, obj, 1);
469
-
470
- if (0 == strcmp("1.2.840.113549.1.9.3", txtobj)) { //V_ASN1_OBJECT
471
- ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
472
- if (NULL != av) {
473
- jvOutput["attrs"]["ContentType"]["obj"] = txtobj;
474
- jvOutput["attrs"]["ContentType"]["data"] = OBJ_nid2ln(OBJ_obj2nid(av->value.object));
475
- }
476
- } else if (0 == strcmp("1.2.840.113549.1.9.4", txtobj)) { //V_ASN1_OCTET_STRING
477
- ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
478
- if (NULL != av) {
479
- string strSHASum;
480
- char buf[16] = { 0 };
481
- for (int m = 0; m < av->value.octet_string->length; m++) {
482
- snprintf(buf, sizeof(buf), "%02x", (uint8_t)av->value.octet_string->data[m]);
483
- strSHASum += buf;
484
- }
485
- jvOutput["attrs"]["MessageDigest"]["obj"] = txtobj;
486
- jvOutput["attrs"]["MessageDigest"]["data"] = strSHASum;
487
- }
488
- } else if (0 == strcmp("1.2.840.113549.1.9.5", txtobj)) { //V_ASN1_UTCTIME
489
- ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
490
- if (NULL != av) {
491
- BIO* mem = BIO_new(BIO_s_mem());
492
- ASN1_UTCTIME_print(mem, av->value.utctime);
493
- BUF_MEM* bptr = NULL;
494
- BIO_get_mem_ptr(mem, &bptr);
495
- BIO_set_close(mem, BIO_NOCLOSE);
496
- string strTime;
497
- strTime.append(bptr->data, bptr->length);
498
- BIO_free_all(mem);
499
-
500
- jvOutput["attrs"]["SigningTime"]["obj"] = txtobj;
501
- jvOutput["attrs"]["SigningTime"]["data"] = strTime;
502
- }
503
- } else if (0 == strcmp("1.2.840.113635.100.9.2", txtobj)) { //V_ASN1_SEQUENCE
504
- jvOutput["attrs"]["CDHashes2"]["obj"] = txtobj;
505
- for (int m = 0; m < nCount; m++) {
506
- ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, m);
507
- if (NULL != av) {
508
- ASN1_STRING* s = av->value.sequence;
509
-
510
- BIO* mem = BIO_new(BIO_s_mem());
511
-
512
- ASN1_parse_dump(mem, s->data, s->length, 2, 0);
513
- BUF_MEM* bptr = NULL;
514
- BIO_get_mem_ptr(mem, &bptr);
515
- BIO_set_close(mem, BIO_NOCLOSE);
516
- string strData;
517
- strData.append(bptr->data, bptr->length);
518
- BIO_free_all(mem);
519
-
520
- string strSHASum;
521
- size_t pos1 = strData.find("[HEX DUMP]:");
522
- if (string::npos != pos1) {
523
- size_t pos2 = strData.find("\n", pos1);
524
- if (string::npos != pos2) {
525
- strSHASum = strData.substr(pos1 + 11, pos2 - pos1 - 11);
526
- }
527
- }
528
- transform(strSHASum.begin(), strSHASum.end(), strSHASum.begin(), ::tolower);
529
- jvOutput["attrs"]["CDHashes2"]["data"].push_back(strSHASum);
530
- }
531
- }
532
- } else if (0 == strcmp("1.2.840.113635.100.9.1", txtobj)) { //V_ASN1_OCTET_STRING
533
- ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
534
- if (NULL != av) {
535
- string strPList;
536
- strPList.append((const char*)av->value.octet_string->data, av->value.octet_string->length);
537
- jvOutput["attrs"]["CDHashes"]["obj"] = txtobj;
538
- jvOutput["attrs"]["CDHashes"]["data"] = strPList;
539
- }
540
- } else {
541
- ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
542
- if (NULL != av) {
543
- jvalue jvAttr;
544
- jvAttr["obj"] = txtobj;
545
- jvAttr["name"] = OBJ_nid2ln(OBJ_obj2nid(obj));
546
- jvAttr["type"] = av->type;
547
- jvAttr["count"] = nCount;
548
- jvOutput["attrs"]["unknown"].push_back(jvAttr);
549
- }
550
- }
551
- }
552
- }
553
-
554
- return true;
555
- }
556
-
557
- ZSignAsset::ZSignAsset()
558
- {
559
- m_evpPKey = NULL;
560
- m_x509Cert = NULL;
561
- m_bAdhoc = false;
562
- m_bSingleBinary = false;
563
- m_bSHA256Only = false;
564
- }
565
-
566
- bool ZSignAsset::Init(
567
- const string& strCertFile,
568
- const string& strPKeyFile,
569
- const string& strProvFile,
570
- const string& strEntitleFile,
571
- const string& strPassword,
572
- bool bAdhoc,
573
- bool bSHA256Only,
574
- bool bSingleBinary)
575
- {
576
- m_bAdhoc = bAdhoc;
577
- m_bSHA256Only = bSHA256Only;
578
- m_bSingleBinary = bSingleBinary;
579
-
580
- if (m_bAdhoc) {
581
- if (!strEntitleFile.empty()) {
582
- if (!ZFile::ReadFile(strEntitleFile.c_str(), m_strEntitleData)) {
583
- ZLog::Error(">>> Can't read entitlements file!\n");
584
- return false;
585
- }
586
- }
587
- return true;
588
- }
589
-
590
- ZFile::ReadFile(strProvFile.c_str(), m_strProvData);
591
- ZFile::ReadFile(strEntitleFile.c_str(), m_strEntitleData);
592
- if (m_strProvData.empty()) {
593
- ZLog::Error(">>> Can't find provision file!\n");
594
- return false;
595
- }
596
-
597
- jvalue jvProv;
598
- string strProvContent;
599
- if (GetCMSContent(m_strProvData, strProvContent)) {
600
- if (jvProv.read_plist(strProvContent)) {
601
- m_strTeamId = jvProv["TeamIdentifier"][0].as_cstr();
602
- if (m_strEntitleData.empty()) {
603
- jvProv["Entitlements"].style_write_plist(m_strEntitleData);
604
- }
605
- }
606
- }
607
-
608
- if (m_strTeamId.empty()) {
609
- ZLog::Error(">>> Can't find TeamId!\n");
610
- return false;
611
- }
612
-
613
- X509* x509Cert = NULL;
614
- EVP_PKEY* evpPKey = NULL;
615
- BIO* bioPKey = BIO_new_file(strPKeyFile.c_str(), "rb");
616
- if (NULL != bioPKey) {
617
- evpPKey = PEM_read_bio_PrivateKey(bioPKey, NULL, NULL, (void*)strPassword.c_str());
618
- if (NULL == evpPKey) {
619
- BIO_reset(bioPKey);
620
- evpPKey = d2i_PrivateKey_bio(bioPKey, NULL);
621
- if (NULL == evpPKey) {
622
- BIO_reset(bioPKey);
623
- OSSL_PROVIDER_load(NULL, "legacy");
624
- PKCS12* p12 = d2i_PKCS12_bio(bioPKey, NULL);
625
- if (NULL != p12) {
626
- if (0 == PKCS12_parse(p12, strPassword.c_str(), &evpPKey, &x509Cert, NULL)) {
627
- CMSError();
628
- }
629
- PKCS12_free(p12);
630
- } else {
631
- CMSError();
632
- }
633
- }
634
- }
635
- BIO_free(bioPKey);
636
- }
637
-
638
- if (NULL == evpPKey) {
639
- ZLog::Error(">>> Can't load p12 or private key file. Please input the correct file and password!\n");
640
- return false;
641
- }
642
-
643
- if (NULL == x509Cert && !strCertFile.empty()) {
644
- BIO* bioCert = BIO_new_file(strCertFile.c_str(), "r");
645
- if (NULL != bioCert) {
646
- x509Cert = PEM_read_bio_X509(bioCert, NULL, 0, NULL);
647
- if (NULL == x509Cert) {
648
- BIO_reset(bioCert);
649
- x509Cert = d2i_X509_bio(bioCert, NULL);
650
- }
651
- BIO_free(bioCert);
652
- }
653
- }
654
-
655
- if (NULL != x509Cert) {
656
- if (!X509_check_private_key(x509Cert, evpPKey)) {
657
- X509_free(x509Cert);
658
- x509Cert = NULL;
659
- }
660
- }
661
-
662
- if (NULL == x509Cert) {
663
- for (size_t i = 0; i < jvProv["DeveloperCertificates"].size(); i++) {
664
- string strCertData = jvProv["DeveloperCertificates"][i].as_data();
665
- BIO* bioCert = BIO_new_mem_buf(strCertData.c_str(), (int)strCertData.size());
666
- if (NULL != bioCert) {
667
- x509Cert = d2i_X509_bio(bioCert, NULL);
668
- if (NULL != x509Cert) {
669
- if (X509_check_private_key(x509Cert, evpPKey)) {
670
- break;
671
- }
672
- X509_free(x509Cert);
673
- x509Cert = NULL;
674
- }
675
- BIO_free(bioCert);
676
- }
677
- }
678
- }
679
-
680
- if (NULL == x509Cert) {
681
- ZLog::Error(">>> Can't find paired certificate and private key!\n");
682
- return false;
683
- }
684
-
685
- if (!GetCertSubjectCN(x509Cert, m_strSubjectCN)) {
686
- ZLog::Error(">>> Can't find paired certificate subject common name!\n");
687
- return false;
688
- }
689
-
690
- m_evpPKey = evpPKey;
691
- m_x509Cert = x509Cert;
692
- return true;
693
- }
694
-
695
- bool ZSignAsset::GenerateCMS(const string& strCDHashData, const string& strCDHashesPlist, const string& strCodeDirectorySlotSHA1, const string& strAltnateCodeDirectorySlot256, string& strCMSOutput)
696
- {
697
- return GenerateCMS((X509*)m_x509Cert, (EVP_PKEY*)m_evpPKey, strCDHashData, strCDHashesPlist, strCodeDirectorySlotSHA1, strAltnateCodeDirectorySlot256, strCMSOutput);
698
- }
1
+ #include "common.h"
2
+ #include "base64.h"
3
+ #include "openssl.h"
4
+ #include <openssl/pem.h>
5
+ #include <openssl/cms.h>
6
+ #include <openssl/err.h>
7
+ #include <openssl/provider.h>
8
+ #include <openssl/pkcs12.h>
9
+ #include <openssl/conf.h>
10
+
11
+ const char* ZSignAsset::s_szAppleDevCACert = ""
12
+ "-----BEGIN CERTIFICATE-----\n"
13
+ "MIIEIjCCAwqgAwIBAgIIAd68xDltoBAwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UE\n"
14
+ "BhMCVVMxEzARBgNVBAoTCkFwcGxlIEluYy4xJjAkBgNVBAsTHUFwcGxlIENlcnRp\n"
15
+ "ZmljYXRpb24gQXV0aG9yaXR5MRYwFAYDVQQDEw1BcHBsZSBSb290IENBMB4XDTEz\n"
16
+ "MDIwNzIxNDg0N1oXDTIzMDIwNzIxNDg0N1owgZYxCzAJBgNVBAYTAlVTMRMwEQYD\n"
17
+ "VQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3JsZHdpZGUgRGV2ZWxv\n"
18
+ "cGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3aWRlIERldmVsb3Bl\n"
19
+ "ciBSZWxhdG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VydGlmaWNhdGUgYnkgYW55IHBhcnR5IGFzc3VtZXMgYWNjZXB0\n"
85
+ "YW5jZSBvZiB0aGUgdGhlbiBhcHBsaWNhYmxlIHN0YW5kYXJkIHRlcm1zIGFuZCBj\n"
86
+ "b25kaXRpb25zIG9mIHVzZSwgY2VydGlmaWNhdGUgcG9saWN5IGFuZCBjZXJ0aWZp\n"
87
+ "Y2F0aW9uIHByYWN0aWNlIHN0YXRlbWVudHMuMA0GCSqGSIb3DQEBBQUAA4IBAQBc\n"
88
+ "NplMLXi37Yyb3PN3m/J20ncwT8EfhYOFG5k9RzfyqZtAjizUsZAS2L70c5vu0mQP\n"
89
+ "y3lPNNiiPvl4/2vIB+x9OYOLUyDTOMSxv5pPCmv/K/xZpwUJfBdAVhEedNO3iyM7\n"
90
+ "R6PVbyTi69G3cN8PReEnyvFteO3ntRcXqNx+IjXKJdXZD9Zr1KIkIxH3oayPc4Fg\n"
91
+ "xhtbCS+SsvhESPBgOJ4V9T0mZyCKM2r3DYLP3uujL/lTaltkwGMzd/c6ByxW69oP\n"
92
+ "IQ7aunMZT7XZNn/Bh1XZp5m5MkL72NVxnn6hUrcbvZNCJBIqxw8dtk2cXmPIS4AX\n"
93
+ "UKqK1drk/NAJBzewdXUh\n"
94
+ "-----END CERTIFICATE-----\n";
95
+
96
+ ZSignAsset::OpenSSLInit::OpenSSLInit()
97
+ {
98
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
99
+ OpenSSL_add_all_algorithms();
100
+ ERR_load_crypto_strings();
101
+ #endif
102
+ }
103
+
104
+ bool ZSignAsset::CMSError()
105
+ {
106
+ ERR_print_errors_fp(stdout);
107
+ return false;
108
+ }
109
+
110
+ void* ZSignAsset::GenerateASN1Type(const string& value)
111
+ {
112
+ long errline = -1;
113
+ char* genstr = NULL;
114
+ BIO* ldapbio = BIO_new(BIO_s_mem());
115
+ CONF* cnf = NCONF_new(NULL);
116
+
117
+ if (cnf == NULL) {
118
+ ZLog::Error(">>> NCONF_new failed\n");
119
+ BIO_free(ldapbio);
120
+ }
121
+ string a = "asn1=SEQUENCE:A\n[A]\nC=OBJECT:sha256\nB=FORMAT:HEX,OCT:" + value + "\n";
122
+ int code = BIO_puts(ldapbio, a.c_str());
123
+ if (NCONF_load_bio(cnf, ldapbio, &errline) <= 0) {
124
+ BIO_free(ldapbio);
125
+ NCONF_free(cnf);
126
+ ZLog::PrintV(">>> NCONF_load_bio failed %d\n", errline);
127
+ }
128
+ BIO_free(ldapbio);
129
+ genstr = NCONF_get_string(cnf, "default", "asn1");
130
+
131
+ if (genstr == NULL) {
132
+ ZLog::Error(">>> NCONF_get_string failed\n");
133
+ NCONF_free(cnf);
134
+ }
135
+ ASN1_TYPE* ret = ASN1_generate_nconf(genstr, cnf);
136
+ NCONF_free(cnf);
137
+ return ret;
138
+ }
139
+
140
+ bool ZSignAsset::GenerateCMS(void* pscert, void* pspkey, const string& strCDHashData, const string& strCDHashesPlist, const string& strCodeDirectorySlotSHA1, const string& strAltnateCodeDirectorySlot256, string& strCMSOutput)
141
+ {
142
+ if (!pscert || !pspkey) {
143
+ return CMSError();
144
+ }
145
+
146
+ X509* scert = (X509*)pscert;
147
+ EVP_PKEY* spkey = (EVP_PKEY*)pspkey;
148
+
149
+ BIO* bother1;
150
+ unsigned long issuerHash = X509_issuer_name_hash(scert);
151
+ if (0x817d2f7a == issuerHash) {
152
+ bother1 = BIO_new_mem_buf(s_szAppleDevCACert, (int)strlen(s_szAppleDevCACert));
153
+ } else if (0x9b16b75c == issuerHash) {
154
+ bother1 = BIO_new_mem_buf(s_szAppleDevCACertG3, (int)strlen(s_szAppleDevCACertG3));
155
+ } else {
156
+ ZLog::Error(">>> Unknown issuer hash!\n");
157
+ return false;
158
+ }
159
+
160
+ BIO* bother2 = BIO_new_mem_buf(s_szAppleRootCACert, (int)strlen(s_szAppleRootCACert));
161
+ if (!bother1 || !bother2) {
162
+ return CMSError();
163
+ }
164
+
165
+ X509* ocert1 = PEM_read_bio_X509(bother1, NULL, 0, NULL);
166
+ X509* ocert2 = PEM_read_bio_X509(bother2, NULL, 0, NULL);
167
+ if (!ocert1 || !ocert2) {
168
+ return CMSError();
169
+ }
170
+
171
+ STACK_OF(X509)* otherCerts = sk_X509_new_null();
172
+ if (!otherCerts) {
173
+ return CMSError();
174
+ }
175
+
176
+ if (!sk_X509_push(otherCerts, ocert1)) {
177
+ return CMSError();
178
+ }
179
+
180
+ if (!sk_X509_push(otherCerts, ocert2)) {
181
+ return CMSError();
182
+ }
183
+
184
+ BIO* in = BIO_new_mem_buf(strCDHashData.c_str(), (int)strCDHashData.size());
185
+ if (!in) {
186
+ return CMSError();
187
+ }
188
+
189
+ int nFlags = CMS_PARTIAL | CMS_DETACHED | CMS_NOSMIMECAP | CMS_BINARY;
190
+ CMS_ContentInfo* cms = CMS_sign(NULL, NULL, otherCerts, NULL, nFlags);
191
+ if (!cms) {
192
+ return CMSError();
193
+ }
194
+
195
+ CMS_SignerInfo* si = CMS_add1_signer(cms, scert, spkey, EVP_sha256(), nFlags);
196
+ // CMS_add1_signer(cms, NULL, NULL, EVP_sha1(), nFlags);
197
+ if (!si) {
198
+ return CMSError();
199
+ }
200
+
201
+ // add plist
202
+ ASN1_OBJECT* obj = OBJ_txt2obj("1.2.840.113635.100.9.1", 1);
203
+ if (!obj) {
204
+ return CMSError();
205
+ }
206
+
207
+ int addHashPlist = CMS_signed_add1_attr_by_OBJ(si, obj, 0x4, strCDHashesPlist.c_str(), (int)strCDHashesPlist.size());
208
+
209
+ if (!addHashPlist) {
210
+ return CMSError();
211
+ }
212
+
213
+ // add CDHashes
214
+ string sha256;
215
+ char buf[16] = { 0 };
216
+ for (size_t i = 0; i < strAltnateCodeDirectorySlot256.size(); i++) {
217
+ snprintf(buf, sizeof(buf), "%02x", (uint8_t)strAltnateCodeDirectorySlot256[i]);
218
+ sha256 += buf;
219
+ }
220
+ transform(sha256.begin(), sha256.end(), sha256.begin(), ::toupper);
221
+
222
+ ASN1_OBJECT* obj2 = OBJ_txt2obj("1.2.840.113635.100.9.2", 1);
223
+ if (!obj2) {
224
+ return CMSError();
225
+ }
226
+
227
+ X509_ATTRIBUTE* attr = X509_ATTRIBUTE_new();
228
+ X509_ATTRIBUTE_set1_object(attr, obj2);
229
+
230
+ ASN1_TYPE* type_256 = (ASN1_TYPE*)GenerateASN1Type(sha256);
231
+ X509_ATTRIBUTE_set1_data(attr, V_ASN1_SEQUENCE,
232
+ type_256->value.asn1_string->data, type_256->value.asn1_string->length);
233
+ int addHashSHA = CMS_signed_add1_attr(si, attr);
234
+ if (!addHashSHA) {
235
+ return CMSError();
236
+ }
237
+
238
+ if (!CMS_final(cms, in, NULL, nFlags)) {
239
+ return CMSError();
240
+ }
241
+
242
+ BIO* out = BIO_new(BIO_s_mem());
243
+ if (!out) {
244
+ return CMSError();
245
+ }
246
+
247
+ //PEM_write_bio_CMS(out, cms);
248
+ if (!i2d_CMS_bio(out, cms)) {
249
+ return CMSError();
250
+ }
251
+
252
+ BUF_MEM* bptr = NULL;
253
+ BIO_get_mem_ptr(out, &bptr);
254
+ if (!bptr) {
255
+ return CMSError();
256
+ }
257
+
258
+ strCMSOutput.clear();
259
+ strCMSOutput.append(bptr->data, bptr->length);
260
+ ASN1_TYPE_free(type_256);
261
+ return (!strCMSOutput.empty());
262
+ }
263
+
264
+ bool ZSignAsset::GetCMSContent(const string& strCMSDataInput, string& strContentOutput)
265
+ {
266
+ if (strCMSDataInput.empty()) {
267
+ return false;
268
+ }
269
+
270
+ BIO* in = BIO_new(BIO_s_mem());
271
+ OPENSSL_assert((size_t)BIO_write(in, strCMSDataInput.data(), (int)strCMSDataInput.size()) == strCMSDataInput.size());
272
+ CMS_ContentInfo* cms = d2i_CMS_bio(in, NULL);
273
+ if (!cms) {
274
+ return CMSError();
275
+ }
276
+
277
+ ASN1_OCTET_STRING** pos = CMS_get0_content(cms);
278
+ if (!pos) {
279
+ return CMSError();
280
+ }
281
+
282
+ if (!(*pos)) {
283
+ return CMSError();
284
+ }
285
+
286
+ strContentOutput.clear();
287
+ strContentOutput.append((const char*)(*pos)->data, (*pos)->length);
288
+ return (!strContentOutput.empty());
289
+ }
290
+
291
+ bool ZSignAsset::GetCertSubjectCN(void* pcert, string& strSubjectCN)
292
+ {
293
+ if (!pcert) {
294
+ return CMSError();
295
+ }
296
+
297
+ X509* cert = (X509*)pcert;
298
+
299
+ X509_NAME* name = X509_get_subject_name(cert);
300
+
301
+ int common_name_loc = X509_NAME_get_index_by_NID(name, NID_commonName, -1);
302
+ if (common_name_loc < 0) {
303
+ return CMSError();
304
+ }
305
+
306
+ X509_NAME_ENTRY* common_name_entry = X509_NAME_get_entry(name, common_name_loc);
307
+ if (common_name_entry == NULL) {
308
+ return CMSError();
309
+ }
310
+
311
+ ASN1_STRING* common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry);
312
+ if (common_name_asn1 == NULL) {
313
+ return CMSError();
314
+ }
315
+
316
+ strSubjectCN.clear();
317
+ strSubjectCN.append((const char*)common_name_asn1->data, common_name_asn1->length);
318
+ return (!strSubjectCN.empty());
319
+ }
320
+
321
+ bool ZSignAsset::GetCertSubjectCN(const string& strCertData, string& strSubjectCN)
322
+ {
323
+ if (strCertData.empty()) {
324
+ return false;
325
+ }
326
+
327
+ BIO* bcert = BIO_new_mem_buf(strCertData.c_str(), (int)strCertData.size());
328
+ if (!bcert) {
329
+ return CMSError();
330
+ }
331
+
332
+ X509* cert = PEM_read_bio_X509(bcert, NULL, 0, NULL);
333
+ if (!cert) {
334
+ return CMSError();
335
+ }
336
+
337
+ return GetCertSubjectCN(cert, strSubjectCN);
338
+ }
339
+
340
+ void ZSignAsset::ParseCertSubject(const string& strSubject, jvalue& jvSubject)
341
+ {
342
+ vector<string> arrNodes;
343
+ ZUtil::StringSplit(strSubject, "/", arrNodes);
344
+ for (size_t i = 0; i < arrNodes.size(); i++) {
345
+ vector<string> arrLines;
346
+ ZUtil::StringSplit(arrNodes[i], "=", arrLines);
347
+ if (2 == arrLines.size()) {
348
+ jvSubject[arrLines[0]] = arrLines[1];
349
+ }
350
+ }
351
+ }
352
+
353
+ string ZSignAsset::ASN1_TIMEtoString(const void* time)
354
+ {
355
+ BIO* out = BIO_new(BIO_s_mem());
356
+ if (!out) {
357
+ CMSError();
358
+ return "";
359
+ }
360
+
361
+ ASN1_TIME_print(out, (const ASN1_TIME*)time);
362
+ BUF_MEM* bptr = NULL;
363
+ BIO_get_mem_ptr(out, &bptr);
364
+ if (!bptr) {
365
+ CMSError();
366
+ return "";
367
+ }
368
+ string strTime;
369
+ strTime.append(bptr->data, bptr->length);
370
+ return strTime;
371
+ }
372
+
373
+ bool ZSignAsset::GetCertInfo(void* pcert, jvalue & jvCertInfo)
374
+ {
375
+ if (!pcert) {
376
+ return CMSError();
377
+ }
378
+
379
+ X509* cert = (X509*)pcert;
380
+
381
+ jvCertInfo["Version"] = (int)X509_get_version(cert);
382
+
383
+ ASN1_INTEGER* asn1_i = X509_get_serialNumber(cert);
384
+ if (asn1_i) {
385
+ BIGNUM* bignum = ASN1_INTEGER_to_BN(asn1_i, NULL);
386
+ if (bignum) {
387
+ jvCertInfo["SerialNumber"] = BN_bn2hex(bignum);
388
+ }
389
+ }
390
+
391
+ jvCertInfo["SignatureAlgorithm"] = OBJ_nid2ln(X509_get_signature_nid(cert));
392
+
393
+ EVP_PKEY* pubkey = X509_get_pubkey(cert);
394
+ int type = EVP_PKEY_id(pubkey);
395
+ jvCertInfo["PublicKey"]["Algorithm"] = OBJ_nid2ln(type);
396
+
397
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
398
+ jvCertInfo["Validity"]["NotBefore"] = ASN1_TIMEtoString(X509_get_notBefore(cert));
399
+ jvCertInfo["Validity"]["NotAfter"] = ASN1_TIMEtoString(X509_get_notAfter(cert));
400
+ #else
401
+ jvCertInfo["Validity"]["NotBefore"] = ASN1_TIMEtoString(X509_get0_notBefore(cert));
402
+ jvCertInfo["Validity"]["NotAfter"] = ASN1_TIMEtoString(X509_get0_notAfter(cert));
403
+ #endif
404
+
405
+ string strIssuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
406
+ string strSubject = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
407
+
408
+ ParseCertSubject(strIssuer, jvCertInfo["Issuer"]);
409
+ ParseCertSubject(strSubject, jvCertInfo["Subject"]);
410
+
411
+ return (!strIssuer.empty() && !strSubject.empty());
412
+ }
413
+
414
+ bool ZSignAsset::GetCMSInfo(uint8_t * pCMSData, uint32_t uCMSLength, jvalue & jvOutput)
415
+ {
416
+ BIO* in = BIO_new(BIO_s_mem());
417
+ OPENSSL_assert((size_t)BIO_write(in, pCMSData, uCMSLength) == uCMSLength);
418
+ CMS_ContentInfo* cms = d2i_CMS_bio(in, NULL);
419
+ if (!cms) {
420
+ return CMSError();
421
+ }
422
+
423
+ int detached = CMS_is_detached(cms);
424
+ jvOutput["detached"] = detached;
425
+
426
+ const ASN1_OBJECT* obj = CMS_get0_type(cms);
427
+ const char* sn = OBJ_nid2ln(OBJ_obj2nid(obj));
428
+ jvOutput["contentType"] = sn;
429
+
430
+ ASN1_OCTET_STRING** pos = CMS_get0_content(cms);
431
+ if (pos) {
432
+ if ((*pos)) {
433
+ jbase64 b64;
434
+ jvOutput["content"] = b64.encode((const char*)(*pos)->data, (*pos)->length);
435
+ }
436
+ }
437
+
438
+ STACK_OF(X509)* certs = CMS_get1_certs(cms);
439
+ for (int i = 0; i < sk_X509_num(certs); i++) {
440
+ jvalue jvCertInfo;
441
+ if (GetCertInfo(sk_X509_value(certs, i), jvCertInfo)) {
442
+ jvOutput["certs"].push_back(jvCertInfo);
443
+ }
444
+ }
445
+
446
+ STACK_OF(CMS_SignerInfo)* sis = CMS_get0_SignerInfos(cms);
447
+ for (int i = 0; i < sk_CMS_SignerInfo_num(sis); i++) {
448
+ CMS_SignerInfo* si = sk_CMS_SignerInfo_value(sis, i);
449
+ //int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, ASN1_OCTET_STRING **keyid, X509_NAME **issuer, ASN1_INTEGER **sno);
450
+
451
+ int nSignedAttsCount = CMS_signed_get_attr_count(si);
452
+ for (int j = 0; j < nSignedAttsCount; j++) {
453
+ X509_ATTRIBUTE* attr = CMS_signed_get_attr(si, j);
454
+ if (!attr) {
455
+ continue;
456
+ }
457
+ int nCount = X509_ATTRIBUTE_count(attr);
458
+ if (nCount <= 0) {
459
+ continue;
460
+ }
461
+
462
+ ASN1_OBJECT* obj = X509_ATTRIBUTE_get0_object(attr);
463
+ if (!obj) {
464
+ continue;
465
+ }
466
+
467
+ char txtobj[128] = { 0 };
468
+ OBJ_obj2txt(txtobj, 128, obj, 1);
469
+
470
+ if (0 == strcmp("1.2.840.113549.1.9.3", txtobj)) { //V_ASN1_OBJECT
471
+ ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
472
+ if (NULL != av) {
473
+ jvOutput["attrs"]["ContentType"]["obj"] = txtobj;
474
+ jvOutput["attrs"]["ContentType"]["data"] = OBJ_nid2ln(OBJ_obj2nid(av->value.object));
475
+ }
476
+ } else if (0 == strcmp("1.2.840.113549.1.9.4", txtobj)) { //V_ASN1_OCTET_STRING
477
+ ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
478
+ if (NULL != av) {
479
+ string strSHASum;
480
+ char buf[16] = { 0 };
481
+ for (int m = 0; m < av->value.octet_string->length; m++) {
482
+ snprintf(buf, sizeof(buf), "%02x", (uint8_t)av->value.octet_string->data[m]);
483
+ strSHASum += buf;
484
+ }
485
+ jvOutput["attrs"]["MessageDigest"]["obj"] = txtobj;
486
+ jvOutput["attrs"]["MessageDigest"]["data"] = strSHASum;
487
+ }
488
+ } else if (0 == strcmp("1.2.840.113549.1.9.5", txtobj)) { //V_ASN1_UTCTIME
489
+ ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
490
+ if (NULL != av) {
491
+ BIO* mem = BIO_new(BIO_s_mem());
492
+ ASN1_UTCTIME_print(mem, av->value.utctime);
493
+ BUF_MEM* bptr = NULL;
494
+ BIO_get_mem_ptr(mem, &bptr);
495
+ BIO_set_close(mem, BIO_NOCLOSE);
496
+ string strTime;
497
+ strTime.append(bptr->data, bptr->length);
498
+ BIO_free_all(mem);
499
+
500
+ jvOutput["attrs"]["SigningTime"]["obj"] = txtobj;
501
+ jvOutput["attrs"]["SigningTime"]["data"] = strTime;
502
+ }
503
+ } else if (0 == strcmp("1.2.840.113635.100.9.2", txtobj)) { //V_ASN1_SEQUENCE
504
+ jvOutput["attrs"]["CDHashes2"]["obj"] = txtobj;
505
+ for (int m = 0; m < nCount; m++) {
506
+ ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, m);
507
+ if (NULL != av) {
508
+ ASN1_STRING* s = av->value.sequence;
509
+
510
+ BIO* mem = BIO_new(BIO_s_mem());
511
+
512
+ ASN1_parse_dump(mem, s->data, s->length, 2, 0);
513
+ BUF_MEM* bptr = NULL;
514
+ BIO_get_mem_ptr(mem, &bptr);
515
+ BIO_set_close(mem, BIO_NOCLOSE);
516
+ string strData;
517
+ strData.append(bptr->data, bptr->length);
518
+ BIO_free_all(mem);
519
+
520
+ string strSHASum;
521
+ size_t pos1 = strData.find("[HEX DUMP]:");
522
+ if (string::npos != pos1) {
523
+ size_t pos2 = strData.find("\n", pos1);
524
+ if (string::npos != pos2) {
525
+ strSHASum = strData.substr(pos1 + 11, pos2 - pos1 - 11);
526
+ }
527
+ }
528
+ transform(strSHASum.begin(), strSHASum.end(), strSHASum.begin(), ::tolower);
529
+ jvOutput["attrs"]["CDHashes2"]["data"].push_back(strSHASum);
530
+ }
531
+ }
532
+ } else if (0 == strcmp("1.2.840.113635.100.9.1", txtobj)) { //V_ASN1_OCTET_STRING
533
+ ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
534
+ if (NULL != av) {
535
+ string strPList;
536
+ strPList.append((const char*)av->value.octet_string->data, av->value.octet_string->length);
537
+ jvOutput["attrs"]["CDHashes"]["obj"] = txtobj;
538
+ jvOutput["attrs"]["CDHashes"]["data"] = strPList;
539
+ }
540
+ } else {
541
+ ASN1_TYPE* av = X509_ATTRIBUTE_get0_type(attr, 0);
542
+ if (NULL != av) {
543
+ jvalue jvAttr;
544
+ jvAttr["obj"] = txtobj;
545
+ jvAttr["name"] = OBJ_nid2ln(OBJ_obj2nid(obj));
546
+ jvAttr["type"] = av->type;
547
+ jvAttr["count"] = nCount;
548
+ jvOutput["attrs"]["unknown"].push_back(jvAttr);
549
+ }
550
+ }
551
+ }
552
+ }
553
+
554
+ return true;
555
+ }
556
+
557
+ ZSignAsset::ZSignAsset()
558
+ {
559
+ m_evpPKey = NULL;
560
+ m_x509Cert = NULL;
561
+ m_bAdhoc = false;
562
+ m_bSingleBinary = false;
563
+ m_bSHA256Only = false;
564
+ }
565
+
566
+ bool ZSignAsset::Init(
567
+ const string& strCertFile,
568
+ const string& strPKeyFile,
569
+ const string& strProvFile,
570
+ const string& strEntitleFile,
571
+ const string& strPassword,
572
+ bool bAdhoc,
573
+ bool bSHA256Only,
574
+ bool bSingleBinary)
575
+ {
576
+ m_bAdhoc = bAdhoc;
577
+ m_bSHA256Only = bSHA256Only;
578
+ m_bSingleBinary = bSingleBinary;
579
+
580
+ if (m_bAdhoc) {
581
+ if (!strEntitleFile.empty()) {
582
+ if (!ZFile::ReadFile(strEntitleFile.c_str(), m_strEntitleData)) {
583
+ ZLog::Error(">>> Can't read entitlements file!\n");
584
+ return false;
585
+ }
586
+ }
587
+ return true;
588
+ }
589
+
590
+ ZFile::ReadFile(strProvFile.c_str(), m_strProvData);
591
+ ZFile::ReadFile(strEntitleFile.c_str(), m_strEntitleData);
592
+ if (m_strProvData.empty()) {
593
+ ZLog::Error(">>> Can't find provision file!\n");
594
+ return false;
595
+ }
596
+
597
+ jvalue jvProv;
598
+ string strProvContent;
599
+ if (GetCMSContent(m_strProvData, strProvContent)) {
600
+ if (jvProv.read_plist(strProvContent)) {
601
+ m_strTeamId = jvProv["TeamIdentifier"][0].as_cstr();
602
+ if (m_strEntitleData.empty()) {
603
+ jvProv["Entitlements"].style_write_plist(m_strEntitleData);
604
+ }
605
+ }
606
+ }
607
+
608
+ if (m_strTeamId.empty()) {
609
+ ZLog::Error(">>> Can't find TeamId!\n");
610
+ return false;
611
+ }
612
+
613
+ X509* x509Cert = NULL;
614
+ EVP_PKEY* evpPKey = NULL;
615
+ BIO* bioPKey = BIO_new_file(strPKeyFile.c_str(), "rb");
616
+ if (NULL != bioPKey) {
617
+ evpPKey = PEM_read_bio_PrivateKey(bioPKey, NULL, NULL, (void*)strPassword.c_str());
618
+ if (NULL == evpPKey) {
619
+ BIO_reset(bioPKey);
620
+ evpPKey = d2i_PrivateKey_bio(bioPKey, NULL);
621
+ if (NULL == evpPKey) {
622
+ BIO_reset(bioPKey);
623
+ OSSL_PROVIDER_load(NULL, "legacy");
624
+ PKCS12* p12 = d2i_PKCS12_bio(bioPKey, NULL);
625
+ if (NULL != p12) {
626
+ if (0 == PKCS12_parse(p12, strPassword.c_str(), &evpPKey, &x509Cert, NULL)) {
627
+ CMSError();
628
+ }
629
+ PKCS12_free(p12);
630
+ } else {
631
+ CMSError();
632
+ }
633
+ }
634
+ }
635
+ BIO_free(bioPKey);
636
+ }
637
+
638
+ if (NULL == evpPKey) {
639
+ ZLog::Error(">>> Can't load p12 or private key file. Please input the correct file and password!\n");
640
+ return false;
641
+ }
642
+
643
+ if (NULL == x509Cert && !strCertFile.empty()) {
644
+ BIO* bioCert = BIO_new_file(strCertFile.c_str(), "r");
645
+ if (NULL != bioCert) {
646
+ x509Cert = PEM_read_bio_X509(bioCert, NULL, 0, NULL);
647
+ if (NULL == x509Cert) {
648
+ BIO_reset(bioCert);
649
+ x509Cert = d2i_X509_bio(bioCert, NULL);
650
+ }
651
+ BIO_free(bioCert);
652
+ }
653
+ }
654
+
655
+ if (NULL != x509Cert) {
656
+ if (!X509_check_private_key(x509Cert, evpPKey)) {
657
+ X509_free(x509Cert);
658
+ x509Cert = NULL;
659
+ }
660
+ }
661
+
662
+ if (NULL == x509Cert) {
663
+ for (size_t i = 0; i < jvProv["DeveloperCertificates"].size(); i++) {
664
+ string strCertData = jvProv["DeveloperCertificates"][i].as_data();
665
+ BIO* bioCert = BIO_new_mem_buf(strCertData.c_str(), (int)strCertData.size());
666
+ if (NULL != bioCert) {
667
+ x509Cert = d2i_X509_bio(bioCert, NULL);
668
+ if (NULL != x509Cert) {
669
+ if (X509_check_private_key(x509Cert, evpPKey)) {
670
+ break;
671
+ }
672
+ X509_free(x509Cert);
673
+ x509Cert = NULL;
674
+ }
675
+ BIO_free(bioCert);
676
+ }
677
+ }
678
+ }
679
+
680
+ if (NULL == x509Cert) {
681
+ ZLog::Error(">>> Can't find paired certificate and private key!\n");
682
+ return false;
683
+ }
684
+
685
+ if (!GetCertSubjectCN(x509Cert, m_strSubjectCN)) {
686
+ ZLog::Error(">>> Can't find paired certificate subject common name!\n");
687
+ return false;
688
+ }
689
+
690
+ m_evpPKey = evpPKey;
691
+ m_x509Cert = x509Cert;
692
+ return true;
693
+ }
694
+
695
+ bool ZSignAsset::GenerateCMS(const string& strCDHashData, const string& strCDHashesPlist, const string& strCodeDirectorySlotSHA1, const string& strAltnateCodeDirectorySlot256, string& strCMSOutput)
696
+ {
697
+ return GenerateCMS((X509*)m_x509Cert, (EVP_PKEY*)m_evpPKey, strCDHashData, strCDHashesPlist, strCodeDirectorySlotSHA1, strAltnateCodeDirectorySlot256, strCMSOutput);
698
+ }