1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/dtlsidentity.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#ifndef dtls_identity_h__ 1.10 +#define dtls_identity_h__ 1.11 + 1.12 +#include <string> 1.13 + 1.14 +#include "m_cpp_utils.h" 1.15 +#include "mozilla/RefPtr.h" 1.16 +#include "nsISupportsImpl.h" 1.17 +#include "ScopedNSSTypes.h" 1.18 + 1.19 +// All code in this module requires NSS to be live. 1.20 +// Callers must initialize NSS and implement the nsNSSShutdownObject 1.21 +// protocol. 1.22 +namespace mozilla { 1.23 + 1.24 +class DtlsIdentity { 1.25 + public: 1.26 + ~DtlsIdentity(); 1.27 + 1.28 + // Generate an identity with a random name. 1.29 + static TemporaryRef<DtlsIdentity> Generate(); 1.30 + 1.31 + // Note: the following two functions just provide access. They 1.32 + // do not transfer ownership. If you want a pointer that lasts 1.33 + // past the lifetime of the DtlsIdentity, you must make 1.34 + // a copy yourself. 1.35 + CERTCertificate *cert() { return cert_; } 1.36 + SECKEYPrivateKey *privkey() { return privkey_; } 1.37 + 1.38 + std::string GetFormattedFingerprint(const std::string &algorithm = DEFAULT_HASH_ALGORITHM); 1.39 + 1.40 + nsresult ComputeFingerprint(const std::string algorithm, 1.41 + unsigned char *digest, 1.42 + std::size_t size, 1.43 + std::size_t *digest_length); 1.44 + 1.45 + static nsresult ComputeFingerprint(const CERTCertificate *cert, 1.46 + const std::string algorithm, 1.47 + unsigned char *digest, 1.48 + std::size_t size, 1.49 + std::size_t *digest_length); 1.50 + 1.51 + static nsresult ParseFingerprint(const std::string fp, 1.52 + unsigned char *digest, 1.53 + size_t size, size_t *length); 1.54 + 1.55 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DtlsIdentity) 1.56 + 1.57 + private: 1.58 + DtlsIdentity(SECKEYPrivateKey *privkey, CERTCertificate *cert) 1.59 + : privkey_(privkey), cert_(cert) {} 1.60 + DISALLOW_COPY_ASSIGN(DtlsIdentity); 1.61 + 1.62 + static const std::string DEFAULT_HASH_ALGORITHM; 1.63 + static const size_t HASH_ALGORITHM_MAX_LENGTH; 1.64 + 1.65 + std::string FormatFingerprint(const unsigned char *digest, 1.66 + std::size_t size); 1.67 + 1.68 + ScopedSECKEYPrivateKey privkey_; 1.69 + CERTCertificate *cert_; // TODO: Using a smart pointer here causes link 1.70 + // errors. 1.71 +}; 1.72 +} // close namespace 1.73 +#endif