source code open
[framework/security/cert-svc.git] / vcore / src / vcore / CertificateLoader.cpp
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 #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>
22
23 #include "Base64.h"
24 #include "CertificateLoader.h"
25 #include "SSLContainers.h"
26
27 namespace {
28 const int MIN_RSA_KEY_LENGTH = 1024;
29 //const char *OID_CURVE_SECP256R1 = "urn:oid:1.2.840.10045.3.1.7";
30 } // namespace anonymous
31
32 namespace ValidationCore {
33 //// COMPARATOR CLASS START ////
34
35 //class CertificateLoaderECDSA : public CertificateLoader::CertificateLoaderComparator, DPL::Noncopyable {
36 //public:
37 //    CertificateLoaderECDSA(const std::string &publicKey)
38 //      : m_ecPublicKey(NULL)
39 //      , m_searchKey(NULL)
40 //    {
41 //        m_bnCtx = BN_CTX_new(); // if fails we can continue anyway
42 //        m_tmpPoint = BN_new();  // if fails we can continue anyway
43 //        m_initialized = CertificateLoader::convertBase64NodeToBigNum(publicKey, &m_searchKey);
44 //
45 //        if(!m_initialized)
46 //            LogError("Init failed!");
47 //    }
48 //
49 //    virtual bool compare(X509 *x509cert){
50 //        if(!m_initialized)
51 //            return false;
52 //
53 //        EVP_PKEY_free(m_ecPublicKey);
54 //
55 //        m_ecPublicKey = X509_get_pubkey(x509cert);
56 //
57 //        if(m_ecPublicKey == NULL)
58 //            return false;
59 //
60 //        if(m_ecPublicKey->type != EVP_PKEY_EC){
61 //            LogError("ecPublicKey has wrong type!");
62 //            return false;
63 //        }
64 //
65 //        // Pointer to internal data of ecPublicKey. Do not free!
66 //        EC_KEY *eckey = m_ecPublicKey->pkey.ec;
67 //
68 //        const EC_POINT *ecpoint = EC_KEY_get0_public_key(eckey);
69 //        const EC_GROUP *ecgroup = EC_KEY_get0_group(eckey);
70 //
71 //        m_tmpPoint = EC_POINT_point2bn(ecgroup, ecpoint, POINT_CONVERSION_UNCOMPRESSED, m_tmpPoint, m_bnCtx);
72 //
73 //        if(BN_cmp(m_tmpPoint, m_searchKey) == 0)
74 //            return true;
75 //
76 //        return false;
77 //    }
78 //
79 //    ~CertificateLoaderECDSA(){
80 //        BN_CTX_free(m_bnCtx);
81 //        EVP_PKEY_free(m_ecPublicKey);
82 //        BN_free(m_searchKey);
83 //        BN_free(m_tmpPoint);
84 //    }
85 //
86 //private:
87 //    bool        m_initialized;
88 //    EVP_PKEY   *m_ecPublicKey;
89 //    BN_CTX     *m_bnCtx;
90 //    BIGNUM     *m_searchKey;
91 //    BIGNUM     *m_tmpPoint;
92 //};
93
94 ///// COMPARETORS CLASS END /////
95
96 //// COMPARATOR RSA CLASS START ////
97
98 //class CertificateLoaderRSA : public CertificateLoader::CertificateLoaderComparator, DPL::Noncopyable {
99 //public:
100 //    CertificateLoaderRSA(const std::string &m_modulus,const std::string &m_exponent )
101 //      : m_rsaPublicKey(NULL)
102 //      , m_modulus_bn(NULL)
103 //      , m_exponent_bn(NULL)
104 //    {
105 //
106 //        m_initialized_modulus = CertificateLoader::convertBase64NodeToBigNum(m_modulus, &m_modulus_bn);
107 //        m_initialized_exponent = CertificateLoader::convertBase64NodeToBigNum(m_exponent, &m_exponent_bn);
108 //
109 //        if(!m_initialized_modulus || !m_initialized_exponent)
110 //            LogError("Init failed!");
111 //    }
112 //
113 //    virtual bool compare(X509 *x509cert){
114 //
115 //        if(!m_initialized_modulus || !m_initialized_exponent)
116 //            return false;
117 //
118 //        EVP_PKEY_free(m_rsaPublicKey);
119 //        m_rsaPublicKey = X509_get_pubkey(x509cert);
120 //
121 //        if(m_rsaPublicKey == NULL)
122 //            return false;
123 //
124 //        if(m_rsaPublicKey->type != EVP_PKEY_RSA){
125 //            LogInfo("rsaPublicKey has wrong type!");
126 //            return false;
127 //        }
128 //
129 //        RSA *rsa = NULL;
130 //        rsa = m_rsaPublicKey->pkey.rsa;
131 //
132 //        if (BN_cmp(m_modulus_bn, rsa->n) == 0 &&
133 //            BN_cmp(m_exponent_bn, rsa->e) == 0 ){
134 //            LogError ("Compare TRUE");
135 //            return true;
136 //        }
137 //        return false;
138 //    }
139 //
140 //    ~CertificateLoaderRSA(){
141 //        EVP_PKEY_free(m_rsaPublicKey);
142 //        BN_free(m_modulus_bn);
143 //        BN_free(m_exponent_bn);
144 //
145 //    }
146 //
147 //private:
148 //    bool        m_initialized_modulus;
149 //    bool        m_initialized_exponent;
150 //    EVP_PKEY   *m_rsaPublicKey;
151 //    BIGNUM     *m_modulus_bn;
152 //    BIGNUM     *m_exponent_bn;
153 //};
154
155 ///// COMPARETORS RSA CLASS END /////
156
157 CertificateLoader::CertificateLoaderResult CertificateLoader::
158     loadCertificateBasedOnExponentAndModulus(const std::string &m_modulus,
159         const std::string &m_exponent)
160 {
161     (void) m_modulus;
162     (void) m_exponent;
163     LogError("Not implemented.");
164     return UNKNOWN_ERROR;
165     //    if (m_exponent.empty() || m_modulus.empty())
166     //        return WRONG_ARGUMENTS;
167     //
168     //    CertificateLoaderRSA comparator(m_modulus,m_exponent);
169     //
170     //    CertificateLoaderResult result = NO_ERROR;
171     //    for(int i=0; storeId[i]; ++i){
172     //        result = loadCertificate(std::string(storeId[i]), &comparator);
173     //
174     //        if(result == ERR_NO_MORE_CERTIFICATES)
175     //            continue;
176     //
177     //        return result;
178     //    }
179     //
180     //    return result;
181 }
182
183 CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificate(
184         const std::string &storageName,
185         CertificateLoader::CertificateLoaderComparator *cmp)
186 {
187     (void) storageName;
188     (void) cmp;
189     LogError("Not Implemented");
190     return UNKNOWN_ERROR;
191     //    long int result = OPERATION_SUCCESS;
192     //
193     //    char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE];
194     //    char type[CERTMGR_MAX_CERT_TYPE_SIZE];
195     //    certmgr_cert_id certId;
196     //    certmgr_ctx context;
197     //    certmgr_mem_buff certRetrieved;
198     //    unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE];
199     //
200     //    certmgr_cert_descriptor descriptor;
201     //
202     //    certRetrieved.data = buffer;
203     //    certRetrieved.firstFree = 0;
204     //    certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE;
205     //    certId.storeId = storeId;
206     //    certId.type = type;
207     //
208     //    CERTMGR_INIT_CONTEXT((&context), (sizeof(context)))
209     //
210     //    strncpy(context.storeId, storageName.c_str(), storageName.size());
211     //
212     //    for(certRetrieved.firstFree = 0;
213     //        OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId));
214     //        certRetrieved.firstFree = 0)
215     //    {
216     //
217     //        if(OPERATION_SUCCESS!=certmgr_extract_certificate_data(&certRetrieved, &descriptor)){
218     //            LogError("Extracting Certificate Data failed \n");
219     //            continue;
220     //        }
221     //
222     //        const unsigned char *ptr = certRetrieved.data;
223     //
224     //        X509 *x509cert = d2i_X509(NULL, &ptr, certRetrieved.size);
225     //        if(x509cert == NULL){
226     //            certmgr_release_certificate_data(&descriptor);
227     //            LogError("Error extracting certificate (d2i_X509).");
228     //            return UNKNOWN_ERROR;
229     //        }
230     //
231     //        LogDebug("The subject of this certificate is " << descriptor.mandatory.subject);
232     //        if(cmp->compare(x509cert)){
233     //            LogDebug("Found match. Coping bytes: " << certRetrieved.size);
234     //            m_certificatePtr = CertificatePtr(new Certificate(certRetrieved));
235     //            certmgr_release_certificate_data(&descriptor);
236     //            X509_free(x509cert);
237     //            break;
238     //        }
239     //
240     //        LogDebug("Release");
241     //        X509_free(x509cert);
242     //        certmgr_release_certificate_data(&descriptor);
243     //    }
244     //
245     //    if(ERR_NO_MORE_CERTIFICATES == result){
246     //        LogError("Certificates for given DN not found\n");
247     //        return CERTIFICATE_NOT_FOUND;
248     //    }
249     //
250     //    if(result!= OPERATION_SUCCESS){
251     //        LogError("Certificate Manager Error\n");
252     //        return UNKNOWN_ERROR;
253     //    }
254     //
255     //    LogDebug("Exit");
256     //    return NO_ERROR;
257 }
258
259 // TODO
260 CertificateLoader::CertificateLoaderResult CertificateLoader::
261     loadCertificateBasedOnSubjectName(const std::string &subjectName)
262 {
263     (void) subjectName;
264     LogError("Not implemented.");
265     return UNKNOWN_ERROR;
266     //    if(subjectName.empty())
267     //    {
268     //        return WRONG_ARGUMENTS;
269     //    }
270     //
271     //    long int result = OPERATION_SUCCESS;
272     //
273     //    char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE];
274     //    char type[CERTMGR_MAX_CERT_TYPE_SIZE];
275     //    certmgr_cert_id certId;
276     //    certmgr_ctx context;
277     //    certmgr_mem_buff certRetrieved;
278     //    unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE];
279     //
280     //    certmgr_cert_descriptor descriptor;
281     //
282     //    certRetrieved.data = buffer;
283     //    certRetrieved.firstFree = 0;
284     //    certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE;
285     //    certId.storeId = storeId;
286     //    certId.type = type;
287     //
288     //    CERTMGR_INIT_CONTEXT((&context), (sizeof(context)))
289     //
290     //    for(certRetrieved.firstFree = 0;
291     //        OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId));
292     //        certRetrieved.firstFree = 0)
293     //    {
294     //
295     //        if(OPERATION_SUCCESS!=certmgr_extract_certificate_data(&certRetrieved, &descriptor)){
296     //            LogError("Extracting Certificate Data failed \n");
297     //            continue;
298     //        }
299     //
300     //        if(!strcmp(subjectName.c_str(), descriptor.mandatory.subject)){
301     //            LogDebug("The subject of this certificate is " << descriptor.mandatory.subject);
302     //            m_certificatePtr = CertificatePtr(new Certificate(certRetrieved));
303     //            certmgr_release_certificate_data(&descriptor);
304     //            break;
305     //        }
306     //        LogDebug("Release");
307     //        certmgr_release_certificate_data(&descriptor);
308     //    }
309     //
310     //    if(ERR_NO_MORE_CERTIFICATES == result) {
311     //        LogError("Certificates for given DN not found\n");
312     //        return CERTIFICATE_NOT_FOUND;
313     //    }
314     //    if(result!= OPERATION_SUCCESS){
315     //        LogError("Certificate Manager Error\n");
316     //        return UNKNOWN_ERROR;
317     //    }
318     //    LogDebug("Exit");
319     //    return NO_ERROR;
320 }
321
322 // KW CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateBasedOnIssuerName(const std::string &issuerName, const std::string &serialNumber)
323 // KW {
324 // KW     if(issuerName.empty() || serialNumber.empty())
325 // KW     {
326 // KW         return WRONG_ARGUMENTS;
327 // KW     }
328 // KW
329 // KW     if(m_cmBuff.data){
330 // KW         delete[] m_cmBuff.data;
331 // KW         memset(&m_cmBuff, 0, sizeof(certmgr_mem_buff));
332 // KW     }
333 // KW
334 // KW     LogDebug("IssuerName: " << issuerName << " serialNumber: " << serialNumber);
335 // KW
336 // KW     //used to check status of retrieved certificate
337 // KW     long int result = OPERATION_SUCCESS;
338 // KW     char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE];
339 // KW     char type[CERTMGR_MAX_CERT_TYPE_SIZE];
340 // KW     certmgr_cert_id certId;
341 // KW     certmgr_ctx context;
342 // KW     certmgr_mem_buff certRetrieved;
343 // KW     unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE];
344 // KW
345 // KW     certmgr_cert_descriptor descriptor;
346 // KW
347 // KW     certRetrieved.data = buffer;
348 // KW     certRetrieved.firstFree = 0;
349 // KW     certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE;
350 // KW     certId.storeId = storeId;
351 // KW     certId.type = type;
352 // KW
353 // KW     CERTMGR_INIT_CONTEXT((&context), (sizeof(context)))
354 // KW
355 // KW     for(certRetrieved.firstFree = 0;
356 // KW         OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId));
357 // KW         certRetrieved.firstFree = 0)
358 // KW     {
359 // KW
360 // KW         LogDebug("Extracting certificate from CertMgr");
361 // KW
362 // KW         if( OPERATION_SUCCESS != certmgr_extract_certificate_data(&certRetrieved, &descriptor) ){
363 // KW             LogError("Extracting Certificate Data failed \n");
364 // KW             continue;
365 // KW         }
366 // KW
367 // KW         LogDebug("Issuer: " << descriptor.mandatory.issuer);
368 // KW
369 // KW         const unsigned char *ptr = certRetrieved.data;
370 // KW         char *tmp;
371 // KW
372 // KW         X509 *x509cert = d2i_X509(NULL, &ptr, certRetrieved.size);
373 // KW         std::string serialNO = std::string(tmp = i2s_ASN1_INTEGER(NULL, X509_get_serialNumber(x509cert)));
374 // KW         OPENSSL_free(tmp);
375 // KW         X509_free(x509cert);
376 // KW
377 // KW         LogInfo("Certificate number found: " << serialNO);
378 // KW         LogInfo("Certificate number looking for: " << serialNumber);
379 // KW
380 // KW         if(!strcmp(issuerName.c_str(), descriptor.mandatory.issuer)
381 // KW               && serialNumber == serialNO)
382 // KW         {
383 // KW             LogError("The issuer of this certificate is " << descriptor.mandatory.issuer);
384 // KW
385 // KW             m_cmBuff.data = new unsigned char[certRetrieved.size];
386 // KW             m_cmBuff.firstFree = m_cmBuff.size = certRetrieved.size;
387 // KW             memcpy(m_cmBuff.data, certRetrieved.data, certRetrieved.size);
388 // KW             certmgr_release_certificate_data(&descriptor);
389 // KW             break;
390 // KW         }
391 // KW         certmgr_release_certificate_data(&descriptor);
392 // KW     }
393 // KW
394 // KW     if(ERR_NO_MORE_CERTIFICATES == result) {
395 // KW         LogError("Certificates not found");
396 // KW         return CERTIFICATE_NOT_FOUND;
397 // KW     }
398 // KW     if(result != OPERATION_SUCCESS){
399 // KW         LogError("Certificate Manager Error");
400 // KW         return UNKNOWN_ERROR;
401 // KW     }
402 // KW     return NO_ERROR;
403 // KW }
404
405 CertificateLoader::CertificateLoaderResult CertificateLoader::
406     loadCertificateWithECKEY(const std::string &curveName,
407         const std::string &publicKey)
408 {
409     (void) curveName;
410     (void) publicKey;
411     LogError("Not implemented.");
412     return UNKNOWN_ERROR;
413     //    if(curveName != OID_CURVE_SECP256R1){
414     //        LogError("Found field id: " << curveName << " Expected: " << OID_CURVE_SECP256R1);
415     //        return UNSUPPORTED_CERTIFICATE_FIELD;
416     //    }
417     //
418     //    CertificateLoaderECDSA comparator(publicKey);
419     //
420     //    CertificateLoaderResult result = NO_ERROR;
421     //    for(int i=0; storeId[i]; ++i){
422     //        result = loadCertificate(std::string(storeId[i]), &comparator);
423     //
424     //        if(result == ERR_NO_MORE_CERTIFICATES)
425     //            continue;
426     //
427     //        return result;
428     //    }
429     //
430     //    return result;
431 }
432
433 CertificateLoader::CertificateLoaderResult CertificateLoader::
434     loadCertificateFromRawData(const std::string &rawData)
435 {
436     Try {
437         m_certificatePtr =
438             CertificatePtr(new Certificate(rawData, Certificate::FORM_BASE64));
439     } Catch(Certificate::Exception::Base) {
440         LogWarning("Error reading certificate by openssl.");
441         return UNKNOWN_ERROR;
442     }
443
444     // Check the key length if sig algorithm is RSA
445     EVP_PKEY *pKey = X509_get_pubkey(m_certificatePtr->getX509());
446
447     if (pKey->type == EVP_PKEY_RSA) {
448         RSA* pRSA = pKey->pkey.rsa;
449
450         if (pRSA) {
451             int keyLength = RSA_size(pRSA);
452
453             // key Length (modulus) is in bytes
454             keyLength <<= 3;
455             LogDebug("RSA key length: " << keyLength << " bits");
456
457             if (keyLength < MIN_RSA_KEY_LENGTH) {
458                 LogError(
459                     "RSA key too short!" << "Has only " << keyLength << " bits");
460                 return CERTIFICATE_SECURITY_ERROR;
461             }
462         }
463     }
464
465     return NO_ERROR;
466 }
467
468 // DEPRACETED FUNCTION
469 //CertificateLoader::CertificateLoaderResult CertificateLoader::loadCertificateFromRawData(const std::string &rawData)
470 //{
471 //    certmgr_mem_buff cmBuff = {0,0,0};
472 //
473 //    long int size;
474 //    cmBuff.data = certmgr_util_base64_decode(const_cast<void*>(static_cast<const void*>(rawData.c_str())), rawData.size(), &size);
475 //
476 //    cmBuff.firstFree = cmBuff.size = size;
477 //
478 //    certmgr_cert_descriptor descriptor;
479 //
480 //    long int result = certmgr_extract_certificate_data(&cmBuff, &descriptor);
481 //
482 //    if (result != OPERATION_SUCCESS)
483 //    {
484 //        LogError("Unable to load certificate");
485 //        return UNKNOWN_ERROR;
486 //    }
487 //
488 //    certmgr_release_certificate_data(&descriptor);
489 //
490 //    m_certificatePtr = CertificatePtr(new Certificate(cmBuff));
491 //
492 //    // we have to use temp pointer cause d2i_x509 modifies its input
493 //    const unsigned char* tmpPtr = cmBuff.data;
494 //    X509* pCertificate = d2i_X509(NULL, &tmpPtr, cmBuff.size);
495 //
496 //    if (pCertificate)
497 //    {
498 //        SSLSmartContainer<X509> pX509(pCertificate);
499 //
500 //        // Check the key length if sig algorithm is RSA
501 //        EVP_PKEY *pKey = X509_get_pubkey(pX509);
502 //
503 //        if (pKey->type == EVP_PKEY_RSA)
504 //        {
505 //            RSA* pRSA = pKey->pkey.rsa;
506 //
507 //            if (pRSA)
508 //            {
509 //                int keyLength = RSA_size(pRSA);
510 //
511 //                // key Length (modulus) is in bytes
512 //                keyLength <<= 3;
513 //                LogDebug("RSA key length: " << keyLength << " bits");
514 //
515 //                if (keyLength < MIN_RSA_KEY_LENGTH)
516 //                {
517 //                    LogError("RSA key too short!" << "Has only " << keyLength << " bits");
518 //                    return CERTIFICATE_SECURITY_ERROR;
519 //                }
520 //            }
521 //        }
522 //    }
523 //
524 //    return NO_ERROR;
525 //}
526
527 CertificateLoader::CertificateLoaderResult CertificateLoader::
528     loadCertificateBasedOnDSAComponents(const std::string& strP,
529         const std::string& strQ,
530         const std::string& strG,
531         const std::string& strY,
532         const std::string& strJ,
533         const std::string& strSeed,
534         const std::string& strPGenCounter)
535 {
536     (void) strP;
537     (void) strQ;
538     (void) strG;
539     (void) strY;
540     (void) strJ;
541     (void) strSeed;
542     (void) strPGenCounter;
543     LogError("Not implemented.");
544     return UNKNOWN_ERROR;
545     //    (void)strY;
546     //    (void)strJ;
547     //    (void)strSeed;
548     //    (void)strPGenCounter;
549     //
550     //    long int result = UNKNOWN_ERROR;
551     //
552     //    char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE];
553     //    char type[CERTMGR_MAX_CERT_TYPE_SIZE];
554     //    certmgr_cert_id certId;
555     //    certmgr_ctx context;
556     //    certmgr_mem_buff certRetrieved;
557     //
558     //    unsigned char buffer[CERTMGR_MAX_BUFFER_SIZE];
559     //
560     //    certmgr_cert_descriptor descriptor;
561     //
562     //    certRetrieved.data = buffer;
563     //    certRetrieved.firstFree = 0;
564     //    certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE;
565     //    certId.storeId = storeId;
566     //    certId.type = type;
567     //
568     //    CERTMGR_INIT_CONTEXT((&context), (sizeof(context)))
569     //    std::string strStoreType("Operator");
570     //    strncpy(context.storeId, strStoreType.c_str(),  strStoreType.length());
571     //
572     //    for (certRetrieved.firstFree = 0;
573     //      OPERATION_SUCCESS == (result = certmgr_retrieve_certificate_from_store(&context, &certRetrieved, &certId));
574     //      certRetrieved.firstFree = 0)
575     //    {
576     //
577     //        if (OPERATION_SUCCESS != certmgr_extract_certificate_data(&certRetrieved, &descriptor))
578     //        {
579     //            LogDebug("unable to retrieve cert from storage");
580     //            continue;
581     //        }
582     //
583     //        X509* pCertificate = d2i_X509(NULL, (const unsigned char**) &(certRetrieved.data), certRetrieved.size);
584     //
585     //        if (pCertificate)
586     //        {
587     //            EVP_PKEY *pKey = X509_get_pubkey(pCertificate);
588     //
589     //            if (pKey->type == EVP_PKEY_DSA)
590     //            {
591     //                DSA* pDSA = pKey->pkey.dsa;
592     //
593     //                if (pDSA)
594     //                {
595     //                    BIGNUM *pDSApBigNum = NULL, *pDSAqBigNum = NULL, *pDSAgBigNum = NULL;
596     //
597     //                    convertBase64NodeToBigNum(strP, &pDSApBigNum);
598     //                    convertBase64NodeToBigNum(strQ, &pDSAqBigNum);
599     //                    convertBase64NodeToBigNum(strG, &pDSAgBigNum);
600     //
601     //                    if (pDSApBigNum && pDSAqBigNum && pDSAgBigNum &&
602     //                      BN_cmp(pDSApBigNum, pDSA->p) == 0 &&
603     //                      BN_cmp(pDSAqBigNum, pDSA->q) == 0 &&
604     //                      BN_cmp(pDSAgBigNum, pDSA->g) == 0)
605     //                    {
606     //                        LogInfo("DSA Certificate found");
607     //                        /* TODO load this certificate to m_cmBuff value */
608     //                        LogError("Not implemented!");
609     //
610     //                        EVP_PKEY_free(pKey);
611     //                        X509_free(pCertificate);
612     //
613     //                        BN_free(pDSApBigNum);
614     //                        BN_free(pDSAqBigNum);
615     //                        BN_free(pDSAgBigNum);
616     //
617     //                        certmgr_release_certificate_data(&descriptor);
618     //                        return NO_ERROR;
619     //                    }
620     //
621     //                    if (pDSApBigNum)
622     //                    {
623     //                        BN_free(pDSApBigNum);
624     //                    }
625     //                    if (pDSAqBigNum)
626     //                    {
627     //                        BN_free(pDSAqBigNum);
628     //                    }
629     //                    if (pDSAgBigNum)
630     //                    {
631     //                        BN_free(pDSAgBigNum);
632     //                    }
633     //
634     //                }
635     //                EVP_PKEY_free(pKey);
636     //            }
637     //            X509_free(pCertificate);
638     //        }
639     //        else
640     //            LogError("Unable to load certificate");
641     //
642     //        certmgr_release_certificate_data(&descriptor);
643     //    }
644     //
645     //    LogError("No DSA certificate with given parameters");
646     //
647     //    return CERTIFICATE_NOT_FOUND;
648 }
649
650 bool CertificateLoader::convertBase64NodeToBigNum(const std::string& strNode,
651         BIGNUM** ppBigNum)
652 {
653     (void) strNode;
654     (void) ppBigNum;
655     LogError("Not implemented.");
656     return false;
657     //    if (!ppBigNum || *ppBigNum != NULL)
658     //    {
659     //        LogError("Ptr variable not initialized properly!");
660     //        return false;
661     //    }
662     //
663     //    // decode base64 to binary
664     //    long int binBuffLength = 0;
665     //    unsigned char* binBuff = NULL;
666     //
667     //    binBuff = certmgr_util_base64_decode(const_cast<char*> (strNode.c_str()), strNode.length(), &binBuffLength);
668     //
669     //    if (!binBuff)
670     //    {
671     //        LogError("base64 decode failed");
672     //        return false;
673     //    }
674     //
675     //    // convert binary to bignum
676     //    *ppBigNum = BN_bin2bn(binBuff, binBuffLength, *ppBigNum);
677     //
678     //    free(binBuff);
679     //
680     //    if (!(*ppBigNum))
681     //    {
682     //        LogError("Conversion from node to bignum failed");
683     //        return false;
684     //    }
685     //
686     //    return true;
687 }
688
689 // KW bool CertificateLoader::convertBigNumToBase64Node(const BIGNUM* pBigNum, std::string& strNode)
690 // KW {
691 // KW     if (!pBigNum)
692 // KW     {
693 // KW         LogError("null ptr");
694 // KW         return false;
695 // KW     }
696 // KW
697 // KW     int nNumLength = BN_num_bytes(pBigNum);
698 // KW     unsigned char* buffer = new unsigned char[nNumLength + 1];
699 // KW
700 // KW     // convert bignum to binary format
701 // KW     if (BN_bn2bin(pBigNum, buffer) < 0)
702 // KW     {
703 // KW         LogError("Conversion from bignum to binary failed");
704 // KW         delete []buffer;
705 // KW         return false;
706 // KW     }
707 // KW
708 // KW     char* pBase64Node = NULL;
709 // KW     unsigned long int buffLen = 0;
710 // KW     certmgr_util_base64_encode(buffer, (unsigned long int) nNumLength, &pBase64Node, &buffLen);
711 // KW
712 // KW     strNode.assign(pBase64Node, buffLen);
713 // KW
714 // KW     delete []buffer;
715 // KW     return true;
716 // KW }
717 } // namespace ValidationCore
718