tizen beta release
[framework/web/wrt-commons.git] / tests / vcore / TestEnv.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 <string>
17 #include <cstring>
18 #include <dpl/log/log.h>
19
20 #include <cert-service.h>
21
22 #include "TestEnv.h"
23
24 const char *storePath = "code-signing_wac";
25
26 int addCertToStore(const char* name){
27     int result = cert_svc_add_certificate_to_store(name, storePath);
28
29     if (CERT_SVC_ERR_NO_ERROR != result) {
30         LogError("Error adding certificate: " << name << " To: " << storePath);
31     }
32     return result;
33 }
34
35 //long int removeCertFromStore(const char* subjectName, const char* issuerName)
36 //{
37 //    long int result = OPERATION_SUCCESS;
38 //    /*  Retrieve all the certificates from store */
39 //    certmgr_cert_id certId;
40 //    certmgr_mem_buff certRetrieved;
41 //    certmgr_ctx context;
42 //    char storeId[CERTMGR_MAX_PLUGIN_ID_SIZE];
43 //    char type[CERTMGR_MAX_CERT_TYPE_SIZE];
44 //    unsigned char certBuff[CERTMGR_MAX_BUFFER_SIZE * 2];
45 //
46 //    certmgr_cert_descriptor descriptor;
47 //    certId.storeId = storeId;
48 //    certId.type = type;
49 //
50 //    CERTMGR_INIT_CONTEXT((&context), (sizeof(certmgr_ctx)))
51 //    std::string storeName("Operator");
52 //    strncpy(context.storeId, storeName.c_str(), storeName.size());
53 //
54 //    certRetrieved.data = certBuff;
55 //    certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE * 2;
56 //
57 //    certRetrieved.firstFree = 0;
58 //
59 //    for(certRetrieved.firstFree = 0;
60 //      OPERATION_SUCCESS ==
61 //      (result = certmgr_retrieve_certificate_from_store( &context, &certRetrieved, &certId));
62 //      certRetrieved.firstFree = 0)
63 //    {
64 //        if(OPERATION_SUCCESS ==
65 //          certmgr_extract_certificate_data(&certRetrieved, &descriptor)){
66 //            LogDebug("The subject of this certificate is " << descriptor.mandatory.subject);
67 //            LogDebug("The issuer of this certificate is " << descriptor.mandatory.issuer);
68 //        }
69 //
70 //        if(strcmp(descriptor.mandatory.subject, subjectName) == 0 &&
71 //          strcmp(descriptor.mandatory.issuer,issuerName) == 0    &&
72 //          OPERATION_SUCCESS == certmgr_remove_certificate_from_store(&certId))
73 //        {
74 //            LogDebug("***Certificate has been REMOVED***");
75 //            return OPERATION_SUCCESS;
76 //        }
77 //    }
78 //
79 //    if(ERR_NO_MORE_CERTIFICATES == result){
80 //        LogDebug("***THIS CERT IS NOT IN STORE***");
81 //        return OPERATION_SUCCESS;
82 //    }
83 //
84 //    return result;
85 //}
86
87 int removeCertGivenByFilename(const char* name){
88     int result = cert_svc_delete_certificate_from_store(name, storePath);
89
90     if (CERT_SVC_ERR_NO_ERROR != result) {
91         LogError("Error removing certificate: " << name << " From: " << storePath);
92     }
93
94     return result;
95 }
96