Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: net/android/keystore.h

Issue 11571059: Add net/android/keystore.h (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: new version with simpler signing support Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_ANDROID_KEYSTORE_H
6 #define NET_ANDROID_KEYSTORE_H
7
8 #include <jni.h>
9 #include <openssl/evp.h>
10
11 #include <string>
12 #include <vector>
13
14 #include "base/basictypes.h"
15 #include "base/string_piece.h"
16 #include "net/base/net_export.h"
17
18 // Misc classes to access the Android platform KeyStore.
19
20 namespace net {
21 namespace android {
22
23 // A ClientCertRequest is used to handle the UI side of a SSL handshake
24 // "Certificate Request" message. I.e. the server provides a list of
25 // certificate key types and CA distinguished names, and expects a client
26 // certificate chain and later a message signed with the corresponding
27 // private key.
28 //
29 // Usage of this class is as follows:
30 //
31 // 1/ The embedder defines a net::android::ClientCertRequest sub-class,
32 // 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.
33 // application thread. Start() returns immediately because the whole
34 // operation is asynchronous.
35 //
36 // 2/ This prompts the user with a dialog to select a pre-installed
37 // client certificate. Once selected, the OnCertificateSelection()
38 // method is called on the main application thread, providing
39 // 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
40 // identify the client certificate and its private key.
41 //
42 // 3/ Later, use GetOpenSSLClientCertificateFromPrivateKeyAlias() to
43 // retrieve the client certificate chain and a "fake" private key
44 // object that can be used for signing.
45 //
46 class ClientCertRequest {
47 public:
48 // Create a new ClientCertRequest. Use Start() to start the request.
49 ClientCertRequest() : request_id_(0) {}
50
51 // Note: The destructor automatically cancels the request
52 // Must be called from the UI thread.
53 virtual ~ClientCertRequest();
54
55 // Return the unique request id for this object.
56 // This number is 0 if the request is not started (or cancelled).
57 int request_id() { return request_id_; }
58
59 // Start a new request from the current activity.
60 // |key_types| is a list of acceptable certificate key types.
61 // |issuers| is the list of certificate issuers accepted by the
62 // server. Each element is a DER-encoded X.509 DistinguishedName.
63 // |host_name| is the server's host name, if available (or empty).
64 // |port| is the server's port if available (or 0).
65 // Returns true on success, or false on error (e.g. if there is no
66 // Chromium activity currently running).
67 // IMPORTANT: Must be called from main application thread.
68 bool Start(const std::vector<std::string>& key_types,
69 const std::vector<std::string>& issuers,
70 const std::string& host,
71 int port);
72
73 // Cancel the current request.
74 // Must be called from main application thread.
75 void Cancel();
76
77 // Called on main application thread when the client certificate
78 // request has completed. This is an abstract method that must be
79 // overriden by client code.
80 //
81 // |private_key_alias| is a string serving as a unique id for the
82 // selected certificate and corresponding private key. Use it for
83 // debugging only.
84 //
85 // |cert_chain| is the client certificate chain, as a list of strings,
86 // where each item is a DER-encoded X.509 certificate.
87 //
88 // |private_key| is a JNI local reference to a Java PrivateKey object
89 // matching the certificate. It is destroyed after the method returns.
90 // If client code wants to keep a reference to the same object, it
91 // shall first copy it into its own local or global JNI reference.
92 // Said saved JNI reference can later be used with SignWithPrivateKey.
93 //
94 virtual void OnCertificateSelection(
95 const std::string& private_key_alias,
96 std::vector<std::string>& cert_chain,
97 jobject private_key) = 0;
98
99 private:
100 int request_id_;
101 };
102
103 // Compute the signature of a given message, using a private key
104 // identified by its unique alias.
105 //
106 // |private_key| is a JNI reference for the private key. Must point
107 // to the object returned by ClientCertRequest::OnCertificateSelection.
108 // |message| is the input message.
109 // |signature| will receive the signature on success.
110 // Returns true on success, false on failure.
111 //
112 bool SignWithPrivateKey(
113 jobject private_key,
114 const base::StringPiece& message,
115 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
116
117 // Register JNI methods
118 NET_EXPORT bool RegisterKeyStore(JNIEnv* env);
119
120 } // namespace android
121 } // namespace net
122
123 #endif // NET_ANDROID_KEYSTORE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698