// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "shill/nss.h"

#include <base/logging.h>
#include <base/string_number_conversions.h>
#include <base/string_util.h>
#include <base/stringprintf.h>

#include "shill/glib.h"

using base::HexEncode;
using base::StringPrintf;
using std::string;
using std::vector;

namespace shill {

namespace {
const char kCertfileBasename[] = "/tmp/nss-cert.";
const char kNSSGetCertScript[] = SCRIPTDIR "/nss-get-cert";
}  // namespace

// TODO(ers): not using LAZY_INSTANCE_INITIALIZER
// because of http://crbug.com/114828
static base::LazyInstance<NSS> g_nss = { 0, {{0}} };

NSS::NSS()
    : glib_(NULL) {
  VLOG(2) << __func__;
}

NSS::~NSS() {
  VLOG(2) << __func__;
}

// static
NSS *NSS::GetInstance() {
  return g_nss.Pointer();
}

void NSS::Init(GLib *glib) {
  glib_ = glib;
}

FilePath NSS::GetPEMCertfile(const string &nickname, const vector<char> &id) {
  return GetCertfile(nickname, id, "pem");
}

FilePath NSS::GetDERCertfile(const string &nickname, const vector<char> &id) {
  return GetCertfile(nickname, id, "der");
}

FilePath NSS::GetCertfile(
    const string &nickname, const vector<char> &id, const string &type) {
  CHECK(glib_);
  string filename =
      kCertfileBasename + StringToLowerASCII(HexEncode(&id[0], id.size()));
  char *argv[] = {
    const_cast<char *>(kNSSGetCertScript),
    const_cast<char *>(nickname.c_str()),
    const_cast<char *>(type.c_str()),
    const_cast<char *>(filename.c_str()),
    NULL
  };
  char *envp[1] = { NULL };
  int status = 0;
  GError *error = NULL;
  if (!glib_->SpawnSync(NULL,
                        argv,
                        envp,
                        static_cast<GSpawnFlags>(0),
                        NULL,
                        NULL,
                        NULL,
                        NULL,
                        &status,
                        &error)) {
    LOG(ERROR) << "nss-get-cert failed: "
               << glib_->ConvertErrorToMessage(error);
    return FilePath();
  }
  if (!WIFEXITED(status) || WEXITSTATUS(status)) {
    LOG(ERROR) << "nss-get-cert failed, status=" << status;
    return FilePath();
  }
  return FilePath(filename);
}

}  // namespace shill
