Exemple #1
0
SSLTLSSettings::SSLTLSSettings(const std::string& host,
                               unsigned short port,
                               Credentials credentials):
    Settings(host,
             port,
             Credentials(credentials),
             Settings::SSLTLS)
{
}
 ShuffleRoundBlame::ShuffleRoundBlame(const Group &group, const Id &local_id,
     const Id &round_id, AsymmetricKey *outer_key) :
   ShuffleRound(group, Credentials(local_id, QSharedPointer<AsymmetricKey>(),
         QSharedPointer<DiffieHellman>()),
       round_id, Dissent::Connections::EmptyNetwork::GetInstance(),
       Dissent::Messaging::EmptyGetDataCallback::GetInstance())
 {
   if(outer_key) {
     Library *lib = CryptoFactory::GetInstance().GetLibrary();
     _outer_key.reset(lib->LoadPrivateKeyFromByteArray(outer_key->GetByteArray()));
   }
   _log.ToggleEnabled();
 }
Exemple #3
0
Settings Settings::loadFromXML(ofxXmlSettings xml,
                               const std::string& accountName)
{
    // if account name is an empty string, then the first unnamed account will be matched
    // expected an <accounts> tag as current root element with child <account> elements

    Settings settings;

    int numAccounts = xml.getNumTags("account:accounts");
    
    int accountIndex = -1;
    
    for (std::size_t i = 0; i < numAccounts; ++i)
    {
        std::string _accountName = xml.getAttribute("account", "name", "", i);

        if (_accountName == accountName)
        {
            accountIndex = i;
            break;
        }
    }
    
    if (accountIndex < 0)
    {
        ofLogWarning("Settings::loadFromXML") << "No account called " << accountName << " found in XML file.";
        return settings;
    }
    
    std::string accountType = xml.getAttribute("account",
                                               "type",
                                               "",
                                               accountIndex);
    
    if ("smtp" != accountType && "SMTP" != accountType)
    {
        ofLogWarning("Settings::loadFromXML") << "Account type \"" << accountType << "\" is invalid.";
        return settings;
    }
    
    std::string host = xml.getValue("account:host", "", accountIndex);
    
    if (host.empty())
    {
        ofLogWarning("Settings::loadFromXML") << "Empty host field.";
        return settings;
    }
    
    unsigned short port = xml.getValue("account:port", 25, accountIndex);
    
    int timeoutInt = xml.getValue("account:timeout", 30000, accountIndex);
    
    Poco::Timespan timeout(timeoutInt * Poco::Timespan::MILLISECONDS);
    
    int messageSendDelayInt = xml.getValue("account:timeout",
                                           100,
                                           accountIndex);
    
    Poco::Timespan messageSendDelay(messageSendDelayInt * Poco::Timespan::MILLISECONDS);
    
    std::string username = xml.getValue("account:authentication:username",
                                        "",
                                        accountIndex);

    std::string password = xml.getValue("account:authentication:password",
                                        "",
                                        accountIndex);

    std::string loginMethodString = xml.getValue("account:authentication:type",
                                                 "AUTH_NONE",
                                                 accountIndex);
    
    Credentials::LoginMethod loginMethod = Poco::Net::SMTPClientSession::AUTH_NONE;
    
    if ("AUTH_NONE" == loginMethodString)
    {
        loginMethod = Poco::Net::SMTPClientSession::AUTH_NONE;
    }
    else if ("AUTH_LOGIN" == loginMethodString)
    {
        loginMethod = Poco::Net::SMTPClientSession::AUTH_LOGIN;
    }
    else if ("AUTH_CRAM_MD5" == loginMethodString)
    {
        loginMethod = Poco::Net::SMTPClientSession::AUTH_CRAM_MD5;
    }
    else if ("AUTH_CRAM_SHA1" == loginMethodString)
    {
        loginMethod = Poco::Net::SMTPClientSession::AUTH_CRAM_SHA1;
    }
    else if ("AUTH_PLAIN" == loginMethodString)
    {
        loginMethod = Poco::Net::SMTPClientSession::AUTH_PLAIN;
    }
    else
    {
        ofLogWarning("Settings::loadFromXML") << "Unsupported authentication type: " << loginMethodString;
        return settings;
    }
    
    std::string encryptionTypeString = xml.getValue("account:encryption",
                                                    "NONE",
                                                    accountIndex);
    
    Settings::EncryptionType encryptionType;
    
    if ("NONE" == encryptionTypeString)
    {
        encryptionType = NONE;
    }
    else if ("SSLTLS" == encryptionTypeString)
    {
        encryptionType = SSLTLS;
    }
    else if ("STARTTLS" == encryptionTypeString)
    {
        encryptionType = STARTTLS;
    }
    else
    {
        ofLogWarning("Settings::loadFromXML") << "Unsupported encyption type: " << encryptionTypeString;
        return settings;
    }
    
    settings = Settings(host,
                        port,
                        Credentials(username,
                                    password,
                                    loginMethod),
                        encryptionType,
                        timeout,
                        messageSendDelay);
    
    return settings;
}