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.
18 #include <dpl/log/log.h>
20 #include <cert-service.h>
24 const char *storePath = "code-signing_wac";
26 int addCertToStore(const char* name){
27 int result = cert_svc_add_certificate_to_store(name, storePath);
29 if (CERT_SVC_ERR_NO_ERROR != result) {
30 LogError("Error adding certificate: " << name << " To: " << storePath);
35 //long int removeCertFromStore(const char* subjectName, const char* issuerName)
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];
46 // certmgr_cert_descriptor descriptor;
47 // certId.storeId = storeId;
48 // certId.type = type;
50 // CERTMGR_INIT_CONTEXT((&context), (sizeof(certmgr_ctx)))
51 // std::string storeName("Operator");
52 // strncpy(context.storeId, storeName.c_str(), storeName.size());
54 // certRetrieved.data = certBuff;
55 // certRetrieved.size = CERTMGR_MAX_BUFFER_SIZE * 2;
57 // certRetrieved.firstFree = 0;
59 // for(certRetrieved.firstFree = 0;
60 // OPERATION_SUCCESS ==
61 // (result = certmgr_retrieve_certificate_from_store( &context, &certRetrieved, &certId));
62 // certRetrieved.firstFree = 0)
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);
70 // if(strcmp(descriptor.mandatory.subject, subjectName) == 0 &&
71 // strcmp(descriptor.mandatory.issuer,issuerName) == 0 &&
72 // OPERATION_SUCCESS == certmgr_remove_certificate_from_store(&certId))
74 // LogDebug("***Certificate has been REMOVED***");
75 // return OPERATION_SUCCESS;
79 // if(ERR_NO_MORE_CERTIFICATES == result){
80 // LogDebug("***THIS CERT IS NOT IN STORE***");
81 // return OPERATION_SUCCESS;
87 int removeCertGivenByFilename(const char* name){
88 int result = cert_svc_delete_certificate_from_store(name, storePath);
90 if (CERT_SVC_ERR_NO_ERROR != result) {
91 LogError("Error removing certificate: " << name << " From: " << storePath);