summaryrefslogtreecommitdiffstats
path: root/security/manager/ssl/WeakCryptoOverride.cpp
blob: 6b86e9f86e581b078b3bebd66600feafe8165bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=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/. */

#include "WeakCryptoOverride.h"

#include "MainThreadUtils.h"
#include "SharedSSLState.h"
#include "nss.h"

using namespace mozilla;
using namespace mozilla::psm;

NS_IMPL_ISUPPORTS(WeakCryptoOverride,
                  nsIWeakCryptoOverride)

WeakCryptoOverride::WeakCryptoOverride()
{
}

WeakCryptoOverride::~WeakCryptoOverride()
{
}

NS_IMETHODIMP
WeakCryptoOverride::AddWeakCryptoOverride(const nsACString& aHostName,
                                          bool aPrivate, bool aTemporary)
{
  if (!NS_IsMainThread()) {
    return NS_ERROR_NOT_SAME_THREAD;
  }

  SharedSSLState* sharedState = aPrivate ? PrivateSSLState()
                                         : PublicSSLState();
  if (!sharedState) {
    return NS_ERROR_NOT_AVAILABLE;
  }
  const nsPromiseFlatCString& host = PromiseFlatCString(aHostName);
  sharedState->IOLayerHelpers().addInsecureFallbackSite(host, aTemporary);

  return NS_OK;
}

NS_IMETHODIMP
WeakCryptoOverride::RemoveWeakCryptoOverride(const nsACString& aHostName,
                                             int32_t aPort, bool aPrivate)
{
  if (!NS_IsMainThread()) {
    return NS_ERROR_NOT_SAME_THREAD;
  }

  SharedSSLState* sharedState = aPrivate ? PrivateSSLState()
                                         : PublicSSLState();
  if (!sharedState) {
    return NS_ERROR_NOT_AVAILABLE;
  }
  const nsPromiseFlatCString& host = PromiseFlatCString(aHostName);
  sharedState->IOLayerHelpers().removeInsecureFallbackSite(host, aPort);

  // Some servers will fail with SSL_ERROR_ILLEGAL_PARAMETER_ALERT
  // unless the session cache is cleared.
  SSL_ClearSessionCache();

  return NS_OK;
}