Index: net/android/keystore.h |
diff --git a/net/android/keystore.h b/net/android/keystore.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b558e8f0cd5e4cdb6291bf5b014afeecaf1b77af |
--- /dev/null |
+++ b/net/android/keystore.h |
@@ -0,0 +1,123 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_ANDROID_KEYSTORE_H |
+#define NET_ANDROID_KEYSTORE_H |
+ |
+#include <jni.h> |
+#include <openssl/evp.h> |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/string_piece.h" |
+#include "net/base/net_export.h" |
+ |
+// Misc classes to access the Android platform KeyStore. |
+ |
+namespace net { |
+namespace android { |
+ |
+// A ClientCertRequest is used to handle the UI side of a SSL handshake |
+// "Certificate Request" message. I.e. the server provides a list of |
+// certificate key types and CA distinguished names, and expects a client |
+// certificate chain and later a message signed with the corresponding |
+// private key. |
+// |
+// Usage of this class is as follows: |
+// |
+// 1/ The embedder defines a net::android::ClientCertRequest sub-class, |
+// creates an instance, and call its Start() routine in the main |
palmer
2013/01/19 01:43:12
Typo: "calls"
digit1
2013/01/21 13:35:35
Done.
|
+// application thread. Start() returns immediately because the whole |
+// operation is asynchronous. |
+// |
+// 2/ This prompts the user with a dialog to select a pre-installed |
+// client certificate. Once selected, the OnCertificateSelection() |
+// method is called on the main application thread, providing |
+// a "private key alias", which is a simple string used to uniquely |
palmer
2013/01/19 01:43:12
How important is that uniqueness? If it is super i
digit1
2013/01/21 13:35:35
The user / system does that. When you install a pr
|
+// identify the client certificate and its private key. |
+// |
+// 3/ Later, use GetOpenSSLClientCertificateFromPrivateKeyAlias() to |
+// retrieve the client certificate chain and a "fake" private key |
+// object that can be used for signing. |
+// |
+class ClientCertRequest { |
+public: |
+ // Create a new ClientCertRequest. Use Start() to start the request. |
+ ClientCertRequest() : request_id_(0) {} |
+ |
+ // Note: The destructor automatically cancels the request |
+ // Must be called from the UI thread. |
+ virtual ~ClientCertRequest(); |
+ |
+ // Return the unique request id for this object. |
+ // This number is 0 if the request is not started (or cancelled). |
+ int request_id() { return request_id_; } |
+ |
+ // Start a new request from the current activity. |
+ // |key_types| is a list of acceptable certificate key types. |
+ // |issuers| is the list of certificate issuers accepted by the |
+ // server. Each element is a DER-encoded X.509 DistinguishedName. |
+ // |host_name| is the server's host name, if available (or empty). |
+ // |port| is the server's port if available (or 0). |
+ // Returns true on success, or false on error (e.g. if there is no |
+ // Chromium activity currently running). |
+ // IMPORTANT: Must be called from main application thread. |
+ bool Start(const std::vector<std::string>& key_types, |
+ const std::vector<std::string>& issuers, |
+ const std::string& host, |
+ int port); |
+ |
+ // Cancel the current request. |
+ // Must be called from main application thread. |
+ void Cancel(); |
+ |
+ // Called on main application thread when the client certificate |
+ // request has completed. This is an abstract method that must be |
+ // overriden by client code. |
+ // |
+ // |private_key_alias| is a string serving as a unique id for the |
+ // selected certificate and corresponding private key. Use it for |
+ // debugging only. |
+ // |
+ // |cert_chain| is the client certificate chain, as a list of strings, |
+ // where each item is a DER-encoded X.509 certificate. |
+ // |
+ // |private_key| is a JNI local reference to a Java PrivateKey object |
+ // matching the certificate. It is destroyed after the method returns. |
+ // If client code wants to keep a reference to the same object, it |
+ // shall first copy it into its own local or global JNI reference. |
+ // Said saved JNI reference can later be used with SignWithPrivateKey. |
+ // |
+ virtual void OnCertificateSelection( |
+ const std::string& private_key_alias, |
+ std::vector<std::string>& cert_chain, |
+ jobject private_key) = 0; |
+ |
+private: |
+ int request_id_; |
+}; |
+ |
+// Compute the signature of a given message, using a private key |
+// identified by its unique alias. |
+// |
+// |private_key| is a JNI reference for the private key. Must point |
+// to the object returned by ClientCertRequest::OnCertificateSelection. |
+// |message| is the input message. |
+// |signature| will receive the signature on success. |
+// Returns true on success, false on failure. |
+// |
+bool SignWithPrivateKey( |
+ jobject private_key, |
+ const base::StringPiece& message, |
+ std::vector<uint8>* signature); |
Ryan Sleevi
2013/01/18 20:05:48
DESIGN: This is not at all clear what type of sign
palmer
2013/01/19 01:43:12
+1
digit1
2013/01/21 13:35:35
Good question. I'm not sure how to best answer thi
|
+ |
+// Register JNI methods |
+NET_EXPORT bool RegisterKeyStore(JNIEnv* env); |
+ |
+} // namespace android |
+} // namespace net |
+ |
+#endif // NET_ANDROID_KEYSTORE_H |