1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.ohos.hapsigntoolcmd; 17 18 import static org.junit.jupiter.api.Assertions.assertArrayEquals; 19 import static org.junit.jupiter.api.Assertions.assertFalse; 20 import static org.junit.jupiter.api.Assertions.assertTrue; 21 22 import com.ohos.hapsigntool.HapSignTool; 23 import com.ohos.hapsigntool.error.CustomException; 24 import com.ohos.hapsigntool.utils.KeyPairTools; 25 import com.ohos.hapsigntool.utils.FileUtils; 26 import com.ohos.hapsigntool.zip.Zip; 27 28 import org.junit.jupiter.api.AfterAll; 29 import org.junit.jupiter.api.BeforeAll; 30 import org.junit.jupiter.api.MethodOrderer; 31 import org.junit.jupiter.api.Order; 32 import org.junit.jupiter.api.Test; 33 import org.junit.jupiter.api.TestMethodOrder; 34 import org.junit.platform.commons.logging.Logger; 35 import org.junit.platform.commons.logging.LoggerFactory; 36 37 import java.io.File; 38 import java.io.FileOutputStream; 39 import java.io.IOException; 40 import java.math.BigInteger; 41 import java.net.URL; 42 import java.nio.file.Files; 43 import java.nio.file.Path; 44 import java.nio.file.Paths; 45 import java.nio.file.StandardCopyOption; 46 import java.util.ArrayList; 47 import java.util.List; 48 import java.util.Random; 49 import java.util.zip.CRC32; 50 import java.util.zip.ZipEntry; 51 import java.util.zip.ZipOutputStream; 52 53 /** 54 * CmdUnitTest. 55 * 56 * @since 2021/12/28 57 */ 58 @TestMethodOrder(MethodOrderer.OrderAnnotation.class) 59 public class CmdUnitTest { 60 /** 61 * Command line parameter appCaCertFile. 62 */ 63 public static final String CMD_SUB_CA_CERT_FILE = "-subCaCertFile"; 64 65 /** 66 * Command line parameter outFile. 67 */ 68 public static final String CMD_OUT_FILE = "-outFile"; 69 70 /** 71 * Command line parameter basicConstraints. 72 */ 73 public static final String CMD_BASIC_CONSTRAINTS = "-basicConstraints"; 74 75 /** 76 * Command line parameter basicConstraintsCa. 77 */ 78 public static final String CMD_BASIC_CONSTRAINTS_CA = "-basicConstraintsCa"; 79 80 /** 81 * Command line parameter basicConstraintsCritical. 82 */ 83 public static final String CMD_BASIC_CONSTRAINTS_CRITICAL = "-basicConstraintsCritical"; 84 85 /** 86 * Command line parameter basicConstraintsPathLen. 87 */ 88 public static final String CMD_BASIC_CONSTRAINTS_PATH_LEN = "-basicConstraintsPathLen"; 89 90 /** 91 * Command line parameter caCertFile. 92 */ 93 public static final String CMD_ROOT_CA_CERT_FILE = "-rootCaCertFile"; 94 95 /** 96 * Command line parameter outForm. 97 */ 98 public static final String CMD_OUT_FORM = "-outForm"; 99 100 /** 101 * Command line parameter cert. 102 */ 103 public static final String CMD_CERT_CHAIN = "certChain"; 104 105 /** 106 * Command line parameter digitalSignature. 107 */ 108 public static final String CMD_DIGITAL_SIGNATURE = "digitalSignature"; 109 110 /** 111 * Command line parameter codeSignature and emailProtection. 112 */ 113 public static final String CMD_CODE_AND_EMAIL = "codeSignature,emailProtection"; 114 115 /** 116 * Command line parameter mode. 117 */ 118 public static final String CMD_MODE = "-mode"; 119 120 /** 121 * Command line parameter keystoreFile. 122 */ 123 public static final String CMD_KEY_STORE_FILE = "-keystoreFile"; 124 125 /** 126 * Command line parameter keystorePwd. 127 */ 128 public static final String CMD_KEY_STORE_RIGHTS = "-keystorePwd"; 129 130 /** 131 * Command line parameter keyAlg. 132 */ 133 public static final String CMD_KEY_ALG = "-keyAlg"; 134 135 /** 136 * Command line parameter keyAlias. 137 */ 138 public static final String CMD_KEY_ALIAS = "-keyAlias"; 139 140 /** 141 * Command line parameter keyPwd. 142 */ 143 public static final String CMD_KEY_RIGHTS = "-keyPwd"; 144 145 /** 146 * Command line parameter keySize. 147 */ 148 public static final String CMD_KEY_SIZE = "-keySize"; 149 150 /** 151 * Command line parameter keyUsage. 152 */ 153 public static final String CMD_KEY_USAGE = "-keyUsage"; 154 155 /** 156 * Command line parameter keyUsageCritical. 157 */ 158 public static final String CMD_KEY_USAGE_CRITICAL = "-keyUsageCritical"; 159 160 /** 161 * Command line parameter extKeyUsage. 162 */ 163 public static final String CMD_EXT_KEY_USAGE = "-extKeyUsage"; 164 165 /** 166 * Command line parameter extKeyUsageCritical. 167 */ 168 public static final String CMD_EXT_KEY_USAGE_CRITICAL = "-extKeyUsageCritical"; 169 170 /** 171 * Command line parameter profileCertFile. 172 */ 173 public static final String CMD_PROFILE_CERT_FILE = "-profileCertFile"; 174 175 /** 176 * Command line parameter subject. 177 */ 178 public static final String CMD_SUBJECT = "-subject"; 179 180 /** 181 * Command line parameter signAlg. 182 */ 183 public static final String CMD_SIGN_ALG = "-signAlg"; 184 185 /** 186 * Command line parameter inFile. 187 */ 188 public static final String CMD_IN_FILE = "-inFile"; 189 190 /** 191 * Command line parameter issuer. 192 */ 193 public static final String CMD_ISSUER = "-issuer"; 194 195 /** 196 * Command line parameter issuerKeyAlias. 197 */ 198 public static final String CMD_ISSUER_KEY_ALIAS = "-issuerKeyAlias"; 199 200 /** 201 * Command line parameter issuerKeyPwd. 202 */ 203 public static final String CMD_ISSUER_KEY_RIGHTS = "-issuerKeyPwd"; 204 205 /** 206 * Command line parameter validity. 207 */ 208 public static final String CMD_VALIDITY = "-validity"; 209 210 /** 211 * Command line parameter appCertFile. 212 */ 213 public static final String CMD_APP_CERT_FILE = "-appCertFile"; 214 215 /** 216 * Command line parameter appCertFile. 217 */ 218 public static final String CMD_PROFILE_FILE = "-profileFile"; 219 220 /** 221 * Command line parameter appCertFile. 222 */ 223 public static final String CMD_OUT_CERT_CHAIN = "-outCertChain"; 224 225 /** 226 * Command line parameter appCertFile. 227 */ 228 public static final String CMD_OUT_PROFILE = "-outProfile"; 229 230 /** 231 * Command line parameter false. 232 */ 233 public static final String CMD_FALSE = "false"; 234 235 /** 236 * Command line parameter true. 237 */ 238 public static final String CMD_TRUE = "true"; 239 240 /** 241 * Command line parameter basicConstraintsPathLen is 0. 242 */ 243 public static final String CMD_BC_PATH_LEN_0 = "0"; 244 245 /** 246 * Command line parameter password is 123456. 247 */ 248 public static final String CMD_RIGHTS_123456 = "123456"; 249 250 /** 251 * Command line parameter RSA is 2048. 252 */ 253 public static final String CMD_RSA_2048 = "2048"; 254 255 /** 256 * Command line parameter ECC is 256. 257 */ 258 public static final String CMD_ECC_256 = "NIST-P-256"; 259 260 /** 261 * Command line parameter validity is 365. 262 */ 263 public static final String CMD_VALIDITY_365 = "365"; 264 265 /** 266 * Command line parameter json file is UnsgnedDebugProfileTemplate. 267 */ 268 public static final String CMD_JSON_FILE = "UnsgnedDebugProfileTemplate.json"; 269 270 /** 271 * Command line parameter json file is UnsgnedReleaseProfileTemplate. 272 */ 273 public static final String CMD_RELEASE_JSON_FILE = "UnsgnedReleaseProfileTemplate.json"; 274 275 /** 276 * Command line parameter localSign. 277 */ 278 public static final String CMD_LOCAL_SIGN = "localSign"; 279 280 /** 281 * Command line parameter SHA256withECDSA. 282 */ 283 public static final String CMD_SHA_256_WITH_ECDSA = "SHA256withECDSA"; 284 285 /** 286 * Command line parameter cer file is test_app-debug-cert. 287 */ 288 public static final String CMD_APP_DEBUG_CERT_PATH = "test_app-debug-cert.pem"; 289 290 /** 291 * Command line parameter cer file is test_app-release-cert. 292 */ 293 public static final String CMD_APP_RELEASE_CERT_PATH = "test_app-release-cert.pem"; 294 295 /** 296 * Command line parameter cer file is test_cert. 297 */ 298 public static final String CMD_CERT_PATH = "test_cert.cer"; 299 300 /** 301 * Command line parameter csr file is test_csr. 302 */ 303 public static final String CMD_CSR_PATH = "test_csr.csr"; 304 305 /** 306 * Command line parameter jks file is test_app_csr. 307 */ 308 public static final String CMD_KEY_APP_STORE_PATH = "test_app_keypair.jks"; 309 310 /** 311 * Command line parameter jks file is test_profile_csr. 312 */ 313 public static final String CMD_KEY_PROFILE_STORE_PATH = "test_profile_keypair.jks"; 314 315 /** 316 * Command line parameter cer file is test_root_app_ca. 317 */ 318 public static final String CMD_ROOT_APP_CA_PATH = "test_root_app_ca.cer"; 319 320 /** 321 * Command line parameter cer file is test_root_profile_ca. 322 */ 323 public static final String CMD_ROOT_PROFILE_CA_PATH = "test_root_profile_ca.cer"; 324 325 /** 326 * Command line parameter cer file is test_sub_app_ca. 327 */ 328 public static final String CMD_SUB_APP_CA_PATH = "test_sub_app_ca.cer"; 329 330 /** 331 * Command line parameter cer file is test_sub_profile_ca. 332 */ 333 public static final String CMD_SUB_PROFILE_CA_PATH = "test_sub_profile_ca.cer"; 334 335 /** 336 * Command line parameter p7b file is test_sign_profile. 337 */ 338 public static final String CMD_SIGN_PROFILE_PATH = "test_sign_profile.p7b"; 339 340 /** 341 * Command line parameter p7b file is test_sign_profile. 342 */ 343 public static final String CMD_SIGN_RELEASE_PROFILE_PATH = "test_sign_release_profile.p7b"; 344 345 /** 346 * Command line parameter cer file is test_profile-debug-cert. 347 */ 348 public static final String CMD_PROFILE_DEBUG_CERT_PATH = "test_profile-debug-cert.pem"; 349 350 /** 351 * Command line parameter cer file is test_profile-release-cert. 352 */ 353 public static final String CMD_PROFILE_RELEASE_CERT_PATH = "test_profile-release-cert.pem"; 354 355 /** 356 * Command line parameter cer file is test_verify_profile. 357 */ 358 public static final String CMD_VERIFY_PROFILE_RESULT_PATH = "test_verify_profile_result.json"; 359 360 /** 361 * Command line parameter oh-profile-key-v1. 362 */ 363 public static final String CMD_OH_PROFILE_KEY_V1 = "oh-profile-key-v1"; 364 365 /** 366 * Command line parameter oh-app1-key-v1. 367 */ 368 public static final String CMD_OH_APP1_KEY_V1 = "oh-app1-key-v1"; 369 370 /** 371 * Command line parameter oh-root-ca-key-v1. 372 */ 373 public static final String CMD_OH_ROOT_CA_KEY_V1 = "oh-root-ca-key-v1"; 374 375 /** 376 * Command line parameter oh-sub-app-ca-key-v1. 377 */ 378 public static final String CMD_OH_SUB_APP_CA_KEY_V1 = "oh-sub-app-ca-key-v1"; 379 380 /** 381 * Command line parameter oh-sub-profile-ca-key-v1. 382 */ 383 public static final String CMD_OH_SUB_PROFILE_CA_KEY_V1 = "oh-sub-profile-ca-key-v1"; 384 385 /** 386 * Command line parameter CN=ROOT CA. 387 */ 388 public static final String CMD_ROOT_CA = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=ROOT CA"; 389 390 /** 391 * Command line parameter CN=App1 Release. 392 */ 393 public static final String CMD_APP1_RELEASE = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; 394 395 /** 396 * Command line parameter CN=Provision Profile Release. 397 */ 398 public static final String CMD_PROFILE_RELEASE = "C=CN,O=OpenHarmony," 399 + "OU=OpenHarmony Community,CN=Provision Profile Release"; 400 401 /** 402 * Command line parameter CN=Provision Profile Signature Service CA. 403 */ 404 public static final String CMD_PROFILE_CA = "C=CN,O=OpenHarmony,OU=OpenHarmony Community," 405 + "CN=Provision Profile Signature Service CA"; 406 407 /** 408 * Command line parameter CN=Application Signature Service CA. 409 */ 410 public static final String CMD_APP_CA = "C=CN," 411 + "O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; 412 413 /** 414 * Add log info. 415 */ 416 private static final Logger logger = LoggerFactory.getLogger(CmdUnitTest.class); 417 418 /** 419 * create test dir 420 */ 421 @BeforeAll mkTestDir()422 public static void mkTestDir() { 423 File dir = new File("test"); 424 dir.mkdir(); 425 } 426 427 /** 428 * delete test dir 429 */ 430 @AfterAll delTestDir()431 public static void delTestDir() { 432 File dir = new File("test"); 433 if (dir.exists()) { 434 for (File file : dir.listFiles()) { 435 file.delete(); 436 } 437 dir.delete(); 438 } 439 } 440 441 /** 442 * test cmdKeypair 443 * 444 * @throws IOException io error 445 */ 446 @Order(1) 447 @Test testCmdKeypair()448 public void testCmdKeypair() throws IOException { 449 try { 450 deleteFile(CMD_KEY_APP_STORE_PATH); 451 deleteFile(CMD_KEY_PROFILE_STORE_PATH); 452 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.GENERATE_KEYPAIR}); 453 assertFalse(result); 454 assertFalse(FileUtils.isFileExist(CMD_KEY_APP_STORE_PATH)); 455 assertFalse(FileUtils.isFileExist(CMD_KEY_PROFILE_STORE_PATH)); 456 } catch (CustomException exception) { 457 logger.info(exception, () -> exception.getMessage()); 458 } 459 460 deleteFile(CMD_KEY_APP_STORE_PATH); 461 boolean result = HapSignTool.processCmd(new String[]{ 462 CmdUtil.Method.GENERATE_KEYPAIR, 463 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 464 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 465 CMD_KEY_ALG, KeyPairTools.ECC_INPUT, 466 CMD_KEY_SIZE, CMD_ECC_256, 467 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 468 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456}); 469 assertTrue(result); 470 assertTrue(FileUtils.isFileExist(CMD_KEY_APP_STORE_PATH)); 471 deleteFile(CMD_KEY_PROFILE_STORE_PATH); 472 result = HapSignTool.processCmd(new String[]{ 473 CmdUtil.Method.GENERATE_KEYPAIR, 474 CMD_KEY_ALIAS, CMD_OH_PROFILE_KEY_V1, 475 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 476 CMD_KEY_ALG, KeyPairTools.ECC_INPUT, 477 CMD_KEY_SIZE, CMD_ECC_256, 478 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 479 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456}); 480 assertTrue(result); 481 assertTrue(FileUtils.isFileExist(CMD_KEY_PROFILE_STORE_PATH)); 482 } 483 484 /** 485 * Csr test case. 486 * 487 * @throws IOException Error 488 */ 489 @Order(2) 490 @Test testCmdCsr()491 public void testCmdCsr() throws IOException { 492 try { 493 deleteFile(CMD_CSR_PATH); 494 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.GENERATE_CSR}); 495 assertFalse(result); 496 assertFalse(FileUtils.isFileExist(CMD_CSR_PATH)); 497 } catch (CustomException exception) { 498 logger.info(exception, () -> exception.getMessage()); 499 } 500 501 deleteFile(CMD_CSR_PATH); 502 boolean result = HapSignTool.processCmd(new String[]{ 503 CmdUtil.Method.GENERATE_CSR, 504 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 505 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 506 CMD_SUBJECT, CMD_APP1_RELEASE, 507 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 508 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 509 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 510 CMD_OUT_FILE, CMD_CSR_PATH}); 511 assertTrue(result); 512 assertTrue(FileUtils.isFileExist(CMD_CSR_PATH)); 513 } 514 515 /** 516 * Cert test case 517 * 518 * @throws IOException Error 519 */ 520 @Order(3) 521 @Test testCmdCert()522 public void testCmdCert() throws IOException { 523 try { 524 deleteFile(CMD_CERT_PATH); 525 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.GENERATE_CERT}); 526 assertFalse(result); 527 assertFalse(FileUtils.isFileExist(CMD_CERT_PATH)); 528 } catch (CustomException exception) { 529 logger.info(exception, () -> exception.getMessage()); 530 } 531 532 deleteFile(CMD_CERT_PATH); 533 boolean result = HapSignTool.processCmd(new String[]{ 534 CmdUtil.Method.GENERATE_CERT, 535 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 536 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 537 CMD_ISSUER, CMD_APP_CA, 538 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 539 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 540 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 541 CMD_OUT_FILE, CMD_CERT_PATH, 542 CMD_ISSUER_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 543 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 544 CMD_SUBJECT, CMD_APP1_RELEASE, 545 CMD_VALIDITY, CMD_VALIDITY_365, 546 CMD_KEY_USAGE, CMD_DIGITAL_SIGNATURE, 547 CMD_KEY_USAGE_CRITICAL, CMD_FALSE, 548 CMD_EXT_KEY_USAGE, CMD_CODE_AND_EMAIL, 549 CMD_EXT_KEY_USAGE_CRITICAL, CMD_TRUE, 550 CMD_BASIC_CONSTRAINTS, CMD_FALSE, 551 CMD_BASIC_CONSTRAINTS_CRITICAL, CMD_TRUE, 552 CMD_BASIC_CONSTRAINTS_CA, CMD_FALSE, 553 CMD_BASIC_CONSTRAINTS_PATH_LEN, CMD_BC_PATH_LEN_0}); 554 assertTrue(result); 555 assertTrue(FileUtils.isFileExist(CMD_CERT_PATH)); 556 } 557 558 /** 559 * Ca test case. 560 * 561 * @throws IOException Error 562 */ 563 @Order(4) 564 @Test testCmdCa()565 public void testCmdCa() throws IOException { 566 try { 567 deleteFile(CMD_ROOT_APP_CA_PATH); 568 deleteFile(CMD_ROOT_PROFILE_CA_PATH); 569 deleteFile(CMD_SUB_APP_CA_PATH); 570 deleteFile(CMD_SUB_PROFILE_CA_PATH); 571 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.GENERATE_CA}); 572 assertFalse(result); 573 assertFalse(FileUtils.isFileExist(CMD_ROOT_APP_CA_PATH)); 574 assertFalse(FileUtils.isFileExist(CMD_ROOT_PROFILE_CA_PATH)); 575 assertFalse(FileUtils.isFileExist(CMD_SUB_APP_CA_PATH)); 576 assertFalse(FileUtils.isFileExist(CMD_SUB_PROFILE_CA_PATH)); 577 } catch (CustomException exception) { 578 logger.info(exception, () -> exception.getMessage()); 579 } 580 deleteFile(CMD_ROOT_APP_CA_PATH); 581 boolean result = generateAppRootCa(); 582 assertTrue(result); 583 assertTrue(FileUtils.isFileExist(CMD_ROOT_APP_CA_PATH)); 584 deleteFile(CMD_ROOT_PROFILE_CA_PATH); 585 result = generateProfileRootCa(); 586 assertTrue(result); 587 assertTrue(FileUtils.isFileExist(CMD_ROOT_PROFILE_CA_PATH)); 588 deleteFile(CMD_SUB_APP_CA_PATH); 589 result = generateAppSubCa(); 590 assertTrue(result); 591 assertTrue(FileUtils.isFileExist(CMD_SUB_APP_CA_PATH)); 592 deleteFile(CMD_SUB_PROFILE_CA_PATH); 593 result = generateProfileSubCa(); 594 assertTrue(result); 595 assertTrue(FileUtils.isFileExist(CMD_SUB_PROFILE_CA_PATH)); 596 } 597 598 /** 599 * App cert test case. 600 * 601 * @throws IOException Error 602 */ 603 @Order(5) 604 @Test testCmdAppCert()605 public void testCmdAppCert() throws IOException { 606 try { 607 deleteFile(CMD_APP_DEBUG_CERT_PATH); 608 deleteFile(CMD_APP_RELEASE_CERT_PATH); 609 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.GENERATE_APP_CERT}); 610 assertFalse(result); 611 assertFalse(FileUtils.isFileExist(CMD_APP_DEBUG_CERT_PATH)); 612 assertFalse(FileUtils.isFileExist(CMD_APP_RELEASE_CERT_PATH)); 613 } catch (CustomException exception) { 614 logger.info(exception, () -> exception.getMessage()); 615 } 616 deleteFile(CMD_APP_DEBUG_CERT_PATH); 617 boolean result = HapSignTool.processCmd(new String[]{ 618 CmdUtil.Method.GENERATE_APP_CERT, 619 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 620 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 621 CMD_ISSUER, CMD_APP_CA, 622 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 623 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 624 CMD_OUT_FILE, CMD_APP_DEBUG_CERT_PATH, 625 CMD_ISSUER_KEY_ALIAS, CMD_OH_SUB_APP_CA_KEY_V1, 626 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 627 CMD_SUBJECT, CMD_APP1_RELEASE, 628 CMD_VALIDITY, CMD_VALIDITY_365, 629 CMD_OUT_FORM, CMD_CERT_CHAIN, 630 CMD_ROOT_CA_CERT_FILE, CMD_ROOT_APP_CA_PATH, 631 CMD_SUB_CA_CERT_FILE, CMD_SUB_APP_CA_PATH, 632 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA}); 633 assertTrue(result); 634 assertTrue(FileUtils.isFileExist(CMD_APP_DEBUG_CERT_PATH)); 635 deleteFile(CMD_APP_RELEASE_CERT_PATH); 636 result = HapSignTool.processCmd(new String[]{ 637 CmdUtil.Method.GENERATE_APP_CERT, 638 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 639 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 640 CMD_ISSUER, CMD_APP_CA, 641 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 642 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 643 CMD_OUT_FILE, CMD_APP_RELEASE_CERT_PATH, 644 CMD_ISSUER_KEY_ALIAS, CMD_OH_SUB_APP_CA_KEY_V1, 645 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 646 CMD_SUBJECT, CMD_APP1_RELEASE, 647 CMD_VALIDITY, CMD_VALIDITY_365, 648 CMD_OUT_FORM, CMD_CERT_CHAIN, 649 CMD_ROOT_CA_CERT_FILE, CMD_ROOT_APP_CA_PATH, 650 CMD_SUB_CA_CERT_FILE, CMD_SUB_APP_CA_PATH, 651 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA}); 652 assertTrue(result); 653 assertTrue(FileUtils.isFileExist(CMD_APP_RELEASE_CERT_PATH)); 654 } 655 656 /** 657 * Profile cert test case 658 * 659 * @throws IOException Error 660 */ 661 @Order(6) 662 @Test testCmdProfileCert()663 public void testCmdProfileCert() throws IOException { 664 try { 665 deleteFile(CMD_PROFILE_DEBUG_CERT_PATH); 666 deleteFile(CMD_PROFILE_RELEASE_CERT_PATH); 667 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.GENERATE_PROFILE_CERT}); 668 assertFalse(result); 669 assertFalse(FileUtils.isFileExist(CMD_PROFILE_DEBUG_CERT_PATH)); 670 assertFalse(FileUtils.isFileExist(CMD_PROFILE_RELEASE_CERT_PATH)); 671 } catch (CustomException exception) { 672 logger.info(exception, () -> exception.getMessage()); 673 } 674 deleteFile(CMD_PROFILE_DEBUG_CERT_PATH); 675 boolean result = HapSignTool.processCmd(new String[]{ 676 CmdUtil.Method.GENERATE_PROFILE_CERT, 677 CMD_KEY_ALIAS, CMD_OH_PROFILE_KEY_V1, 678 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 679 CMD_ISSUER, CMD_PROFILE_CA, 680 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 681 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 682 CMD_OUT_FILE, CMD_PROFILE_DEBUG_CERT_PATH, 683 CMD_ISSUER_KEY_ALIAS, CMD_OH_SUB_PROFILE_CA_KEY_V1, 684 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 685 CMD_SUBJECT, CMD_PROFILE_RELEASE, 686 CMD_VALIDITY, CMD_VALIDITY_365, 687 CMD_OUT_FORM, CMD_CERT_CHAIN, 688 CMD_ROOT_CA_CERT_FILE, CMD_ROOT_PROFILE_CA_PATH, 689 CMD_SUB_CA_CERT_FILE, CMD_SUB_PROFILE_CA_PATH, 690 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA}); 691 assertTrue(result); 692 assertTrue(FileUtils.isFileExist(CMD_PROFILE_DEBUG_CERT_PATH)); 693 deleteFile(CMD_PROFILE_RELEASE_CERT_PATH); 694 result = HapSignTool.processCmd(new String[]{ 695 CmdUtil.Method.GENERATE_PROFILE_CERT, 696 CMD_KEY_ALIAS, CMD_OH_PROFILE_KEY_V1, 697 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 698 CMD_ISSUER, CMD_PROFILE_CA, 699 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 700 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 701 CMD_OUT_FILE, CMD_PROFILE_RELEASE_CERT_PATH, 702 CMD_ISSUER_KEY_ALIAS, CMD_OH_SUB_PROFILE_CA_KEY_V1, 703 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 704 CMD_SUBJECT, CMD_PROFILE_RELEASE, 705 CMD_VALIDITY, CMD_VALIDITY_365, 706 CMD_OUT_FORM, CMD_CERT_CHAIN, 707 CMD_ROOT_CA_CERT_FILE, CMD_ROOT_PROFILE_CA_PATH, 708 CMD_SUB_CA_CERT_FILE, CMD_SUB_PROFILE_CA_PATH, 709 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA}); 710 assertTrue(result); 711 assertTrue(FileUtils.isFileExist(CMD_PROFILE_RELEASE_CERT_PATH)); 712 } 713 714 /** 715 * Sign profile test case. 716 * 717 * @throws IOException error 718 */ 719 @Order(7) 720 @Test testCmdSignProfile()721 public void testCmdSignProfile() throws IOException { 722 try { 723 deleteFile(CMD_SIGN_PROFILE_PATH); 724 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.SIGN_PROFILE}); 725 assertFalse(result); 726 assertFalse(FileUtils.isFileExist(CMD_SIGN_PROFILE_PATH)); 727 } catch (CustomException exception) { 728 logger.info(exception, () -> exception.getMessage()); 729 } 730 731 deleteFile(CMD_SIGN_PROFILE_PATH); 732 loadFile(CMD_JSON_FILE); 733 boolean result = HapSignTool.processCmd(new String[]{ 734 CmdUtil.Method.SIGN_PROFILE, 735 CMD_MODE, CMD_LOCAL_SIGN, 736 CMD_KEY_ALIAS, CMD_OH_PROFILE_KEY_V1, 737 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 738 CMD_PROFILE_CERT_FILE, CMD_PROFILE_DEBUG_CERT_PATH, 739 CMD_IN_FILE, CMD_JSON_FILE, 740 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 741 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 742 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 743 CMD_OUT_FILE, CMD_SIGN_PROFILE_PATH}); 744 assertTrue(result); 745 assertTrue(FileUtils.isFileExist(CMD_SIGN_PROFILE_PATH)); 746 747 deleteFile(CMD_SIGN_RELEASE_PROFILE_PATH); 748 loadFile(CMD_RELEASE_JSON_FILE); 749 result = HapSignTool.processCmd(new String[]{ 750 CmdUtil.Method.SIGN_PROFILE, 751 CMD_MODE, CMD_LOCAL_SIGN, 752 CMD_KEY_ALIAS, CMD_OH_PROFILE_KEY_V1, 753 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 754 CMD_PROFILE_CERT_FILE, CMD_PROFILE_RELEASE_CERT_PATH, 755 CMD_IN_FILE, CMD_RELEASE_JSON_FILE, 756 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 757 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 758 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 759 CMD_OUT_FILE, CMD_SIGN_RELEASE_PROFILE_PATH}); 760 assertTrue(result); 761 assertTrue(FileUtils.isFileExist(CMD_SIGN_RELEASE_PROFILE_PATH)); 762 } 763 764 /** 765 * Verify profile test case. 766 */ 767 @Order(8) 768 @Test testVerifyProfile()769 public void testVerifyProfile() { 770 try { 771 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.VERIFY_PROFILE}); 772 assertFalse(result); 773 } catch (CustomException exception) { 774 logger.info(exception, () -> exception.getMessage()); 775 } 776 777 boolean result = HapSignTool.processCmd(new String[]{ 778 CmdUtil.Method.VERIFY_PROFILE, 779 CMD_IN_FILE, CMD_SIGN_PROFILE_PATH, 780 CMD_OUT_FILE, CMD_VERIFY_PROFILE_RESULT_PATH}); 781 assertTrue(result); 782 } 783 784 /** 785 * Sign hap test case. 786 */ 787 @Order(9) 788 @Test testCmdSignApp()789 public void testCmdSignApp() { 790 try { 791 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.SIGN_APP}); 792 assertFalse(result); 793 } catch (CustomException exception) { 794 logger.info(exception, () -> exception.getMessage()); 795 } 796 } 797 798 /** 799 * Verify signed app test case. 800 */ 801 @Order(10) 802 @Test testCmdVerifyApp()803 public void testCmdVerifyApp() { 804 try { 805 boolean result = HapSignTool.processCmd(new String[]{CmdUtil.Method.VERIFY_APP}); 806 assertFalse(result); 807 } catch (CustomException exception) { 808 logger.info(exception, () -> exception.getMessage()); 809 } 810 } 811 812 /** 813 * test sign and verify hap file include multi lib 814 * 815 * @throws IOException error 816 */ 817 @Order(11) 818 @Test testCmdMultiHap()819 public void testCmdMultiHap() throws IOException { 820 multiBundleTest(".hap"); 821 } 822 823 /** 824 * test sign and verify hqf file include multi lib 825 * 826 * @throws IOException error 827 */ 828 @Order(12) 829 @Test testCmdMultiHqf()830 public void testCmdMultiHqf() throws IOException { 831 multiBundleTest(".hqf"); 832 } 833 multiBundleTest(String bundleSuffix)834 private void multiBundleTest(String bundleSuffix) throws IOException { 835 for (FileType abcFile : FileType.values()) { 836 for (FileType soFile : FileType.values()) { 837 for (FileType anFile : FileType.values()) { 838 File unsignedHap = generateHapFile(abcFile, soFile, anFile, FileType.FILE_NOT_EXISTED, 839 bundleSuffix); 840 signAndVerifyHap(unsignedHap.getAbsolutePath(), bundleSuffix); 841 842 unsignedHap = generateHapFile(abcFile, soFile, anFile, FileType.FILE_UNCOMPRESSED, bundleSuffix); 843 signAndVerifyHap(unsignedHap.getAbsolutePath(), bundleSuffix); 844 845 unsignedHap = generateHapFile(abcFile, soFile, anFile, FileType.FILE_COMPRESSED, bundleSuffix); 846 signAndVerifyHap(unsignedHap.getAbsolutePath(), bundleSuffix); 847 } 848 } 849 } 850 } 851 generateHapFile(FileType abc, FileType so, FileType an, FileType otherFile, String bundleSuffix)852 private File generateHapFile(FileType abc, FileType so, FileType an, FileType otherFile, String bundleSuffix) 853 throws IOException { 854 File unsignedHap = File.createTempFile("unsigned-", bundleSuffix, new File("test")); 855 try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(unsignedHap))) { 856 for (int i = 0; i < 10; i++) { 857 fillZipEntryFile(abc, ".abc", out); 858 if (".hqf".equals(bundleSuffix)) { 859 fillZipEntryFile(so, ".so.diff", out); 860 } 861 fillZipEntryFile(so, ".solib", out); 862 fillZipEntryFile(so, ".so", out); 863 fillZipEntryFile(so, ".so.111", out); 864 fillZipEntryFile(so, ".so.111.111", out); 865 fillZipEntryFile(so, ".so.111.111.111", out); 866 fillZipEntryFile(an, ".an", out); 867 fillZipEntryFile(otherFile, ".json", out); 868 } 869 } 870 return unsignedHap; 871 } 872 fillZipEntryFile(FileType ft, String suffix, ZipOutputStream out)873 private void fillZipEntryFile(FileType ft, String suffix, ZipOutputStream out) throws IOException { 874 String tempSuffix = suffix; 875 if (FileType.FILE_NOT_EXISTED.equals(ft)) { 876 tempSuffix = ""; 877 } 878 String fileName = new BigInteger(Long.SIZE, new Random()).toString() + tempSuffix; 879 if (tempSuffix.startsWith(".so")) { 880 fileName = "libs/" + fileName; 881 } 882 if (tempSuffix.startsWith(".an")) { 883 fileName = "an/" + fileName; 884 } 885 ZipEntry zipEntry = new ZipEntry(fileName); 886 byte[] bytes = generateChunkBytes(); 887 if (FileType.FILE_UNCOMPRESSED.equals(ft)) { 888 zipEntry.setMethod(ZipEntry.STORED); 889 zipEntry.setSize(bytes.length); 890 CRC32 crc32 = new CRC32(); 891 crc32.reset(); 892 crc32.update(bytes, 0, bytes.length); 893 zipEntry.setCrc(crc32.getValue()); 894 } else { 895 zipEntry.setMethod(ZipEntry.DEFLATED); 896 } 897 out.putNextEntry(zipEntry); 898 out.write(bytes); 899 out.closeEntry(); 900 } 901 generateChunkBytes()902 private byte[] generateChunkBytes() { 903 Random random = new Random(); 904 int size = Math.max(4096, random.nextInt(1024 * 1024 * 2)); 905 byte[] bytes = new byte[size]; 906 random.nextBytes(bytes); 907 return bytes; 908 } 909 signAndVerifyHap(String unsignedHap, String bundleSuffix)910 private void signAndVerifyHap(String unsignedHap, String bundleSuffix) throws IOException { 911 String signedHap = File.createTempFile("signed-", bundleSuffix, new File("test")).getAbsolutePath(); 912 // debug 913 boolean result = HapSignTool.processCmd(new String[] { 914 CmdUtil.Method.SIGN_APP, 915 CMD_MODE, CMD_LOCAL_SIGN, 916 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 917 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 918 CMD_APP_CERT_FILE, CMD_APP_DEBUG_CERT_PATH, 919 CMD_PROFILE_FILE, CMD_SIGN_PROFILE_PATH, 920 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 921 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 922 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 923 CMD_IN_FILE, unsignedHap, 924 CMD_OUT_FILE, signedHap 925 }); 926 assertTrue(result); 927 928 result = HapSignTool.processCmd(new String[] { 929 CmdUtil.Method.VERIFY_APP, CMD_IN_FILE, signedHap, CMD_OUT_CERT_CHAIN, "test" + File.separator + "1.cer", 930 CMD_OUT_PROFILE, "test" + File.separator + "1.p7b" 931 }); 932 assertTrue(result); 933 // release 934 result = HapSignTool.processCmd(new String[] { 935 CmdUtil.Method.SIGN_APP, 936 CMD_MODE, CMD_LOCAL_SIGN, 937 CMD_KEY_ALIAS, CMD_OH_APP1_KEY_V1, 938 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 939 CMD_APP_CERT_FILE, CMD_APP_RELEASE_CERT_PATH, 940 CMD_PROFILE_FILE, CMD_SIGN_RELEASE_PROFILE_PATH, 941 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 942 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 943 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 944 CMD_IN_FILE, unsignedHap, 945 CMD_OUT_FILE, signedHap 946 }); 947 assertTrue(result); 948 949 result = HapSignTool.processCmd(new String[] { 950 CmdUtil.Method.VERIFY_APP, CMD_IN_FILE, signedHap, CMD_OUT_CERT_CHAIN, "test" + File.separator + "1.cer", 951 CMD_OUT_PROFILE, "test" + File.separator + "1.p7b" 952 }); 953 assertTrue(result); 954 } 955 956 /** 957 * Test Method: isRunnableFile() 958 */ 959 @Test testIsRunnableFile()960 public void testIsRunnableFile() { 961 List<String> correctName = new ArrayList<>(); 962 correctName.add("libs/中文.so"); 963 correctName.add("srtjdwrtj.an"); 964 correctName.add("srtjdwrtj.abc"); 965 correctName.add("libs/srtjdwrtj.so"); 966 correctName.add("libs/srtjdwrtj.so.1"); 967 correctName.add("libs/srtjdwrtj.so.1.1"); 968 correctName.add("libs/srtjdwrtj.so.1.1.1"); 969 correctName.add("libs/srtjdwrtj.aaaa.111.111.1111"); 970 correctName.add("libs/srtjdwrtj.so.111.111.1111"); 971 correctName.add("libs/中文.so.111.111.1111"); 972 correctName.add("libs/srtjdwrtj.so.111.%%%.1111"); 973 for (String name : correctName) { 974 assertTrue(FileUtils.isRunnableFile(name)); 975 } 976 977 List<String> incorrectName = new ArrayList<>(); 978 incorrectName.add("srtjdwrtj.so"); 979 incorrectName.add("srtjdwrtj.so.111.111.1111.54645"); 980 incorrectName.add("srtjdwrtjso.111.111.11111"); 981 incorrectName.add("srtjdwrtj.so.abc.111.111.1111"); 982 incorrectName.add("srtjdwrtj.so.111.111.json"); 983 incorrectName.add("srtjdwrtj.abc.json"); 984 incorrectName.add("srtjdwrtj.an.json"); 985 incorrectName.add("中文.so.111.111.json"); 986 for (String name : incorrectName) { 987 assertFalse(FileUtils.isRunnableFile(name)); 988 } 989 } 990 991 /** 992 * Test Method: testByteToZip() 993 * 994 * @throws IOException read file exception 995 */ 996 @Test testByteToZip()997 public void testByteToZip() throws IOException { 998 for (int i = 0; i < 10; i++) { 999 File file = generateHapFile(FileType.FILE_UNCOMPRESSED, FileType.FILE_UNCOMPRESSED, 1000 FileType.FILE_UNCOMPRESSED, FileType.FILE_UNCOMPRESSED, ".hap"); 1001 Zip zip = new Zip(file); 1002 String outFileName = "test" + File.separator + "testOut.hap"; 1003 zip.toFile(outFileName); 1004 File outFile = new File(outFileName); 1005 byte[] bytes = FileUtils.readFile(file); 1006 byte[] outBytes = FileUtils.readFile(outFile); 1007 assertArrayEquals(outBytes, bytes); 1008 1009 deleteFile(file.getCanonicalPath()); 1010 deleteFile(outFileName); 1011 } 1012 } 1013 generateAppRootCa()1014 private boolean generateAppRootCa() { 1015 return HapSignTool.processCmd(new String[]{ 1016 CmdUtil.Method.GENERATE_CA, 1017 CMD_KEY_ALIAS, CMD_OH_ROOT_CA_KEY_V1, 1018 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 1019 CMD_KEY_ALG, KeyPairTools.ECC_INPUT, 1020 CMD_KEY_SIZE, CMD_ECC_256, 1021 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 1022 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 1023 CMD_OUT_FILE, CMD_ROOT_APP_CA_PATH, 1024 CMD_SUBJECT, CMD_ROOT_CA, 1025 CMD_VALIDITY, CMD_VALIDITY_365, 1026 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 1027 CMD_BASIC_CONSTRAINTS_PATH_LEN, CMD_BC_PATH_LEN_0}); 1028 } 1029 generateProfileRootCa()1030 private boolean generateProfileRootCa() { 1031 return HapSignTool.processCmd(new String[]{ 1032 CmdUtil.Method.GENERATE_CA, 1033 CMD_KEY_ALIAS, CMD_OH_ROOT_CA_KEY_V1, 1034 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 1035 CMD_KEY_ALG, KeyPairTools.ECC_INPUT, 1036 CMD_KEY_SIZE, CMD_ECC_256, 1037 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 1038 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 1039 CMD_OUT_FILE, CMD_ROOT_PROFILE_CA_PATH, 1040 CMD_SUBJECT, CMD_ROOT_CA, 1041 CMD_VALIDITY, CMD_VALIDITY_365, 1042 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 1043 CMD_BASIC_CONSTRAINTS_PATH_LEN, CMD_BC_PATH_LEN_0}); 1044 } 1045 generateAppSubCa()1046 private boolean generateAppSubCa() { 1047 return HapSignTool.processCmd(new String[]{ 1048 CmdUtil.Method.GENERATE_CA, 1049 CMD_KEY_ALIAS, CMD_OH_SUB_APP_CA_KEY_V1, 1050 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 1051 CMD_ISSUER, CMD_ROOT_CA, 1052 CMD_KEY_ALG, KeyPairTools.ECC_INPUT, 1053 CMD_KEY_SIZE, CMD_ECC_256, 1054 CMD_KEY_STORE_FILE, CMD_KEY_APP_STORE_PATH, 1055 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 1056 CMD_OUT_FILE, CMD_SUB_APP_CA_PATH, 1057 CMD_ISSUER_KEY_ALIAS, CMD_OH_ROOT_CA_KEY_V1, 1058 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 1059 CMD_SUBJECT, CMD_APP_CA, 1060 CMD_VALIDITY, CMD_VALIDITY_365, 1061 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 1062 CMD_BASIC_CONSTRAINTS_PATH_LEN, CMD_BC_PATH_LEN_0}); 1063 } 1064 generateProfileSubCa()1065 private boolean generateProfileSubCa() { 1066 return HapSignTool.processCmd(new String[]{ 1067 CmdUtil.Method.GENERATE_CA, 1068 CMD_KEY_ALIAS, CMD_OH_SUB_PROFILE_CA_KEY_V1, 1069 CMD_KEY_RIGHTS, CMD_RIGHTS_123456, 1070 CMD_ISSUER, CMD_ROOT_CA, 1071 CMD_KEY_ALG, KeyPairTools.ECC_INPUT, 1072 CMD_KEY_SIZE, CMD_ECC_256, 1073 CMD_KEY_STORE_FILE, CMD_KEY_PROFILE_STORE_PATH, 1074 CMD_KEY_STORE_RIGHTS, CMD_RIGHTS_123456, 1075 CMD_OUT_FILE, CMD_SUB_PROFILE_CA_PATH, 1076 CMD_ISSUER_KEY_ALIAS, CMD_OH_ROOT_CA_KEY_V1, 1077 CMD_ISSUER_KEY_RIGHTS, CMD_RIGHTS_123456, 1078 CMD_SUBJECT, CMD_PROFILE_CA, 1079 CMD_VALIDITY, CMD_VALIDITY_365, 1080 CMD_SIGN_ALG, CMD_SHA_256_WITH_ECDSA, 1081 CMD_BASIC_CONSTRAINTS_PATH_LEN, CMD_BC_PATH_LEN_0}); 1082 } 1083 loadFile(String filePath)1084 private void loadFile(String filePath) throws IOException { 1085 ClassLoader classLoader = CmdUnitTest.class.getClassLoader(); 1086 URL resource = classLoader.getResource(filePath); 1087 assert resource != null; 1088 Files.copy(new File(resource.getPath()).toPath(), new File(filePath).toPath(), 1089 StandardCopyOption.REPLACE_EXISTING); 1090 } 1091 deleteFile(String filePath)1092 private void deleteFile(String filePath) throws IOException { 1093 if (FileUtils.isFileExist(filePath)) { 1094 Path path = Paths.get(filePath); 1095 Files.delete(path); 1096 } 1097 } 1098 1099 /** 1100 * Enumerated value of file type in zip. 1101 */ 1102 public enum FileType { 1103 FILE_NOT_EXISTED, 1104 FILE_UNCOMPRESSED, 1105 FILE_COMPRESSED; 1106 } 1107 } 1108