nsIContentSignatureVerifier.idl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "nsISupports.idl"
  5. interface nsIContentSignatureReceiverCallback;
  6. /**
  7. * An interface for verifying content-signatures, inspired by
  8. * https://tools.ietf.org/html/draft-thomson-http-content-signature-00
  9. * described here https://github.com/franziskuskiefer/content-signature/tree/pki
  10. *
  11. * A new signature verifier instance should be created for each signature
  12. * verification - you can create these instances with do_CreateInstance.
  13. *
  14. * There are two ways to use this functionality:
  15. * The first allows a signature to be verified all at once by simply calling
  16. * verifyContentSignature.
  17. * The second allows for streaming; call createContext with the signature
  18. * information (and initial data), call update with more data as it becomes
  19. * available then, finally, call end to verify the signature.
  20. */
  21. [scriptable, uuid(45a5fe2f-c350-4b86-962d-02d5aaaa955a)]
  22. interface nsIContentSignatureVerifier : nsISupports
  23. {
  24. /**
  25. * Verifies that the data matches the data that was used to generate the
  26. * signature.
  27. *
  28. * @param aData The data to be tested.
  29. * @param aContentSignatureHeader The content-signature header,
  30. * url-safe base64 encoded.
  31. * @param aCertificateChain The certificate chain to use for verification.
  32. * PEM encoded string.
  33. * @param aName The (host)name for which the end entity must
  34. be valid.
  35. * @returns true if the signature matches the data and aCertificateChain is
  36. * valid within aContext, false if not.
  37. */
  38. boolean verifyContentSignature(in ACString aData,
  39. in ACString aContentSignatureHeader,
  40. in ACString aCertificateChain,
  41. in ACString aName);
  42. /**
  43. * Creates a context to verify a content signature against data that is added
  44. * later with update calls.
  45. *
  46. * @param aData The first chunk of data to be tested.
  47. * @param aContentSignatureHeader The signature of the data, url-safe base64
  48. * encoded.
  49. * @param aCertificateChain The certificate chain to use for
  50. * verification. PEM encoded string.
  51. * @param aName The (host)name for which the end entity must
  52. be valid.
  53. */
  54. void createContext(in ACString aData, in ACString aContentSignatureHeader,
  55. in ACString aCertificateChain, in ACString aName);
  56. /**
  57. * Creates a context to verify a content signature against data that is added
  58. * later with update calls.
  59. * This does not require the caller to download the certificate chain. It's
  60. * done internally.
  61. * It requires the x5u parameter to be present in aContentSignatureHeader
  62. *
  63. * NOTE: Callers have to wait for aCallback to return before invoking anything
  64. * else. Otherwise the ContentSignatureVerifier will fail.
  65. *
  66. * @param aCallback Callback that's invoked when the cert chain
  67. * got fetched.
  68. * @param aContentSignatureHeader The signature of the data, url-safe base64
  69. * encoded, and the x5u value.
  70. * @param aName The (host)name for which the end entity must
  71. be valid.
  72. */
  73. void createContextWithoutCertChain(in nsIContentSignatureReceiverCallback aCallback,
  74. in ACString aContentSignatureHeader,
  75. in ACString aName);
  76. /**
  77. * Adds data to the context that was used to generate the signature.
  78. *
  79. * @param aData More data to be tested.
  80. */
  81. void update(in ACString aData);
  82. /**
  83. * Finalises the signature and returns the result of the signature
  84. * verification.
  85. *
  86. * @returns true if the signature matches the data added with createContext
  87. * and update, false if not.
  88. */
  89. boolean end();
  90. };
  91. /**
  92. * Callback for nsIContentSignatureVerifier.
  93. * { 0x1eb90707, 0xdf59, 0x48b7, \
  94. * { 0x9d, 0x42, 0xd8, 0xbf, 0x63, 0x0a, 0xe7, 0x44 } }
  95. */
  96. [scriptable, uuid(1eb90707-df59-48b7-9d42-d8bf630ae744)]
  97. interface nsIContentSignatureReceiverCallback : nsISupports
  98. {
  99. /**
  100. * Notification callback that's called by nsIContentSignatureVerifier when
  101. * the cert chain is downloaded.
  102. * If download and initialisation were successful, successful is true,
  103. * otherwise false. If successful is false, the verification must be aborted.
  104. */
  105. void contextCreated(in boolean successful);
  106. };