2012-10-03 00:04:58 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 dtls_identity_h__
|
|
|
|
#define dtls_identity_h__
|
|
|
|
|
|
|
|
#include <string>
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
2019-01-29 17:56:19 +03:00
|
|
|
#include <vector>
|
2012-10-03 00:04:58 +04:00
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "ScopedNSSTypes.h"
|
2012-10-03 00:04:58 +04:00
|
|
|
#include "m_cpp_utils.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-10-03 00:04:58 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2019-01-29 17:56:19 +03:00
|
|
|
#include "nsTArray.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "sslt.h"
|
2012-10-03 00:04:58 +04:00
|
|
|
|
|
|
|
// All code in this module requires NSS to be live.
|
|
|
|
// Callers must initialize NSS and implement the nsNSSShutdownObject
|
|
|
|
// protocol.
|
|
|
|
namespace mozilla {
|
|
|
|
|
2019-01-29 17:56:19 +03:00
|
|
|
class DtlsDigest {
|
|
|
|
public:
|
|
|
|
const static size_t kMaxDtlsDigestLength = HASH_LENGTH_MAX;
|
2019-02-26 00:50:42 +03:00
|
|
|
DtlsDigest() = default;
|
2019-01-29 17:56:19 +03:00
|
|
|
explicit DtlsDigest(const std::string& algorithm) : algorithm_(algorithm) {}
|
|
|
|
DtlsDigest(const std::string& algorithm, const std::vector<uint8_t>& value)
|
|
|
|
: algorithm_(algorithm), value_(value) {
|
|
|
|
MOZ_ASSERT(value.size() <= kMaxDtlsDigestLength);
|
|
|
|
}
|
|
|
|
~DtlsDigest() = default;
|
|
|
|
|
|
|
|
bool operator!=(const DtlsDigest& rhs) const { return !operator==(rhs); }
|
|
|
|
|
|
|
|
bool operator==(const DtlsDigest& rhs) const {
|
|
|
|
if (algorithm_ != rhs.algorithm_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value_ == rhs.value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string algorithm_;
|
|
|
|
std::vector<uint8_t> value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<DtlsDigest> DtlsDigestList;
|
|
|
|
|
2015-07-06 20:40:04 +03:00
|
|
|
class DtlsIdentity final {
|
2014-06-20 15:08:24 +04:00
|
|
|
public:
|
2015-07-06 20:40:04 +03:00
|
|
|
// This constructor takes ownership of privkey and cert.
|
2016-12-21 17:09:10 +03:00
|
|
|
DtlsIdentity(UniqueSECKEYPrivateKey privkey, UniqueCERTCertificate cert,
|
2015-07-06 20:40:04 +03:00
|
|
|
SSLKEAType authType)
|
2018-05-30 22:15:35 +03:00
|
|
|
: private_key_(std::move(privkey)),
|
|
|
|
cert_(std::move(cert)),
|
|
|
|
auth_type_(authType) {}
|
2012-10-03 00:04:58 +04:00
|
|
|
|
2019-01-29 17:56:19 +03:00
|
|
|
// Allows serialization/deserialization; cannot write IPC serialization code
|
|
|
|
// directly for DtlsIdentity, since IPC-able types need to be constructable
|
|
|
|
// on the stack.
|
|
|
|
nsresult Serialize(nsTArray<uint8_t>* aKeyDer, nsTArray<uint8_t>* aCertDer);
|
|
|
|
static RefPtr<DtlsIdentity> Deserialize(const nsTArray<uint8_t>& aKeyDer,
|
|
|
|
const nsTArray<uint8_t>& aCertDer,
|
|
|
|
SSLKEAType authType);
|
|
|
|
|
2015-07-06 20:40:04 +03:00
|
|
|
// This is only for use in tests, or for external linkage. It makes a (bad)
|
|
|
|
// instance of this class.
|
2015-10-18 08:24:48 +03:00
|
|
|
static RefPtr<DtlsIdentity> Generate();
|
2012-10-03 00:04:58 +04:00
|
|
|
|
2015-07-06 20:40:04 +03:00
|
|
|
// These don't create copies or transfer ownership. If you want these to live
|
|
|
|
// on, make a copy.
|
2019-01-29 17:56:19 +03:00
|
|
|
const UniqueCERTCertificate& cert() const { return cert_; }
|
|
|
|
const UniqueSECKEYPrivateKey& privkey() const { return private_key_; }
|
2015-07-06 20:40:04 +03:00
|
|
|
// Note: this uses SSLKEAType because that is what the libssl API requires.
|
|
|
|
// This is a giant confusing mess, but libssl indexes certificates based on a
|
|
|
|
// key exchange type, not authentication type (as you might have reasonably
|
|
|
|
// expected).
|
|
|
|
SSLKEAType auth_type() const { return auth_type_; }
|
2012-10-03 00:04:58 +04:00
|
|
|
|
2019-01-29 17:56:19 +03:00
|
|
|
nsresult ComputeFingerprint(DtlsDigest* digest) const;
|
|
|
|
static nsresult ComputeFingerprint(const UniqueCERTCertificate& cert,
|
|
|
|
DtlsDigest* digest);
|
2015-07-06 20:40:04 +03:00
|
|
|
|
2014-11-20 03:16:29 +03:00
|
|
|
static const std::string DEFAULT_HASH_ALGORITHM;
|
|
|
|
enum { HASH_ALGORITHM_MAX_LENGTH = 64 };
|
2012-10-03 00:04:58 +04:00
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DtlsIdentity)
|
|
|
|
|
2015-07-06 20:40:04 +03:00
|
|
|
private:
|
2020-03-06 12:21:47 +03:00
|
|
|
~DtlsIdentity() = default;
|
2012-10-03 00:04:58 +04:00
|
|
|
DISALLOW_COPY_ASSIGN(DtlsIdentity);
|
|
|
|
|
2016-12-21 17:09:10 +03:00
|
|
|
UniqueSECKEYPrivateKey private_key_;
|
2016-10-20 03:29:58 +03:00
|
|
|
UniqueCERTCertificate cert_;
|
2015-07-06 20:40:04 +03:00
|
|
|
SSLKEAType auth_type_;
|
2012-10-03 00:04:58 +04:00
|
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|