/* Copyright (C) 2003 Frédéric Giudicelli (contact_nos@yahoo.com). All rights reserved. This product includes cryptographic software written by Eric Young (eay@cryptsoft.com) This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Entity_BACKUP.cpp: implementation of the Entity_BACKUP class. // ////////////////////////////////////////////////////////////////////// #include "Entity_BACKUP.h" #include "svintl.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// Entity_BACKUP::Entity_BACKUP(ENTITY_CONSTRUCTOR_PARAMETERS): Entity(ENTITY_CONSTRUCTOR_PARAM_PASSTHRU, &myConf, &BackStore), BackStore(EntityName, e) { } Entity_BACKUP::~Entity_BACKUP() { m_Jobs.StopAll(); } bool Entity_BACKUP::Create(const EntityCreationDatas & Params, AdminResponseBody & response) { if(!Params) { NEWPKIerr(PKI_ERROR_TXT, ERROR_BAD_PARAM); return false; } if(Params.get_type() != ENTITY_TYPE_BACKUP) { NEWPKIerr(PKI_ERROR_TXT, ERROR_BAD_PARAM); return false; } if(!Params.get_entityKey()) { NEWPKIerr(PKI_ERROR_TXT, ERROR_BAD_PARAM); return false; } //We create the database if(!Common_Create(Params.get_entityKey(), NULL)) { NEWPKIerr(PKI_ERROR_TXT, ERROR_ABORT); return false; } if(!response.get_creEntity().set_type(ENTITY_TYPE_BACKUP)) { NEWPKIerr(PKI_ERROR_TXT, ERROR_ABORT); Destroy(); return false; } if(!response.get_creEntity().set_entityPubKey(m_EntityKey.GetPublicKey())) { NEWPKIerr(PKI_ERROR_TXT, ERROR_MALLOC); Destroy(); return false; } return true; } bool Entity_BACKUP::Load() { if(!Common_Load()) { NEWPKIerr(PKI_ERROR_TXT, ERROR_ABORT); return false; } if(!IsFullyInit()) { return true; } //Start the conf synch if(!m_Jobs.StartConfSync()) { NEWPKIerr(PKI_ERROR_TXT, ERROR_ABORT); return false; } return true; } bool Entity_BACKUP::Init(const EntitySignatureResp & init_datas) { if(IsFullyInit()) { NEWPKIerr(PKI_ERROR_TXT, ERROR_NOT_ALLOWED); return false; } if(!init_datas) { NEWPKIerr(PKI_ERROR_TXT, ERROR_BAD_PARAM); return false; } if(init_datas.get_body().get_type() != ENTITY_TYPE_BACKUP) { NEWPKIerr(PKI_ERROR_TXT, ERROR_BAD_PARAM); return false; } if(!Common_Init(init_datas.get_body().get_entitycert(), init_datas)) { NEWPKIerr(PKI_ERROR_TXT, ERROR_ABORT); return false; } return true; } bool Entity_BACKUP::LoginUser(UserHandle & hUser, int & UserType) { if(!AclValidator.CanUserPerform(hUser.GetUserCert(), ACL_TYPE_AUTHENTICATE_ON_ENTITY)) { NEWPKIerr(PKI_ERROR_TXT, ERROR_NOT_ALLOWED); return false; } UserType = USER_TYPE_KEYSTORE; return true; } void Entity_BACKUP::LogoutUser(const UserHandle & hUser) { } bool Entity_BACKUP::ParseNewConf() { return true; } bool Entity_BACKUP::Upgrade(const char * Version) { return true; } void Entity_BACKUP::GetACL_List(mVector & acl_list) { int i; static ACL_TYPE list_acls[] = { ACL_TYPE_VIEW_LOGS, (ACL_TYPE)0 }; for(i=0; list_acls[i]; i++) { acl_list.push_back(list_acls[i]); } } bool Entity_BACKUP::ParseAdminCommand(AdminResponseBody & response, const PKI_CERT & ClientCert, const AdminRequest & AdminRequest) { //We only accept SSLv3 connection if(!ClientCert) { NEWPKIerr(PKI_ERROR_TXT, ERROR_NOT_ALLOWED); ERR_to_ADMIN_RESPONSE(response); return false; } return Private_ParseAdminCommand(true, this, LogsType, response, ClientCert, AdminRequest, GetUserHandle()); } bool Entity_BACKUP::Private_ParseAdminCommand(bool ExecuteCmd, Entity * me_this, mVector & mLogsType, AdminResponseBody & response, const PKI_CERT & ClientCert, const AdminRequest & AdminRequest, UserHandle & hUser) { PARSER_COMMAND_BEGIN(Entity_BACKUP, response, 0, AdminRequest, ClientCert, hUser, ExecuteCmd, me_this, mLogsType) PARSER_ADD_LOG_ENTRY(LOG_MESSAGE_TYPE_ENTITY_GET_MY_CONF) PARSER_ADD_LOG_ENTRY(LOG_MESSAGE_TYPE_SEND_ADMIN_MAIL) PARSER_ADD_LOG_ENTRY(LOG_MESSAGE_TYPE_SEND_MAIL) PARSER_COMMAND_ENTRY_LOG( ADMIN_REQ_TYPE_LOGIN, Entity_BACKUP::UserLogin, LOG_MESSAGE_TYPE_USER_LOGIN, (ClientCert)?(char*)ClientCert.GetStringName():NULL, LOG_NO_OBJECTID) PARSER_COMMAND_ENTRY( ADMIN_REQ_TYPE_ENUM_LOGS, Entity_BACKUP::EnumLogs) PARSER_COMMAND_ENTRY( ADMIN_REQ_TYPE_GET_LOGS_COUNT, Entity_BACKUP::GetLogsCount) PARSER_COMMAND_ENTRY( ADMIN_REQ_TYPE_GET_MY_ACL, Entity_BACKUP::GetMyACL) PARSER_COMMAND_ENTRY( ADMIN_REQ_TYPE_GET_LOGS_TYPE, Entity_BACKUP::GetLogsType) PARSER_COMMAND_ENTRY_LOG( ADMIN_REQ_TYPE_SEND_ADMIN_MAIL, Entity_BACKUP::AdminSendMail, LOG_MESSAGE_TYPE_ADD_ADMIN_MAIL_QUEUE, _sv("none"), LOG_NO_OBJECTID) PARSER_COMMAND_ENTRY( ADMIN_REQ_TYPE_CHECK_LOGS, Entity_BACKUP::CheckLogsIntegrity) PARSER_COMMAND_END(Entity_BACKUP) } void Entity_BACKUP::LogsTypeGet(mVector & cLogsType) { Private_ParseAdminCommand(false, NULL, cLogsType, AdminResponseBody::EmptyInstance, PKI_CERT::EmptyInstance, AdminRequest::EmptyInstance, UserHandle::EmptyInstance); } bool Entity_BACKUP::Responder_TreatRequest(const NewpkiRequest & Request, const mString & SenderName, NewpkiResponse & Response) { return true; } bool Entity_BACKUP::Responder_ValidateRequest(const NewpkiRequest & Request, const X509_PUBKEY * Requester, mString & SenderName) { return true; } bool Entity_BACKUP::Requester_OnNewResponse(const Asn1OctetString & transactionID, const X509_PUBKEY * sender, const NewpkiResponse & Response) { return true; } bool Entity_BACKUP::PrepareConfToWrite() { return true; }