mirror of
https://github.com/biergaizi/codecrypt
synced 2024-06-29 18:33:10 +00:00
109 lines
2.4 KiB
C++
109 lines
2.4 KiB
C++
|
|
/*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include "keyring.h"
|
|
|
|
void keyring::clear()
|
|
{
|
|
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();
|
|
}
|
|
|
|
/*
|
|
* KeyID is SHA256 of pubkey string representation. Also serves as a
|
|
* simple fingerprint.
|
|
*/
|
|
|
|
#include "sha2.h"
|
|
#include <stdint.h>
|
|
|
|
std::string keyring::get_keyid (const std::string&pubkey)
|
|
{
|
|
SHA256_CTX ctx;
|
|
uint8_t t;
|
|
|
|
SHA256_Init (&ctx);
|
|
|
|
for (size_t i = 0; i < pubkey.length(); ++i) {
|
|
t = pubkey[i];
|
|
SHA256_Update (&ctx, &t, 1);
|
|
}
|
|
|
|
std::string r;
|
|
r.resize (64, ' ');
|
|
SHA256_End (&ctx, & (r[0]) );
|
|
|
|
return r;
|
|
}
|
|
|
|
/*
|
|
* DISK KEYRING STORAGE
|
|
*
|
|
* Whole thing is stored in two files just like in GnuPG:
|
|
*
|
|
* ${CCR_DIR}/pubring
|
|
* ${CCR_DIR}/secrets
|
|
*
|
|
* CCR_DIR is taken from environment, and defaults to ${HOME}/.ccr
|
|
*
|
|
* format of the files is raw sencode.
|
|
*
|
|
* Public key file is organized as follows:
|
|
*
|
|
* (
|
|
* "ccr public key storage"
|
|
* ( "key-name" pubkey_as_embedded_sencode )
|
|
* ( "key-name" pubkey_as_embedded_sencode )
|
|
* ( "key-name" pubkey_as_embedded_sencode )
|
|
* ...
|
|
* )
|
|
*
|
|
* 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"
|
|
* ( "key-name" privkey pubkey )
|
|
* ( "key-name" privkey pubkey )
|
|
* ( "key-name" privkey pubkey )
|
|
* ...
|
|
* )
|
|
*
|
|
*/
|
|
|
|
bool keyring::load()
|
|
{
|
|
|
|
return false;
|
|
}
|
|
|
|
bool keyring::save()
|
|
{
|
|
|
|
return false;
|
|
}
|