diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/extensions/smime/nsMsgComposeSecure.h | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/extensions/smime/nsMsgComposeSecure.h')
-rw-r--r-- | comm/mailnews/extensions/smime/nsMsgComposeSecure.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/comm/mailnews/extensions/smime/nsMsgComposeSecure.h b/comm/mailnews/extensions/smime/nsMsgComposeSecure.h new file mode 100644 index 0000000000..14f7b54157 --- /dev/null +++ b/comm/mailnews/extensions/smime/nsMsgComposeSecure.h @@ -0,0 +1,103 @@ +/* -*- Mode: idl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef _nsMsgComposeSecure_H_ +#define _nsMsgComposeSecure_H_ + +#include "nsIMsgComposeSecure.h" +#include "nsCOMPtr.h" +#include "nsICMSEncoder.h" +#include "nsIX509Cert.h" +#include "nsIStringBundle.h" +#include "nsICryptoHash.h" +#include "nsICMSMessage.h" +#include "nsString.h" +#include "nsTHashMap.h" +#include "nsIOutputStream.h" +#include "mozilla/UniquePtr.h" +#include "mozilla/StaticMutex.h" + +class nsIMsgCompFields; +namespace mozilla { +namespace mailnews { +class MimeEncoder; +} +} // namespace mozilla + +typedef enum { + mime_crypto_none, /* normal unencapsulated MIME message */ + mime_crypto_clear_signed, /* multipart/signed encapsulation */ + mime_crypto_opaque_signed, /* application/x-pkcs7-mime (signedData) */ + mime_crypto_encrypted, /* application/x-pkcs7-mime */ + mime_crypto_signed_encrypted /* application/x-pkcs7-mime */ +} mimeDeliveryCryptoState; + +class nsMsgComposeSecure : public nsIMsgComposeSecure { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGCOMPOSESECURE + + nsMsgComposeSecure(); + + void GetOutputStream(nsIOutputStream** stream) { + NS_IF_ADDREF(*stream = mStream); + } + nsresult GetSMIMEBundleString(const char16_t* name, nsString& outString); + + private: + virtual ~nsMsgComposeSecure(); + typedef mozilla::mailnews::MimeEncoder MimeEncoder; + nsresult MimeInitMultipartSigned(bool aOuter, nsIMsgSendReport* sendReport); + nsresult MimeInitEncryption(bool aSign, nsIMsgSendReport* sendReport); + nsresult MimeFinishMultipartSigned(bool aOuter, nsIMsgSendReport* sendReport); + nsresult MimeFinishEncryption(bool aSign, nsIMsgSendReport* sendReport); + nsresult MimeCryptoHackCerts(const char* aRecipients, + nsIMsgSendReport* sendReport, bool aEncrypt, + bool aSign, nsIMsgIdentity* aIdentity); + bool InitializeSMIMEBundle(); + nsresult SMIMEBundleFormatStringFromName(const char* name, + nsTArray<nsString>& params, + nsAString& outString); + nsresult ExtractEncryptionState(nsIMsgIdentity* aIdentity, + nsIMsgCompFields* aComposeFields, + bool* aSignMessage, bool* aEncrypt); + + bool mSignMessage; + bool mAlwaysEncryptMessage; + mimeDeliveryCryptoState mCryptoState; + nsCOMPtr<nsIOutputStream> mStream; + int16_t mHashType; + nsCOMPtr<nsICryptoHash> mDataHash; + mozilla::UniquePtr<MimeEncoder> mSigEncoder; + char* mMultipartSignedBoundary; + nsString mSigningCertName; + nsAutoCString mSigningCertDBKey; + nsCOMPtr<nsIX509Cert> mSelfSigningCert; + nsString mEncryptionCertName; + nsAutoCString mEncryptionCertDBKey; + nsCOMPtr<nsIX509Cert> mSelfEncryptionCert; + nsTArray<RefPtr<nsIX509Cert>> mCerts; + nsCOMPtr<nsICMSMessage> mEncryptionCinfo; + nsCOMPtr<nsICMSEncoder> mEncryptionContext; + nsCOMPtr<nsIStringBundle> mSMIMEBundle; + + // Maps email address to nsIX509Cert.dbKey of a verified certificate. + nsTHashMap<nsCStringHashKey, nsCString> mValidCertForEmailAddr; + static mozilla::StaticMutex sMutex; + + mozilla::UniquePtr<MimeEncoder> mCryptoEncoder; + bool mIsDraft; + + enum { eBufferSize = 8192 }; + char* mBuffer; + uint32_t mBufferedBytes; + + bool mErrorAlreadyReported; + void SetError(nsIMsgSendReport* sendReport, const char16_t* bundle_string); + void SetErrorWithParam(nsIMsgSendReport* sendReport, + const char* bundle_string, const char* param); +}; + +#endif |