Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
identity.h
1 /*
2  * Copyright (c) 2017-2021 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <hicn/transport/auth/signer.h>
21 #include <unistd.h>
22 
23 extern "C" {
24 #include <openssl/pkcs12.h>
25 #include <openssl/rand.h>
26 #include <openssl/x509.h>
27 #include <openssl/x509v3.h>
28 }
29 
30 namespace transport {
31 namespace auth {
32 
33 class Identity {
34  // This class holds several information about a client, including its public
35  // key.
36  public:
37  // Generate a new identity from the given parameters. The identity will be
38  // saved in 'keystore_path' and encrypted using 'keystore_pwd'.
39  Identity(const std::string &keystore_path, const std::string &keystore_pwd,
40  CryptoSuite suite, unsigned int signature_len,
41  unsigned int validity_days, const std::string &subject_name);
42 
43  // Create an identity from an already existing keystore path.
44  Identity(std::string &keystore_path, std::string &keystore_pwd,
45  CryptoHashType hash_type);
46 
47  Identity(const Identity &other);
48  Identity(Identity &&other);
49  ~Identity();
50 
51  // Return the asymmetric signer object created from the public key.
52  std::shared_ptr<AsymmetricSigner> getSigner() const;
53 
54  // Return the key store filename.
55  std::string getFilename() const;
56 
57  // Return the key store password.
58  std::string getPassword() const;
59 
60  std::shared_ptr<X509> getCertificate() const;
61 
62  std::shared_ptr<EVP_PKEY> getPrivateKey() const;
63 
64  // Generate a new random identity.
65  static Identity generateIdentity(const std::string &subject_name = "");
66 
67  private:
68  static void free_key(EVP_PKEY *T) { EVP_PKEY_free(T); }
69 
70  std::string pwd_;
71  std::string filename_;
72  std::shared_ptr<AsymmetricSigner> signer_;
73  std::shared_ptr<X509> cert_;
74 };
75 
76 } // namespace auth
77 } // namespace transport
transport
Definition: forwarder_config.h:32
transport::auth::Identity
Definition: identity.h:33