Index: net/base/openssl_util.h |
diff --git a/net/base/openssl_util.h b/net/base/openssl_util.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7dfdd5a7140fa2ef5607d3e49a3d36e3b83ec8a |
--- /dev/null |
+++ b/net/base/openssl_util.h |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2013 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_BASE_OPENSSL_UTIL_H |
+#define NET_BASE_OPENSSL_UTIL_H |
+ |
+#include <vector> |
+ |
+typedef struct evp_pkey_st EVP_PKEY; |
+ |
+namespace net { |
+ |
+class X509Certificate; |
+ |
+// Helper routine because EVP_PKEY_dup() doesn't exist in the |
+// version of OpenSSL used by Chromium at the moment. Avoid future |
+// name clases by using a different name too. |
+EVP_PKEY* EVP_PKEY_dup(EVP_PKEY* key); |
+ |
+// Helper class to hold a pair of public/private keys with |
+// appropriate ownership. |
+class OpenSSLKeyPairList { |
+public: |
+ OpenSSLKeyPairList() {} |
+ ~OpenSSLKeyPairList() {} |
+ |
+ // Find the private key corresponding to a given public one. |
+ // |public_key| is an EVP_PKEY holding a public key. |
+ // Returns the matching EVP_PKEY holding the private key, or NULL if |
+ // not found. This increases the returned key's reference count, so |
+ // the caller shall call EVP_PKEY_free() on it. |
+ EVP_PKEY* FindPrivateKey(EVP_PKEY* public_key); |
+ |
+ // Add a (public/private) key pair |
+ // |public_key| is the public key EVP_PKEY. Cannot be NULL. |
+ // |private_key| is the private key EVP_PKEY, this can be the same |
+ // object than |public_key| is it holds both a public and a private key. |
+ // Cannot be NULL. |
+ // Returns true on success, false otherwise. |
+ // Can be called multiple times with the same data. If there is already |
+ // a pair recorded for |public_key|, this returns immediately. Otherwise |
+ // this increases the reference counts of both objects. |
+ bool AddKeyPair(EVP_PKEY* public_key, EVP_PKEY* private_key); |
+ |
+private: |
+ // KeyPair is an internal class used to hold a pair of private / public |
+ // EVP_PKEY objects, with appropriate ownership. |
+ class KeyPair { |
+ public: |
+ explicit KeyPair(EVP_PKEY* pub_key, EVP_PKEY* priv_key); |
+ KeyPair(const KeyPair& other); |
+ ~KeyPair(); |
+ |
+ EVP_PKEY* public_key_; |
+ EVP_PKEY* private_key_; |
+ |
+ private: |
+ KeyPair(); // intentionally not implemented. |
+ }; |
+ |
+ std::vector<KeyPair> pairs_; |
+}; |
+ |
+// Returns the public key of a given certificate, as an OpenSSL EVP_PKEY. |
+// |cert| is the client certificate. |
+// On success, returns an EVP_PKEY* handle that must be freed by the |
+// caller with EVP_PKEY_free(). On failure, returns NULL. |
+EVP_PKEY* GetCertificatePublicKeyOpenSSL(const X509Certificate& cert); |
+ |
+} // namespace net |
+ |
+#endif // NET_BASE_OPENSSL_UTIL_H |