nsNSSCertTrust.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef nsNSSCertTrust_h
  5. #define nsNSSCertTrust_h
  6. #include "certdb.h"
  7. #include "certt.h"
  8. /*
  9. * Class for maintaining trust flags for an NSS certificate.
  10. */
  11. class nsNSSCertTrust
  12. {
  13. public:
  14. nsNSSCertTrust();
  15. nsNSSCertTrust(unsigned int ssl, unsigned int email, unsigned int objsign);
  16. explicit nsNSSCertTrust(CERTCertTrust *t);
  17. virtual ~nsNSSCertTrust();
  18. /* query */
  19. bool HasAnyCA();
  20. bool HasAnyUser();
  21. bool HasPeer(bool checkSSL = true,
  22. bool checkEmail = true,
  23. bool checkObjSign = true);
  24. bool HasTrustedCA(bool checkSSL = true,
  25. bool checkEmail = true,
  26. bool checkObjSign = true);
  27. bool HasTrustedPeer(bool checkSSL = true,
  28. bool checkEmail = true,
  29. bool checkObjSign = true);
  30. /* common defaults */
  31. /* equivalent to "c,c,c" */
  32. void SetValidCA();
  33. /* equivalent to "p,p,p" */
  34. void SetValidPeer();
  35. /* general setters */
  36. /* read: "p, P, c, C, T, u, w" */
  37. void SetSSLTrust(bool peer, bool tPeer,
  38. bool ca, bool tCA, bool tClientCA,
  39. bool user, bool warn);
  40. void SetEmailTrust(bool peer, bool tPeer,
  41. bool ca, bool tCA, bool tClientCA,
  42. bool user, bool warn);
  43. void SetObjSignTrust(bool peer, bool tPeer,
  44. bool ca, bool tCA, bool tClientCA,
  45. bool user, bool warn);
  46. /* set c <--> CT */
  47. void AddCATrust(bool ssl, bool email, bool objSign);
  48. /* set p <--> P */
  49. void AddPeerTrust(bool ssl, bool email, bool objSign);
  50. /* get it (const?) (shallow?) */
  51. CERTCertTrust * GetTrust() { return &mTrust; }
  52. private:
  53. void addTrust(unsigned int *t, unsigned int v);
  54. void removeTrust(unsigned int *t, unsigned int v);
  55. bool hasTrust(unsigned int t, unsigned int v);
  56. CERTCertTrust mTrust;
  57. };
  58. #endif // nsNSSCertTrust_h