Botan  1.11.15
src/lib/misc/srp6/srp6_files.cpp
Go to the documentation of this file.
00001 /*
00002 * SRP-6a File Handling
00003 * (C) 2011 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #include <botan/srp6_files.h>
00009 #include <botan/parsing.h>
00010 #include <botan/base64.h>
00011 #include <fstream>
00012 
00013 namespace Botan {
00014 
00015 SRP6_Authenticator_File::SRP6_Authenticator_File(const std::string& filename)
00016    {
00017    std::ifstream in(filename.c_str());
00018 
00019    if(!in)
00020       return; // no entries
00021 
00022    while(in.good())
00023       {
00024       std::string line;
00025       std::getline(in, line);
00026 
00027       std::vector<std::string> parts = split_on(line, ':');
00028 
00029       if(parts.size() != 4)
00030          throw Decoding_Error("Invalid line in SRP authenticator file");
00031 
00032       std::string username = parts[0];
00033       BigInt v = BigInt::decode(base64_decode(parts[1]));
00034       std::vector<byte> salt = unlock(base64_decode(parts[2]));
00035       BigInt group_id_idx = BigInt::decode(base64_decode(parts[3]));
00036 
00037       std::string group_id;
00038 
00039       if(group_id_idx == 1)
00040          group_id = "modp/srp/1024";
00041       else if(group_id_idx == 2)
00042          group_id = "modp/srp/1536";
00043       else if(group_id_idx == 3)
00044          group_id = "modp/srp/2048";
00045       else
00046          continue; // unknown group, ignored
00047 
00048       entries[username] = SRP6_Data(v, salt, group_id);
00049       }
00050    }
00051 
00052 bool SRP6_Authenticator_File::lookup_user(const std::string& username,
00053                                           BigInt& v,
00054                                           std::vector<byte>& salt,
00055                                           std::string& group_id) const
00056    {
00057    std::map<std::string, SRP6_Data>::const_iterator i = entries.find(username);
00058 
00059    if(i == entries.end())
00060       return false;
00061 
00062    v = i->second.v;
00063    salt = i->second.salt;
00064    group_id = i->second.group_id;
00065 
00066    return true;
00067    }
00068 
00069 }