michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _NS_NSSCERTIFICATE_H_ michael@0: #define _NS_NSSCERTIFICATE_H_ michael@0: michael@0: #include "nsIX509Cert.h" michael@0: #include "nsIX509Cert2.h" michael@0: #include "nsIX509Cert3.h" michael@0: #include "nsIX509CertDB.h" michael@0: #include "nsIX509CertList.h" michael@0: #include "nsIASN1Object.h" michael@0: #include "nsISMimeCert.h" michael@0: #include "nsIIdentityInfo.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsNSSShutDown.h" michael@0: #include "nsISimpleEnumerator.h" michael@0: #include "nsISerializable.h" michael@0: #include "nsIClassInfo.h" michael@0: #include "pkix/pkixtypes.h" michael@0: #include "certt.h" michael@0: michael@0: class nsAutoString; michael@0: class nsINSSComponent; michael@0: class nsIASN1Sequence; michael@0: michael@0: class nsNSSCertificate : public nsIX509Cert3, michael@0: public nsIIdentityInfo, michael@0: public nsISMimeCert, michael@0: public nsISerializable, michael@0: public nsIClassInfo, michael@0: public nsNSSShutDownObject michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIX509CERT michael@0: NS_DECL_NSIX509CERT2 michael@0: NS_DECL_NSIX509CERT3 michael@0: NS_DECL_NSIIDENTITYINFO michael@0: NS_DECL_NSISMIMECERT michael@0: NS_DECL_NSISERIALIZABLE michael@0: NS_DECL_NSICLASSINFO michael@0: michael@0: friend class nsNSSCertificateFakeTransport; michael@0: michael@0: nsNSSCertificate(CERTCertificate* cert, SECOidTag* evOidPolicy = nullptr); michael@0: nsNSSCertificate(); michael@0: virtual ~nsNSSCertificate(); michael@0: nsresult FormatUIStrings(const nsAutoString& nickname, michael@0: nsAutoString& nickWithSerial, michael@0: nsAutoString& details); michael@0: static nsNSSCertificate* Create(CERTCertificate*cert = nullptr, michael@0: SECOidTag* evOidPolicy = nullptr); michael@0: static nsNSSCertificate* ConstructFromDER(char* certDER, int derLen); michael@0: michael@0: private: michael@0: mozilla::pkix::ScopedCERTCertificate mCert; michael@0: bool mPermDelete; michael@0: uint32_t mCertType; michael@0: nsresult CreateASN1Struct(nsIASN1Object** aRetVal); michael@0: nsresult CreateTBSCertificateASN1Struct(nsIASN1Sequence** retSequence, michael@0: nsINSSComponent* nssComponent); michael@0: nsresult GetSortableDate(PRTime aTime, nsAString& _aSortableDate); michael@0: virtual void virtualDestroyNSSReference(); michael@0: void destructorSafeDestroyNSSReference(); michael@0: bool InitFromDER(char* certDER, int derLen); // return false on failure michael@0: michael@0: enum { michael@0: ev_status_invalid = 0, ev_status_valid = 1, ev_status_unknown = 2 michael@0: } mCachedEVStatus; michael@0: SECOidTag mCachedEVOidTag; michael@0: nsresult hasValidEVOidTag(SECOidTag& resultOidTag, bool& validEV); michael@0: nsresult getValidEVOidTag(SECOidTag& resultOidTag, bool& validEV); michael@0: }; michael@0: michael@0: class nsNSSCertList: public nsIX509CertList, michael@0: public nsNSSShutDownObject michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIX509CERTLIST michael@0: michael@0: // certList is adopted michael@0: nsNSSCertList(mozilla::pkix::ScopedCERTCertList& certList, michael@0: const nsNSSShutDownPreventionLock& proofOfLock); michael@0: michael@0: nsNSSCertList(); michael@0: michael@0: static CERTCertList* DupCertList(CERTCertList* aCertList, michael@0: const nsNSSShutDownPreventionLock& michael@0: proofOfLock); michael@0: private: michael@0: virtual ~nsNSSCertList(); michael@0: virtual void virtualDestroyNSSReference(); michael@0: void destructorSafeDestroyNSSReference(); michael@0: michael@0: mozilla::pkix::ScopedCERTCertList mCertList; michael@0: michael@0: nsNSSCertList(const nsNSSCertList&) MOZ_DELETE; michael@0: void operator=(const nsNSSCertList&) MOZ_DELETE; michael@0: }; michael@0: michael@0: class nsNSSCertListEnumerator: public nsISimpleEnumerator, michael@0: public nsNSSShutDownObject michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSISIMPLEENUMERATOR michael@0: michael@0: nsNSSCertListEnumerator(CERTCertList* certList, michael@0: const nsNSSShutDownPreventionLock& proofOfLock); michael@0: private: michael@0: virtual ~nsNSSCertListEnumerator(); michael@0: virtual void virtualDestroyNSSReference(); michael@0: void destructorSafeDestroyNSSReference(); michael@0: michael@0: mozilla::pkix::ScopedCERTCertList mCertList; michael@0: michael@0: nsNSSCertListEnumerator(const nsNSSCertListEnumerator&) MOZ_DELETE; michael@0: void operator=(const nsNSSCertListEnumerator&) MOZ_DELETE; michael@0: }; michael@0: michael@0: michael@0: #define NS_NSS_LONG 4 michael@0: #define NS_NSS_GET_LONG(x) ((((unsigned long)((x)[0])) << 24) | \ michael@0: (((unsigned long)((x)[1])) << 16) | \ michael@0: (((unsigned long)((x)[2])) << 8) | \ michael@0: ((unsigned long)((x)[3])) ) michael@0: #define NS_NSS_PUT_LONG(src,dest) (dest)[0] = (((src) >> 24) & 0xff); \ michael@0: (dest)[1] = (((src) >> 16) & 0xff); \ michael@0: (dest)[2] = (((src) >> 8) & 0xff); \ michael@0: (dest)[3] = ((src) & 0xff); michael@0: michael@0: #define NS_X509CERT_CID { /* 660a3226-915c-4ffb-bb20-8985a632df05 */ \ michael@0: 0x660a3226, \ michael@0: 0x915c, \ michael@0: 0x4ffb, \ michael@0: { 0xbb, 0x20, 0x89, 0x85, 0xa6, 0x32, 0xdf, 0x05 } \ michael@0: } michael@0: michael@0: #endif // _NS_NSSCERTIFICATE_H_