/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * 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"nsPK11TokenDB.h"
// Set the Manufacturer field if (mIsInternalCryptoToken || mIsInternalKeyToken) {
rv = GetPIPNSSBundleString("ManufacturerID", mTokenManufacturerID); if (NS_FAILED(rv)) { return rv;
}
} else { constchar* ccManID =
mozilla::BitwiseCast<char*, CK_UTF8CHAR*>(tokInfo.manufacturerID);
mTokenManufacturerID.Assign(
ccManID, strnlen(ccManID, sizeof(tokInfo.manufacturerID)));
mTokenManufacturerID.Trim(" ", false, true);
}
// Set the Hardware Version field
mTokenHWVersion.Truncate();
mTokenHWVersion.AppendInt(tokInfo.hardwareVersion.major);
mTokenHWVersion.Append('.');
mTokenHWVersion.AppendInt(tokInfo.hardwareVersion.minor);
// Set the Firmware Version field
mTokenFWVersion.Truncate();
mTokenFWVersion.AppendInt(tokInfo.firmwareVersion.major);
mTokenFWVersion.Append('.');
mTokenFWVersion.AppendInt(tokInfo.firmwareVersion.minor);
// Set the Serial Number field constchar* ccSerial =
mozilla::BitwiseCast<char*, CK_CHAR*>(tokInfo.serialNumber);
mTokenSerialNum.Assign(ccSerial,
strnlen(ccSerial, sizeof(tokInfo.serialNumber)));
mTokenSerialNum.Trim(" ", false, true);
NS_IMETHODIMP
nsPK11Token::LogoutSimple() { // PK11_Logout() can fail if the user wasn't logged in beforehand. We want // this method to succeed even in this case, so we ignore the return value.
mozilla::Unused << PK11_Logout(mSlot.get()); return NS_OK;
}
NS_IMETHODIMP
nsPK11Token::InitPassword(const nsACString& initialPassword) { const nsCString& passwordCStr = PromiseFlatCString(initialPassword); // PSM initializes the sqlite-backed softoken with an empty password. The // implementation considers this not to be a password (GetHasPassword returns // false), but we can't actually call PK11_InitPin again. Instead, we call // PK11_ChangePW with the empty password. bool hasPassword;
nsresult rv = GetHasPassword(&hasPassword); if (NS_FAILED(rv)) { return rv;
} if (!PK11_NeedUserInit(mSlot.get()) && !hasPassword) { return mozilla::MapSECStatus(
PK11_ChangePW(mSlot.get(), "", passwordCStr.get()));
} return mozilla::MapSECStatus(
PK11_InitPin(mSlot.get(), "", passwordCStr.get()));
}
NS_IMETHODIMP
nsPK11Token::ChangePassword(const nsACString& oldPassword, const nsACString& newPassword) { // PK11_ChangePW() has different semantics for the empty string and for // nullptr. In order to support this difference, we need to check IsVoid() to // find out if our caller supplied null/undefined args or just empty strings. // See Bug 447589. return mozilla::MapSECStatus(PK11_ChangePW(
mSlot.get(),
oldPassword.IsVoid() ? nullptr : PromiseFlatCString(oldPassword).get(),
newPassword.IsVoid() ? nullptr : PromiseFlatCString(newPassword).get()));
}
NS_IMETHODIMP
nsPK11Token::GetHasPassword(bool* hasPassword) {
NS_ENSURE_ARG_POINTER(hasPassword); // PK11_NeedLogin returns true if the token is currently configured to require // the user to log in (whether or not the user is actually logged in makes no // difference).
*hasPassword = PK11_NeedLogin(mSlot.get()) && !PK11_NeedUserInit(mSlot.get()); return NS_OK;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.