2
0

pkcs12-keystore-validation.spec.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true */
  9. 'use strict';
  10. var keyStore = require('../lib/index');
  11. describe('The key store module that should be able to ...', function() {
  12. var PASSWORD = 'PM6XtkOTbefJmhHGFgbz';
  13. var PRIVATE_KEY_ALIAS = 'root_rsa_private_key';
  14. var PKCS12_DER_B64 =
  15. 'MIIaAQIBAzCCGbsGCSqGSIb3DQEHAaCCGawEghmoMIIZpDCCCvEGCSqGSIb3DQEHAaCCCuIEggreMIIK2jCCBWkGCyqGSIb3DQEMCgECoIIE+jCCBPYwKAYKKoZIhvcNAQwBAzAaBBSSjjJGUYGJDejWdN+I9JtoUS5GlwICBAAEggTIIm/j53Vt9JV14SyNUCY2Fe2FI0iwKRwr12N/4/mmLU6nSONnrp0awB5z+d5T4sLpekMUvayn8o3r0NTzzasdadH7tK3UDEgcSCuutGMk3JxZr2QbzRzHOr2qxUN6Y+069InDKO+8NNt+uC2vewPs8X3Q9qsrbhhQJdrjmKRwmmO9IJmYnbIBxl6Y3h0D3KZfCetYleKDuuv78Gx6Z2VFh+lw3Dx2CSaSNXwOWLGTfMxXbzKXfHu8GlT7s9I3qmgxluC1PTJUb1Kpc56sEhQ6kHSoDFXuC5fJRl5qhaMtcQmhZvRb6TIxWwIK6bNfxw2jQbK0ZkXOFtkZFAMKh34jW+F2xjEP49IqbH4e1buXY62KvUQLJwtb7pZehwWrf544ycX8eKNPf8tqepE5jZZVR/VPk8VgLYhg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nmUL2XwVZ4PFuOJvaViOOUvUFt4SXPIzCWU4j5PqKo/W17OAxgzZ+iIsVENGSikMWiiNolSsMhcrI9DrhKBroI4T5njo0tab0Ne4FpJq5WqpVhnMD5zSZPeODz7aYaXufN/JNBLRo9QLTFaqw/IzUwuM7RZnvQb00k05r4isYDIxCI9FvLN+/MRnZjOdwsrcdk1zF2+23b4DIntbWbx7gMvto7IwJ/McGG4Zf2IG87W6vZN9UrFEcZ2lIoukk6mDUUtKB84aUDBWnHW2Josh2pKHAAmFZP9GuEW0ojFT4siVgv9VijYzSgNsfAFIwmsY/O7OOboE9BiaznrpB/CqmiVpKFWwynNoFrYZCVyW3pE5me8xqo1M/mR+TiZuWrSCyj7K9jBNCRlRoqQji8/bqtB28Eoo1c8KySoLpdRubtN/29fYNllkL2O5BQQFA7X58XWqZjlAh6KmHqKAyVziolP3siVxmpuVZrHbnr+8s1Vcbc4oYEcwdO+f3Y+GA5dWF6GeM7dcHTezvOLKBZejXbuUynl+irr+NwbPzcC9f7FDLBP1h5cRrkmgnKiGdEjVLWsEjUoDYClqTOI25TXI3auOHBqQtzXRTpz+R5mOSuvue6ifIq12Rpd5ovSFnFEpszs9/goz50uNmBe+iRM0n3/8BH6kK9DmWQOwxszA9MCEwCQYFKw4DAhoFAAQU6ffIRNpv/llqy14lwxuR657JqwkEFEFFQdo2eXJXuycTRX1idoXa2FEJAgIEAA==';
  16. var keyStoreService_;
  17. var pkcs12KeyStore_;
  18. var nonUint8Array_;
  19. var nonString_;
  20. var emptyString_;
  21. var wrongPkcs12DerB64_;
  22. var wrongPassword_;
  23. var wrongAlias_;
  24. var wrongSubjectCn_;
  25. beforeAll(function() {
  26. keyStoreService_ = keyStore.newService();
  27. pkcs12KeyStore_ =
  28. keyStoreService_.newPkcs12KeyStore(PKCS12_DER_B64, PASSWORD);
  29. nonUint8Array_ = [1, 2, 3];
  30. nonString_ = 0;
  31. emptyString_ = '';
  32. wrongPkcs12DerB64_ = 'Wrong PKCS12';
  33. wrongPassword_ = 'Wrong password';
  34. wrongAlias_ = 'Wrong alias';
  35. wrongSubjectCn_ = 'Wrong subject common name';
  36. });
  37. describe('create a key store service that should be able to ..', function() {
  38. it('throw an error when loading a PKCS12 key store, using an invalid store',
  39. function() {
  40. expect(function() {
  41. keyStoreService_.newPkcs12KeyStore(undefined, PASSWORD);
  42. }).toThrow();
  43. expect(function() {
  44. keyStoreService_.newPkcs12KeyStore(null, PASSWORD);
  45. }).toThrow();
  46. expect(function() {
  47. keyStoreService_.newPkcs12KeyStore(nonUint8Array_, PASSWORD);
  48. }).toThrow();
  49. expect(function() {
  50. keyStoreService_.newPkcs12KeyStore(emptyString_, PASSWORD);
  51. }).toThrow();
  52. });
  53. it('throw an error when loading a PKCS12 key store, using an invalid password',
  54. function() {
  55. expect(function() {
  56. keyStoreService_.newPkcs12KeyStore(PKCS12_DER_B64);
  57. }).toThrow();
  58. expect(function() {
  59. keyStoreService_.newPkcs12KeyStore(PKCS12_DER_B64, undefined);
  60. }).toThrow();
  61. expect(function() {
  62. keyStoreService_.newPkcs12KeyStore(PKCS12_DER_B64, null);
  63. }).toThrow();
  64. expect(function() {
  65. keyStoreService_.newPkcs12KeyStore(PKCS12_DER_B64, nonString_);
  66. }).toThrow();
  67. expect(function() {
  68. keyStoreService_.newPkcs12KeyStore(PKCS12_DER_B64, wrongPassword_);
  69. }).toThrow();
  70. });
  71. describe('load a PKCS12 key store that should be able to', function() {
  72. it('throw an error when retrieving a private key, using an invalid alias',
  73. function() {
  74. expect(function() {
  75. pkcs12KeyStore_.getPrivateKey(undefined, PASSWORD);
  76. }).toThrow();
  77. expect(function() {
  78. pkcs12KeyStore_.getPrivateKey(null, PASSWORD);
  79. }).toThrow();
  80. expect(function() {
  81. pkcs12KeyStore_.getPrivateKey('', PASSWORD);
  82. }).toThrow();
  83. expect(function() {
  84. pkcs12KeyStore_.getPrivateKey(nonString_, PASSWORD);
  85. }).toThrow();
  86. expect(function() {
  87. pkcs12KeyStore_.getPrivateKey(wrongAlias_, PASSWORD);
  88. }).toThrow();
  89. });
  90. it('throw an error when retrieving a private key, using an invalid password',
  91. function() {
  92. expect(function() {
  93. pkcs12KeyStore_.getPrivateKey(PRIVATE_KEY_ALIAS);
  94. }).toThrow();
  95. expect(function() {
  96. pkcs12KeyStore_.getPrivateKey(PRIVATE_KEY_ALIAS, undefined);
  97. }).toThrow();
  98. expect(function() {
  99. pkcs12KeyStore_.getPrivateKey(PRIVATE_KEY_ALIAS, null);
  100. }).toThrow();
  101. expect(function() {
  102. pkcs12KeyStore_.getPrivateKey(PRIVATE_KEY_ALIAS, nonString_);
  103. }).toThrow();
  104. expect(function() {
  105. pkcs12KeyStore_.getPrivateKey(PRIVATE_KEY_ALIAS, wrongPassword_);
  106. }).toThrow();
  107. });
  108. it('throw an error when retrieving a certificate, using invalid input data',
  109. function() {
  110. expect(function() {
  111. pkcs12KeyStore_.getCertificate();
  112. }).toThrow();
  113. expect(function() {
  114. pkcs12KeyStore_.getCertificate(undefined);
  115. }).toThrow();
  116. expect(function() {
  117. pkcs12KeyStore_.getCertificate(null);
  118. }).toThrow();
  119. expect(function() {
  120. pkcs12KeyStore_.getCertificate('');
  121. }).toThrow();
  122. expect(function() {
  123. pkcs12KeyStore_.getCertificate(nonString_);
  124. }).toThrow();
  125. expect(function() {
  126. pkcs12KeyStore_.getCertificate(wrongAlias_);
  127. }).toThrow();
  128. });
  129. it('throw an error when retrieving a certificate by subject, using invalid input data',
  130. function() {
  131. expect(function() {
  132. pkcs12KeyStore_.getCertificateBySubject();
  133. }).toThrow();
  134. expect(function() {
  135. pkcs12KeyStore_.getCertificateBySubject(undefined);
  136. }).toThrow();
  137. expect(function() {
  138. pkcs12KeyStore_.getCertificateBySubject(null);
  139. }).toThrow();
  140. expect(function() {
  141. pkcs12KeyStore_.getCertificateBySubject('');
  142. }).toThrow();
  143. expect(function() {
  144. pkcs12KeyStore_.getCertificateBySubject(nonString_);
  145. }).toThrow();
  146. expect(function() {
  147. pkcs12KeyStore_.getCertificateBySubject(wrongSubjectCn_);
  148. }).toThrow();
  149. });
  150. it('throw and error when retrieving a certificate chain, using invalid input data',
  151. function() {
  152. expect(function() {
  153. pkcs12KeyStore_.getCertificateChain();
  154. }).toThrow();
  155. expect(function() {
  156. pkcs12KeyStore_.getCertificateChain(undefined);
  157. }).toThrow();
  158. expect(function() {
  159. pkcs12KeyStore_.getCertificateChain(null);
  160. }).toThrow();
  161. expect(function() {
  162. pkcs12KeyStore_.getCertificateChain('');
  163. }).toThrow();
  164. expect(function() {
  165. pkcs12KeyStore_.getCertificateChain(nonString_);
  166. }).toThrow();
  167. expect(function() {
  168. pkcs12KeyStore_.getCertificateChain(wrongAlias_);
  169. }).toThrow();
  170. });
  171. });
  172. });
  173. });