Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 72 lines (58 sloc) 1.744 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/**
* Powerhose worker spawning the processus and receiving / sending back
* messages through zeromq.
**/
#include <iostream>

#include "tokencrypto.h"
#include "libhose.h"
#include "response.pb.h"

using namespace tokencrypto;
using namespace std;
using namespace powerhose;

/**
* Reads the master secret and put it in the registry
*
* @param Registry reg the registry to use
* @returns void
**/
void readMasterSecret(Registry reg)
{
    string master = (char*) readFile("master");

    pair <string, string> master_pair = pair <string, string>("master", master);
    reg.insert(master_pair);
}

/**
* Regarding the information contained in the registry, generates a salt and
* derivate the master secret with it.
*
* This function is meant to be used with the powerhose library, thus the
* signature.
*
* @param
**/
 
string deriveSecret(string job, Registry registry)
{

    // get the master secret value from the registry
    byte* master = (byte*) (registry.find("master")->second).c_str();

    // Generate the salt
    byte* salt = generateRandomSalt(DEFAULT_SALT_SIZE);

    // Derivate the key
    byte* okm = deriveKey(256, (byte*) master, 256, salt, 256);

    cout << "salt" << endl << salt << endl << endl;
    cout << "okm" << endl << okm << endl << endl;
    cout << "master" << endl << master << endl << endl;

    // return the OKM and the salt XXX check that sizeof is doing what's
    // intended
    Response resp;
    resp.set_salt(&salt, 256);
    resp.set_secret(&okm, 256);

    string string_resp;
    resp.SerializeToString(&string_resp);
    return string_resp;
}

int main(int argc, const char *argv[])
{
    map<string, string> reg;
    readMasterSecret(reg);
    cout << deriveSecret("", reg);
}
Something went wrong with that request. Please try again.