1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-28 18:03:36 +00:00
codecrypt/src/keyring.cpp

109 lines
2.4 KiB
C++
Raw Normal View History

2012-09-30 09:55:23 +00:00
2012-11-05 21:45:35 +00:00
/*
* This file is part of Codecrypt.
*
* Codecrypt is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Codecrypt 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Codecrypt. If not, see <http://www.gnu.org/licenses/>.
*/
2013-01-04 11:43:36 +00:00
#include "keyring.h"
2012-11-06 08:46:18 +00:00
2013-04-01 15:49:58 +00:00
void keyring::clear()
2013-01-04 11:43:36 +00:00
{
2013-04-01 15:49:58 +00:00
for (std::map<std::string, pubkey_entry>::iterator
i = pubs.begin(), e = pubs.end(); i != e; ++i)
sencode_destroy (i->second.key);
pubs.clear();
for (std::map<std::string, keypair_entry>::iterator
i = pairs.begin(), e = pairs.end(); i != e; ++i) {
sencode_destroy (i->second.pub.key);
sencode_destroy (i->second.privkey);
}
pairs.clear();
2013-01-04 11:43:36 +00:00
}
2013-04-01 15:49:58 +00:00
/*
* KeyID is SHA256 of pubkey string representation. Also serves as a
* simple fingerprint.
*/
2013-01-04 11:43:36 +00:00
2013-04-01 15:49:58 +00:00
#include "sha2.h"
#include <stdint.h>
2013-01-04 11:43:36 +00:00
2013-04-01 15:49:58 +00:00
std::string keyring::get_keyid (const std::string&pubkey)
2013-01-04 11:43:36 +00:00
{
2013-04-01 15:49:58 +00:00
SHA256_CTX ctx;
uint8_t t;
2013-01-04 11:43:36 +00:00
2013-04-01 15:49:58 +00:00
SHA256_Init (&ctx);
2013-01-04 11:43:36 +00:00
2013-04-01 15:49:58 +00:00
for (size_t i = 0; i < pubkey.length(); ++i) {
t = pubkey[i];
SHA256_Update (&ctx, &t, 1);
}
2013-01-04 11:43:36 +00:00
2013-04-01 15:49:58 +00:00
std::string r;
r.resize (64, ' ');
SHA256_End (&ctx, & (r[0]) );
2013-01-04 11:43:36 +00:00
2013-04-01 15:49:58 +00:00
return r;
2013-01-04 11:43:36 +00:00
}
2012-09-30 09:55:23 +00:00
2013-01-21 16:00:20 +00:00
/*
* DISK KEYRING STORAGE
*
* Whole thing is stored in two files just like in GnuPG:
*
2013-04-01 15:49:58 +00:00
* ${CCR_DIR}/pubring
* ${CCR_DIR}/secrets
*
* CCR_DIR is taken from environment, and defaults to ${HOME}/.ccr
2013-01-21 16:00:20 +00:00
*
* format of the files is raw sencode.
*
* Public key file is organized as follows:
*
* (
* "ccr public key storage"
2013-04-01 15:49:58 +00:00
* ( "key-name" pubkey_as_embedded_sencode )
* ( "key-name" pubkey_as_embedded_sencode )
* ( "key-name" pubkey_as_embedded_sencode )
2013-01-21 16:00:20 +00:00
* ...
* )
*
* Private keys are stored together with their pubkeys, so that they don't have
* to be generated everytime user asks for them:
*
* (
* "ccr private keyring"
2013-04-01 15:49:58 +00:00
* ( "key-name" privkey pubkey )
* ( "key-name" privkey pubkey )
* ( "key-name" privkey pubkey )
2013-01-21 16:00:20 +00:00
* ...
* )
*
*/
2013-04-01 15:49:58 +00:00
bool keyring::load()
{
return false;
}
bool keyring::save()
2013-01-21 16:00:20 +00:00
{
2013-04-01 15:49:58 +00:00
2013-01-21 16:00:20 +00:00
return false;
}