/* -*- 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/. */
nsresult MaybeLoadLibSecret() {
MOZ_ASSERT(NS_IsMainThread()); if (!NS_IsMainThread()) { return NS_ERROR_NOT_SAME_THREAD;
}
if (!libsecret) {
libsecret = PR_LoadLibrary("libsecret-1.so.0"); if (!libsecret) { return NS_ERROR_NOT_AVAILABLE;
}
// With TSan, we cannot unload libsecret once we have loaded it because // TSan does not support unloading libraries that are matched from its // suppression list. Hence we just keep the library loaded in TSan builds. #ifdef MOZ_TSAN # define UNLOAD_LIBSECRET(x) \ do { \
} while (0) #else # define UNLOAD_LIBSECRET(x) PR_UnloadLibrary(x) #endif
nsresult LibSecret::RetrieveSecret(const nsACString& aLabel, /* out */ nsACString& aSecret) {
MOZ_ASSERT(secret_password_lookup_sync && secret_password_free); if (!secret_password_lookup_sync || !secret_password_free) { return NS_ERROR_FAILURE;
}
GUniquePtr<GError> error;
aSecret.Truncate();
ScopedPassword s(
secret_password_lookup_sync(&kSchema,
nullptr, // GCancellable
getter_Transfers(error), "string",
PromiseFlatCString(aLabel).get(), nullptr)); if (error || !s) {
MOZ_LOG(gLibSecretLog, LogLevel::Debug,
("Error retrieving secret or didn't find it")); return NS_ERROR_FAILURE;
} // libsecret expects a null-terminated string, so to be safe we store the // secret (which could be arbitrary bytes) base64-encoded, which means we have // to base64-decode it here.
nsAutoCString base64Encoded(s.get());
nsresult rv = Base64Decode(base64Encoded, aSecret); if (NS_FAILED(rv)) {
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error base64-decoding secret")); return rv;
}
return NS_OK;
}
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
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.