Refactor SignatureValidator and reduce interface headers
[platform/core/security/cert-svc.git] / vcore / vcore / CertificateLoader.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #ifndef _CERTIFICATELOADER_H_
17 #define _CERTIFICATELOADER_H_
18
19 #include <string>
20 #include <string.h>
21
22 #include <dpl/noncopyable.h>
23 #include <openssl/ssl.h>
24
25 #include <cert-service.h>
26
27 #include <vcore/Certificate.h>
28
29 namespace ValidationCore {
30 class CertificateLoader : public VcoreDPL::Noncopyable
31 {
32   public:
33     class CertificateLoaderComparator
34     {
35       public:
36         virtual bool compare(X509 *x509cert) = 0;
37         virtual ~CertificateLoaderComparator()
38         {
39         }
40     };
41
42     enum CertificateLoaderResult
43     {
44         NO_ERROR,
45         CERTIFICATE_NOT_FOUND,
46         UNSUPPORTED_CERTIFICATE_FIELD,
47         WRONG_ARGUMENTS,
48         CERTIFICATE_SECURITY_ERROR,                  //!< there are some issues with certificate security (i.e. key too short)
49         UNKNOWN_ERROR
50     };
51
52     CertificateLoader()
53     {
54     }
55
56     virtual ~CertificateLoader()
57     {
58     }
59
60     CertificateLoaderResult loadCertificate(const std::string& storage,
61             CertificateLoaderComparator *cmp);
62
63     CertificateLoaderResult loadCertificateBasedOnSubjectName(
64             const std::string &subjectName);
65     CertificateLoaderResult loadCertificateBasedOnExponentAndModulus(
66             const std::string &m_modulus,
67             const std::string  &m_exponent);
68     // KW     CertificateLoaderResult loadCertificateBasedOnIssuerName(const std::string &isserName,
69     // KW       const std::string &serialNumber);
70
71     CertificateLoaderResult loadCertificateFromRawData(
72             const std::string &rawData);
73
74     CertificateLoaderResult loadCertificateBasedOnDSAComponents(
75             const std::string& strP,
76             const std::string& strQ,
77             const std::string& strG,
78             const std::string& strY,
79             const std::string& strJ,
80             const std::string& strSeed,
81             const std::string& strPGenCounter);
82
83     CertificateLoaderResult loadCertificateWithECKEY(
84             const std::string &curveName,
85             const std::string &publicKey);
86
87     /**
88      * converts base64 encoded node to SSL bignum
89      * allocates mem on *ppBigNum, don't forget to free it later with BN_free!
90      * returns conversion status
91      */
92     static bool convertBase64NodeToBigNum(const std::string& strNode,
93             BIGNUM** ppBigNum);
94
95     /*
96      * encodes SSL bignum into base64 octstring
97      * returns conversion status
98      */
99     // KW     static bool convertBigNumToBase64Node(const BIGNUM* pBigNum, std::string& strNode);
100
101     CertificatePtr getCertificatePtr() const
102     {
103         return m_certificatePtr;
104     }
105   private:
106     CertificatePtr m_certificatePtr;
107 };
108 } // namespace ValidationCore
109
110 #endif // _CERTIFICATELOADER_H_