stores.pkcs12.spec.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. describe('Stores', function() {
  9. 'use strict';
  10. var _testString = 'Ox2fUJq1gAbX';
  11. var _testPassword = 'PM6XtkOTbefJmhHGFgbz';
  12. var _rootRsaPrivateKeyAlias = 'root_rsa_private_key';
  13. var _userRsaPrivateKeyAlias = 'user_rsa_private_key';
  14. var _pkcs12DerBase64 =
  15. 'MIIaAQIBAzCCGbsGCSqGSIb3DQEHAaCCGawEghmoMIIZpDCCCvEGCSqGSIb3DQEHAaCCCuIEggreMIIK2jCCBWkGCyqGSIb3DQEMCgECoIIE+jCCBPYwKAYKKoZIhvcNAQwBAzAaBBSSjjJGUYGJDejWdN+I9JtoUS5GlwICBAAEggTIIm/j53Vt9JV14SyNUCY2Fe2FI0iwKRwr12N/4/mmLU6nSONnrp0awB5z+d5T4sLpekMUvayn8o3r0NTzzasdadH7tK3UDEgcSCuutGMk3JxZr2QbzRzHOr2qxUN6Y+069InDKO+8NNt+uC2vewPs8X3Q9qsrbhhQJdrjmKRwmmO9IJmYnbIBxl6Y3h0D3KZfCetYleKDuuv78Gx6Z2VFh+lw3Dx2CSaSNXwOWLGTfMxXbzKXfHu8GlT7s9I3qmgxluC1PTJUb1Kpc56sEhQ6kHSoDFXuC5fJRl5qhaMtcQmhZvRb6TIxWwIK6bNfxw2jQbK0ZkXOFtkZFAMKh34jW+F2xjEP49IqbH4e1buXY62KvUQLJwtb7pZehwWrf544ycX8eKNPf8tqepE5jZZVR/VPk8VgLYhgngzDsgPZvndGoG/UWQgzBbI3O9cx9pGmc0mcJBw68bg2BR6dLt3x6lvIdp7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VENGSikMWiiNolSsMhcrI9DrhKBroI4T5njo0tab0Ne4FpJq5WqpVhnMD5zSZPeODz7aYaXufN/JNBLRo9QLTFaqw/IzUwuM7RZnvQb00k05r4isYDIxCI9FvLN+/MRnZjOdwsrcdk1zF2+23b4DIntbWbx7gMvto7IwJ/McGG4Zf2IG87W6vZN9UrFEcZ2lIoukk6mDUUtKB84aUDBWnHW2Josh2pKHAAmFZP9GuEW0ojFT4siVgv9VijYzSgNsfAFIwmsY/O7OOboE9BiaznrpB/CqmiVpKFWwynNoFrYZCVyW3pE5me8xqo1M/mR+TiZuWrSCyj7K9jBNCRlRoqQji8/bqtB28Eoo1c8KySoLpdRubtN/29fYNllkL2O5BQQFA7X58XWqZjlAh6KmHqKAyVziolP3siVxmpuVZrHbnr+8s1Vcbc4oYEcwdO+f3Y+GA5dWF6GeM7dcHTezvOLKBZejXbuUynl+irr+NwbPzcC9f7FDLBP1h5cRrkmgnKiGdEjVLWsEjUoDYClqTOI25TXI3auOHBqQtzXRTpz+R5mOSuvue6ifIq12Rpd5ovSFnFEpszs9/goz50uNmBe+iRM0n3/8BH6kK9DmWQOwxszA9MCEwCQYFKw4DAhoFAAQU6ffIRNpv/llqy14lwxuR657JqwkEFEFFQdo2eXJXuycTRX1idoXa2FEJAgIEAA==';
  16. var _rootCn = 'Root CN';
  17. var _userCn = 'Subject CN';
  18. var _rootRsaPrivateKeyPem =
  19. '-----BEGIN RSA PRIVATE KEY-----MIIEogIBAAKCAQEAngCJ2RYh3XOvghmAi2MT26/fx4Hx8gYkYS2zaf9c2H8Qns1hnIHO8pIlHze/stUmNzim6nlytbJLQHmVDu64Pf9dn1ClAW2caKqUo4ofjnOzDd6RocQByjTsvZ1nOcG5BMYtOWGua+QIVFrxvxZgL6T3ShQ+9J3/1LiQDUmWj0kMoct6vRJuNkJxVFegtIEqYZYTTFI1+Y25k040NFu0e9IDwDXQA63EqKL3DjrgxdjOY+KXu4zU6DUcL4VcKaTMs1+pDfU6bSOtrecuasKkE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4DW8Svhd+igIviQ2JnP68Z4OeKZBx2tcrrOfwrRAoGAGyXTcOvhr+5ayXkQ36VAr2YcAUs2SeN0HwmYBP2ErCgd/KXri7RwWXqEQtvpvAOGJq/tXyc7P5BnBhlqQtUm9WX7kqTy/dIS+pJP0UMm02N9U+b02G0auPmBKM35LXO4YGhZep1Vig+MLycR8OSe0cd4gzk52u3Th9I3e0bV9Fw=-----END RSA PRIVATE KEY-----';
  20. var _rootRsaPublicKeyPem =
  21. '-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAngCJ2RYh3XOvghmAi2MT26/fx4Hx8gYkYS2zaf9c2H8Qns1hnIHO8pIlHze/stUmNzim6nlytbJLQHmVDu64Pf9dn1ClAW2caKqUo4ofjnOzDd6RocQByjTsvZ1nOcG5BMYtOWGua+QIVFrxvxZgL6T3ShQ+9J3/1LiQDUmWj0kMoct6vRJuNkJxVFegtIEqYZYTTFI1+Y25k040NFu0e9IDwDXQA63EqKL3DjrgxdjOY+KXu4zU6DUcL4VcKaTMs1+pDfU6bSOtrecuasKkEmNE9fuy9WejFqNGqlrNVCeYmOOnNXvI0vCdH1bw4/CpqddxvGZOStczF8vGJVcMVQIDAQAB-----END PUBLIC KEY-----';
  22. var _userRsaPrivateKeyPem =
  23. '-----BEGIN RSA PRIVATE KEY-----MIIEowIBAAKCAQEAglypZU45bnf2opnRI+Y51VqouBpvDT33xIB/OtbwKzwVpi+JrjBFtfk33tE9t/dSRs79CK94HRhCWcOiLa2qWPrjeZ9SBiEyScrhIvRZVBF41zBgwQNuRvJCsKmAqlZaFNJDZxEP4repmlBn1CfVFmfrXmOKqwP5F7l9ZtucveRzsfmF1yVPFkW8TMuB3YqMiyymyqHlS8ujCsu5I8tpgPbwuxdMOY94fNhSXrYkY8IuX1g1zdq/Z1jluOaR/UqK4UpnbuJaH/F0VgDNiWh6cTD0DFGEk0b70i5wU4Q3L/S6XZQRvSuADoCbhwBKuFL5pW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H7cmWQnWvvJ5izrx/7PogQVPOLELeUIGLu/hjsSdDKiFCxCUZ948+9NuG+DnpXDWzw//r8mPBRRGGsqFws5Aipp7yjQ3kRDCCzGelPCVhHyfmKqA+8ewXPulKS3/wIyHIvaXmsuAtTfurHtpRyzjKmCBK1Y6WQ3trIXvo7s-----END RSA PRIVATE KEY-----';
  24. var _userRsaPublicKeyPem =
  25. '-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAglypZU45bnf2opnRI+Y51VqouBpvDT33xIB/OtbwKzwVpi+JrjBFtfk33tE9t/dSRs79CK94HRhCWcOiLa2qWPrjeZ9SBiEyScrhIvRZVBF41zBgwQNuRvJCsKmAqlZaFNJDZxEP4repmlBn1CfVFmfrXmOKqwP5F7l9ZtucveRzsfmF1yVPFkW8TMuB3YqMiyymyqHlS8ujCsu5I8tpgPbwuxdMOY94fNhSXrYkY8IuX1g1zdq/Z1jluOaR/UqK4UpnbuJaH/F0VgDNiWh6cTD0DFGEk0b70i5wU4Q3L/S6XZQRvSuADoCbhwBKuFL5pW5n865oLVb5S3wuVdWaGwIDAQAB-----END PUBLIC KEY-----';
  26. var _rootX509CertificatePem =
  27. '-----BEGIN CERTIFICATE-----MIIEKjCCAxKgAwIBAgIQQtWFdPN4NAvUIWyyJyUlbTANBgkqhkiG9w0BAQsFADBUMRAwDgYDVQQDDAdSb290IENOMRYwFAYDVQQLDA1Sb290IE9yZyBVbml0MREwDwYDVQQKDAhSb290IE9yZzEVMBMGA1UEBhMMUm9vdCBDb3VudHJ5MB4XDTE0MDYxODEwMjMyOFoXDTE1MDYxODEwMjMyOFowVDEQMA4GA1UEAwwHUm9vdCBDTjEWMBQGA1UECwwNUm9vdCBPcmcgVW5pdDERMA8GA1UECgwIUm9vdCBPcmcxFTATBgNVBAYTDFJvb3QgQ291bnRyeTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ4AidkWId1zr4IZgItjE9uv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vcNAQELBQADggEBAAWZDJD6bg4ohHewszrAbL2tdUNxhrwCgNaHUhwNK43kiLGH0U9innhL1i0jP1VHNkL1G/+ZCo1qzh/Usji/jtlurfAWtrXku6VRF9NP+itKOY5jJ91Ijkc7t4dgoeJq6iMHn6JbDKIQ88r/Ikd0GdF04o5Qjqq1HlUVmqyIOHeHFla4i4tOxTyUBj34eE1No/xmaKYV1QtR1dqSHblR7OagEo7Dd3fXp7iSrKrXaN0Ef/6zeF3zjU5SMKcUcU9d3CbhS/CrGb+UGlqTXgzPXQWESH9AqBNl67+HF3mYktDQOZYPT5WRO5IKSko2cy9pP9UCsLk4oU3xyOxacWDpk1k=-----END CERTIFICATE-----';
  30. // Test opening PKCS12 and retrieving multiple private keys.
  31. describe('Pkcs12 ...', function() {
  32. describe('should be able to ..', function() {
  33. it('retrieve its private key chain and certificate chain, when PKCS12 was generated using Java.',
  34. function() {
  35. cryptolib(
  36. 'stores.pkcs12', 'certificates', 'asymmetric.signer',
  37. 'primitives.securerandom', 'commons.utils', function(box) {
  38. // Retrieve PKCS12.
  39. var pkcs12 = new box.stores.pkcs12.Pkcs12(_pkcs12DerBase64);
  40. var converters = new box.commons.utils.Converters();
  41. // Retrieve private key chain from PKCS12.
  42. var passwordBase64Encoded =
  43. converters.base64Encode(_testPassword);
  44. var privateKeyChain =
  45. pkcs12.getPrivateKeyChain(passwordBase64Encoded);
  46. var userPrivateKeyPem =
  47. privateKeyChain.get(_userRsaPrivateKeyAlias)
  48. .replace(/(\r\n|\n|\r)/gm, '');
  49. var userPrivateKey =
  50. forge.pki.privateKeyFromPem(_userRsaPrivateKeyPem);
  51. var rootPrivateKeyPem =
  52. privateKeyChain.get(_rootRsaPrivateKeyAlias)
  53. .replace(/(\r\n|\n|\r)/gm, '');
  54. var rootPrivateKey =
  55. forge.pki.privateKeyFromPem(rootPrivateKeyPem);
  56. // Retrieve certificate chain from PKCS12, in PEM format.
  57. var userCertificatePem =
  58. pkcs12
  59. .getCertificateBySubject(
  60. passwordBase64Encoded, _userCn)
  61. .replace(/(\r\n|\n|\r)/gm, '');
  62. var rootCertificatePem =
  63. pkcs12
  64. .getCertificateBySubject(
  65. passwordBase64Encoded, _rootCn)
  66. .replace(/(\r\n|\n|\r)/gm, '');
  67. // Retrieve user public key from PKCS12.
  68. var userPublicKey =
  69. forge.pki.certificateFromPem(userCertificatePem).publicKey;
  70. var userPublicKeyPem = forge.pki.publicKeyToPem(userPublicKey)
  71. .replace(/(\r\n|\n|\r)/gm, '');
  72. // Check whether user key pair retrieved from PKCS12 is same as
  73. // original.
  74. var userPrivateKeyOrig =
  75. forge.pki.privateKeyFromPem(_userRsaPrivateKeyPem);
  76. expect(userPrivateKey.p).toEqual(userPrivateKeyOrig.p);
  77. expect(userPrivateKey.q).toEqual(userPrivateKeyOrig.q);
  78. var userPublicKeyOrig =
  79. forge.pki.publicKeyFromPem(_userRsaPublicKeyPem);
  80. expect(userPublicKey.e).toEqual(userPublicKeyOrig.e);
  81. expect(userPublicKey.n).toEqual(userPublicKeyOrig.n);
  82. expect(userPublicKeyPem).toBe(_userRsaPublicKeyPem);
  83. var dataB64 = converters.base64Encode(_testString);
  84. var arrayDataBase64 = [dataB64];
  85. // Check whether retrieved user key pair can be used to
  86. // generate and verify a signature.
  87. var signerFactory =
  88. new box.asymmetric.signer.factory.SignerFactory();
  89. var rsaSigner = signerFactory.getCryptoSigner();
  90. var signatureB64 =
  91. rsaSigner.sign(userPrivateKeyPem, arrayDataBase64);
  92. expect(rsaSigner.verify(
  93. signatureB64, userPublicKeyPem, arrayDataBase64))
  94. .toBeTruthy();
  95. // Retrieve root public key from PKCS12, in PEM format.
  96. var rootPublicKey =
  97. forge.pki.certificateFromPem(rootCertificatePem).publicKey;
  98. var rootPublicKeyPem = forge.pki.publicKeyToPem(rootPublicKey)
  99. .replace(/(\r\n|\n|\r)/gm, '');
  100. // Check whether root key pair retrieved from PKCS12 is same as
  101. // original.
  102. var rootPrivateKeyOrig =
  103. forge.pki.privateKeyFromPem(_rootRsaPrivateKeyPem);
  104. expect(rootPrivateKey.p).toEqual(rootPrivateKeyOrig.p);
  105. expect(rootPrivateKey.q).toEqual(rootPrivateKeyOrig.q);
  106. var rootPublicKeyOrig =
  107. forge.pki.publicKeyFromPem(_rootRsaPublicKeyPem);
  108. expect(rootPublicKey.e).toEqual(rootPublicKeyOrig.e);
  109. expect(rootPublicKey.n).toEqual(rootPublicKeyOrig.n);
  110. expect(rootPublicKeyPem).toBe(_rootRsaPublicKeyPem);
  111. // Check whether retrieved root key pair can be used to
  112. // generate and verify a signature.
  113. signatureB64 =
  114. rsaSigner.sign(rootPrivateKeyPem, arrayDataBase64);
  115. expect(rsaSigner.verify(
  116. signatureB64, rootPublicKeyPem, arrayDataBase64))
  117. .toBeTruthy();
  118. // Check whether certificate chain retrieved from PKCS12 is
  119. // same as original.
  120. expect(userCertificatePem).toBe(_userX509CertificatePem);
  121. expect(rootCertificatePem).toBe(_rootX509CertificatePem);
  122. // Verify signatures of certificate chain retrieved from
  123. // PKCS12.
  124. var rootCertificate =
  125. new box.certificates.CryptoX509Certificate(
  126. rootCertificatePem);
  127. expect(rootCertificate.verify(rootCertificatePem))
  128. .toBeTruthy();
  129. expect(rootCertificate.verify(userCertificatePem))
  130. .toBeTruthy();
  131. });
  132. });
  133. });
  134. });
  135. });