⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clicmgr.cpp

📁 研读AxCrypt对加解密的处理方法
💻 CPP
字号:
/*
    @(#) $Id$

    AxCrypt - Compressing and Encrypting Wrapper and Application Launcher for Secure Local,
    Server or Web Storage of Document Files.

    Copyright (C) 2004 Svante Seleborg/Axantum Software AB, All rights reserved.

    This program is free software; you can redistribute it and/or modify it under the terms
    of the GNU General Public License as published by the Free Software Foundation;
    either version 2 of the License, or (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License along with this program;
    if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA 02111-1307 USA

    The author may be reached at mailto:axcrypt@axondata.se and http://axcrypt.sourceforge.net
----
    CLicMgr.cpp                     Handle and validate licenses
*/
#include "stdafx.h"
#include "CLicMgr.h"
#include "hex.h"

#include "AxAssert.h"
#define AXLIB_ASSERT_FILE "CLicMgr.cpp"

/// \brief Set the public key to use
void
CLicMgr::SetVerifier(const string &sVerifierHex) {
    try {
        // Prime the StringSource with the Hex string, decode it and decode the result for the
        // public key.
        m_Verifier.AccessKey().BERDecode(StringSource(sVerifierHex, true, new HexDecoder));
    } catch (CryptoPP::Exception Err) {
        ASSCHK(false, Err.GetWhat().c_str());
    }
    return;
}

/// \brief Add a specified license type after checking the sig for the licensee
bool
CLicMgr::AddChkType(const string &sType, const string &sLicensee, const string &sSig) {
    // First check if any is empty - this is not valid.
    if (sLicensee.empty() || sSig.empty()) {
        return false;
    }
    m_sLastErrorMsg = "";
    try {
        // Decode the signature from the string base 34 representation
	    StringSource signatureSource(sSig, true, new Base34Decoder(ShortRbits + SBits));
        // Check that we can get just the right amount of bits from it
	    if (signatureSource.MaxRetrievable() != m_Verifier.SignatureLength()) {
            m_sLastErrorMsg =  "Internal error. Signature wrong length.";
        } else {
            // Allocate a block and put the signature there 
            SecByteBlock signature(m_Verifier.SignatureLength());
	        signatureSource.Get(signature, signature.size());

	        // Make us a filter, taking both a signature and a message as input
            VerifierFilter *verifierFilter = new VerifierFilter(m_Verifier);
            // First we put the signature to the filter
	        verifierFilter->Put(signature, m_Verifier.SignatureLength());
            // Then we send the message to it
	        StringSource messageSource(m_Verifier.CanonicalizeMessage(sType + sLicensee), true, verifierFilter);

	        // And now we check the result.
            if (verifierFilter->GetLastResult()) {
                // It was ok - add this to the map of valid licenses
                m_smspValidLic[sType] = stringpair(sLicensee, sSig);
                return true;
	        }
        }
    } catch (CryptoPP::Exception Err) {
        m_sLastErrorMsg = Err.GetWhat();
    }
    return false;
}

/// \brief Check if we have a valid license for a given type
bool
CLicMgr::ChkType(const string &sType) {
    // Just iterate through the list of currently valid licenses and return true
    // if we find an exact match.
    return m_smspValidLic.find(sType) != m_smspValidLic.end();
}

/// \brief Get a valid license, if any, for a given type
stringpair
CLicMgr::GetType(const string &sType) {
    map<string, stringpair>::const_iterator it = m_smspValidLic.find(sType);
    if (it != m_smspValidLic.end()) {
        return it->second;
    }
    return stringpair("", "");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -