示例#1
0
/**
 * @return Extracts RSA exponent from X.509 certificate and returns it.
 * @throws IOException throws exception if the RSA exponent extraction failed.
 */
std::vector<unsigned char> digidoc::X509Cert::getRsaExponent() const throw(IOException)
{
    EVP_PKEY* pubKey = getPublicKey();

    // Get size of the RSA exponent.
    int bufSize = BN_num_bytes(pubKey->pkey.rsa->e);

    if(bufSize <= 0)
    {
        EVP_PKEY_free(pubKey);
        THROW_IOEXCEPTION("Failed to extract RSA exponent.");
    }

    // Allocate memory for the RSA exponent.
    std::vector<unsigned char> rsaExponent(bufSize, 0);

    // Extract RSA exponent.
    if(BN_bn2bin(pubKey->pkey.rsa->e, &rsaExponent[0]) <= 0)
    {
        EVP_PKEY_free(pubKey);
        THROW_IOEXCEPTION("Failed to extract RSA exponent.");
    }

    EVP_PKEY_free(pubKey);
    return rsaExponent;
}
示例#2
0
std::string GPGWrapper::encrypt(const std::string & recipientName, const std::string& message)
{
    init();

    ScopedGPGData clear_text, sign_text, encrypted_text;

    gpgme_error_t error = clear_text.init(message.c_str(), message.length());
    fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do zaszyfrowana (clear_text).");
    error = sign_text.init();
    fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do zaszyfrowana (sign_text).");

    error = gpgme_op_sign(context, clear_text.get(), sign_text.get(), GPGME_SIG_MODE_NORMAL);
    fail_if_err(error, L"Nie uda³o siê podpisaæ wiadomoœci.");

    error = gpgme_data_rewind(sign_text.get());
    fail_if_err(error, L"Nie uda³o siê przewin¹æ na pocz¹tek podpisanego strumienia, aby go póŸniej zaszyfrowaæ.");

    error = encrypted_text.init();
    fail_if_err(error, L"Nie uda³o siê zainicjowaæ danych do zaszyfrowana (encrypted_text).");

    gpgme_key_t recipient = getPublicKey(recipientName.c_str());

    gpgme_key_t recipients[2] = { NULL, NULL };
    recipients[0] = recipient;
    error = gpgme_op_encrypt(context, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, sign_text.get(), encrypted_text.get());
    fail_if_err(error, L"Nie uda³o siê zaszyfrowaæ podpisanej wiadomoœci.");

    gpgme_encrypt_result_t result = gpgme_op_encrypt_result(context);
    fail_if_err(result->invalid_recipients, L"Nie poprawny klucz szyfrowania odbiorcy.");

    return copyData(encrypted_text.get());
}
示例#3
0
std::string bdoc::X509Cert::getRsaExponent() const
{
	EVP_PKEY* pubKey = getPublicKey();
	if (EVP_PKEY_type(pubKey->type) != EVP_PKEY_RSA) {
		EVP_PKEY_free(pubKey);
		THROW_STACK_EXCEPTION("Public key is not a RSA key.");
	}

	int bufSize = BN_num_bytes(pubKey->pkey.rsa->e);

	if (bufSize <= 0) {
		EVP_PKEY_free(pubKey);
		THROW_STACK_EXCEPTION("Failed to extract RSA exponent.");
	}

	std::string exp(bufSize, '\0');

	if (BN_bn2bin(pubKey->pkey.rsa->e, (unsigned char *)&exp[0]) <= 0) {
		EVP_PKEY_free(pubKey);
		THROW_STACK_EXCEPTION("Failed to extract RSA exponent.");
	}

	EVP_PKEY_free(pubKey);
	return exp;
}
示例#4
0
std::string bdoc::X509Cert::getRsaModulus() const
{
	EVP_PKEY* pubKey = getPublicKey();
	if (EVP_PKEY_type(pubKey->type) != EVP_PKEY_RSA) {
		EVP_PKEY_free(pubKey);
		THROW_STACK_EXCEPTION("Public key is not a RSA key.");
	}


	int bufSize = BN_num_bytes(pubKey->pkey.rsa->n);

	if (bufSize <= 0) {
		EVP_PKEY_free(pubKey);
		THROW_STACK_EXCEPTION("Failed to extract RSA modulus.");
	}

	std::string modulus(bufSize, '\0');

	if (BN_bn2bin(pubKey->pkey.rsa->n, (unsigned char*)&modulus[0]) <= 0) {
		EVP_PKEY_free(pubKey);
		THROW_STACK_EXCEPTION("Failed to extract RSA modulus.");
	}

	EVP_PKEY_free(pubKey);
	return modulus;
}
示例#5
0
int do_check_signature(JNIEnv* env, jobject thiz){
    int equal = -1;
    jobject signature = getSignature(env, thiz);
    if(signature == NULL){
        return equal;
    }
    //PublicKey key 
    jobject publicKey = getPublicKey(env, signature);
    if(publicKey == NULL){
        return equal;
    }

    //BigInteger modulus = ((RSAPublicKey)key).getModulus().hashCode();
    jobject modulus = JNU_CallMethodByName(env, publicKey, "getModulus", "()Ljava/math/BigInteger;").l;
    //String strModulus = modulus.toString(10)
    jstring strKey = (jstring)JNU_CallMethodByName(env, modulus, "toString", "(I)Ljava/lang/String;", 10).l;

#ifndef TEST_HASH_CODE
    const char *nativeKeyString = (*env)->GetStringUTFChars(env, strKey, 0);
    LOGI("this app publicKey of signature is %s", nativeKeyString);
    equal = 0 == strncmp(nativeKeyString, global_app_signature_public_key, 1000);
    (*env)->ReleaseStringUTFChars(env, strKey, nativeKeyString);
#else
    int hash_code = (int)JNU_CallMethodByName(env, modulus, "hashCode", "()I").i;
    LOGI("this app hash_code of signature is %d", hash_code);
    equal = hash_code == global_app_signature_hash_code;
#endif
    
    //合法返回1
    return equal == 1;
}
示例#6
0
BOOST_FIXTURE_TEST_CASE(SaveLoadKeyPairTest, KeyUtilsFixture)
{
    saveKeyPairToFiles();
    auto loadedKeyPair = loadKeyPairsFromFiles();

    BOOST_CHECK_MESSAGE(generatedKeyPair.getPublicKey() == loadedKeyPair.getPublicKey()
                        , "Loaded and saved public key don't match");
    BOOST_CHECK_MESSAGE(generatedKeyPair.getPrivateKey() == loadedKeyPair.getPrivateKey()
                        , "Loaded and saved private key don't match");

    BOOST_CHECK(keyUtils.checkKeyPair(loadedKeyPair));
}
示例#7
0
ContactvCard::ConvertStatus ContactvCard::convert(Contact* contact)
{ 
  contact->first_name       = getFirstName().toStdString();
  contact->last_name        = getLastName().toStdString();
  contact->dac_id_string    = getKHID().toStdString();
  contact->notes            = getNotes().toStdString();
  contact->privacy_setting  = bts::addressbook::secret_contact;
  contact->setIcon(QIcon(":/images/user.png"));
  if (public_key_address::convert(getPublicKey().toStdString(), &contact->public_key) == false)
    return ConvertStatus::PUBLIC_KEY_INVALID;

  return ConvertStatus::SUCCESS;
}
示例#8
0
/**
 * @return returns padding size.
 * @throws IOException exception is thrown when failed to get padding size.
 */
int digidoc::X509Cert::getPaddingSize() const throw(IOException)
{
    EVP_PKEY *pubKey = getPublicKey();
    RSA *rsa = EVP_PKEY_get1_RSA(pubKey);
    if(!rsa)
    {
        EVP_PKEY_free(pubKey);
        THROW_IOEXCEPTION("Failed to read certificate RSA key: %s", ERR_reason_error_string(ERR_get_error()));
    }
    int size = RSA_size(rsa);
    RSA_free(rsa);
    EVP_PKEY_free(pubKey);
    return size;
}
示例#9
0
文件: signal.cpp 项目: l29ah/plugins
  Bundle Signal::collectBundle() {
    generatePreKeys();

    Bundle bundle;

    bundle.signedPreKeyId = m_storage.signedPreKeyid();

    session_signed_pre_key *signed_pre_key = nullptr;
    if (signal_protocol_signed_pre_key_load_key(m_storage.storeContext(), &signed_pre_key, bundle.signedPreKeyId) != SG_SUCCESS) {
      return bundle;
    }

    bundle.signedPreKeySignature = toQByteArray(session_signed_pre_key_get_signature(signed_pre_key),
                                                session_signed_pre_key_get_signature_len(signed_pre_key));

    QByteArray signedPreKeyPublicKey = getPublicKey(session_signed_pre_key_get_key_pair(signed_pre_key));
    if (!signedPreKeyPublicKey.isNull()) {
      bundle.signedPreKeyPublic = signedPreKeyPublicKey;
      bundle.identityKeyPublic = getIdentityPublicKey();

      foreach (auto preKey, m_storage.loadAllPreKeys()) {
        session_pre_key *pre_key = nullptr;
        if (session_pre_key_deserialize(&pre_key,
                                        reinterpret_cast<const uint8_t *>(preKey.second.data()),
                                        static_cast<size_t>(preKey.second.size()),
                                        m_signalContext) == SG_SUCCESS) {
          QByteArray preKeyPublicKey = getPublicKey(session_pre_key_get_key_pair(pre_key));
          if (!preKeyPublicKey.isNull()) {
            bundle.preKeys.append(qMakePair(preKey.first, preKeyPublicKey));
          }
          SIGNAL_UNREF(pre_key);
        }
      }
      if (!bundle.preKeys.isEmpty()) {
        bundle.loaded = true;
      }
    }
示例#10
0
void 
SecPublicInfoMemory::addCertificate(const IdentityCertificate& certificate)
{
  const Name& certificateName = certificate.getName();
  const Name& keyName = certificate.getPublicKeyName();

  if (!doesPublicKeyExist(keyName))
    throw Error("No corresponding Key record for certificate! " + keyName.toUri() + " " + certificateName.toUri());

  // Check if certificate has already existed!
  if (doesCertificateExist(certificateName))
    throw Error("Certificate has already been installed!");

  // Check if the public key of certificate is the same as the key record. 
  ptr_lib::shared_ptr<PublicKey> pubKey = getPublicKey(keyName);
  if (!pubKey || (*pubKey) != certificate.getPublicKeyInfo())
    throw Error("Certificate does not match the public key!");
  
  // Insert the certificate.
  certificateStore_[certificateName.toUri()] = ptr_lib::make_shared<IdentityCertificate> (certificate);
}
namespace stellar
{

TEST_CASE("TCPPeer can communicate", "[overlay]")
{
    Hash networkID = sha256(getTestConfig().NETWORK_PASSPHRASE);
    Simulation::pointer s =
        std::make_shared<Simulation>(Simulation::OVER_TCP, networkID);

    auto v10SecretKey = SecretKey::fromSeed(sha256("v10"));
    auto v11SecretKey = SecretKey::fromSeed(sha256("v11"));

    SCPQuorumSet n0_qset;
    n0_qset.threshold = 1;
    n0_qset.validators.push_back(v10SecretKey.getPublicKey());
    auto n0 = s->getNode(s->addNode(v10SecretKey, n0_qset, s->getClock()));

    SCPQuorumSet n1_qset;
    n1_qset.threshold = 1;
    n1_qset.validators.push_back(v11SecretKey.getPublicKey());
    auto n1 = s->getNode(s->addNode(v11SecretKey, n1_qset, s->getClock()));

    s->addPendingConnection(v10SecretKey.getPublicKey(),
                            v11SecretKey.getPublicKey());
    s->startAllNodes();
    s->crankForAtLeast(std::chrono::seconds(1), false);

    auto p0 = n0->getOverlayManager().getConnectedPeer(
                  "127.0.0.1", n1->getConfig().PEER_PORT);
示例#12
0
bool OnlineUnlockStatus::applyKeyFile (String keyFileContent)
{
    KeyFileUtils::KeyFileData data;
    data = KeyFileUtils::getDataFromKeyFile (KeyFileUtils::getXmlFromKeyFile (keyFileContent, getPublicKey()));

    if (data.licensee.isNotEmpty() && data.email.isNotEmpty() && doesProductIDMatch (data.appID))
    {
        setUserEmail (data.email);
        status.setProperty (keyfileDataProp, keyFileContent, nullptr);
        status.removeProperty (data.keyFileExpires ? expiryTimeProp : unlockedProp, nullptr);

        var actualResult (0), dummyResult (1.0);
        var v (machineNumberAllowed (data.machineNumbers, getLocalMachineIDs()));
        actualResult.swapWith (v);
        v = machineNumberAllowed (StringArray ("01"), getLocalMachineIDs());
        dummyResult.swapWith (v);
        jassert (! dummyResult);

        if (data.keyFileExpires)
        {
            if ((! dummyResult) && actualResult)
                status.setProperty (expiryTimeProp, data.expiryTime.toMilliseconds(), nullptr);

            return getExpiryTime().toMilliseconds() > 0;
        }

        if ((! dummyResult) && actualResult)
            status.setProperty (unlockedProp, actualResult, nullptr);

        return isUnlocked();
    }

    return false;
}
示例#13
0
void OnlineUnlockStatus::load()
{
    MemoryBlock mb;
    mb.fromBase64Encoding (getState());

    if (mb.getSize() > 0)
        status = ValueTree::readFromGZIPData (mb.getData(), mb.getSize());
    else
        status = ValueTree (stateTagName);

    StringArray localMachineNums (getLocalMachineIDs());

    if (machineNumberAllowed (StringArray ("1234"), localMachineNums))
        status.removeProperty (unlockedProp, nullptr);

    KeyFileUtils::KeyFileData data;
    data = KeyFileUtils::getDataFromKeyFile (KeyFileUtils::getXmlFromKeyFile (status[keyfileDataProp], getPublicKey()));

    if (data.keyFileExpires)
    {
        if (! doesProductIDMatch (data.appID))
            status.removeProperty (expiryTimeProp, nullptr);

        if (! machineNumberAllowed (data.machineNumbers, localMachineNums))
            status.removeProperty (expiryTimeProp, nullptr);
    }
    else
    {
        if (! doesProductIDMatch (data.appID))
            status.removeProperty (unlockedProp, nullptr);

        if (! machineNumberAllowed (data.machineNumbers, localMachineNums))
            status.removeProperty (unlockedProp, nullptr);
    }
}
示例#14
0
文件: toxid.cpp 项目: Grokafar/qTox
/**
 * @brief Compares the inequality of the Public Key.
 * @param other Tox ID to compare.
 * @return True if both Tox IDs have different public keys, false otherwise.
 */
bool ToxId::operator!=(const ToxId& other) const
{
    return getPublicKey() != other.getPublicKey();
}
示例#15
0
bool bdoc::X509Cert::verifySignature(int digestMethod, int digestSize,
		std::vector<unsigned char> digest,
		std::vector<unsigned char> signature)
{
	int result = 0;
	EVP_PKEY* key = getPublicKey();

	switch (EVP_PKEY_type(key->type)) {
	case EVP_PKEY_RSA:
	{
		if (digest.size() > static_cast<size_t>(digestSize)) {
			// The digest already has an ASN.1 DigestInfo header.
			break;
		}
		X509_SIG *sig = X509_SIG_new();
		// Prefer set0 to set_md, so we don't have to initialize the
		// digest lookup table with OpenSSL_add_all_digests. None of
		// our supported digests have parameters anyway.
		X509_ALGOR_set0(sig->algor, OBJ_nid2obj(digestMethod), V_ASN1_NULL, NULL);
		ASN1_OCTET_STRING_set(sig->digest, &digest[0], digest.size());

		unsigned char *asn1 = NULL;
		size_t asn1_len = i2d_X509_SIG(sig, &asn1);
		digest = std::vector<unsigned char>(asn1, asn1 + asn1_len);
		X509_SIG_free(sig);
		break;
	}
	case EVP_PKEY_EC:
	{
		ECDSA_SIG *sig = ECDSA_SIG_new();
		// signature is just r and s concatenated, so split them.
		size_t n_len = signature.size() >> 1;
		BN_bin2bn(&signature[0],     n_len, sig->r);
		BN_bin2bn(&signature[n_len], n_len, sig->s);

		unsigned char *asn1 = NULL;
		size_t asn1_len = i2d_ECDSA_SIG(sig, &asn1);
		signature = std::vector<unsigned char>(asn1, asn1 + asn1_len);
		ECDSA_SIG_free(sig);
		break;
	}
	default:
		THROW_STACK_EXCEPTION("Certificate '%s' has an unsupported "
				"public key type, can not verify signature.",
				getSubject().c_str());
	}

	EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(key, NULL);
	if (!ctx) {
		EVP_PKEY_free(key);
		THROW_STACK_EXCEPTION("Creating signature verification "
				"context failed: %s",
				ERR_reason_error_string(ERR_get_error()));
	}

	if (EVP_PKEY_verify_init(ctx) <= 0) {
		EVP_PKEY_CTX_free(ctx);
		EVP_PKEY_free(key);
		THROW_STACK_EXCEPTION("Initializing signature "
				"verification context failed: %s",
				ERR_reason_error_string(ERR_get_error()));
	}
	result = EVP_PKEY_verify(ctx, &signature[0], signature.size(),
			&digest[0], digest.size());
	if (result < 0) {
		EVP_PKEY_CTX_free(ctx);
		EVP_PKEY_free(key);
		THROW_STACK_EXCEPTION("Error during signature verification: %s",
				ERR_reason_error_string(ERR_get_error()));
	}

	EVP_PKEY_CTX_free(ctx);
	EVP_PKEY_free(key);

	return (result == 1);
}
示例#16
0
crypto::Identity
generateIdentity(const std::string& name, crypto::Identity ca)
{
    int rc = gnutls_global_init();
    if (rc != GNUTLS_E_SUCCESS)
        return {};

    auto shared_key = std::make_shared<PrivateKey>(PrivateKey::generate());

    gnutls_x509_crt_t cert;
    if (gnutls_x509_crt_init(&cert) != GNUTLS_E_SUCCESS)
        return {};
    auto shared_crt = std::make_shared<Certificate>(cert);

    gnutls_x509_crt_set_activation_time(cert, time(NULL));
    gnutls_x509_crt_set_expiration_time(cert, time(NULL) + (700 * 24 * 60 * 60));
    if (gnutls_x509_crt_set_key(cert, shared_key->x509_key) != GNUTLS_E_SUCCESS) {
        std::cerr << "Error when setting certificate key" << std::endl;
        return {};
    }
    if (gnutls_x509_crt_set_version(cert, 3) != GNUTLS_E_SUCCESS) {
        std::cerr << "Error when setting certificate version" << std::endl;
        return {};
    }

    // TODO: compute the subject key using the recommended RFC method
    auto pk_id = shared_key->getPublicKey().getId();
    gnutls_x509_crt_set_subject_key_id(cert, &pk_id, sizeof(pk_id));

    gnutls_x509_crt_set_dn_by_oid(cert, GNUTLS_OID_X520_COMMON_NAME, 0, name.data(), name.length());

    const std::string& uid_str = shared_key->getPublicKey().getId().toString();
    gnutls_x509_crt_set_dn_by_oid(cert, GNUTLS_OID_LDAP_UID, 0, uid_str.data(), uid_str.length());

    {
        random_device rdev;
        std::uniform_int_distribution<uint64_t> dist{};
        uint64_t cert_serial = dist(rdev);
        gnutls_x509_crt_set_serial(cert, &cert_serial, sizeof(cert_serial));
    }

    if (ca.first && ca.second) {
        gnutls_x509_crt_set_key_usage (cert, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_DATA_ENCIPHERMENT);
        //if (gnutls_x509_crt_sign2(cert, ca.second->cert, ca.first->x509_key, get_dig(cert), 0) != GNUTLS_E_SUCCESS) {
        if (gnutls_x509_crt_privkey_sign(cert, ca.second->cert, ca.first->key, get_dig(cert), 0) != GNUTLS_E_SUCCESS) {
            std::cerr << "Error when signing certificate" << std::endl;
            return {};
        }
        shared_crt->issuer = ca.second;
    } else {
        gnutls_x509_crt_set_ca_status(cert, 1);
        gnutls_x509_crt_set_key_usage (cert, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_CERT_SIGN);
        //if (gnutls_x509_crt_sign2(cert, cert, key, get_dig(cert), 0) != GNUTLS_E_SUCCESS) {
        if (gnutls_x509_crt_privkey_sign(cert, cert, shared_key->key, get_dig(cert), 0) != GNUTLS_E_SUCCESS) {
            std::cerr << "Error when signing certificate" << std::endl;
            return {};
        }
    }

    gnutls_global_deinit();

    return {shared_key, shared_crt};
}
示例#17
0
int lssproto_ServerDispatchMessage(int fd, char *encoded) {
  int func;
  char raw[1024 * 64];
  util_DecodeMessage(raw, encoded);
  if(!util_SplitMessage(raw, SEPARATOR)) {
    print("\nDME1:package=%s\n", raw);
    return -1;
  }

  if(!util_GetFunctionFromSlice(&func)) {
    logHack(fd, HACK_GETFUNCFAIL);
    return -1;
  }

  print("RECEIVED - %d\n", func);
  if(func == LSSPROTO_W_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    char direction[1024 * 64];

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_destring(4, direction);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_W_recv(fd, x, y, direction);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_W2_RECV) {
    int checksumrecv;
    int x;
    int y;
    char direction[1024 * 64];

    int checksum = util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_destring(4, direction);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_W2_recv(fd, x, y, direction);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_EV_RECV) {
    int checksum = 0, checksumrecv;
    int event;
    int seqno;
    int x;
    int y;
    int dir;

    checksum += util_deint(2, &event);
    checksum += util_deint(3, &seqno);
    checksum += util_deint(4, &x);
    checksum += util_deint(5, &y);
    checksum += util_deint(6, &dir);
    util_deint(7, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_EV_recv(fd, event, seqno, x, y, dir);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_DU_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_DU_recv(fd, x, y);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_EO_RECV) {
    int checksum = 0, checksumrecv;
    int dummy;

    checksum += util_deint(2, &dummy);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_EO_recv(fd, dummy);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_BU_RECV) {
    int checksum = 0, checksumrecv;
    int dummy;

    checksum += util_deint(2, &dummy);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_BU_recv(fd, dummy);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_JB_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_JB_recv(fd, x, y);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_LB_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_LB_recv(fd, x, y);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_B_RECV) {
    int checksum = 0, checksumrecv;
    char command[1024 * 64];

    checksum += util_destring(2, command);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_B_recv(fd, command);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_SKD_RECV) {
    int checksum = 0, checksumrecv;
    int dir;
    int index;

    checksum += util_deint(2, &dir);
    checksum += util_deint(3, &index);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_SKD_recv(fd, dir, index);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_ID_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int haveitemindex;
    int toindex;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &haveitemindex);
    checksum += util_deint(5, &toindex);
    util_deint(6, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_ID_recv(fd, x, y, haveitemindex, toindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PI_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int dir;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &dir);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_PI_recv(fd, x, y, dir);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_DI_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int itemindex;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &itemindex);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_DI_recv(fd, x, y, itemindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_DG_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int amount;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &amount);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_DG_recv(fd, x, y, amount);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_DP_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int petindex;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &petindex);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_DP_recv(fd, x, y, petindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_MI_RECV) {
    int checksum = 0, checksumrecv;
    int fromindex;
    int toindex;

    checksum += util_deint(2, &fromindex);
    checksum += util_deint(3, &toindex);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_MI_recv(fd, fromindex, toindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_MSG_RECV) {
    int checksum = 0, checksumrecv;
    int index;
    char message[1024 * 64];
    int color;

    checksum += util_deint(2, &index);
    checksum += util_destring(3, message);
    checksum += util_deint(4, &color);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_MSG_recv(fd, index, message, color);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PMSG_RECV) {
    int checksum = 0, checksumrecv;
    int index;
    int petindex;
    int itemindex;
    char message[1024 * 64];
    int color;

    checksum += util_deint(2, &index);
    checksum += util_deint(3, &petindex);
    checksum += util_deint(4, &itemindex);
    checksum += util_destring(5, message);
    checksum += util_deint(6, &color);
    util_deint(7, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_PMSG_recv(fd, index, petindex, itemindex, message, color);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_AB_RECV) {
    int checksum = 0, checksumrecv;
    util_deint(2, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_AB_recv(fd);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_DAB_RECV) {
    int checksum = 0, checksumrecv;
    int index;

    checksum += util_deint(2, &index);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_DAB_recv(fd, index);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_AAB_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_AAB_recv(fd, x, y);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_L_RECV) {
    int checksum = 0, checksumrecv;
    int dir;

    checksum += util_deint(2, &dir);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_L_recv(fd, dir);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_TK_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    char message[1024 * 64];
    int color;
    int area;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_destring(4, message);
    checksum += util_deint(5, &color);
    checksum += util_deint(6, &area);
    util_deint(7, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_TK_recv(fd, x, y, message, color, area);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_M_RECV) {
    int checksum = 0, checksumrecv;
    int fl;
    int x1;
    int y1;
    int x2;
    int y2;

    checksum += util_deint(2, &fl);
    checksum += util_deint(3, &x1);
    checksum += util_deint(4, &y1);
    checksum += util_deint(5, &x2);
    checksum += util_deint(6, &y2);
    util_deint(7, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_M_recv(fd, fl, x1, y1, x2, y2);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_C_RECV) {
    int checksumrecv;
    int index;

    int checksum = util_deint(2, &index);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_C_recv(fd, index);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_S_RECV) {
    int checksum = 0, checksumrecv;
    char category[1024 * 64];

    checksum += util_destring(2, category);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_S_recv(fd, category);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_FS_RECV) {
    int checksum = 0, checksumrecv;
    int flg;

    checksum += util_deint(2, &flg);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_FS_recv(fd, flg);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_HL_RECV) {
    int checksum = 0, checksumrecv;
    int flg;

    checksum += util_deint(2, &flg);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_HL_recv(fd, flg);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PR_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int request;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &request);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_PR_recv(fd, x, y, request);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_KS_RECV) {
    int checksum = 0, checksumrecv;
    int petarray;
    checksum += util_deint(2, &petarray);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_KS_recv(fd, petarray);
    util_DiscardMessage();
    return 0;
  }

#ifdef _STANDBYPET
  if(func == LSSPROTO_SPET_RECV) {
    int checksum = 0, checksumrecv;
    int standbypet;
    checksum += util_deint(2, &standbypet);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_SPET_recv(fd, standbypet);
    util_DiscardMessage();
    return 0;
  }
#endif

  if(func == LSSPROTO_AC_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int actionno;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &actionno);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_AC_recv(fd, x, y, actionno);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_MU_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int array;
    int toindex;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &array);
    checksum += util_deint(5, &toindex);
    util_deint(6, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_MU_recv(fd, x, y, array, toindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PS_RECV) {
    int checksum = 0, checksumrecv;
    int havepetindex;
    int havepetskill;
    int toindex;
    char data[1024 * 64];

    checksum += util_deint(2, &havepetindex);
    checksum += util_deint(3, &havepetskill);
    checksum += util_deint(4, &toindex);
    checksum += util_destring(5, data);
    util_deint(6, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);

      return -1;
    }

    lssproto_PS_recv(fd, havepetindex, havepetskill, toindex, data);

    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_ST_RECV) {
    int checksum = 0, checksumrecv;
    int titleindex;

    checksum += util_deint(2, &titleindex);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_ST_recv(fd, titleindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_DT_RECV) {
    int checksum = 0, checksumrecv;
    int titleindex;

    checksum += util_deint(2, &titleindex);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_DT_recv(fd, titleindex);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_FT_RECV) {
    int checksum = 0, checksumrecv;
    char data[1024 * 64];

    checksum += util_destring(2, data);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_FT_recv(fd, data);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_SKUP_RECV) {
    int checksum = 0, checksumrecv;
    int skillid;

    checksum += util_deint(2, &skillid);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_SKUP_recv(fd, skillid);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_KN_RECV) {
    int checksum = 0, checksumrecv;
    int havepetindex;
    char data[1024 * 64];

    checksum += util_deint(2, &havepetindex);
    checksum += util_destring(3, data);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_KN_recv(fd, havepetindex, data);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_WN_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int seqno;
    int objindex;
    int select;
    char data[1024 * 64];

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &seqno);
    checksum += util_deint(5, &objindex);
    checksum += util_deint(6, &select);
    checksum += util_destring(7, data);

    util_deint(8, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_WN_recv(fd, x, y, seqno, objindex, select, data);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_SP_RECV) {
    int checksum = 0, checksumrecv;
    int x;
    int y;
    int dir;

    checksum += util_deint(2, &x);
    checksum += util_deint(3, &y);
    checksum += util_deint(4, &dir);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_SP_recv(fd, x, y, dir);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_CLIENTLOGIN_RECV) {
    int checksum = 0, checksumrecv;
    char cdkey[CDKEYLEN];
    char passwd[PASSWDLEN];

    strcpy(PersonalKey, getPublicKey());

    checksum += util_destring(2, cdkey);
    checksum += util_destring(3, passwd);

    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();

      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_ClientLogin_recv(fd, cdkey, passwd);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_CREATENEWCHAR_RECV) {
    int checksum = 0, checksumrecv;
    int dataplacenum;
    char charname[CHARNAMELEN];;
    int imgno;
    int faceimgno;
    int vital;
    int str;
    int tgh;
    int dex;
    int earth;
    int water;
    int fire;
    int wind;
    int hometown;

    checksum += util_deint(2, &dataplacenum);
    checksum += util_destring(3, charname);
    checksum += util_deint(4, &imgno);
    checksum += util_deint(5, &faceimgno);
    checksum += util_deint(6, &vital);
    checksum += util_deint(7, &str);
    checksum += util_deint(8, &tgh);
    checksum += util_deint(9, &dex);
    checksum += util_deint(10, &earth);
    checksum += util_deint(11, &water);
    checksum += util_deint(12, &fire);
    checksum += util_deint(13, &wind);
    checksum += util_deint(14, &hometown);
    util_deint(15, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_CreateNewChar_recv(fd, dataplacenum, charname, imgno, faceimgno, vital, str, tgh, dex, earth, water, fire, wind, hometown);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_CHARDELETE_RECV) {
    int checksum = 0, checksumrecv;
    char charname[CHARNAMELEN];;

    checksum += util_destring(2, charname);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_CharDelete_recv(fd, charname);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_CHARLOGIN_RECV) {
    int checksumrecv;
    char charname[CHARNAMELEN];
    int checksum = util_destring(2, charname);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_CharLogin_recv(fd, charname);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_CHARLIST_RECV) {
    int checksumrecv;
    util_deint(2, &checksumrecv);
    if(0 != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_CharList_recv(fd);

    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_CHARLOGOUT_RECV) {
    int checksumrecv;
    int Flg = 1;
    util_deint(2, &checksumrecv);
    if(0 != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_CharLogout_recv(fd, Flg);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PROCGET_RECV) {
    int checksumrecv;

    strcpy(PersonalKey, getPublicKey());

    util_deint(2, &checksumrecv);
    if(0 != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_ProcGet_recv(fd);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PLAYERNUMGET_RECV) {
    int checksum = 0, checksumrecv;
    util_deint(2, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_PlayerNumGet_recv(fd);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_ECHO_RECV) {
    int checksum = 0, checksumrecv;
    char test[1024 * 64];

    checksum += util_destring(2, test);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_Echo_recv(fd, test);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_SHUTDOWN_RECV) {
    int checksum = 0, checksumrecv;
    char passwd[1024 * 64];
    int min;

    checksum += util_destring(2, passwd);
    checksum += util_deint(3, &min);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_Shutdown_recv(fd, passwd, min);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_TD_RECV) {
    int checksum = 0, checksumrecv;
    char message[1024 * 64];

    checksum += util_destring(2, message);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_TD_recv(fd, message);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_FM_RECV) {
    int checksum = 0, checksumrecv;
    char message[1024 * 64];

    checksum += util_destring(2, message);
    util_deint(3, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }
    lssproto_FM_recv(fd, message);
    util_DiscardMessage();
    return 0;
  }

  if(func == LSSPROTO_PETST_RECV) {
    int checksum = 0, checksumrecv;
    int nPet;
    int sPet;

    checksum += util_deint(2, &nPet);
    checksum += util_deint(3, &sPet);
    util_deint(4, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_PETST_recv(fd, nPet, sPet);
    util_DiscardMessage();
    return 0;
  }

#ifdef _CHECK_GAMESPEED
  if (func==LSSPROTO_CS_RECV) {
      char buffer[2];
      buffer[0] = '\0';

    lssproto_CS_recv( fd );
    util_DiscardMessage();
    return 0;
  }
#endif

#ifdef _MIND_ICON
  if(func == LSSPROTO_MA_RECV) {
    int checksum = 0, checksumrecv;
    int nMind;
    int x, y;

    checksum += util_deint(2, &nMind);
    checksum += util_deint(3, &x);
    checksum += util_deint(4, &y);
    util_deint(5, &checksumrecv);
    if(checksum != checksumrecv) {
      util_DiscardMessage();
      logHack(fd, HACK_CHECKSUMERROR);
      return -1;
    }

    lssproto_MA_recv(fd, x, y, nMind);
    util_DiscardMessage();
    return 0;
  }
#endif

#ifdef _OUTOFBATTLESKILL      // (不可开) Syu ADD 非战斗时技能Protocol
  if(func==LSSPROTO_BATTLESKILL_RECV){
      int checksum = 0, checksumrecv;
      int iNum;
      
      checksum += util_deint( 2, &iNum);
      util_deint( 3, &checksumrecv);
      if(checksum!=checksumrecv){
        util_DiscardMessage();
        logHack( fd, HACK_CHECKSUMERROR);
        return -1;
      }		

      lssproto_BATTLESKILL_recv(fd, iNum);
      util_DiscardMessage();
      return 0;
  }
#endif

  printf("\n无法找到客户端接口=%d\n", func);

  util_DiscardMessage();
  logHack(fd, HACK_NOTDISPATCHED);
  return -1;
}
示例#18
0
#include "simulation/Simulation.h"
#include "overlay/OverlayManager.h"

namespace stellar
{

TEST_CASE("TCPPeer can communicate", "[overlay]")
{
    Simulation::pointer s = std::make_shared<Simulation>(Simulation::OVER_TCP);

    auto v10SecretKey = SecretKey::fromSeed(sha256("v10"));
    auto v11SecretKey = SecretKey::fromSeed(sha256("v11"));

    SCPQuorumSet n0_qset;
    n0_qset.threshold = 1;
    n0_qset.validators.push_back(v10SecretKey.getPublicKey());
    auto n0 =
        s->getNode(s->addNode(v10SecretKey, n0_qset, s->getClock()));

    SCPQuorumSet n1_qset;
    n1_qset.threshold = 1;
    n1_qset.validators.push_back(v11SecretKey.getPublicKey());
    auto n1 =
        s->getNode(s->addNode(v11SecretKey, n1_qset, s->getClock()));

    s->startAllNodes();

    auto b = TCPPeer::initiate(*n0, "127.0.0.1", n1->getConfig().PEER_PORT);

    s->crankForAtLeast(std::chrono::seconds(3), false);
示例#19
0
static int testKeysetWrite( const CRYPT_KEYSET_TYPE keysetType,
							const C_STR keysetName )
	{
	CRYPT_KEYSET cryptKeyset;
	CRYPT_CERTIFICATE cryptCert;
	CRYPT_CONTEXT pubKeyContext, privKeyContext;
	C_CHR filenameBuffer[ FILENAME_BUFFER_SIZE ];
	C_CHR name[ CRYPT_MAX_TEXTSIZE + 1 ];
	int length, status;

	/* Import the certificate from a file - this is easier than creating one
	   from scratch.  We use one of the later certs in the test set, since
	   this contains an email address, which the earlier ones don't */
	status = importCertFromTemplate( &cryptCert, CERT_FILE_TEMPLATE, 
									 EMAILADDR_CERT_NO );
	if( cryptStatusError( status ) )
		{
		printf( "Couldn't read certificate from file, status %d, line %d.\n",
				status, __LINE__ );
		return( FALSE );
		}

	/* Make sure that the certificate does actually contain an email 
	   address */
	status = cryptGetAttributeString( cryptCert, CRYPT_CERTINFO_EMAIL,
									  name, &length );
	if( cryptStatusError( status ) )
		{
		printf( "Certificate doesn't contain an email address and can't be "
				"used for testing,\n  line %d.\n", __LINE__ );
		return( FALSE );
		}

	/* Create the database keyset with a check to make sure this access
	   method exists so we can return an appropriate error message.  If the
	   database table already exists, this will return a duplicate data
	   error so we retry the open with no flags to open the existing database
	   keyset for write access */
	status = cryptKeysetOpen( &cryptKeyset, CRYPT_UNUSED, keysetType,
							  keysetName, CRYPT_KEYOPT_CREATE );
	if( cryptStatusOK( status ) )
		printf( "Created new certificate database '%s'.\n", keysetName );
	if( status == CRYPT_ERROR_PARAM3 )
		{
		/* This type of keyset access isn't available, return a special error
		   code to indicate that the test wasn't performed, but that this
		   isn't a reason to abort processing */
		cryptDestroyCert( cryptCert );
		return( CRYPT_ERROR_NOTAVAIL );
		}
	if( status == CRYPT_ERROR_DUPLICATE )
		status = cryptKeysetOpen( &cryptKeyset, CRYPT_UNUSED, keysetType,
								  keysetName, 0 );
	if( cryptStatusError( status ) )
		{
		cryptDestroyCert( cryptCert );
		printf( "cryptKeysetOpen() failed with error code %d, line %d.\n",
				status, __LINE__ );
		if( status == CRYPT_ERROR_OPEN )
			return( CRYPT_ERROR_FAILED );
		return( FALSE );
		}

	/* Write the key to the database */
	puts( "Adding certificate." );
	status = cryptAddPublicKey( cryptKeyset, cryptCert );
	if( status == CRYPT_ERROR_DUPLICATE )
		{
		/* The key is already present, delete it and retry the write */
		status = cryptGetAttributeString( cryptCert,
								CRYPT_CERTINFO_COMMONNAME, name, &length );
		if( cryptStatusOK( status ) )
			{
#ifdef UNICODE_STRINGS
			length /= sizeof( wchar_t );
#endif /* UNICODE_STRINGS */
			name[ length ] = TEXT( '\0' );
			status = cryptDeleteKey( cryptKeyset, CRYPT_KEYID_NAME, name );
			}
		if( cryptStatusError( status ) )
			return( extErrorExit( cryptKeyset, "cryptDeleteKey()", status,
								  __LINE__ ) );
		status = cryptAddPublicKey( cryptKeyset, cryptCert );
		}
	if( cryptStatusError( status ) )
		{
		printExtError( cryptKeyset, "cryptAddPublicKey()", status, __LINE__ );

		/* LDAP writes can fail due to the chosen directory not supporting the
		   schema du jour, so we're a bit more careful about cleaning up since
		   we'll skip the error and continue processing */
		cryptDestroyCert( cryptCert );
		cryptKeysetClose( cryptKeyset );
		return( FALSE );
		}
	cryptDestroyCert( cryptCert );

	/* Add a second certificate with C=US so that we've got enough certs to 
	   properly exercise the query code.  This certificate is highly unusual 
	   in that it doesn't have a DN, so we have to move up the DN looking 
	   for higher-up values, in this case the OU */
	if( keysetType != CRYPT_KEYSET_LDAP )
		{
		status = importCertFromTemplate( &cryptCert, CERT_FILE_TEMPLATE, 2 );
		if( cryptStatusError( status ) )
			{
			printf( "Couldn't read certificate from file, status %d, "
					"line %d.\n", status, __LINE__ );
			return( FALSE );
			}
		status = cryptAddPublicKey( cryptKeyset, cryptCert );
		if( status == CRYPT_ERROR_DUPLICATE )
			{
			status = cryptGetAttributeString( cryptCert,
							CRYPT_CERTINFO_COMMONNAME, name, &length );
			if( cryptStatusError( status ) )
				status = cryptGetAttributeString( cryptCert,
							CRYPT_CERTINFO_ORGANIZATIONALUNITNAME, name, &length );
			if( cryptStatusOK( status ) )
				{
#ifdef UNICODE_STRINGS
				length /= sizeof( wchar_t );
#endif /* UNICODE_STRINGS */
				name[ length ] = TEXT( '\0' );
				status = cryptDeleteKey( cryptKeyset, CRYPT_KEYID_NAME, name );
				}
			if( cryptStatusOK( status ) )
				status = cryptAddPublicKey( cryptKeyset, cryptCert );
			}
		if( cryptStatusError( status ) )
			return( extErrorExit( cryptKeyset, "cryptAddPublicKey()",
								  status, __LINE__ ) );
		cryptDestroyCert( cryptCert );
		}

	/* Add a third certificate with a DN that'll cause problems for some 
	   storage technologies */
	if( !loadRSAContexts( CRYPT_UNUSED, &pubKeyContext, &privKeyContext ) )
		return( FALSE );
	status = cryptCreateCert( &cryptCert, CRYPT_UNUSED,
							  CRYPT_CERTTYPE_CERTIFICATE );
	if( cryptStatusError( status ) )
		{
		printf( "cryptCreateCert() failed with error code %d, line %d.\n",
				status, __LINE__ );
		return( FALSE );
		}
	status = cryptSetAttribute( cryptCert,
					CRYPT_CERTINFO_SUBJECTPUBLICKEYINFO, pubKeyContext );
	if( cryptStatusError( status ) )
		return( attrErrorExit( cryptCert, "cryptSetAttribute()", status,
							   __LINE__ ) );
	if( !addCertFields( cryptCert, sqlCertData, __LINE__ ) )
		return( FALSE );
	status = cryptSignCert( cryptCert, privKeyContext );
	if( cryptStatusError( status ) )
		return( attrErrorExit( cryptCert, "cryptSignCert()", status,
							   __LINE__ ) );
	destroyContexts( CRYPT_UNUSED, pubKeyContext, privKeyContext );
	status = cryptAddPublicKey( cryptKeyset, cryptCert );
	if( cryptStatusError( status ) )
		{
		/* The key is already present, delete it and retry the write */
		status = cryptGetAttributeString( cryptCert,
								CRYPT_CERTINFO_COMMONNAME, name, &length );
		if( cryptStatusOK( status ) )
			{
#ifdef UNICODE_STRINGS
			length /= sizeof( wchar_t );
#endif /* UNICODE_STRINGS */
			name[ length ] = TEXT( '\0' );
			status = cryptDeleteKey( cryptKeyset, CRYPT_KEYID_NAME, name );
			}
		if( cryptStatusError( status ) )
			return( extErrorExit( cryptKeyset, "cryptDeleteKey()", status,
								  __LINE__ ) );
		status = cryptAddPublicKey( cryptKeyset, cryptCert );
		}
	if( cryptStatusError( status ) )
		{
		return( extErrorExit( cryptKeyset, "cryptAddPublicKey()",
							  status, __LINE__ ) );
		}
	cryptDestroyCert( cryptCert );

	/* Now try the same thing with a CRL.  This code also tests the
	   duplicate-detection mechanism, if we don't get a duplicate error
	   there's a problem */
	puts( "Adding CRL." );
	status = importCertFromTemplate( &cryptCert, CRL_FILE_TEMPLATE, 1 );
	if( cryptStatusError( status ) )
		{
		printf( "Couldn't read CRL from file, status %d, line %d.\n", 
				status, __LINE__ );
		return( TRUE );
		}
	status = cryptAddPublicKey( cryptKeyset, cryptCert );
	if( cryptStatusError( status ) && status != CRYPT_ERROR_DUPLICATE )
		return( extErrorExit( cryptKeyset, "cryptAddPublicKey()", status,
							  __LINE__ ) );
	status = cryptAddPublicKey( cryptKeyset, cryptCert );
	if( status != CRYPT_ERROR_DUPLICATE )
		{
		printf( "Addition of duplicate item to keyset failed to produce "
			    "CRYPT_ERROR_DUPLICATE, status %d, line %d.\n", status,
				__LINE__ );
		return( FALSE );
		}
	cryptDestroyCert( cryptCert );

	/* Finally, try it with a certificate chain */
	puts( "Adding certificate chain." );
	filenameParamFromTemplate( filenameBuffer, CERTCHAIN_FILE_TEMPLATE, 
							   CERT_CHAIN_NO );
	status = importCertFile( &cryptCert, filenameBuffer );
	if( cryptStatusError( status ) )
		{
		printf( "Couldn't read certificate chain from file, status %d, "
				"line %d.\n", status, __LINE__ );
		return( FALSE );
		}
	status = cryptAddPublicKey( cryptKeyset, cryptCert );
	if( cryptStatusError( status ) && status != CRYPT_ERROR_DUPLICATE )
		return( extErrorExit( cryptKeyset, "cryptAddPublicKey()", status,
							  __LINE__ ) );
	cryptDestroyCert( cryptCert );

	/* In addition to the other certs we also add the generic user 
	   certificate, which is used later in other tests.  Since it may have 
	   been added earlier we try and delete it first (we can't use the 
	   existing version since the issuerAndSerialNumber won't match the one 
	   in the private-key keyset) */
	status = getPublicKey( &cryptCert, USER_PRIVKEY_FILE,
						   USER_PRIVKEY_LABEL );
	if( cryptStatusError( status ) )
		{
		printf( "Couldn't read user certificate from file, status %d, line "
				"%d.\n", status, __LINE__ );
		return( FALSE );
		}
	status = cryptGetAttributeString( cryptCert, CRYPT_CERTINFO_COMMONNAME,
									  name, &length );
	if( cryptStatusError( status ) )
		return( FALSE );
#ifdef UNICODE_STRINGS
	length /= sizeof( wchar_t );
#endif /* UNICODE_STRINGS */
	name[ length ] = TEXT( '\0' );
	do
		status = cryptDeleteKey( cryptKeyset, CRYPT_KEYID_NAME, name );
	while( cryptStatusOK( status ) );
	status = cryptAddPublicKey( cryptKeyset, cryptCert );
	if( status == CRYPT_ERROR_NOTFOUND )
		{
		/* This can occur if a database keyset is defined but hasn't been
		   initialised yet so the necessary tables don't exist, it can be
		   opened but an attempt to add a key will return a not found error
		   since it's the table itself rather than any item within it that
		   isn't being found */
		status = CRYPT_OK;
		}
	if( cryptStatusError( status ) )
		return( extErrorExit( cryptKeyset, "cryptAddPublicKey()", status,
							  __LINE__ ) );
	cryptDestroyCert( cryptCert );

	/* Finally, if ECC is enabled we also add ECC certificates that are used
	   later in other tests */
	if( cryptStatusOK( cryptQueryCapability( CRYPT_ALGO_ECDSA, NULL ) ) )
		{
#ifdef UNICODE_STRINGS
		wchar_t wcBuffer[ FILENAME_BUFFER_SIZE ];
#endif /* UNICODE_STRINGS */
		void *fileNamePtr = filenameBuffer;

		/* Add the P256 certificate */
		filenameFromTemplate( filenameBuffer, 
							  SERVER_ECPRIVKEY_FILE_TEMPLATE, 256 );
#ifdef UNICODE_STRINGS
		mbstowcs( wcBuffer, filenameBuffer, strlen( filenameBuffer ) + 1 );
		fileNamePtr = wcBuffer;
#endif /* UNICODE_STRINGS */
		status = getPublicKey( &cryptCert, fileNamePtr,
							   USER_PRIVKEY_LABEL );
		if( cryptStatusError( status ) )
			{
			printf( "Couldn't read user certificate from file, status %d, "
					"line %d.\n", status, __LINE__ );
			return( FALSE );
			}
		status = cryptAddPublicKey( cryptKeyset, cryptCert );
		if( cryptStatusError( status ) && status != CRYPT_ERROR_DUPLICATE )
			return( extErrorExit( cryptKeyset, "cryptAddPublicKey()", status,
								  __LINE__ ) );
		cryptDestroyCert( cryptCert );

		/* Add the P384 certificate */
		filenameFromTemplate( filenameBuffer, 
							  SERVER_ECPRIVKEY_FILE_TEMPLATE, 384 );
#ifdef UNICODE_STRINGS
		mbstowcs( wcBuffer, filenameBuffer, strlen( filenameBuffer ) + 1 );
		fileNamePtr = wcBuffer;
#endif /* UNICODE_STRINGS */
		status = getPublicKey( &cryptCert, fileNamePtr,
							   USER_PRIVKEY_LABEL );
		if( cryptStatusError( status ) )
			{
			printf( "Couldn't read user certificate from file, status %d, "
					"line %d.\n", status, __LINE__ );
			return( FALSE );
			}
		status = cryptAddPublicKey( cryptKeyset, cryptCert );
		if( cryptStatusError( status ) && status != CRYPT_ERROR_DUPLICATE )
			return( extErrorExit( cryptKeyset, "cryptAddPublicKey()", status,
								  __LINE__ ) );
		cryptDestroyCert( cryptCert );
		}

	/* Make sure the deletion code works properly.  This is an artifact of
	   the way RDBMS' work, the delete query can execute successfully but
	   not delete anything so we make sure the glue code correctly
	   translates this into a CRYPT_DATA_NOTFOUND */
	status = cryptDeleteKey( cryptKeyset, CRYPT_KEYID_NAME,
							 TEXT( "Mr.Not Appearing in this Keyset" ) );
	if( status != CRYPT_ERROR_NOTFOUND )
		{
		puts( "Attempt to delete a nonexistant key reports success, the "
			  "database backend glue\ncode needs to be fixed to handle this "
			  "correctly." );
		return( FALSE );
		}

	/* Close the keyset */
	status = cryptKeysetClose( cryptKeyset );
	if( cryptStatusError( status ) )
		{
		printf( "cryptKeysetClose() failed with error code %d, line %d.\n",
				status, __LINE__ );
		}

	return( TRUE );
	}