author Sven Sauleau <>
Tue, 05 Mar 2019 12:19:31 +0000
changeset 522212 64cc60d52a04d0c97162b18b4c3c744a11684e41
parent 518880 f18e61be455d493f10a2cc651cd254859894e02e
permissions -rw-r--r--
Bug 1526694 [wpt PR 15276] - [wasm] update js-api test runner and expectations, a=testonly Automatic update from web-platform-tests [wasm] update js-api test runner and expectations wasm-module-builder: - consistently adds the end opcode in function bodies (using addBody). - add missing setTableLength method table/get-set: - Avoid unrelated errors like: Cannot destructure property `fn` of 'undefined' or 'null'. Bug: 926311, v8:8319 Change-Id: Ia7db1ee5c3a9b1c1d6092cdce8885ddee4dd9b0e Reviewed-on: Reviewed-by: Michael Lippautz <> Commit-Queue: Sven Sauleau <> Cr-Commit-Position: refs/heads/master@{#633121} -- wpt-commits: 22400f9755a49a50632a8f2067cb06bca74efff8 wpt-pr: 15276

/* -*- 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 */
#ifndef dtls_identity_h__
#define dtls_identity_h__

#include <string>
#include <vector>

#include "m_cpp_utils.h"
#include "mozilla/Move.h"
#include "mozilla/RefPtr.h"
#include "nsISupportsImpl.h"
#include "ScopedNSSTypes.h"
#include "sslt.h"
#include "nsTArray.h"

// All code in this module requires NSS to be live.
// Callers must initialize NSS and implement the nsNSSShutdownObject
// protocol.
namespace mozilla {

class DtlsDigest {
  const static size_t kMaxDtlsDigestLength = HASH_LENGTH_MAX;
  DtlsDigest() = default;
  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;

class DtlsIdentity final {
  // This constructor takes ownership of privkey and cert.
  DtlsIdentity(UniqueSECKEYPrivateKey privkey, UniqueCERTCertificate cert,
               SSLKEAType authType)
      : private_key_(std::move(privkey)),
        auth_type_(authType) {}

  // 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);

  // This is only for use in tests, or for external linkage.  It makes a (bad)
  // instance of this class.
  static RefPtr<DtlsIdentity> Generate();

  // These don't create copies or transfer ownership. If you want these to live
  // on, make a copy.
  const UniqueCERTCertificate& cert() const { return cert_; }
  const UniqueSECKEYPrivateKey& privkey() const { return private_key_; }
  // 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_; }

  nsresult ComputeFingerprint(DtlsDigest* digest) const;
  static nsresult ComputeFingerprint(const UniqueCERTCertificate& cert,
                                     DtlsDigest* digest);

  static const std::string DEFAULT_HASH_ALGORITHM;


  ~DtlsIdentity() {}

  UniqueSECKEYPrivateKey private_key_;
  UniqueCERTCertificate cert_;
  SSLKEAType auth_type_;
}  // namespace mozilla