Example #1
0
static int load_rsakey(CcnetSession *session)
{
    char *path;
    FILE *fp;
    RSA *key;

    path = g_build_filename(session->config_dir, PEER_KEYFILE, NULL);
    if (!g_file_test(path, G_FILE_TEST_EXISTS))
        ccnet_error ("Can't load rsa private key from %s\n", path);
    if ((fp = g_fopen(path, "rb")) == NULL)
        ccnet_error ("Can't open private key file %s: %s\n", path,
                     strerror(errno));
    if ((key = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL)) == NULL)
        ccnet_error ("Can't open load key file %s: format error\n", path);
    fclose(fp);

    session->privkey = key;
    session->pubkey = private_key_to_pub(key);
    g_free(path);

    return 0; 
}
Example #2
0
static void
create_peerkey ()
{
    peer_privkey = generate_private_key (bits);
    peer_pubkey = private_key_to_pub (peer_privkey);
}