2 * Copyright (c) 2000 - 2014 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
17 * @file key-provider.cpp
18 * @author kyungwook tak (k.tak@samsung.com)
20 * @brief Provide Domain KEK and Application KEK for key-manager.
24 #include <openssl/rand.h>
25 #include <openssl/err.h>
26 #include <openssl/evp.h>
27 #include <openssl/sha.h>
29 #include <key-provider.h>
30 #include <dpl/log/log.h>
35 CKM::RawBuffer toRawBuffer(const T &data)
37 CKM::RawBuffer output;
38 const unsigned char *ptr = reinterpret_cast<const unsigned char*>(&data);
39 output.assign(ptr, ptr + sizeof(T));
43 // You cannot use toRawBuffer template with pointers
45 CKM::RawBuffer toRawBuffer(T *)
47 class NoPointerAllowed { NoPointerAllowed(){} };
49 return CKM::RawBuffer();
52 int cleanMemory(void *targetPtr, size_t targetSize)
54 char *ptr = reinterpret_cast<char *>(targetPtr);
57 for (size_t size = 0; size < targetSize; ++size)
61 for (size_t size = 0; size < targetSize; ++size) {
69 } // anonymous namespace
73 WrappedKeyAndInfoContainer::WrappedKeyAndInfoContainer()
75 wrappedKeyAndInfo = new WrappedKeyAndInfo;
76 memset(wrappedKeyAndInfo, 0, sizeof(WrappedKeyAndInfo));
79 WrappedKeyAndInfoContainer::WrappedKeyAndInfoContainer(const WrappedKeyAndInfoContainer &second)
81 wrappedKeyAndInfo = new WrappedKeyAndInfo;
82 memcpy(wrappedKeyAndInfo, second.wrappedKeyAndInfo, sizeof(WrappedKeyAndInfo));
85 WrappedKeyAndInfoContainer &WrappedKeyAndInfoContainer::operator=(const WrappedKeyAndInfoContainer &second)
90 if (wrappedKeyAndInfo)
91 delete wrappedKeyAndInfo;
93 wrappedKeyAndInfo = new WrappedKeyAndInfo;
94 memcpy(wrappedKeyAndInfo, second.wrappedKeyAndInfo, sizeof(WrappedKeyAndInfo));
98 WrappedKeyAndInfoContainer::WrappedKeyAndInfoContainer(const unsigned char *data)
100 wrappedKeyAndInfo = new WrappedKeyAndInfo;
101 memcpy(wrappedKeyAndInfo, data, sizeof(WrappedKeyAndInfo));
104 WrappedKeyAndInfo& WrappedKeyAndInfoContainer::getWrappedKeyAndInfo()
106 return *wrappedKeyAndInfo;
109 void WrappedKeyAndInfoContainer::setKeyInfoKeyLength(const unsigned int length){
110 wrappedKeyAndInfo->keyInfo.keyLength = length;
113 void WrappedKeyAndInfoContainer::setKeyInfoLabel(const std::string label)
115 int labelLength = label.length();
118 if(labelLength <= (MAX_LABEL_SIZE - 1)) {
119 copyLength = labelLength;
122 copyLength = (MAX_LABEL_SIZE - 1);
126 wrappedKeyAndInfo->keyInfo.label,
131 void WrappedKeyAndInfoContainer::setKeyInfoSalt(const unsigned char *salt, const int size)
133 memcpy(wrappedKeyAndInfo->keyInfo.salt, salt, size);
136 void WrappedKeyAndInfoContainer::setKeyInfo(const KeyComponentsInfo *keyComponentsInfo)
138 memcpy(&(wrappedKeyAndInfo->keyInfo), keyComponentsInfo, sizeof(KeyComponentsInfo));
141 WrappedKeyAndInfoContainer::~WrappedKeyAndInfoContainer()
143 delete wrappedKeyAndInfo;
146 KeyAndInfoContainer::KeyAndInfoContainer()
148 keyAndInfo = new KeyAndInfo;
149 memset(keyAndInfo, 0, sizeof(KeyAndInfo));
152 KeyAndInfoContainer::KeyAndInfoContainer(const KeyAndInfoContainer &second)
154 keyAndInfo = new KeyAndInfo;
155 memcpy(keyAndInfo, second.keyAndInfo, sizeof(KeyAndInfo));
158 KeyAndInfoContainer &KeyAndInfoContainer::operator=(const KeyAndInfoContainer &second)
164 if (cleanMemory(keyAndInfo, sizeof(KeyAndInfo))) {
166 ThrowMsg(Exception::Base,
167 "KeyAndInfo in KeyAndInfoContainer was not destroyed!");
172 keyAndInfo = new KeyAndInfo;
173 memcpy(keyAndInfo, second.keyAndInfo, sizeof(KeyAndInfo));
177 KeyAndInfoContainer::KeyAndInfoContainer(const unsigned char *data)
179 keyAndInfo = new KeyAndInfo;
180 memcpy(keyAndInfo, data, sizeof(KeyAndInfo));
183 KeyAndInfo& KeyAndInfoContainer::getKeyAndInfo()
188 void KeyAndInfoContainer::setKeyInfoKeyLength(unsigned int length)
190 keyAndInfo->keyInfo.keyLength = length;
193 void KeyAndInfoContainer::setKeyInfo(const KeyComponentsInfo *keyComponentsInfo)
195 memcpy(&(keyAndInfo->keyInfo), keyComponentsInfo, sizeof(KeyComponentsInfo));
198 KeyAndInfoContainer::~KeyAndInfoContainer()
200 if (cleanMemory(keyAndInfo, sizeof(KeyAndInfo))) {
201 // destroy verification failed.
203 ThrowMsg(Exception::Base,
204 "KeyAndInfo in KeyAndInfoContainer was not destroyed!");
210 KeyProvider::KeyProvider()
212 , m_isInitialized(false)
214 LogDebug("Created empty KeyProvider");
217 KeyProvider::KeyProvider(
218 const RawBuffer &domainKEKInWrapForm,
219 const Password &password)
220 : m_kmcDKEK(new KeyAndInfoContainer())
221 , m_isInitialized(true)
223 if (domainKEKInWrapForm.size() != sizeof(WrappedKeyAndInfo)) {
224 ThrowMsg(Exception::InputParamError,
225 "domainKEKInWrapForm "
226 "input size:" << domainKEKInWrapForm.size() <<
227 " Expected:" << sizeof(WrappedKeyAndInfo));
230 WrappedKeyAndInfoContainer wkmcDKEK(domainKEKInWrapForm.data());
232 char *concat_user_pass = NULL;
233 uint8_t PKEK1[MAX_KEY_SIZE];
235 concat_user_pass = concat_password_user(
236 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.label,
237 getConvertedStr(password));
239 if (!PKCS5_PBKDF2_HMAC_SHA1(
241 strlen(concat_user_pass),
242 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.salt,
248 delete[] concat_user_pass;
249 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
252 delete[] concat_user_pass;
256 if (0 > (keyLength = decryptAes256Gcm(
257 wkmcDKEK.getWrappedKeyAndInfo().wrappedKey,
258 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.keyLength,
259 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.tag,
261 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.iv,
262 m_kmcDKEK->getKeyAndInfo().key))) {
264 ThrowMsg(Exception::PassWordError,
265 "VerifyDomainKEK failed in KeyProvider Constructor");
268 m_kmcDKEK->setKeyInfo(&(wkmcDKEK.getWrappedKeyAndInfo().keyInfo));
269 m_kmcDKEK->setKeyInfoKeyLength((unsigned int)keyLength);
272 KeyProvider& KeyProvider::operator=(KeyProvider &&second)
274 LogDebug("Moving KeyProvider");
277 m_isInitialized = second.m_isInitialized;
278 m_kmcDKEK = second.m_kmcDKEK;
279 second.m_isInitialized = false;
280 second.m_kmcDKEK = NULL;
284 KeyProvider::KeyProvider(KeyProvider &&second)
286 LogDebug("Moving KeyProvider");
287 m_isInitialized = second.m_isInitialized;
288 m_kmcDKEK = second.m_kmcDKEK;
289 second.m_isInitialized = false;
290 second.m_kmcDKEK = NULL;
293 bool KeyProvider::isInitialized()
295 return m_isInitialized;
298 RawBuffer KeyProvider::getPureDomainKEK()
300 if (!m_isInitialized) {
301 ThrowMsg(Exception::InitFailed, "Object not initialized!");
304 return RawBuffer(m_kmcDKEK->getKeyAndInfo().key,
305 (m_kmcDKEK->getKeyAndInfo().key)
306 + m_kmcDKEK->getKeyAndInfo().keyInfo.keyLength);
309 RawBuffer KeyProvider::getWrappedDomainKEK(const Password &password)
311 if (!m_isInitialized) {
312 ThrowMsg(Exception::InitFailed, "Object not initialized!");
315 WrappedKeyAndInfoContainer wkmcDKEK;
317 char *concat_user_pass = NULL;
318 uint8_t PKEK1[MAX_KEY_SIZE];
320 concat_user_pass = concat_password_user(
321 m_kmcDKEK->getKeyAndInfo().keyInfo.label,
322 getConvertedStr(password));
324 if (!PKCS5_PBKDF2_HMAC_SHA1(
326 strlen(concat_user_pass),
327 m_kmcDKEK->getKeyAndInfo().keyInfo.salt,
333 delete[] concat_user_pass;
334 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
337 delete[] concat_user_pass;
339 wkmcDKEK.setKeyInfo(&(m_kmcDKEK->getKeyAndInfo().keyInfo));
341 int wrappedKeyLength;
343 if (0 > (wrappedKeyLength = encryptAes256Gcm(
344 m_kmcDKEK->getKeyAndInfo().key,
345 m_kmcDKEK->getKeyAndInfo().keyInfo.keyLength,
347 m_kmcDKEK->getKeyAndInfo().keyInfo.iv,
348 wkmcDKEK.getWrappedKeyAndInfo().wrappedKey,
349 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.tag))) {
351 ThrowMsg(Exception::InitFailed, "WrapDKEK Failed in KeyProvider::getDomainKEK");
354 wkmcDKEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
356 LogDebug("getDomainKEK(password) Success");
357 return toRawBuffer(wkmcDKEK.getWrappedKeyAndInfo());
361 RawBuffer KeyProvider::getPureDEK(const RawBuffer &DEKInWrapForm)
363 if (!m_isInitialized) {
364 ThrowMsg(Exception::InitFailed, "Object not initialized!");
367 if (DEKInWrapForm.size() != sizeof(WrappedKeyAndInfo)){
368 ThrowMsg(Exception::InputParamError,
370 "input size:" << DEKInWrapForm.size() <<
371 " Expected:" << sizeof(WrappedKeyAndInfo));
374 KeyAndInfoContainer kmcDEK;
375 WrappedKeyAndInfoContainer wkmcDEK(DEKInWrapForm.data());
377 uint8_t PKEK2[MAX_KEY_SIZE];
380 if (!PKCS5_PBKDF2_HMAC_SHA1(
381 wkmcDEK.getWrappedKeyAndInfo().keyInfo.label,
382 strlen(wkmcDEK.getWrappedKeyAndInfo().keyInfo.label),
383 m_kmcDKEK->getKeyAndInfo().key,
389 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
392 if (0 > (keyLength = decryptAes256Gcm(
393 wkmcDEK.getWrappedKeyAndInfo().wrappedKey,
394 wkmcDEK.getWrappedKeyAndInfo().keyInfo.keyLength,
395 wkmcDEK.getWrappedKeyAndInfo().keyInfo.tag,
397 wkmcDEK.getWrappedKeyAndInfo().keyInfo.iv,
398 kmcDEK.getKeyAndInfo().key))) {
400 ThrowMsg(Exception::UnwrapFailed,
401 "UnwrapDEK Failed in KeyProvider::getPureDEK");
404 kmcDEK.setKeyInfoKeyLength((unsigned int)keyLength);
406 LogDebug("getPureDEK SUCCESS");
408 kmcDEK.getKeyAndInfo().key,
409 (kmcDEK.getKeyAndInfo().key)
410 + kmcDEK.getKeyAndInfo().keyInfo.keyLength);
413 RawBuffer KeyProvider::generateDEK(const std::string &smackLabel)
415 if (!m_isInitialized) {
416 ThrowMsg(Exception::InitFailed,
417 "Object not initialized!");
420 WrappedKeyAndInfoContainer wkmcDEK;
421 std::string resized_smackLabel;
423 if (smackLabel.length() < APP_LABEL_SIZE)
424 resized_smackLabel = smackLabel;
426 resized_smackLabel = smackLabel.substr(0, APP_LABEL_SIZE-1);
428 uint8_t key[MAX_KEY_SIZE], PKEK2[MAX_KEY_SIZE];
430 if (!RAND_bytes(key, m_kmcDKEK->getKeyAndInfo().keyInfo.keyLength) ||
431 !RAND_bytes(wkmcDEK.getWrappedKeyAndInfo().keyInfo.iv, MAX_IV_SIZE)) {
433 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
436 if (!PKCS5_PBKDF2_HMAC_SHA1(
437 resized_smackLabel.c_str(),
438 strlen(resized_smackLabel.c_str()),
439 m_kmcDKEK->getKeyAndInfo().key,
445 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
448 int wrappedKeyLength;
450 if (0 > (wrappedKeyLength = encryptAes256Gcm(
452 m_kmcDKEK->getKeyAndInfo().keyInfo.keyLength,
454 wkmcDEK.getWrappedKeyAndInfo().keyInfo.iv,
455 wkmcDEK.getWrappedKeyAndInfo().wrappedKey,
456 wkmcDEK.getWrappedKeyAndInfo().keyInfo.tag))) {
458 ThrowMsg(Exception::GenFailed,
459 "GenerateDEK Failed in KeyProvider::generateDEK");
462 wkmcDEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
463 wkmcDEK.setKeyInfoSalt(m_kmcDKEK->getKeyAndInfo().key, MAX_SALT_SIZE);
464 wkmcDEK.setKeyInfoLabel(resized_smackLabel);
466 LogDebug("GenerateDEK Success");
467 return toRawBuffer(wkmcDEK.getWrappedKeyAndInfo());
470 RawBuffer KeyProvider::reencrypt(
471 const RawBuffer &domainKEKInWrapForm,
472 const Password &oldPass,
473 const Password &newPass)
475 if (domainKEKInWrapForm.size() != sizeof(WrappedKeyAndInfo)) {
476 ThrowMsg(Exception::InputParamError,
477 "domainKEKInWrapForm "
478 "input size:" << domainKEKInWrapForm.size() <<
479 " Expected:" << sizeof(WrappedKeyAndInfo));
482 WrappedKeyAndInfoContainer wkmcOldDKEK(domainKEKInWrapForm.data());
483 WrappedKeyAndInfoContainer wkmcNewDKEK;
484 KeyAndInfoContainer kmcDKEK;
486 char *concat_user_pass = NULL;
487 uint8_t PKEK1[MAX_KEY_SIZE];
491 concat_user_pass = concat_password_user(
492 wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo.label,
493 getConvertedStr(oldPass));
495 if (!PKCS5_PBKDF2_HMAC_SHA1(
497 strlen(concat_user_pass),
498 wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo.salt,
504 delete[] concat_user_pass;
505 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
507 delete[] concat_user_pass;
509 if (0 > (keyLength = decryptAes256Gcm(
510 wkmcOldDKEK.getWrappedKeyAndInfo().wrappedKey,
511 wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo.keyLength,
512 wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo.tag,
514 wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo.iv,
515 kmcDKEK.getKeyAndInfo().key))) {
517 ThrowMsg(Exception::PassWordError,
518 "Incorrect Old Password ");
521 kmcDKEK.setKeyInfo(&(wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo));
522 kmcDKEK.setKeyInfoKeyLength((unsigned int)keyLength);
524 concat_user_pass = concat_password_user(
525 kmcDKEK.getKeyAndInfo().keyInfo.label,
526 getConvertedStr(newPass));
528 if (!PKCS5_PBKDF2_HMAC_SHA1(
530 strlen(concat_user_pass),
531 kmcDKEK.getKeyAndInfo().keyInfo.salt,
537 delete[] concat_user_pass;
538 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
541 delete[] concat_user_pass;
543 int wrappedKeyLength = 0;
544 wkmcNewDKEK.setKeyInfo(&(kmcDKEK.getKeyAndInfo().keyInfo));
546 if (0 > (wrappedKeyLength = encryptAes256Gcm(
547 kmcDKEK.getKeyAndInfo().key,
548 kmcDKEK.getKeyAndInfo().keyInfo.keyLength,
550 kmcDKEK.getKeyAndInfo().keyInfo.iv,
551 wkmcNewDKEK.getWrappedKeyAndInfo().wrappedKey,
552 wkmcNewDKEK.getWrappedKeyAndInfo().keyInfo.tag))) {
554 ThrowMsg(Exception::UnwrapFailed,
555 "UpdateDomainKEK in KeyProvider::reencrypt Failed");
558 wkmcNewDKEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
560 LogDebug("reencrypt SUCCESS");
561 return toRawBuffer(wkmcNewDKEK.getWrappedKeyAndInfo());
565 RawBuffer KeyProvider::generateDomainKEK(
566 const std::string &user,
567 const Password &userPassword)
569 WrappedKeyAndInfoContainer wkmcDKEK;
570 uint8_t key[MAX_KEY_SIZE], PKEK1[MAX_KEY_SIZE];
572 if (!RAND_bytes(wkmcDKEK.getWrappedKeyAndInfo().keyInfo.salt, MAX_SALT_SIZE) ||
573 !RAND_bytes(key, MAX_KEY_SIZE) ||
574 !RAND_bytes(wkmcDKEK.getWrappedKeyAndInfo().keyInfo.iv, MAX_IV_SIZE))
575 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
577 int wrappedKeyLength;
578 char *concat_user_pass = NULL;
579 concat_user_pass = concat_password_user(user.c_str(), getConvertedStr(userPassword));
580 if (!PKCS5_PBKDF2_HMAC_SHA1(
582 strlen(concat_user_pass),
583 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.salt,
589 delete[] concat_user_pass;
590 ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINED_ERROR");
593 delete[] concat_user_pass;
595 if (0 > (wrappedKeyLength = encryptAes256Gcm(
599 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.iv,
600 wkmcDKEK.getWrappedKeyAndInfo().wrappedKey,
601 wkmcDKEK.getWrappedKeyAndInfo().keyInfo.tag))) {
603 ThrowMsg(Exception::GenFailed,
604 "GenerateDomainKEK Failed in KeyProvider::generateDomainKEK");
607 wkmcDKEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
608 wkmcDKEK.setKeyInfoLabel(user);
610 LogDebug("generateDomainKEK Success");
611 return toRawBuffer(wkmcDKEK.getWrappedKeyAndInfo());
614 int KeyProvider::initializeLibrary()
616 LogDebug("initializeLibrary Success");
620 int KeyProvider::closeLibrary()
622 LogDebug("closeLibrary Success");
626 KeyProvider::~KeyProvider()
628 LogDebug("KeyProvider Destructor");
631 int KeyProvider::encryptAes256Gcm(const unsigned char *plaintext,
633 const unsigned char *key,
634 const unsigned char *iv,
635 unsigned char *ciphertext,
641 int ciphertext_len = 0;
643 if (!(ctx = EVP_CIPHER_CTX_new())) {
644 return OPENSSL_ENGINE_ERROR;
647 if (!EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL)) {
648 return OPENSSL_ENGINE_ERROR;
651 if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) {
652 return OPENSSL_ENGINE_ERROR;
655 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, MAX_IV_SIZE, NULL)) {
656 return OPENSSL_ENGINE_ERROR;
659 if (!EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len)) {
660 return OPENSSL_ENGINE_ERROR;
662 ciphertext_len = len;
664 if (!EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)) {
665 return OPENSSL_ENGINE_ERROR;
667 ciphertext_len += len;
669 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, MAX_IV_SIZE, tag)) {
670 return OPENSSL_ENGINE_ERROR;
673 EVP_CIPHER_CTX_free(ctx);
675 return ciphertext_len;
678 int KeyProvider::decryptAes256Gcm(const unsigned char *ciphertext,
681 const unsigned char *key,
682 const unsigned char *iv,
683 unsigned char *plaintext)
691 if (!(ctx = EVP_CIPHER_CTX_new())) {
692 return OPENSSL_ENGINE_ERROR;
695 if (!EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL)) {
696 return OPENSSL_ENGINE_ERROR;
698 if (!EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv)) {
699 return OPENSSL_ENGINE_ERROR;
702 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, MAX_IV_SIZE, NULL)) {
703 return OPENSSL_ENGINE_ERROR;
706 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, MAX_IV_SIZE, tag)) {
707 return OPENSSL_ENGINE_ERROR;
710 if (!EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) {
711 return OPENSSL_ENGINE_ERROR;
715 if (!(ret = EVP_DecryptFinal_ex(ctx, plaintext + len, &len))) {
716 return OPENSSL_ENGINE_ERROR;
719 EVP_CIPHER_CTX_free(ctx);
722 plaintext_len += len;
723 return plaintext_len;
730 char * KeyProvider::concat_password_user(const char *user, const char *password)
732 char *concat_user_pass = NULL;
733 char *resized_user = NULL;
734 int concat_user_pass_len = 0;
736 if (strlen(user) > MAX_LABEL_SIZE-1) {
737 resized_user = new char[MAX_LABEL_SIZE];
738 memcpy(resized_user, user, MAX_LABEL_SIZE-1);
739 resized_user[MAX_LABEL_SIZE-1] = '\0';
742 resized_user = new char[strlen(user)+1];
743 memcpy(resized_user, user, strlen(user));
744 resized_user[strlen(user)] = '\0';
746 concat_user_pass_len = strlen(resized_user) + strlen(password) + 1;
747 concat_user_pass = new char[concat_user_pass_len];
749 memset(concat_user_pass, '\0', concat_user_pass_len);
750 memcpy(concat_user_pass, password, strlen(password));
751 memcpy(&(concat_user_pass[strlen(password)]), resized_user, strlen(resized_user));
752 concat_user_pass[strlen(resized_user) + strlen(password)] = '\0';
754 delete[] resized_user;
755 return concat_user_pass;
758 const char* KeyProvider::getConvertedStr(const Password &password)
760 return password.c_str();