scytl-keystore.spec.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. var cryptoPolicy = require('scytl-cryptopolicy');
  12. var elGamal = require('scytl-elgamal');
  13. var certificate = require('scytl-certificate');
  14. var symmetric = require('scytl-symmetric');
  15. var pbkdf = require('scytl-pbkdf');
  16. var codec = require('scytl-codec');
  17. describe('The key store module that should be able to ...', function() {
  18. var PASSWORD = '01234567890abcdefghijk';
  19. var PRIVATE_KEY_1_ALIAS = 'user1';
  20. var PRIVATE_KEY_2_ALIAS = 'user2';
  21. var SECRET_KEY_1_ALIAS = 'symmetricalias1';
  22. var SECRET_KEY_2_ALIAS = 'symmetricalias2';
  23. var ELGAMAL_PRIVATE_KEY_1_ALIAS = 'elgamalprivatekeyalias1';
  24. var ELGAMAL_PRIVATE_KEY_2_ALIAS = 'elgamalprivatekeyalias2';
  25. var SUBJECT_COMMON_NAME = 'SecDev';
  26. var SCYTL_KEY_STORE = {
  27. 'salt': 'AWnL9mtD1UoAQ58l+8GH9aHPlrDMgeMF8m+0wHyCPAI=',
  28. 'secrets': {
  29. 'symmetricalias1':
  30. '7mgsaxqwL1oBASLQ40bcP5btCcLF1kgo+382PsIeqkyw3JeQIYsEIdRuUxdmP/9lUqQj+2sxxlCk6XU=',
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c5+kKpJh/egtsbxBNVeb12MmFPXzrockM6+ZlyOSdHxdFYUxlFaBnEs8MHTOXgoCpU93U/3uu7l+Kqm+i4ErpGliyYqguvMizxAHk8jckmzoMkcztvFFv18qlgG22Nz1BqwCobAc6DT7QQIlAQsQMY0d1QMlcxH35aTN5kS0/G2EDZ3ZG5AQEwQmczf4kNVWwk62XhTRcKcqdRRX/7h6OOMDc1nP5/GmcderDbaRFV28eFrzi4Mjjcjzpz889ttmHXPN7D8AvbTtHqRm4ujAFAvYbhU5hguY7x7BP+OOB01jvOM/F1U7Zzgg12FQoaMvcacJECaMR1Alz22htPaK0VIxCmxZd+q/T1xAJYPNwver4QbKJX6Pg==',
  42. 'elgamalprivatekeyalias2':
  43. 'vezAhuUI9Rqb9SNp9QXGpdiiKjJCGjK3MWmQbSC+NV+4HYEKKuCP6N9RuKAprssqmGYDWUc3ecYD6JsRlW2PNnbAv0oK/aGGogh3gqrVDLqBqSet1hmnN3NImAmXscpioAAnfPd1RR4V2lv8+Lc3aUPKTvNwl1P3jATM3TViGzb0hxMhsCuUwFOX'
  44. },
  45. 'store':
  46. 'MFUCAQMwEQYJKoZIhvcNAQcBoAQEAjAAMD0wITAJBgUrDgMCGgUABBR+zoG7NsLvE8zqUFX7HXeP/yK07gQUQaC4BDlbcjaPJxp4KTcJh9wSzMMCAgQA'
  47. };
  48. var ELGAMAL_PRIVATE_KEY_P_B64 =
  49. '25878792566670842099842137716422866466252991028815773139028451679515364679624923581358662655689289205766441980239548823737806954397019411202244121935752456749381769565031670387914863935577896116425654849306598185507995737892509839616944496073707445338806101425467388977937489020456783676102620561970644684015868766028080049372849872115052208214439472603355483095640041515460851475971118272125133224007949688443680429668091313474118875081620746919907567682398209044343652147328622866834600839878114285018818463110227111614032671442085465843940709084719667865761125514800243342061732684028802646193202210299179139410607';
  50. var ELGAMAL_PRIVATE_KEY_Q_B64 =
  51. '12939396283335421049921068858211433233126495514407886569514225839757682339812461790679331327844644602883220990119774411868903477198509705601122060967876228374690884782515835193957431967788948058212827424653299092753997868946254919808472248036853722669403050712733694488968744510228391838051310280985322342007934383014040024686424936057526104107219736301677741547820020757730425737985559136062566612003974844221840214834045656737059437540810373459953783841199104522171826073664311433417300419939057142509409231555113555807016335721042732921970354542359833932880562757400121671030866342014401323096601105149589569705303';
  52. var ELGAMAL_PRIVATE_KEY_G_B64 =
  53. '23337993065784550228812110720552652305178266477392633588884900695706615523553977368516877521940228584865573144621632575456086035440118913707895716109366641541746808409917179478292952139273396531060021729985473121368590574110220870149822495151519706210399569901298027813383104891697930149341258267962490850297875794622068418425473578455187344232698462829084010585324877420343904740081787639502967515631687068869545665294697583750184911025514712871193837246483893950501015755683415509019863976071649325968623617568219864744389709563087949389080252971419711636380986100047871404548371112472694814597772988558887480308242';
  54. var ELGAMAL_PRIVATE_KEY_EXPONENT_B64 =
  55. '4859259447320592668819568962669961246561051865212874540681243424367801394774393725734829250015941495215558771019728908939132002055237814853650010734496771955581048260699707147620967124841995608460226547395857304134089405473568889471419858106512603895297560717994246768950866491384823569118637582497519403351819609184883390558852906911976387433283350856334618005481106148226480670760580586739976814586223883428847209532777965666220529265035157816712732743895240103023779784827727286610206045924297284258748757461471125260095895029712193814187300268672295894546694634423997510695194818714918502470470193799175083856878';
  56. var policy_;
  57. var keyStoreService_;
  58. var scytlKeyStore_;
  59. var certificateService_;
  60. var policyForElGamal_;
  61. var scytlKeyStoreWithElGamalKeys_;
  62. var elGamalPrivateKeyP_;
  63. var elGamalPrivateKeyQ_;
  64. var elGamalPrivateKeyG_;
  65. var elGamalPrivateKeyExponent_;
  66. var scytlKeyStoreJson_;
  67. beforeAll(function() {
  68. policy_ = cryptoPolicy.newInstance();
  69. policy_.symmetric.secretKey.encryption.lengthBytes = 32;
  70. policy_.primitives.keyDerivation.pbkdf.keyLengthBytes = 16;
  71. policy_.primitives.keyDerivation.pbkdf.minSaltLengthBytes = 20;
  72. policy_.primitives.keyDerivation.pbkdf.hashAlgorithm = 'SHA256';
  73. policy_.primitives.keyDerivation.pbkdf.numIterations = 1;
  74. keyStoreService_ = keyStore.newService({policy: policy_});
  75. scytlKeyStore_ =
  76. keyStoreService_.newScytlKeyStore(SCYTL_KEY_STORE, PASSWORD);
  77. certificateService_ = certificate.newService();
  78. policyForElGamal_ = cryptoPolicy.newInstance();
  79. policyForElGamal_.symmetric.secretKey.encryption.lengthBytes = 32;
  80. policyForElGamal_.primitives.keyDerivation.pbkdf.keyLengthBytes = 16;
  81. policyForElGamal_.primitives.keyDerivation.pbkdf.minSaltLengthBytes = 32;
  82. policyForElGamal_.primitives.keyDerivation.pbkdf.hashAlgorithm = 'SHA256';
  83. policyForElGamal_.primitives.keyDerivation.pbkdf.numIterations = 32000;
  84. var keyStoreService = keyStore.newService({policy: policyForElGamal_});
  85. scytlKeyStoreWithElGamalKeys_ = keyStoreService.newScytlKeyStore(
  86. SCYTL_KEY_STORE_WITH_ELGAMAL_KEYS, PASSWORD);
  87. elGamalPrivateKeyP_ =
  88. codec.bytesToBigInteger(codec.base64Decode(ELGAMAL_PRIVATE_KEY_P_B64));
  89. elGamalPrivateKeyQ_ =
  90. codec.bytesToBigInteger(codec.base64Decode(ELGAMAL_PRIVATE_KEY_Q_B64));
  91. elGamalPrivateKeyG_ =
  92. codec.bytesToBigInteger(codec.base64Decode(ELGAMAL_PRIVATE_KEY_G_B64));
  93. elGamalPrivateKeyExponent_ = codec.bytesToBigInteger(
  94. codec.base64Decode(ELGAMAL_PRIVATE_KEY_EXPONENT_B64));
  95. scytlKeyStoreJson_ = JSON.stringify(SCYTL_KEY_STORE);
  96. });
  97. describe('create a key store service that should be able to ..', function() {
  98. describe('load a Scytl key store that should be able to', function() {
  99. it('retrieve one or more private keys', function() {
  100. var privateKey1Pem =
  101. scytlKeyStore_.getPrivateKey(PRIVATE_KEY_1_ALIAS, PASSWORD);
  102. expect(privateKey1Pem).toBeDefined();
  103. var privateKey2Pem =
  104. scytlKeyStore_.getPrivateKey(PRIVATE_KEY_2_ALIAS, PASSWORD);
  105. expect(privateKey2Pem).toBeDefined();
  106. });
  107. it('retrieve a private key, using a specified PBKDF service object',
  108. function() {
  109. var keyStoreService = keyStore.newService({
  110. policy: policy_,
  111. pbkdfService: pbkdf.newService({policy: policy_})
  112. });
  113. var scytlKeyStore =
  114. keyStoreService.newScytlKeyStore(SCYTL_KEY_STORE, PASSWORD);
  115. var privateKey1Pem =
  116. scytlKeyStore.getPrivateKey(PRIVATE_KEY_1_ALIAS, PASSWORD);
  117. expect(privateKey1Pem).toBeDefined();
  118. });
  119. it('retrieve one or more certificates', function() {
  120. var certificate1Pem =
  121. scytlKeyStore_.getCertificate(PRIVATE_KEY_1_ALIAS);
  122. expect(certificate1Pem).toBeDefined();
  123. var certificate2Pem =
  124. scytlKeyStore_.getCertificate(PRIVATE_KEY_2_ALIAS);
  125. expect(certificate2Pem).toBeDefined();
  126. });
  127. it('retrieve a certificate by subject', function() {
  128. var certificatePem =
  129. scytlKeyStore_.getCertificateBySubject(SUBJECT_COMMON_NAME);
  130. expect(certificatePem).toBeDefined();
  131. var certificate =
  132. certificateService_.newX509Certificate(certificatePem);
  133. expect(certificate.subjectCommonName).toBe('SecDev');
  134. expect(certificate.subjectOrganizationalUnit).toBe('QA');
  135. expect(certificate.subjectOrganization).toBe('Scytl');
  136. expect(certificate.subjectCountry).toBe('ES');
  137. expect(certificate.verify(certificatePem)).toBe(true);
  138. });
  139. it('retrieve one or more certificate chains', function() {
  140. var certificateChain1 =
  141. scytlKeyStore_.getCertificateChain(PRIVATE_KEY_1_ALIAS);
  142. expect(certificateChain1).toBeDefined();
  143. expect(certificateChain1.length).toBe(3);
  144. var certificateChain2 =
  145. scytlKeyStore_.getCertificateChain(PRIVATE_KEY_2_ALIAS);
  146. expect(certificateChain2).toBeDefined();
  147. expect(certificateChain2.length).toBe(4);
  148. var rootCertificate =
  149. certificateService_.newX509Certificate(certificateChain1[2]);
  150. var intermediateCertificate =
  151. certificateService_.newX509Certificate(certificateChain1[1]);
  152. var leafCertificate =
  153. certificateService_.newX509Certificate(certificateChain1[0]);
  154. expect(rootCertificate.subjectCommonName).toBe('SecDev');
  155. expect(intermediateCertificate.subjectCommonName).toBe('SecQA');
  156. expect(leafCertificate.subjectCommonName).toBe('SecEndEntity');
  157. expect(rootCertificate.verify(certificateChain1[2])).toBe(true);
  158. expect(rootCertificate.verify(certificateChain1[1])).toBe(true);
  159. expect(intermediateCertificate.verify(certificateChain1[0])).toBe(true);
  160. });
  161. it('retrieve one or more secret keys', function() {
  162. var secretKey1 =
  163. scytlKeyStore_.getSecretKey(SECRET_KEY_1_ALIAS, PASSWORD);
  164. expect(secretKey1).toBeDefined();
  165. expect(secretKey1.length).toBe(16);
  166. var secretKey2 =
  167. scytlKeyStore_.getSecretKey(SECRET_KEY_2_ALIAS, PASSWORD);
  168. expect(secretKey2).toBeDefined();
  169. expect(secretKey2.length).toBe(16);
  170. });
  171. it('retrieve a secret key, using a specified symmetric cryptography service object',
  172. function() {
  173. var keyStoreService = keyStore.newService({
  174. policy: policy_,
  175. symmetricCryptographyService:
  176. symmetric.newService({policy: policy_})
  177. });
  178. var scytlKeyStore =
  179. keyStoreService.newScytlKeyStore(SCYTL_KEY_STORE, PASSWORD);
  180. var secretKey1 =
  181. scytlKeyStore.getSecretKey(SECRET_KEY_1_ALIAS, PASSWORD);
  182. expect(secretKey1).toBeDefined();
  183. expect(secretKey1.length).toBe(16);
  184. });
  185. it('retrieve one or more ElGamal private keys', function() {
  186. var elGamalPrivateKey1 =
  187. scytlKeyStoreWithElGamalKeys_.getElGamalPrivateKey(
  188. ELGAMAL_PRIVATE_KEY_1_ALIAS, PASSWORD);
  189. expect(elGamalPrivateKey1).toBeDefined();
  190. var elGamalPrivateKey2 =
  191. scytlKeyStoreWithElGamalKeys_.getElGamalPrivateKey(
  192. ELGAMAL_PRIVATE_KEY_2_ALIAS, PASSWORD);
  193. expect(elGamalPrivateKey2).toBeDefined();
  194. var group = elGamalPrivateKey1.group;
  195. expect(group.p.toString()).toEqual(elGamalPrivateKeyP_.toString());
  196. expect(group.q.toString()).toEqual(elGamalPrivateKeyQ_.toString());
  197. expect(group.generator.value.toString())
  198. .toEqual(elGamalPrivateKeyG_.toString());
  199. var exponents = elGamalPrivateKey1.exponents;
  200. expect(exponents.length).toBe(1);
  201. expect(exponents[0].value.toString())
  202. .toEqual(elGamalPrivateKeyExponent_.toString());
  203. });
  204. it('retrieve an ElGamal private key, using a specified ElGamal service object',
  205. function() {
  206. var keyStoreService = keyStore.newService({
  207. policy: policyForElGamal_,
  208. elGamalService: elGamal.newService()
  209. });
  210. var scytlKeyStoreWithElGamalKeys = keyStoreService.newScytlKeyStore(
  211. SCYTL_KEY_STORE_WITH_ELGAMAL_KEYS, PASSWORD);
  212. var elGamalPrivateKey1 =
  213. scytlKeyStoreWithElGamalKeys.getElGamalPrivateKey(
  214. ELGAMAL_PRIVATE_KEY_1_ALIAS, PASSWORD);
  215. expect(elGamalPrivateKey1).toBeDefined();
  216. });
  217. });
  218. it('load a Scytl key store, in JSON format', function() {
  219. var scytlKeyStore = keyStoreService_.newScytlKeyStore(
  220. JSON.stringify(SCYTL_KEY_STORE), PASSWORD);
  221. expect(scytlKeyStore).toBeDefined();
  222. // Check private keys.
  223. var privateKey1Pem =
  224. scytlKeyStore_.getPrivateKey(PRIVATE_KEY_1_ALIAS, PASSWORD);
  225. expect(privateKey1Pem).toBeDefined();
  226. var privateKey2Pem =
  227. scytlKeyStore_.getPrivateKey(PRIVATE_KEY_2_ALIAS, PASSWORD);
  228. expect(privateKey2Pem).toBeDefined();
  229. // Check certificates.
  230. var certificate1Pem = scytlKeyStore_.getCertificate(PRIVATE_KEY_1_ALIAS);
  231. expect(certificate1Pem).toBeDefined();
  232. var certificate2Pem = scytlKeyStore_.getCertificate(PRIVATE_KEY_2_ALIAS);
  233. expect(certificate2Pem).toBeDefined();
  234. // Check secret keys.
  235. var secretKey1 =
  236. scytlKeyStore_.getSecretKey(SECRET_KEY_1_ALIAS, PASSWORD);
  237. expect(secretKey1).toBeDefined();
  238. expect(secretKey1.length).toBe(16);
  239. var secretKey2 =
  240. scytlKeyStore_.getSecretKey(SECRET_KEY_2_ALIAS, PASSWORD);
  241. expect(secretKey2).toBeDefined();
  242. expect(secretKey2.length).toBe(16);
  243. var keyStoreService = keyStore.newService({policy: policyForElGamal_});
  244. var scytlKeyStoreWithElGamalKeys = keyStoreService.newScytlKeyStore(
  245. JSON.stringify(SCYTL_KEY_STORE_WITH_ELGAMAL_KEYS), PASSWORD);
  246. expect(scytlKeyStoreWithElGamalKeys).toBeDefined();
  247. // Check ElGamal keys.
  248. var elGamalPrivateKey1 =
  249. scytlKeyStoreWithElGamalKeys.getElGamalPrivateKey(
  250. ELGAMAL_PRIVATE_KEY_1_ALIAS, PASSWORD);
  251. expect(elGamalPrivateKey1).toBeDefined();
  252. var elGamalPrivateKey2 =
  253. scytlKeyStoreWithElGamalKeys.getElGamalPrivateKey(
  254. ELGAMAL_PRIVATE_KEY_2_ALIAS, PASSWORD);
  255. expect(elGamalPrivateKey2).toBeDefined();
  256. });
  257. });
  258. });