2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <dpl/assert.h>
17 #include <openssl/x509v3.h>
18 #include <dpl/log/log.h>
19 #include <dpl/noncopyable.h>
20 #include <openssl/ecdsa.h>
21 #include <openssl/evp.h>
23 #include <vcore/Base64.h>
24 #include <vcore/CertificateLoader.h>
27 const int MIN_RSA_KEY_LENGTH = 1024;
28 } // namespace anonymous
30 namespace ValidationCore {
31 CertificateLoader::CertificateLoaderResult CertificateLoader::
32 loadCertificateBasedOnExponentAndModulus(const std::string &m_modulus,
33 const std::string &m_exponent)
37 LogError("Not implemented.");
41 CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificate(
42 const std::string &storageName,
43 CertificateLoader::CertificateLoaderComparator *cmp)
47 LogError("Not Implemented");
51 CertificateLoader::CertificateLoaderResult CertificateLoader::
52 loadCertificateBasedOnSubjectName(const std::string &subjectName)
55 LogError("Not implemented.");
59 CertificateLoader::CertificateLoaderResult CertificateLoader::
60 loadCertificateWithECKEY(const std::string &curveName,
61 const std::string &publicKey)
65 LogError("Not implemented.");
69 CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFromRawData(const std::string &rawData)
72 m_certificatePtr = CertificatePtr(new Certificate(rawData, Certificate::FORM_BASE64));
73 } VcoreCatch(Certificate::Exception::Base) {
74 LogWarning("Error reading certificate by openssl.");
78 // Check the key length if sig algorithm is RSA
79 EVP_PKEY *pKey = X509_get_pubkey(m_certificatePtr->getX509());
82 if (pKey->type == EVP_PKEY_RSA) {
83 RSA* pRSA = pKey->pkey.rsa;
86 int keyLength = RSA_size(pRSA);
88 // key Length (modulus) is in bytes
90 LogDebug("RSA key length: " << keyLength << " bits");
92 if (keyLength < MIN_RSA_KEY_LENGTH) {
93 LogError("RSA key too short! Has only " << keyLength << " bits");
94 return CERTIFICATE_SECURITY_ERROR;
103 CertificateLoader::CertificateLoaderResult CertificateLoader::
104 loadCertificateBasedOnDSAComponents(const std::string& strP,
105 const std::string& strQ,
106 const std::string& strG,
107 const std::string& strY,
108 const std::string& strJ,
109 const std::string& strSeed,
110 const std::string& strPGenCounter)
118 (void) strPGenCounter;
119 LogError("Not implemented.");
120 return UNKNOWN_ERROR;
123 bool CertificateLoader::convertBase64NodeToBigNum(const std::string& strNode,
128 LogError("Not implemented.");
132 } // namespace ValidationCore