media/mtransport/dtlsidentity.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef dtls_identity_h__
     7 #define dtls_identity_h__
     9 #include <string>
    11 #include "m_cpp_utils.h"
    12 #include "mozilla/RefPtr.h"
    13 #include "nsISupportsImpl.h"
    14 #include "ScopedNSSTypes.h"
    16 // All code in this module requires NSS to be live.
    17 // Callers must initialize NSS and implement the nsNSSShutdownObject
    18 // protocol.
    19 namespace mozilla {
    21 class DtlsIdentity {
    22  public:
    23   ~DtlsIdentity();
    25   // Generate an identity with a random name.
    26   static TemporaryRef<DtlsIdentity> Generate();
    28   // Note: the following two functions just provide access. They
    29   // do not transfer ownership. If you want a pointer that lasts
    30   // past the lifetime of the DtlsIdentity, you must make
    31   // a copy yourself.
    32   CERTCertificate *cert() { return cert_; }
    33   SECKEYPrivateKey *privkey() { return privkey_; }
    35   std::string GetFormattedFingerprint(const std::string &algorithm = DEFAULT_HASH_ALGORITHM);
    37   nsresult ComputeFingerprint(const std::string algorithm,
    38                               unsigned char *digest,
    39                               std::size_t size,
    40                               std::size_t *digest_length);
    42   static nsresult ComputeFingerprint(const CERTCertificate *cert,
    43                                      const std::string algorithm,
    44                                      unsigned char *digest,
    45                                      std::size_t size,
    46                                      std::size_t *digest_length);
    48   static nsresult ParseFingerprint(const std::string fp,
    49                                    unsigned char *digest,
    50                                    size_t size, size_t *length);
    52   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DtlsIdentity)
    54  private:
    55   DtlsIdentity(SECKEYPrivateKey *privkey, CERTCertificate *cert)
    56       : privkey_(privkey), cert_(cert) {}
    57   DISALLOW_COPY_ASSIGN(DtlsIdentity);
    59   static const std::string DEFAULT_HASH_ALGORITHM;
    60   static const size_t HASH_ALGORITHM_MAX_LENGTH;
    62   std::string FormatFingerprint(const unsigned char *digest,
    63                                 std::size_t size);
    65   ScopedSECKEYPrivateKey privkey_;
    66   CERTCertificate *cert_;  // TODO: Using a smart pointer here causes link
    67                            // errors.
    68 };
    69 }  // close namespace
    70 #endif

mercurial