summaryrefslogtreecommitdiffstats
path: root/net/base/keygen_handler_mac.cc
diff options
context:
space:
mode:
authordavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 23:12:12 +0000
committerdavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 23:12:12 +0000
commit6f9ebd9f3a6e14139a3e28d9bd415cc250e644d5 (patch)
tree2846cbd1efffada03ae9f87cc5df46caf1c78e07 /net/base/keygen_handler_mac.cc
parentd2586b55a1e253f23d91517e0d757bacb7223435 (diff)
downloadchromium_src-6f9ebd9f3a6e14139a3e28d9bd415cc250e644d5.zip
chromium_src-6f9ebd9f3a6e14139a3e28d9bd415cc250e644d5.tar.gz
chromium_src-6f9ebd9f3a6e14139a3e28d9bd415cc250e644d5.tar.bz2
Give keys friendly names in NSS and OS X
This will make them browsing them easier in Keychain Access and certutil. It also gives them a more useful name in Keychain permission dialogs. The friendly name is currently just the hostname which requested the key. It would be nice to have some surrounding text with localization, but this works for now. BUG=none TEST=none Review URL: http://codereview.chromium.org/2806045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56774 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/keygen_handler_mac.cc')
-rw-r--r--net/base/keygen_handler_mac.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/net/base/keygen_handler_mac.cc b/net/base/keygen_handler_mac.cc
index c2c63d7..f5097a3 100644
--- a/net/base/keygen_handler_mac.cc
+++ b/net/base/keygen_handler_mac.cc
@@ -13,6 +13,8 @@
#include "base/lock.h"
#include "base/logging.h"
#include "base/scoped_cftyperef.h"
+#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
// These are in Security.framework but not declared in a public header.
extern const SecAsn1Template kSecAsn1AlgorithmIDTemplate[];
@@ -89,6 +91,7 @@ static const SecAsn1Template kSignedPublicKeyAndChallengeTemplate[] = {
static OSStatus CreateRSAKeyPair(int size_in_bits,
+ SecAccessRef initial_access,
SecKeyRef* out_pub_key,
SecKeyRef* out_priv_key);
static OSStatus SignData(CSSM_DATA data,
@@ -98,14 +101,31 @@ static OSStatus SignData(CSSM_DATA data,
std::string KeygenHandler::GenKeyAndSignChallenge() {
std::string result;
OSStatus err;
+ SecAccessRef initial_access = NULL;
SecKeyRef public_key = NULL;
SecKeyRef private_key = NULL;
SecAsn1CoderRef coder = NULL;
CSSM_DATA signature = {0, NULL};
{
+ if (url_.has_host()) {
+ // TODO(davidben): Use something like "Key generated for
+ // example.com", but localize it.
+ scoped_cftyperef<CFStringRef> label(
+ base::SysUTF8ToCFStringRef(url_.host()));
+ // Create an initial access object to set the SecAccessRef. This
+ // sets a label on the Keychain dialogs. Pass NULL as the second
+ // argument to use the default trusted list; only allow the
+ // current application to access without user confirmation.
+ err = SecAccessCreate(label, NULL, &initial_access);
+ // If we fail, just continue without a label.
+ if (err)
+ base::LogCSSMError("SecAccessCreate", err);
+ }
+
// Create the key-pair.
- err = CreateRSAKeyPair(key_size_in_bits_, &public_key, &private_key);
+ err = CreateRSAKeyPair(key_size_in_bits_, initial_access,
+ &public_key, &private_key);
if (err)
goto failure;
@@ -188,6 +208,8 @@ std::string KeygenHandler::GenKeyAndSignChallenge() {
free(signature.Data);
if (coder)
SecAsn1CoderRelease(coder);
+ if (initial_access)
+ CFRelease(initial_access);
if (public_key)
CFRelease(public_key);
if (private_key)
@@ -196,7 +218,12 @@ std::string KeygenHandler::GenKeyAndSignChallenge() {
}
+// Create an RSA key pair with size |size_in_bits|. |initial_access|
+// is passed as the initial access control list in Keychain. The
+// public and private keys are placed in |out_pub_key| and
+// |out_priv_key|, respectively.
static OSStatus CreateRSAKeyPair(int size_in_bits,
+ SecAccessRef initial_access,
SecKeyRef* out_pub_key,
SecKeyRef* out_priv_key) {
OSStatus err;
@@ -221,7 +248,7 @@ static OSStatus CreateRSAKeyPair(int size_in_bits,
CSSM_KEYUSE_DECRYPT | CSSM_KEYUSE_SIGN | CSSM_KEYUSE_UNWRAP,
CSSM_KEYATTR_EXTRACTABLE | CSSM_KEYATTR_PERMANENT |
CSSM_KEYATTR_SENSITIVE,
- NULL,
+ initial_access,
out_pub_key, out_priv_key);
}
if (err)