2
0

certificate-chain-validation.spec.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 certificate = require('../lib/index');
  11. describe('The certificate module should be able to ...', function() {
  12. var validChain_ = {
  13. leaf: {
  14. pem:
  15. '-----BEGIN CERTIFICATE-----MIICCzCCAXSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBHMRswGQYDVQQDDBJ3aGl0ZSBpbnRlcm1lZGlhdGUxDjAMBgNVBAoMBXNjeXRsMQswCQYDVQQLDAJzZTELMAkGA1UEBhMCRVMwHhcNMTQwOTA1MTAxNDEzWhcNMjQwODEzMTAxNDEzWjA/MRMwEQYDVQQDDAp3aGl0ZSBsZWFmMQ4wDAYDVQQKDAVzY3l0bDELMAkGA1UECwwCc2UxCzAJBgNVBAYTAkVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3yWZQRc5xk14TIL3/2UGVgNz94dHq7vg4ORduUvtio4nVMSriQNSPnEbAfV9FR8qA6UCzqXQroNX6eSpQfJ4MblyUWUj7VYtY/jC2UxGcE4GJxhngiwfO+It2ejTr6I7EPlj7pwPOVTDWByaDsYWtJ3JeaVhR9Tcf5L+H5k7HTQIDAQABow8wDTALBgNVHQ8EBAMCBsAwDQYJKoZIhvcNAQEFBQADgYEAQNoV1G2zwceE1/4VppH3eJYi8u1CUWUoaQe1rH3owm9CH9/OfS+MicUIW/7yRi86rtATnhTcfN34E18AwbJsmESBnCkx+WaVZ/WC1jGJ/Dd5rgxvRfZpwd1RKivKzZsoYm19PVFRDg9K9qqA6dkuq29wTnwMV48rQPkfix9lWjg=-----END CERTIFICATE-----',
  16. keyType: 'Sign',
  17. subject: {
  18. commonName: 'white leaf',
  19. organizationalUnit: 'se',
  20. organization: 'scytl',
  21. country: 'ES'
  22. },
  23. time: '2014-12-25\'T\'00:00:00Z'
  24. },
  25. intermediates: {
  26. pems: [
  27. '-----BEGIN CERTIFICATE-----MIICGjCCAYOgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MREwDwYDVQQDDAh3aGl0ZSBjYTEOMAwGA1UECgwFc2N5dGwxCzAJBgNVBAsMAnNlMQswCQYDVQQGEwJFUzAeFw0xNDA5MDUwOTM1MThaFw0yNDA4MjMwOTM1MThaMEcxGzAZBgNVBAMMEndoaXRlIGludGVybWVkaWF0ZTEOMAwGA1UECgwFc2N5dGwxCzAJBgNVBAsMAnNlMQswCQYDVQQGEwJFUzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwUmpmT/rNcxIP8Xulj0RcbdvaNGJNoEPMzEGztguB+mKsTPgJIlrKvdskY5NIPd1+hzS+HjvW11uwyT2FnmyfKBqND4EH5BqU8Ph4bAyrT950DPcOGE4vG0fLO0jTD3h0n4d4yugWmrND2sScFZQsGLbgOYX4QM8vV+owoKNRxMCAwEAAaMgMB4wDwYDVR0TBAgwBgEB/wIBADALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEFBQADgYEAF0B5LQDo3uRs9dSkxp39ER64XIa6XYV0zdbq+fqHg8Qcoggpox7vwmc6YoCNQpfY2zLiIUMbb6VMP4pkp7jZMju9TBKPOjMFrQKom0cowT/gYdokgnsk8yUYOdo46GJR43PjFLTiQk5JDawWaECbhcgyLf59AalX9z9dbY0AwqI=-----END CERTIFICATE-----'
  28. ],
  29. subjects: [{
  30. commonName: 'white intermediate',
  31. organizationalUnit: 'se',
  32. organization: 'scytl',
  33. country: 'ES'
  34. }]
  35. },
  36. root: {
  37. pem:
  38. '-----BEGIN CERTIFICATE-----MIICSDCCAbGgAwIBAgIJAPJ2LYuwqa81MA0GCSqGSIb3DQEBBQUAMD0xETAPBgNVBAMMCHdoaXRlIGNhMQ4wDAYDVQQKDAVzY3l0bDELMAkGA1UECwwCc2UxCzAJBgNVBAYTAkVTMB4XDTE0MDkwNTA5MzQwNloXDTI0MDkwMjA5MzQwNlowPTERMA8GA1UEAwwId2hpdGUgY2ExDjAMBgNVBAoMBXNjeXRsMQswCQYDVQQLDAJzZTELMAkGA1UEBhMCRVMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALnpKp2eeY1hC4V8E1nUIZJpJVhAZk3oJeEbq0Xi2uSYrh6wmfuQIHFs5rYF4yHoGvf+PM66od8ccHa1GNGB/b6lFb4/+2vEvYWA51OWY9BBdgjhAsqoks9ANNDQ1oxX4dqLwjM/GDDg2v9xoT9tj0CaJnieQbhMkH8oQveBBR57AgMBAAGjUDBOMB0GA1UdDgQWBBRwKg/RntWH8EvCkEX3jtHuvSpbwTAfBgNVHSMEGDAWgBRwKg/RntWH8EvCkEX3jtHuvSpbwTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBADk/OOoc2tbfxja95RqH22EcAVJ/mDin2ev9cXhZ2A2xh4SrUad0fNsyFnY+m3EzfA0KPrI46sEPDeuWqwnGAYccmp7ylVIS6edYRvnI5mdLze2CnuDNJYQzZXjASQF2ih5wTNm3VMZkN0SqGQZiOCa9NQHPfmNj8mJe0Ooj2b3o-----END CERTIFICATE-----'
  39. }
  40. };
  41. var validChainFromJava_ = {
  42. leaf: {
  43. pem:
  44. '-----BEGIN CERTIFICATE-----MIIDeDCCAmCgAwIBAgIVAJ81fEEjKAKK8Yg5D654L3suMkbVMA0GCS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LEAJZD0xDv4ohir5FWcnMPdUvmwfya/mZZhns94y5aiql/kTJPl0f0G1t0AOkRYqbB/w==-----END CERTIFICATE-----',
  45. keyType: 'Sign',
  46. subject: {
  47. commonName: 'VoterSign 41154974123973128044422774175187306997',
  48. organizationalUnit: 'sg1001-000',
  49. organization: 'NSWEC',
  50. country: 'AU'
  51. },
  52. time: '2014-12-25\'T\'00:00:00Z'
  53. },
  54. intermediates: {
  55. pems: [
  56. '-----BEGIN CERTIFICATE-----MIIDWzCCAkOgAwIBAgIULFolrOnoUb8h6GroW8JoRZtvSrcwDQYJKoZIhvcNAQELBQAwWTEaMBgGA1UEAwwRRWxlY3Rpb24gRXZlbnQgQ0ExEzARBgNVBAsMCnNnMTAwMS0wMDAxDjAMBgNVBAoMBU5TV0VDMQkwBwYDVQQHDAAxCzAJBgNVBAYTAkFVMB4XDTE0MDkwODA3NDM1N1oXDTE1MDkwODA3NDM1NFowUTESMBAGA1UEAwwJVm90ZXJzIENBMRMwEQYDVQQLDApzZzEwMDEtMDAwMQ4wDAYDVQQKDAVOU1dFQzEJMAcGA1UEBwwAMQswCQYDVQQGEwJBVTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALAjG+fLhtK6FS0iLdAPscY9jCGYjROueU0F+ans8a5e214RDNS2WdnYhJSuPRcbftztncze6vCD0/KSZO6MTwagqx7iudFhSITJA96tTDT0pEQ/fInkcJbOh8LYAHukEXYPxQSiHTD52UTLwPpAVd/DhBflf7LKL0VEjXuDifU/EvVDp96g6yoyHMiv6REsIrr8o2cSI5UbrxPIX7V/fAwfHKDyRp2ECrqaMmz/7dKWjhB0zoBQGI7r4WCIDmUbU9psn90a5y6xj5XhuF6HzozaZH1IibCTULdTQEUfs4dPaF+5oWlCZrF+dkBTXQh4Pm1h+iOboCk+8FcZtt4ijC0CAwEAAaMjMCEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAD96TL6FvCMtoRJqjowqVRSQTAhnCcPesmG6+yzz9YXWu46koEM/XkeZm+wtIF6YC2R59vAvbFNtrnkThvFG3sDXDUAeDS4vrVr8S0BApbHDa94ri7Km8aYrPhwy5sDOsq5QR//RZORPOJaMeZHiJA0MP31GJJjwcJJs4uOm3sQHEdNArSEp8+Dzim3X/EY6NWo8COeKEwcPSm0c/jMung1NYKFV6CGF/jOOEcrESNdnBWi7LYAWn/ba9XiyuKhD26bLX1L20IFEO+EvcnEvLrhulmRe/bZsLkyZMieZqh+w3KFUe2F452J6o+/i2TbHcn8/c2B9T490/dV5w8sB1bM=-----END CERTIFICATE-----'
  57. ],
  58. subjects: [{
  59. commonName: 'Voters CA',
  60. organizationalUnit: 'sg1001-000',
  61. organization: 'NSWEC',
  62. country: 'AU'
  63. }]
  64. },
  65. root: {
  66. pem:
  67. '-----BEGIN CERTIFICATE-----MIIDYzCCAkugAwIBAgIUax82wdIaGWRKCH3J1h1u4Ij4F7AwDQYJKoZIhvcNAQELBQAwWTEaMBgGA1UEAwwRRWxlY3Rpb24gRXZlbnQgQ0ExEzARBgNVBAsMCnNnMTAwMS0wMDAxDjAMBgNVBAoMBU5TV0VDMQkwBwYDVQQHDAAxCzAJBgNVBAYTAkFVMB4XDTE0MDkwODA3NDM1NloXDTE1MDkwODA3NDM1NFowWTEaMBgGA1UEAwwRRWxlY3Rpb24gRXZlbnQgQ0ExEzARBgNVBAsMCnNnMTAwMS0wMDAxDjAMBgNVBAoMBU5TV0VDMQkwBwYDVQQHDAAxCzAJBgNVBAYTAkFVMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgXYi9cTerqmun+SS56tByn9Z9OYwP2cS8NkvHO0Pv04lTEJ//1jo8uUpn3kza4m5lgUFEr6hl+e+G21yk/NrieD4Ke008Be0F9arSedsYyQvqcg1VcssY3+mtbz8osOH8f/jB6cMkASrzESvDOIM45MkaFlAYqkxN4q819qaOgWvlotkQKUKu+Dnb59Cpqf8MQ2nVv+mEwXVZiVCKquOnEN29vqppI8GigE1jqRkKx5mIwmUBYWrOalWVexMNJVSAqyxlJ1ozgKC6Z/o37l/pRFJMG1iIiAiMRucokWn7p9414O+3O4OuDP1lkBG7PxzmOHEl3WrJ7hseGLWIF/mcwIDAQABoyMwITAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAQEAO89PQSEeZkGxydWgFJ61DKq6eiaNjCRXKorH3yDCd7wwuOiKamJRojk29zrLZR+0BrYGVLV4JPj/0ZStNtbQfz1jeadEVdrpjlk9NfNgPcYIbb9tENNNFRqeQR8JB1K+qOELZt87jX9wg1jzgAo0kSHDAIIADDOhX//lzeE2amaXgYYHmLtdKpZI2lXKj1VmdeeR/wGtpkXGkDO65FkvcY65lj25wzksanpk/juy4ENLoY1AvC6f30Kw7CSduoctsB58MOPPtlR6rA7EmSWUAdfTmobB3kHOm6OZN+nikUhC73l1kS9mZXg/oabO7yoOmRQ7ttqqNmecaB7EnS5nHg==-----END CERTIFICATE-----'
  68. }
  69. };
  70. var timeCheckChain_ = {
  71. leaf: {
  72. pem:
  73. '-----BEGIN CERTIFICATE-----MIIDszCCApugAwIBAgIJALAhpG3UDbqKMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNVBAYTAkVTMRMwEQYDVQQIDApUZXN0LVN0YXRlMQ4wDAYDVQQKDAVTY3l0bDELMAkGA1UECwwCUUExDjAMBgNVBAMMBVNlY1FBMB4XDTE0MTAyMzE1MTMxMVoXDTE1MTAyMzE1MTMxMVowVjELMAkGA1UEBhMCRVMxEzARBgNVBAgMClRlc3QtU3RhdGUxDjAMBgNVBAoMBVNjeXRsMQswCQYDVQQLDAJRQTEVMBMGA1UEAwwMU2VjRW5kRW50aXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1isXtrHkDvChE1jGCSnleAc547Hnswxhuf3XcTs6cG4y5oOgLgEZrbzHAe6Z47wBmt/35OC5oIa5tgmWBs7QVnAZ4PZWAdZTAq2J5TBQCcpilw2Kc5NHp231Ckw52pHT6/O4VieeZdOA/+PCbL7/4PrQ/Uq/23W1kHvUqToJTRwrOZFMg8QfTlo3RYN6xFmlW6hXCCHkolqihbK44jX6FELCLwbE1dw43eao5Pnbxw//2jyqReC2qrpcKQ4MdgJJYgK9rA+zCCj0m7H+LsNyiat4OTYvDVx9Lg7nmjgD2cFWewLDE9t4QVST41vYgWObJjisLyGsbEwLfOjXkf8jrQIDAQABo4GKMIGHMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgbAMC0GCWCGSAGG+EIBDQQgFh5TY3l0bCBRQSBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFLBtuBGwweIxC3h8ILFblDSg2x8SMB8GA1UdIwQYMBaAFL0z1LklZYtSH+ayTVfCjxPfiDf4MA0GCSqGSIb3DQEBCwUAA4IBAQBDTsidJItoNaPPp+idbBCLm8VrNxlVpWYQ4KmA6glCw5z7TcH1JW+GsfSxXfXo2bFGtxDFsjZCV76fBwoQVAvJ6ntCyn/vrslSQy6RvArM2e7Di6h6ND500so0a5mfycN7rauhj0tWcmZv3zExJcwgtar/P3BHYpfN9/eG46NpxRq4Sq9uwfYEH9lzAfZ3xgLWgIRAEoF6b2VRMU9ApVX/Ifai17+0JKhNkmBp63EUJCcXNSjTV4UtKTO2QFply4hOqluhMkFZDqFsbzB+mrSQcCget+6ymCVdTaN3GwVuW4CKIoR85Nr+3OV1VupDz3bnzqDjeiTNIJEV6aONP2zD-----END CERTIFICATE-----',
  74. keyType: 'Sign',
  75. subject: {
  76. commonName: 'SecEndEntity',
  77. organizationalUnit: 'QA',
  78. organization: 'Scytl',
  79. country: 'ES'
  80. },
  81. time: '2014-10-23\'T\'19:11:28Z'
  82. },
  83. intermediates: {
  84. pems: [
  85. '-----BEGIN CERTIFICATE-----MIIDsDCCApigAwIBAgIJALAhpG3UDbqJMA0GCSqGSIb3DQEBCwUAMFAxCz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iY9PSKwXcKPjcHXxs8LgPbbZjLRZ2FSvfgya/9drHfu7QYHRBFFHYljdgcpF/Z/nerocmvTgX8iuOu133JA3JmMOy3E7riVUfRkKh4Nnivh9S5mCKSff0yW4i+kJJ9TuAuDi30FN3tR-----END CERTIFICATE-----'
  86. ],
  87. subjects: [{
  88. commonName: 'SecQA',
  89. organizationalUnit: 'QA',
  90. organization: 'Scytl',
  91. country: 'ES'
  92. }]
  93. },
  94. root: {
  95. pem:
  96. '-----BEGIN CERTIFICATE-----MIIDgDCCAmigAwIBAgIJALAhpG3UDbqIMA0GCSqGSIb3DQEBCwUAMFAxCzAJBgNVBAYTAkVTMRMwEQYDVQQIDApUZXN0LVN0YXRlMQ4wDAYDVQQKDAVTY3l0bDELMAkGA1UECwwCUUExDzANBgNVBAMMBlNlY0RldjAeFw0xNDEwMjMxNTExMTJaFw0yNDEwMjAxNTExMTJaMFAxCzAJBgNVBAYTAkVTMRMwEQYDVQQIDApUZXN0LVN0YXRlMQ4wDAYDVQQKDAVTY3l0bDELMAkGA1UECwwCUUExDzANBgNVBAMMBlNlY0RldjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKanbx9BsuYLjq4RVAS269FD2Gtpp3YkcvKHwHO5XI89+pJELO9CVnyIvEmon3ndbvPTqM3D/HOvl0M4/kPFeHij8d24iM48GVbYfLVBrV3BtKe24pHeIagSn6hl9ouiknbvDBqF8qZcBTNhnH8yX7isoJf3TShBpTOdyJ6XkDOQ+R0GtS1M4NN9BS74oGt0REC17VlBrO6JyR9rNswk4abqqpF7ekw1yXxcnrqa480+oyEcY9ji5QNoP9kGyibeB08seeB+wlt0fCWcJXtecsnPRpBNJmhLr4ziNyXoIOCEeVMA/MFx7vrrl+pkyhd49rQybbctv/mQGUM4QG6IZ3cCAwEAAaNdMFswHQYDVR0OBBYEFA56IIf2S8G0LjsIlSASdPBgMi2kMB8GA1UdIwQYMBaAFA56IIf2S8G0LjsIlSASdPBgMi2kMAwGA1UdEw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jsFvU6NAkgEvKeaIMVMA0GCSqGSIb3DQEBCwUAA4IBAQAQH64q51KivF3lUd78nOvHzuv04pUGihcVnYm3MTnXiODpwj4f6s5sZnAUWB+BOCJ1btaJvNAWUpnOH36nLr+qKV5mIxOyiKQWxY0tunySctsOpSscW/OfatvOUdkjshC7QuNq0fhjYh8SGO9Bk4ePO0uaIEWWywaH0wHVJPFaETklFXg3TZr61T5scrDEfs+lk+fQjkJ0YiS4e5VKfS7uVPLtDLgT9sx3l1QlVV2xZ8jF7hPpTy0JX8adp0NEQd+kfFFQuuSnY0QfLKtut9LHIjrl2q2sLfi0ibJ+uokCY85XZeyPzovIaSu3b2941E3dxL6UbDCEJyjlffybakyN-----END CERTIFICATE-----';
  103. var tooEarlyStartIntermediateCertificatePem_ =
  104. '-----BEGIN CERTIFICATE-----MIIDsDCCApigAwIBAgIJAJZdx2FxigSPMA0GCSqGSIb3DQEBCwUAMFAxCzAJBgNVBAYTAkVTMRMwEQYDVQQIDApUZXN0LVN0YXRlMQ4wDAYDVQQKDAVTY3l0bDELMAkGA1UECwwCUUExDzANBgNVBAMMBlNlY0RldjAeFw0xNDEwMjMxNTQyMDJaFw0xNTEwMjMxNTQyMDJaME8xCzAJBgNVBAYTAkVTMRMwEQYDVQQIDApUZXN0LVN0YXRlMQ4wDAYDVQQKDAVTY3l0bDELMAkGA1UECwwCUUExDjAMBgNVBAMMBVNlY1FBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlvRn5OjWMaQfWCknqnsTzupcpx6zPQCLDe9DbizYRBghJcr4UlxI1uLsCHHzEMXCta5rJ+PSQ+TZ71PP7Ep3JyLAYObhVM8ltQyAKm8fgZa/FhCer46O3CohiD0Cdjg3r+qGOB+OKcGigXnNSoEsBlJ7HTzi5egiSg6D1Mx4uNw35F15ahTDxzIT/HN/Dnl3fEGzuJFebhSxj3u/+EEFJQrYvl62bUzzpXKlg/1C8BUYUXcPqhuUwZhyxE/DKyunA489XwpvN11y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qJpuQtcbywy9aYeH1X8cvlueJNPG/ixZsZjXY5KUdq7bjBLDlns49UWw96uxbU+JEL5aKMibtA8sJP9ZhDKY15ps9+wtceFnkT0g0IZ1shupQPEOKH2UfIS5/2teL7vjCplX3mDX8YOgzLqlqFrVtifejH2ETRzpDFc7K/P3KtSQqGKYUEZw5olCdLcg9Fp+I9QVkNGGr6Ds16BGWnb6Pgm5NOegdoOJLF6vZkhvyTYz9/Tg2men/HJLCVCXhbYwfUcu0ezj8w5G6zCdxVrqSTvjHVzp0kskVGRZjlrEOFLvswOGTjAon/U4iuBtqR+pLZg4Law+ETujPJPs0CAwEAAaNdMFswHQYDVR0OBBYEFKh4F63r8K3uM97VcdOYg3vylSHzMB8GA1UdIwQYMBaAFKh4F63r8K3uM97VcdOYg3vylSHzMAwGA1UdEwQFMAMBAf8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQAq2bLqJ+cLtnivXrNP5j9YL031zAO6xQDehxqasKOb7e6pdB8NKAOwa7smXCRsJxphT2vTv+VsecD/b8D3irEV000pbemeVmyrnOyaJxTCjBRvhjIbOmaBZ5k0KfxDubT8xx9H8Im+jxX0tZU5IQuTBG+Izd+5Dm5kxAhh7JDzclUYfUMDYrv43/7zm5wPkRqqK5SY7J4CPMiW3Uzxpc+uPCwydMSTYbDTdNN5nf0eDGepm2h/iewfickgkCFoNe6b3nxlQiK8EL9FUSKeq+1AWVnT3riC8C/CXTZwKo3ULXkKe3Jl3mvVYjkz/O/3NzeTfFdktuNaSh28Wrzlb9h4-----END CERTIFICATE-----';
  107. var certificateValidator_;
  108. beforeAll(function() {
  109. certificateValidator_ = certificate.newService().newValidator();
  110. });
  111. describe('create a certificate service that should be able to ..', function() {
  112. describe('create a CertificateValidator object that should be able to', function() {
  113. it('successfully validate a valid certificate chain', function() {
  114. var validations = certificateValidator_.validateChain(validChain_);
  115. expect(validations).toEqual([[], []]);
  116. });
  117. it('successfully validate a valid certificate chain, generated with Java',
  118. function() {
  119. var validations =
  120. certificateValidator_.validateChain(validChainFromJava_);
  121. expect(validations).toEqual([[], []]);
  122. });
  123. it('flatten a two-dimensional array of certificate chain failed validations',
  124. function() {
  125. var validationFailed = [['SIGNATURE', 'NOT_AFTER'], ['NOT_BEFORE']];
  126. var validationFailedFlattened =
  127. ['signature_0', 'not_after_0', 'not_before_1'];
  128. expect(
  129. certificateValidator_.flattenFailedValidations(validationFailed))
  130. .toEqual(validationFailedFlattened);
  131. });
  132. it('usuccessfully validate a certificate chain for which the leaf certificate subject common name is invalid',
  133. function() {
  134. var invalidChain = clone(validChain_);
  135. invalidChain.leaf.subject.commonName = 'Invalid common name';
  136. var validations = certificateValidator_.validateChain(invalidChain);
  137. expect(certificateValidator_.flattenFailedValidations(validations))
  138. .toContain('subject_0');
  139. });
  140. it('usuccessfully validate a certificate chain for which the leaf certificate subject organizational unit is invalid',
  141. function() {
  142. var invalidChain = clone(validChain_);
  143. invalidChain.leaf.subject.organizationalUnit =
  144. 'Invalid organizational unit';
  145. var validations = certificateValidator_.validateChain(invalidChain);
  146. expect(certificateValidator_.flattenFailedValidations(validations))
  147. .toContain('subject_0');
  148. });
  149. it('usuccessfully validate a certificate chain for which the leaf certificate subject organization is invalid',
  150. function() {
  151. var invalidChain = clone(validChain_);
  152. invalidChain.leaf.subject.organization = 'Invalid organization';
  153. var validations = certificateValidator_.validateChain(invalidChain);
  154. expect(certificateValidator_.flattenFailedValidations(validations))
  155. .toContain('subject_0');
  156. });
  157. it('usuccessfully validate a certificate chain for which the leaf certificate country is invalid',
  158. function() {
  159. var invalidChain = clone(validChain_);
  160. invalidChain.leaf.subject.country = 'Invalid country';
  161. var validations = certificateValidator_.validateChain(invalidChain);
  162. expect(certificateValidator_.flattenFailedValidations(validations))
  163. .toContain('subject_0');
  164. });
  165. it('usuccessfully validate a certificate chain for which an intermediate certificate subject common name is invalid',
  166. function() {
  167. var invalidChain = clone(validChain_);
  168. invalidChain.intermediates.subjects[0].commonName =
  169. 'Invalid common name';
  170. var validations = certificateValidator_.validateChain(invalidChain);
  171. expect(certificateValidator_.flattenFailedValidations(validations))
  172. .toContain('subject_1');
  173. });
  174. it('usuccessfully validate a certificate chain for which an intermediate certificate subject organizational unit is invalid',
  175. function() {
  176. var invalidChain = clone(validChain_);
  177. invalidChain.intermediates.subjects[0].organizationalUnit =
  178. 'Invalid organizational unit';
  179. var validations = certificateValidator_.validateChain(invalidChain);
  180. expect(certificateValidator_.flattenFailedValidations(validations))
  181. .toContain('subject_1');
  182. });
  183. it('usuccessfully validate a certificate chain for which an intermediate certificate subject organization is invalid',
  184. function() {
  185. var invalidChain = clone(validChain_);
  186. invalidChain.intermediates.subjects[0].organization =
  187. 'Invalid organization';
  188. var validations = certificateValidator_.validateChain(invalidChain);
  189. expect(certificateValidator_.flattenFailedValidations(validations))
  190. .toContain('subject_1');
  191. });
  192. it('usuccessfully validate a certificate chain for which an intermediate certificate subject country is invalid',
  193. function() {
  194. var invalidChain = clone(validChain_);
  195. invalidChain.intermediates.subjects[0].country = 'Invalid country';
  196. var validations = certificateValidator_.validateChain(invalidChain);
  197. expect(certificateValidator_.flattenFailedValidations(validations))
  198. .toContain('subject_1');
  199. });
  200. it('usuccessfully validate a certificate chain for which a leaf certificate with a Sign key type is validated as being an CA key type',
  201. function() {
  202. var invalidChain = clone(validChain_);
  203. invalidChain.leaf.keyType = 'CA';
  204. var validations = certificateValidator_.validateChain(invalidChain);
  205. expect(certificateValidator_.flattenFailedValidations(validations))
  206. .toContain('key_type_0');
  207. });
  208. it('usuccessfully validate a certificate chain for which a leaf certificate with a Sign key type is validated as being an Encryption key type',
  209. function() {
  210. var invalidChain = clone(validChain_);
  211. invalidChain.leaf.keyType = 'Encryption';
  212. var validations = certificateValidator_.validateChain(invalidChain);
  213. expect(certificateValidator_.flattenFailedValidations(validations))
  214. .toContain('key_type_0');
  215. });
  216. it('usuccessfully validate a certificate chain for which the leaf certificate signature cannot be verified by the next certificate in the chain',
  217. function() {
  218. var invalidChain = clone(validChain_);
  219. invalidChain.leaf.pem = intermediateCertificatePem_;
  220. var validations = certificateValidator_.validateChain(invalidChain);
  221. expect(certificateValidator_.flattenFailedValidations(validations))
  222. .toContain('signature_0');
  223. });
  224. it('usuccessfully validate a certificate chain for which the leaf certificate ending time of validity is after that of an intermediate certificate',
  225. function() {
  226. var validations =
  227. certificateValidator_.validateChain(timeCheckChain_);
  228. expect(certificateValidator_.flattenFailedValidations(validations))
  229. .toEqual(['not_after_0']);
  230. });
  231. it('usuccessfully validate a certificate chain for which the leaf and intermediate certificate starting times of validity are earlier than that of the root certificate',
  232. function() {
  233. var invalidChain = clone(timeCheckChain_);
  234. invalidChain.leaf.pem = tooEarlyStartLeafCertificatePem_;
  235. invalidChain.intermediates.pems[0] =
  236. tooEarlyStartIntermediateCertificatePem_;
  237. invalidChain.root.pem = tooLateStartRootCertificatePem_;
  238. var validations = certificateValidator_.validateChain(invalidChain);
  239. expect(certificateValidator_.flattenFailedValidations(validations))
  240. .toContain('not_before_0');
  241. expect(certificateValidator_.flattenFailedValidations(validations))
  242. .toContain('not_before_1');
  243. });
  244. it('successfully validate a certificate chain time reference if the time reference is set to the leaf certificate starting time of validity',
  245. function() {
  246. var chain = clone(timeCheckChain_);
  247. chain.leaf.time = '2014-10-23\'T\'15:13:11Z';
  248. var validations = certificateValidator_.validateChain(chain);
  249. expect(certificateValidator_.flattenFailedValidations(validations))
  250. .not.toContain('time_0');
  251. });
  252. it('successfully validate a certificate chain time reference if the time reference is set to the leaf certificate ending time of validity',
  253. function() {
  254. var chain = clone(timeCheckChain_);
  255. chain.leaf.time = '2015-10-23\'T\'15:13:11Z';
  256. var validations = certificateValidator_.validateChain(chain);
  257. expect(certificateValidator_.flattenFailedValidations(validations))
  258. .not.toContain('time_0');
  259. });
  260. it('usuccessfully validate a certificate chain time reference if the time reference is set to 1 second before the leaf certificate starting time of validity',
  261. function() {
  262. var invalidChain = clone(timeCheckChain_);
  263. invalidChain.leaf.time = '2014-10-23\'T\'15:13:10Z';
  264. var validations = certificateValidator_.validateChain(invalidChain);
  265. expect(certificateValidator_.flattenFailedValidations(validations))
  266. .toContain('time_0');
  267. });
  268. it('usuccessfully validate a certificate chain time reference if the time reference is set to 1 second after the leaf certificate ending time of validity',
  269. function() {
  270. var invalidChain = clone(timeCheckChain_);
  271. invalidChain.leaf.time = '2015-10-23\'T\'15:13:12Z';
  272. var validations = certificateValidator_.validateChain(invalidChain);
  273. expect(certificateValidator_.flattenFailedValidations(validations))
  274. .toContain('time_0');
  275. });
  276. });
  277. });
  278. function clone(object) {
  279. return JSON.parse(JSON.stringify(object));
  280. }
  281. });