diff --git a/openssl/openssl-net-0.5/ManagedOpenSsl.XML b/openssl/openssl-net-0.5/ManagedOpenSsl.XML new file mode 100755 index 00000000..acb72113 --- /dev/null +++ b/openssl/openssl-net-0.5/ManagedOpenSsl.XML @@ -0,0 +1,4929 @@ + + + + ManagedOpenSsl + + + + + Base class for all openssl wrapped objects. + Contains the raw unmanaged pointer and has a Handle property to get access to it. + Also overloads the ToString() method with a BIO print. + + + + + Constructor which takes the raw unmanged pointer. + This is the only way to construct this object and all dervied types. + + + + + + + This finalizer just calls Dispose(). + + + + + This method is used by the ToString() implementation. A great number of + openssl objects support printing, so this is a conveinence method. + Dervied types should override this method and not ToString(). + + The BIO stream object to print into + + + + Override of ToString() which uses Print() into a BIO memory buffer. + + + + + + This method must be implemented in derived classes. + + + + + Do nothing in the base class. + + + + + + Implementation of the IDisposable interface. + If the native pointer is not null, we haven't been disposed, and we are the owner, + then call the virtual OnDispose() method. + + + + + Throws NotImplementedException + + + + + Raw unmanaged pointer + + + + + If this object is the owner, then call the appropriate native free function. + + + + + This is to prevent double-deletion issues. + + + + + gets/sets whether the object owns the Native pointer + + + + + Access to the raw unmanaged pointer. + + + + + Wraps ASN1_STRING_* + + + + + Helper base class that handles the AddRef() method by using a _dup() method. + + + + + Derived classes must use a _dup() method to make a copy of the underlying native data structure. + + + + + + Calls ASN1_STRING_type_new() + + + + + Wrap existing native pointer + + + + + + + Calls ASN1_STRING_set() + + + + + + Calls ASN1_STRING_free() + + + + + Returns ASN1_STRING_cmp() + + + + + + + Returns ASN1_STRING_length() + + + + + Returns ASN1_STRING_data() + + + + + Helper type that handles the AddRef() method. + Derived classes must implement the LockType and RawReferenceType properties + + + + + Prints the current underlying reference count + + + + + Derived classes must return a CryptoLockTypes for this type + + + + + Derived classes must return a Type that matches the underlying type + + + + + Implements the CopyRef() method + + + + + + Encapsulates the BIO_* functions. + + + + + Calls BIO_new_mem_buf() from the specified buffer. + + + + + + Calls BIO_new_mem_buf() from the specified string. + + + + + + Calls BIO_new(BIO_s_mem()) + + + + + + + Factory method that calls BIO_new() with BIO_s_mem() + + + + + + Factory method that calls BIO_new_file() + + + + + + + + Factory method that calls BIO_new() with BIO_f_md() + + + + + + + Calls BIO_set_close() + + + + + + Calls BIO_push() + + + + + + Calls BIO_write() + + + + + + Calls BIO_write() + + + + + + + Calls BIO_write() + + + + + + Calls BIO_write() + + + + + + Calls BIO_write() + + + + + + Calls BIO_puts() + + + + + + Calls BIO_read() + + + + + + + Calls BIO_gets() + + + + + + Returns the MessageDigestContext if this BIO's type if BIO_f_md() + + + + + + Calls BIO_free() + + + + + Returns BIO_number_read() + + + + + Returns BIO_number_written() + + + + + Returns number of bytes buffered in the BIO - calls BIO_ctrl_pending + + + + + BIO Close Options + + + + + Don't close on free + + + + + Close on freee + + + + + V_CRYPTO_MDEBUG_* + + + + + V_CRYPTO_MDEBUG_TIME + + + + + V_CRYPTO_MDEBUG_THREAD + + + + + V_CRYPTO_MDEBUG_ALL + + + + + CRYPTO_MEM_CHECK_* + + + + + CRYPTO_MEM_CHECK_OFF + for applications + + + + + CRYPTO_MEM_CHECK_ON + for applications + + + + + CRYPTO_MEM_CHECK_ENABLE + for library-internal use + + + + + CRYPTO_MEM_CHECK_DISABLE + for library-internal use + + + + + Exposes the CRYPTO_* functions + + + + + Calls CRYPTO_malloc_debug_init() + + + + + Calls CRYPTO_dbg_set_options() + + + + + + Calls CRYPTO_mem_ctrl() + + + + + + Calls CRYPTO_cleanup_all_ex_data() + + + + + Calls ERR_remove_state() + + + + + + Calls CRYPTO_mem_leaks_cb() + + + + + + Returns MD2_options() + + + + + Returns RC4_options() + + + + + Returns DES_options() + + + + + Returns idea_options() + + + + + Returns BF_options() + + + + + CRYPTO_MEM_LEAK_CB + + + + + + + + + + Useful for tracking down memory leaks + + + + + Begins memory tracking + + + + + Stops memory tracking and reports any leaks found since Start() was called. + + + + + Returns the number of bytes leaked between Start() and Finish() + + + + + Wraps the EVP_CIPHER object. + + + + + Prints the LongName of this cipher. + + + + + + Not implemented, these objects should never be disposed + + + + + Returns EVP_get_cipherbyname() + + + + + + + EVP_enc_null() + + + + + EVP_des_ecb() + + + + + EVP_des_ede() + + + + + EVP_des_ede3() + + + + + EVP_des_ede_ecb() + + + + + EVP_des_ede3_ecb() + + + + + EVP_des_cfb64() + + + + + EVP_des_cfb1() + + + + + EVP_des_cfb8() + + + + + EVP_des_ede_cfb64() + + + + + EVP_des_ede3_cfb64() + + + + + EVP_des_ede3_cfb1() + + + + + EVP_des_ede3_cfb8() + + + + + EVP_des_ofb() + + + + + EVP_ded_ede_ofb() + + + + + EVP_des_ede3_ofb() + + + + + EVP_des_cbc() + + + + + EVP_des_ede_cbc() + + + + + EVP_des_ede3_cbc() + + + + + EVP_desx_cbc() + + + + + EVP_rc4() + + + + + EVP_rc4_40() + + + + + EVP_idea_ecb() + + + + + EVP_idea_cfb64() + + + + + EVP_idea_ofb() + + + + + EVP_idea_cbc() + + + + + EVP_rc2_ecb() + + + + + EVP_rc2_cbc() + + + + + EVP_rc2_40_cbc() + + + + + EVP_rc2_64_cbc() + + + + + EVP_rc2_cfb64() + + + + + EVP_rc2_ofb() + + + + + EVP_bf_ecb() + + + + + EVP_bf_cbc() + + + + + EVP_bf_cfb64() + + + + + EVP_bf_ofb() + + + + + EVP_cast5_ecb() + + + + + EVP_cast5_cbc() + + + + + EVP_cast5_cfb64() + + + + + EVP_cast5_ofb() + + + + + EVP_aes_128_ecb() + + + + + EVP_aes_128_cbc() + + + + + EVP_aes_128_cfb1() + + + + + EVP_aes_128_cfb8() + + + + + EVP_aes_128_cfb128() + + + + + EVP_aes_128_ofb() + + + + + EVP_aes_192_ecb() + + + + + EVP_aes_192_cbc() + + + + + EVP_aes_192_cfb1() + + + + + EVP_aes_192_cfb8() + + + + + EVP_aes_192_cfb128() + + + + + EVP_aes_192_ofb() + + + + + EVP_aes_256_ecb() + + + + + EVP_aes_256_cbc() + + + + + EVP_aes_256_cfb1() + + + + + EVP_aes_256_cfb8() + + + + + EVP_aes_256_cfb128() + + + + + EVP_aes_256_ofb() + + + + + Calls OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH) + + + + + Calls OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH) + + + + + Returns the key_len field + + + + + Returns the iv_len field + + + + + Returns the block_size field + + + + + Returns the flags field + + + + + Returns the long name for the nid field using OBJ_nid2ln() + + + + + Returns the name for the nid field using OBJ_nid2sn() + + + + + Returns EVP_CIPHER_type() + + + + + Returns the long name for the type using OBJ_nid2ln() + + + + + Simple struct to encapsulate common parameters for crypto functions + + + + + The key for a crypto operation + + + + + The IV (Initialization Vector) + + + + + The payload (contains plaintext or ciphertext) + + + + + Wraps the EVP_CIPHER_CTX object. + + + + + Calls OPENSSL_malloc() and initializes the buffer using EVP_CIPHER_CTX_init() + + + + + + Returns the cipher's LongName + + + + + + Calls EVP_OpenInit() and EVP_OpenFinal() + + + + + + + + + Calls EVP_SealInit() and EVP_SealFinal() + + + + + + + + Encrypts or decrypts the specified payload. + + + + + + + + + + Calls EVP_CipherInit_ex(), EVP_CipherUpdate(), and EVP_CipherFinal_ex() + + + + + + + + + + + Encrypts the specified plaintext + + + + + + + + + Decrypts the specified ciphertext + + + + + + + + + Encrypts the specified plaintext + + + + + + + + + + Decrypts the specified ciphertext + + + + + + + + + + Calls EVP_BytesToKey + + + + + + + + + + + Calls EVP_CIPHER_CTX_clean() and then OPENSSL_free() + + + + + Returns the EVP_CIPHER for this context. + + + + + Wraps X509V3_CTX + + + + + Calls OPENSSL_malloc() + + + + + Calls X509V3_set_ctx() + + + + + + + + X509V3_set_ctx_nodb - sets the db pointer to NULL + + + + + Calls X509V3_set_nconf() + + + + + + Calls OPENSSL_free() + + + + + Wraps the NCONF_* functions + + + + + Calls NCONF_new() + + + + + Calls NCONF_load() + + + + + + Calls NCONF_load() + + + + + + Creates a X509v3Context(), calls X509V3_set_ctx() on it, then calls + X509V3_EXT_add_nconf() + + + + + + + + + Calls NCONF_free() + + + + + Wraps the native OpenSSL EVP_PKEY object + + + + + Calls EVP_PKEY_new() + + + + + Calls PEM_read_bio_PUBKEY() + + + + + + + + Calls PEM_read_bio_PUBKEY() + + + + + + + + Calls PEM_read_bio_PUBKEY() + + + + + + + + + Calls PEM_read_bio_PrivateKey() + + + + + + + + Calls PEM_read_bio_PrivateKey() + + + + + + + + Calls PEM_read_bio_PrivateKey() + + + + + + + + + Calls EVP_PKEY_set1_DSA() + + + + + + Calls EVP_PKEY_set1_RSA() + + + + + + Calls EVP_PKEY_set1_DH() + + + + + + Calls EVP_PKEY_assign() + + + + + + + Returns EVP_PKEY_get1_DSA() + + + + + + Returns EVP_PKEY_get1_DH() + + + + + + Returns EVP_PKEY_get1_RSA() + + + + + + Calls PEM_write_bio_PKCS8PrivateKey + + + + + + + + Calls PEM_write_bio_PKCS8PrivateKey + + + + + + + + + Calls EVP_PKEY_free() + + + + + Returns CompareTo(obj) + + + + + + + + + + + + + Calls appropriate Print() based on the type. + + + + + + Returns EVP_PKEY_type() + + + + + Returns EVP_PKEY_bits() + + + + + Returns EVP_PKEY_size() + + + + + Set of types that this CryptoKey can be. + + + + + EVP_PKEY_RSA + + + + + EVP_PKEY_DSA + + + + + EVP_PKEY_DH + + + + + EVP_PKEY_EC + + + + + Encapsulates the native openssl Diffie-Hellman functions (DH_*) + + + + + Constant generator value of 2. + + + + + Constant generator value of 5. + + + + + Calls DH_generate_parameters() + + + + + + + Calls DH_generate_parameters_ex() + + + + + + + + + Calls DH_new(). + + + + + Calls DH_new(). + + + + + + + Calls DH_new(). + + + + + + + + + Factory method that calls FromParametersPEM() to deserialize + a DH object from a PEM-formatted string. + + + + + + + Factory method that calls PEM_read_bio_DHparams() to deserialize + a DH object from a PEM-formatted string using the BIO interface. + + + + + + + Factory method that calls XXX() to deserialize + a DH object from a DER-formatted buffer using the BIO interface. + + + + + + + Calls DH_generate_key(). + + + + + Calls DH_compute_key(). + + + + + + + Calls PEM_write_bio_DHparams(). + + + + + + Calls ASN1_i2d_bio() with the i2d = i2d_DHparams(). + + + + + + Calls DHparams_print(). + + + + + + Calls DH_check(). + + + + + + Calls DH_free(). + + + + + Accessor for the p value. + + + + + Accessor for the g value. + + + + + Accessor for the pub_key value. + + + + + Accessor for the priv_key value. + + + + + Creates a BIO.MemoryBuffer(), calls WriteParametersPEM() into this buffer, + then returns the buffer as a string. + + + + + Creates a BIO.MemoryBuffer(), calls WriteParametersDER() into this buffer, + then returns the buffer. + + + + + Sets or clears the FlagNoExpConstTime bit in the flags field. + + + + + Flags for the return value of DH_check(). + + + + + + + + + + + + + + + + + + + + + + + + + Wraps the DSA_* functions + + + + + Calls DSA_new() then DSA_generate_parameters_ex() + + + + + Calls DSA_new() then DSA_generate_parameters_ex() + + + + + + + + Calls DSA_new() then DSA_generate_parameters_ex() + + + + + + + + + + Returns PEM_read_bio_DSA_PUBKEY() + + + + + + + Returns PEM_read_bio_DSA_PUBKEY() + + + + + + + Returns PEM_read_bio_DSAPrivateKey() + + + + + + + Returns PEM_read_bio_DSAPrivateKey() + + + + + + + Calls DSA_generate_key() + + + + + Returns DSA_sign() + + + + + + + Returns DSA_verify() + + + + + + + + Calls PEM_write_bio_DSA_PUBKEY() + + + + + + Calls PEM_write_bio_DSAPrivateKey() + + + + + + + + + Calls DSA_print() + + + + + + Calls DSA_free() + + + + + If both objects have a private key, those are compared. + Otherwise just the params and public keys are compared. + + + + + + + Xor of the params, public key, and optionally the private key + + + + + + Returns the p field + + + + + Returns the q field + + + + + Returns the g field + + + + + Returns DSA_size() + + + + + Returns the pub_key field + + + + + Returns the priv_key field + + + + + Returns the pub_key field as a PEM string + + + + + Returns the priv_key field as a PEM string + + + + + Returns the counter + + + + + Returns the h value + + + + + Accessor for the FlagNoExpConstTime flag + + + + + Wraps HMAC + + + + + Calls OPENSSL_malloc() and then HMAC_CTX_init() + + + + + Calls HMAC() + + + + + + + + + Calls HMAC_Init_ex() + + + + + + + Calls HMAC_Update() + + + + + + Calls HMAC_Update() + + + + + + + + Calls HMAC_Final() + + + + + + Calls HMAC_CTX_cleanup() and then OPENSSL_free() + + + + + Simple encapsulation of a local identity. + This includes the private key and the X509Certificate. + + + + + Construct an Identity with a private key + + + + + + Create a X509Request for this identity, using the specified name. + + + + + + + Create a X509Request for this identity, using the specified name and digest. + + + + + + + + Verify that the specified chain can be trusted. + + + + + + + + Returns the embedded public key of the X509Certificate + + + + + Returns the private key + + + + + Returns the X509Certificate + + + + + Wraps the EVP_MD object + + + + + Creates a EVP_MD struct + + + + + + + Prints MessageDigest + + + + + + Not implemented, these objects should never be disposed. + + + + + Calls EVP_get_digestbyname() + + + + + + + EVP_md_null() + + + + + EVP_md4() + + + + + EVP_md5() + + + + + EVP_sha() + + + + + EVP_sha1() + + + + + EVP_sha224() + + + + + EVP_sha256() + + + + + EVP_sha384() + + + + + EVP_sha512() + + + + + EVP_dss() + + + + + EVP_dss1() + + + + + EVP_ripemd160() + + + + + EVP_ecdsa() + + + + + Calls OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH) + + + + + Calls OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH) + + + + + Returns the block_size field + + + + + Returns the md_size field + + + + + Returns the type field using OBJ_nid2ln() + + + + + Returns the type field using OBJ_nid2sn() + + + + + Wraps the EVP_MD_CTX object + + + + + Calls BIO_get_md_ctx() then BIO_get_md() + + + + + + Calls EVP_MD_CTX_create() then EVP_MD_CTX_init() + + + + + + Prints the long name + + + + + + Calls EVP_DigestInit_ex(), EVP_DigestUpdate(), and EVP_DigestFinal_ex() + + + + + + + Calls EVP_DigestInit_ex() + + + + + Calls EVP_DigestUpdate() + + + + + + Calls EVP_DigestFinal_ex() + + + + + + Calls EVP_SignFinal() + + + + + + + Calls EVP_VerifyFinal() + + + + + + + + Calls EVP_DigestInit_ex(), EVP_DigestUpdate(), and EVP_SignFinal() + + + + + + + + Calls EVP_SignFinal() + + + + + + + + + Calls EVP_DigestInit_ex(), EVP_DigestUpdate(), and EVP_VerifyFinal() + + + + + + + + + Calls EVP_VerifyFinal() + + + + + + + + + + Calls EVP_MD_CTX_cleanup() and EVP_MD_CTX_destroy() + + + + + + + + + + + + + + + static class for initialize OpenSSL/Crypto libraries for threading + + + + + Calls Native.InitializeThreads() + + + + + Calls Native.UninitializeThreads() + + + + + This is the low-level C-style interface to the crypto API. + Use this interface with caution. + + + + + This is the name of the DLL that P/Invoke loads and tries to bind all of + these native functions to. + + + + + #define OPENSSL_free(addr) CRYPTO_free(addr) + + + + + + #define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__) + + + + + + + #define SSL_CTX_ctrl in ssl.h - calls SSL_CTX_ctrl() + + + + + + + + #define SSL_CTX_set_options in ssl.h - calls SSL_CTX_ctrl + + + + + + + + #define SSL_CTX_get_mode in ssl.h - calls SSL_CTX_ctrl + + + + + + + #define SSL_CTX_get_options in ssl.h - calls SSL_CTX_ctrl + + + Int32 representation of options set in the context + + + To handle binary (in)compatibility + + + callback-specific data + + + + This is a struct that contains a uint for the native openssl error code. + It provides helper methods to convert this error code into strings. + + + + + Constructs an OpenSslError object. + + The native error code + + + + Returns the native error code + + + + + Returns the result of ERR_lib_error_string() + + + + + Returns the results of ERR_reason_error_string() + + + + + Returns the results of ERR_func_error_string() + + + + + Returns the results of ERR_error_string_n() + + + + + Exception class to provide OpenSSL specific information when errors occur. + + + + + When this class is instantiated, GetErrorMessage() is called automatically. + This will call ERR_get_error() on the native openssl interface, once for every + error that is in the current context. The exception message is the concatination + of each of these errors turned into strings using ERR_error_string_n(). + + + + + Returns the list of errors associated with this exception. + + + + + Callback prototype. Must return the password or prompt for one. + + + + + + + + Simple password callback that returns the contained password. + + + + + Constructs a PasswordCallback + + + + + + Suitable callback to be used as a PasswordHandler + + + + + + + + Wraps PCKS12_* + + + + + Calls PKCS12_create() + + + + + + + + + Calls PKCS12_create() with more options + + + friendly name + + + + How to encrypt the key + How to encrypt the certificate + # of iterations during encryption + + + + + Calls d2i_PKCS12_bio() and then PKCS12_parse() + + + + + + + Calls i2d_PKCS12_bio() + + + + + + Calls PKCS12_free() + + + + + Returns the Certificate, with the PrivateKey attached if there is one. + + + + + Returns the PrivateKey + + + + + Returns a stack of CA Certificates + + + + + Password-Based Encryption (from PKCS #5) + + + + + + + + + + NID_pbeWithMD2AndDES_CBC + + + + + NID_pbeWithMD5AndDES_CBC + + + + + NID_pbeWithMD2AndRC2_CBC + + + + + NID_pbeWithMD5AndRC2_CBC + + + + + NID_pbeWithSHA1AndDES_CBC + + + + + NID_pbeWithSHA1AndRC2_CBC + + + + + NID_pbe_WithSHA1And128BitRC4 + + + + + NID_pbe_WithSHA1And40BitRC4 + + + + + NID_pbe_WithSHA1And3_Key_TripleDES_CBC + + + + + NID_pbe_WithSHA1And2_Key_TripleDES_CBC + + + + + NID_pbe_WithSHA1And128BitRC2_CBC + + + + + NID_pbe_WithSHA1And40BitRC2_CBC + + + + + This is a non standard extension that is only currently interpreted by MSIE + + + + + omit the flag from the private key + + + + + the key can be used for signing only + + + + + the key can be used for signing and encryption + + + + + Wraps PKCS7 + + + + + Calls d2i_PKCS7_bio() + + + + + + + Calls PEM_read_bio_PKCS7() + + + + + + + Calls PKCS7_free() + + + + + Extracts the X509Chain of certifcates from the internal PKCS7 structure + + + + + Exposes the RAND_* functions. + + + + + Calls RAND_seed() + + + + + + Calls RAND_seed() + + + + + + Calls RAND_pseudo_bytes() + + + + + + + Calls RAND_cleanup() + + + + + Calls RAND_bytes() + + + + + + + Calls RAND_add() + + + + + + + Calls RAND_load_file() + + + + + + + Calls RAND_write_file() + + + + + + Calls RAND_file_name() + + + + + + Calls RAND_query_egd_bytes() + + + + + + + + Calls RAND_egd() + + + + + + Calls RAND_egd_bytes() + + + + + + + Calls RAND_poll() + + + + + Calls BN_rand() + + + + + + + + + Returns RAND_status() + + + + + Wraps the RSA_* functions + + + + + Calls RSA_new() + + + + + Calls PEM_read_bio_RSA_PUBKEY() + + + + + + + Calls PEM_read_bio_RSAPrivateKey() + + + + + + + Calls PEM_read_bio_RSA_PUBKEY() + + + + + + + + + Calls PEM_read_bio_RSAPrivateKey() + + + + + + + + + Calls RSA_generate_key_ex() + + + + + + + + + Calls RSA_public_encrypt() + + + + + + + + Calls RSA_private_encrypt() + + + + + + + + Calls RSA_public_decrypt() + + + + + + + + Calls RSA_private_decrypt() + + + + + + + + Calls PEM_write_bio_RSA_PUBKEY() + + + + + + Calls PEM_write_bio_RSAPrivateKey() + + + + + + + + + Returns RSA_check_key() + + + + + + Calls RSA_print() + + + + + + Calls RSA_free() + + + + + Returns RSA_size() + + + + + Not finished + + + + + Accessor for the e field + + + + + Accessor for the n field + + + + + Accessor for the d field + + + + + Accessor for the p field + + + + + Accessor for the q field + + + + + Accessor for the dmp1 field. + d mod (p-1) + + + + + Accessor for the dmq1 field. + d mod (q-1) + + + + + Accessor for the iqmp field. + q^-1 mod p + + + + + Returns the public key field as a PEM string + + + + + Returns the private key field as a PEM string + + + + + RSA padding scheme + + + + + RSA_PKCS1_PADDING + + + + + RSA_SSLV23_PADDING + + + + + RSA_NO_PADDING + + + + + RSA_PKCS1_OAEP_PADDING + Optimal Asymmetric Encryption Padding + + + + + RSA_X931_PADDING + + + + + Override to implement client/server specific handshake processing + + + + + + Renegotiate session keys - calls SSL_renegotiate + + + + + + + + + + + + + + + + + + + + + + + + + + + Implments an AuthenticatedStream and is the main interface to the SSL library. + + + + + Create an SslStream based on an existing stream. + + + + + + Create an SslStream based on an existing stream. + + + + + + + Create an SslStream based on an existing stream. + + + + + + + + Create an SslStream based on an existing stream. + + + + + + + + + Clears all buffers for this stream and causes any buffered data to be written to the underlying device. + + + + + Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. + + + + + + + + + Begins an asynchronous read operation. + + + + + + + + + + + Waits for the pending asynchronous read to complete. + + + + + + + Not supported + + + + + + + + Sets the length of the current stream. + + + + + + Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. + + + + + + + + Begins an asynchronous write operation. + + + + + + + + + + + Ends an asynchronous write operation. + + + + + + Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Returns whether authentication was successful. + + + + + Indicates whether data sent using this SslStream is encrypted. + + + + + Indicates whether both server and client have been authenticated. + + + + + Indicates whether the local side of the connection was authenticated as the server. + + + + + Indicates whether the data sent using this stream is signed. + + + + + Gets a value indicating whether the current stream supports reading. + + + + + Gets a value indicating whether the current stream supports seeking. + + + + + Gets a value indicating whether the current stream supports writing. + + + + + Gets the length in bytes of the stream. + + + + + Gets or sets the position within the current stream. + + + + + Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out. + + + + + Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The Stack class can only contain objects marked with this interface. + + + + + Encapsultes the sk_* functions + + + + + + Calls sk_new_null() + + + + + Calls sk_shift() + + + + + + Calls sk_free() + + + + + Calls sk_dup() + + + + + + Returns sk_find() + + + + + + + Calls sk_insert() + + + + + + + Calls sk_delete() + + + + + + Calls sk_push() + + + + + + Clear all items from the stack + + + + + Returns true if the specified item exists in this stack. + + + + + + + Not implemented + + + + + + + Calls sk_delete_ptr() + + + + + + + Returns an enumerator for this stack + + + + + + Indexer that returns sk_value() or calls sk_insert() + + + + + + + Returns sk_num() + + + + + Returns false. + + + + + Contains the set of elements that make up a Version. + + + + + Create a Version from a raw uint value + + + + + + Conversion to a string. + + + + + + Calls SSLeay_version() + + + + + + Returns the current version of the native library. + + + + + Returns the version that this wrapper is built for. + + + + + Major portion of the Version. + + + + + Minor portion of the Version. + + + + + Fix portion of the Version. + + + + + Patch portion of the Version. These should start at 'a' and continue to 'z'. + + + + + Status portion of the Version. + + + + + The raw uint value. + + + + + Returns the raw status portion of a Version. + + + + + The kinds of status that + + + + + The status nibble has the value 0 + + + + + The status nibble is 1 to 14 (0x0e) + + + + + The status nibble is 0x0f + + + + + SSLEAY_* constants used for with GetVersion() + + + + + SSLEAY_VERSION + + + + + SSLEAY_CFLAGS + + + + + SSLEAY_BUILT_ON + + + + + SSLEAY_PLATFORM + + + + + SSLEAY_DIR + + + + + Wraps the X509 object + + + + + Calls X509_new() + + + + + Calls PEM_read_bio_X509() + + + + + + Factory method that returns a X509 using d2i_X509_bio() + + + + + + + Factory method to create a X509Certificate from a PKCS7 encoded in PEM + + + + + + + Factory method to create a X509Certificate from a PKCS7 encoded in DER + + + + + + + Factory method to create a X509Certificate from a PKCS12 + + + + + + + + Creates a new X509 certificate + + + + + + + + + + + Calls X509_sign() + + + + + + + Returns X509_check_private_key() + + + + + + + Returns X509_check_trust() + + + + + + + + Returns X509_verify() + + + + + + + Returns X509_digest() + + + + + + + + Returns X509_pubkey_digest() + + + + + + + + Calls PEM_write_bio_X509() + + + + + + Calls i2d_X509_bio() + + + + + + Calls X509_print() + + + + + + Converts a X509 into a request using X509_to_X509_REQ() + + + + + + + + Calls X509_add_ext() + + + + + + Calls X509_add1_ext_i2d() + + + + + + + + + + + + + + + Calls X509_free() + + + + + Compares X509Certificate + + + + + + + Returns the hash code of the issuer's oneline xor'd with the serial number + + + + + + Returns X509_cmp() + + + + + + + Uses X509_get_subject_name() and X509_set_issuer_name() + + + + + Uses X509_get_issuer_name() and X509_set_issuer_name() + + + + + Uses X509_get_serialNumber() and X509_set_serialNumber() + + + + + Uses the notBefore field and X509_set_notBefore() + + + + + Uses the notAfter field and X509_set_notAfter() + + + + + Uses the version field and X509_set_version() + + + + + Uses X509_get_pubkey() and X509_set_pubkey() + + + + + Returns whether or not a Private Key is attached to this Certificate + + + + + Gets and Sets the Private Key for this Certificate. + The Private Key MUST match the Public Key. + + + + + Returns the PEM formatted string of this object + + + + + Returns the DER formatted byte array for this object + + + + + + + + + + Used for generating sequence numbers by the CertificateAuthority + + + + + Returns the next available sequence number + + + + + + Implements the ISequenceNumber interface. + The sequence number is read from a file, incremented, + then written back to the file + + + + + Constructs a FileSerialNumber. The path specifies where + the serial number should be read and written to. + + + + + + Implements the Next() method of the ISequenceNumber interface. + The sequence number is read from a file, incremented, + then written back to the file + + + + + + Simple implementation of the ISequenceNumber interface. + + + + + Construct a SimpleSerialNumber with the initial sequence number set to 0. + + + + + Construct a SimpleSerialNumber with the initial sequence number + set to the value specified by the seed parameter. + + + + + + Returns the next available sequence number. + This implementation simply increments the current + sequence number and returns it. + + + + + + High-level interface which does the job of a CA (Certificate Authority) + Duties include processing incoming X509 requests and responding + with signed X509 certificates, signed by this CA's private key. + + + + + Factory method which creates a X509CertifiateAuthority where + the internal certificate is self-signed + + + + + + + + + + + Factory method that creates a X509CertificateAuthority instance with + an internal self signed certificate + + + + + + + + + + + + + Factory method that creates a X509CertificateAuthority instance with + an internal self signed certificate. This method allows creation without + the need for the Configuration file, X509V3Extensions may be added + with the X509V3ExtensionList parameter + + + + + + + + + + + + + Constructs a X509CertifcateAuthority with the specified parameters. + + + + + + + + + Process and X509Request. This includes creating a new X509Certificate + and signing this certificate with this CA's private key. + + + + + + + + + Process and X509Request. This includes creating a new X509Certificate + and signing this certificate with this CA's private key. + + + + + + + + + + Dispose the key, certificate, and the configuration + + + + + Accessor to the CA's X509 Certificate + + + + + Accessor to the CA's key used for signing. + + + + + Contains a chain X509_INFO objects. + + + + + Default null constructor + + + + + Creates a chain from a BIO. Expects the stream to contain + a collection of X509_INFO objects in PEM format by calling + PEM_X509_INFO_read_bio() + + + + + + Creates a new chain from the specified PEM-formatted string + + + + + + Returns X509_find_by_issuer_and_serial() + + + + + + + + Returns X509_find_by_subject() + + + + + + + A List for X509Certificate types. + + + + + Creates an empty X509List + + + + + Calls PEM_x509_INFO_read_bio() + + + + + + Populates this list from a PEM-formatted string + + + + + + Populates this list from a DER buffer. + + + + + + Wraps the X509_EXTENSION object + + + + + Calls X509_EXTENSION_new() + + + + + Calls X509V3_EXT_conf_nid() + + + + + + + + + + Calls X509_EXTENSION_free() + + + + + Calls X509V3_EXT_print() + + + + + + Calls X509_EXTENSION_dup() + + + + + + Uses X509_EXTENSION_get_object() and OBJ_nid2ln() + + + + + Uses X509_EXTENSION_get_object() and OBJ_obj2nid() + + + + + returns X509_EXTENSION_get_critical() + + + + + Returns X509_EXTENSION_get_data() + + + + + X509 Extension entry + + + + + + + + + + + + + + + + + + + + + + + + Dictionary for X509 v3 extensions - Name, Value + + + + + Encapsulates the X509_NAME_* functions + + + + + Calls X509_NAME_new() + + + + + Calls X509_NAME_dup() + + + + + + Calls X509_NAME_new() + + + + + + Parses the string and returns an X509Name based on value. + + + + + + + Calls X509_NAME_add_entry_by_NID after converting the + name to a NID using OBJ_txt2nid() + + + + + + + Calls X509_NAME_add_entry_by_NID() + + + + + + + Returns X509_NAME_get_text_by_NID() + + + + + + + Returns X509_NAME_get_text_by_NID() after converting the name + into a NID using OBJ_txt2nid() + + + + + + + Calls X509_NAME_get_index_by_NID() + + + + + + + + Returns the index of a name entry using GetIndexByNid() + + + + + + + + Returns the index of a name entry using GetIndexByNid() + + + + + + + Returns true if the name entry with the specified name exists. + + + + + + + Returns X509_NAME_digest() + + + + + + + + Calls X509_NAME_print_ex() + + + + + + Calls X509_NAME_free() + + + + + Returns CompareTo(rhs) == 0 + + + + + Returns ToString().GetHashCode() + + + + + Returns X509_NAME_cmp() + + + + + + + Returns X509_NAME_oneline() + + + + + Accessor to the name entry for 'CN' + + + + + Accessor to the name entry for 'C' + + + + + Accessor to the name entry for 'L' + + + + + Accessor to the name entry for 'ST' + + + + + Accessor to the name entry for 'O' + + + + + Accessor to the name entry for 'OU' + + + + + Accessor to the name entry for 'G' + + + + + Accessor to the name entry for 'S' + + + + + Accessor to the name entry for 'I' + + + + + Accessor to the name entry for 'UID' + + + + + Accessor to the name entry for 'SN' + + + + + Accessor to the name entry for 'T' + + + + + Accessor to the name entry for 'D' + + + + + Accessor to the name entry for 'X509' + + + + + Returns X509_NAME_entry_count() + + + + + Indexer to a name entry by name + + + + + + + Indexer to a name entry by index + + + + + + + Wraps the X509_OBJECT: a glorified union + + + + + Calls X509_OBJECT_up_ref_count() + + + + + Calls X509_OBJECT_free_contents() + + + + + Returns a Certificate if the type is X509_LU_X509 + + + + + Returns the PrivateKey if the type is X509_LU_PKEY + + + + + Wraps a X509_REQ object. + + + + + Calls X509_REQ_new() + + + + + Calls X509_REQ_new() and then initializes version, subject, and key. + + + + + + + + Calls PEM_read_bio_X509_REQ() + + + + + + Creates a X509_REQ from a PEM formatted string. + + + + + + Sign this X509Request using the supplied key and digest. + + + + + + + Verify this X509Request against the supplied key. + + + + + + + Calls X509_REQ_print() + + + + + + Calls PEM_write_bio_X509_REQ() + + + + + + Converts this request into a certificate using X509_REQ_to_X509(). + + + + + + + + Calls X509_REQ_free() + + + + + Accessor to the version field. The settor calls X509_REQ_set_version(). + + + + + Accessor to the pubkey field. Uses X509_REQ_get_pubkey() and X509_REQ_set_pubkey() + + + + + Accessor to the subject field. Setter calls X509_REQ_set_subject_name(). + + + + + Returns the PEM formatted string for this object. + + + + + Wraps the X509_STORE object + + + + + Calls X509_STORE_new() + + + + + Initializes the X509Store object with a pre-existing native X509_STORE pointer + + + + + + + Calls X509_STORE_new() and then adds the specified chain as trusted. + + + + + + Calls X509_STORE_new() and then adds the specified chaing as trusted. + + + + + + + Returns the trusted state of the specified certificate + + + + + + + + Adds a chain to the trusted list. + + + + + + Adds a certificate to the trusted list, calls X509_STORE_add_cert() + + + + + + Add an untrusted certificate + + + + + + Calls X509_STORE_free() + + + + + Wraps the objs member on the raw X509_STORE structure + + + + + Accessor to the untrusted list + + + + + Wraps the X509_STORE_CTX object + + + + + Calls X509_STORE_CTX_new() + + + + + Calls X509_STORE_CTX_init() + + + + + + + + Returns X509_verify_cert() + + + + + + Calls X509_STORE_CTX_free() + + + + + Returns X509_STORE_CTX_get_current_cert() + + + + + Returns X509_STORE_CTX_get_error_depth() + + + + + Getter returns X509_STORE_CTX_get_error(), setter calls X509_STORE_CTX_set_error() + + + + + Returns an X509Store based on this context + + + + + Returns X509_verify_cert_error_string() + + + + + Calls SSL_new() + + + + + + Calls SSL_free() + + + + + Returns SSL_CIPHER_name() + + + + + Returns SSL_CIPHER_description() + + + + + Returns SSL_CIPHER_get_bits() + + + + + Wraps the SST_CTX structure and methods + + + + + Calls SSL_CTX_new() + + + + + + Sets the certificate store for the context - calls SSL_CTX_set_cert_store + The X509Store object and contents will be freed when the context is disposed. + Ensure that the store object and it's contents have IsOwner set to false + before assigning them into the context. + + + + + + Sets the certificate verification mode and callback - calls SSL_CTX_set_verify + + + + + + + Sets the certificate verification depth - calls SSL_CTX_set_verify_depth + + + + + + base override - calls SSL_CTX_free() + + + + + Calls SSL_CTX_set_options + + + + + Calls SSL_CTX_set_client_CA_list/SSL_CTX_get_client_CA_list + The Stack and the X509Name objects contined within them + are freed when the context is disposed. Make sure that + the Stack and X509Name objects have set IsOwner to false + before assigning them to the context. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SSL_FILETYPE_PEM + + + + + SSL_FILETYPE_ASN1 + + + + + Options enumeration for Options property + + + + + X509_V_* + + + + + X509_V_OK + + + + + X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT + + + + + X509_V_ERR_UNABLE_TO_GET_CRL + + + + + X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE + + + + + X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE + + + + + X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY + + + + + X509_V_ERR_CERT_SIGNATURE_FAILURE + + + + + X509_V_ERR_CRL_SIGNATURE_FAILURE + + + + + X509_V_ERR_CERT_NOT_YET_VALID + + + + + X509_V_ERR_CERT_HAS_EXPIRED + + + + + X509_V_ERR_CRL_NOT_YET_VALID + + + + + X509_V_ERR_CRL_HAS_EXPIRED + + + + + X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD + + + + + X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD + + + + + X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD + + + + + X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD + + + + + X509_V_ERR_OUT_OF_MEM + + + + + X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT + + + + + X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN + + + + + X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY + + + + + X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE + + + + + X509_V_ERR_CERT_CHAIN_TOO_LONG + + + + + X509_V_ERR_CERT_REVOKED + + + + + X509_V_ERR_INVALID_CA + + + + + X509_V_ERR_PATH_LENGTH_EXCEEDED + + + + + X509_V_ERR_INVALID_PURPOSE + + + + + X509_V_ERR_CERT_UNTRUSTED + + + + + X509_V_ERR_CERT_REJECTED + + + + + X509_V_ERR_SUBJECT_ISSUER_MISMATCH + + + + + X509_V_ERR_AKID_SKID_MISMATCH + + + + + X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH + + + + + X509_V_ERR_KEYUSAGE_NO_CERTSIGN + + + + + X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER + + + + + X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION + + + + + X509_V_ERR_KEYUSAGE_NO_CRL_SIGN + + + + + X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION + + + + + X509_V_ERR_INVALID_NON_CA + + + + + X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED + + + + + X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE + + + + + X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED + + + + + X509_V_ERR_APPLICATION_VERIFICATION + + + + + Wraps the SSL_METHOD structure and methods + + + + + Throws NotImplementedException() + + + + + SSLv2_method() + + + + + SSLv2_server_method() + + + + + SSLv2_client_method() + + + + + SSLv3_method() + + + + + SSLv3_server_method() + + + + + SSLv3_client_method() + + + + + SSLv23_method() + + + + + SSLv23_server_method() + + + + + SSLv23_client_method() + + + + + TLSv1_method() + + + + + TLSv1_server_method() + + + + + TLSv1_client_method() + + + + + DTLSv1_method() + + + + + DTLSv1_server_method() + + + + + DTLSv1_client_method() + + + + + Wraps the BN_* set of functions. + + + + + Creates a BigNumber object by calling BN_value_one() + + + + + Calls BN_new() + + + + + Calls BN_dup() on the BigNumber passed in. + + + + + + Creates a BigNumber by calling BN_set_word() + + + + + + Calls BN_dec2bn() + + + + + + + Calls BN_hex2bn() + + + + + + + Calls BN_bin2bn() + + + + + + + Calls BN_bn2dec() + + + + + + Calls BN_bn2hex() + + + + + + Calls BN_get_word() + + + + + + + Creates a new BigNumber object from a uint. + + + + + + + Calls BN_bn2bin() + + + + + + + Calls BN_bn2bin() + + + + + + Calls BN_clear() + + + + + Calls BN_rand_range() + + + + + + + Calls BN_pseudo_rand() + + + + + + + + + Calls BN_pseudo_rand_range() + + + + + + + Calls BN_add() + + + + + + + + Calls BN_sub() + + + + + + + + Determines if lhs is by-value equal to rhs + + + + + + + + Determines if lhs is by-value different than rhs + + + + + + + + Calls BN_cmp() + + + + + + + Creates a hash code by converting this object to a decimal string and + returns the hash code of that string. + + + + + + Calls BN_print() + + + + + + Calls BN_free() + + + + + Calls BN_cmp() + + + + + + + Calls BN_options() + + + + + Returns BN_num_bits() + + + + + Converts the result of Bits into the number of bytes. + + + + + Generator callback. Used mostly for status indications for long- + running generator functions. + + + + + + + + diff --git a/openssl/openssl-net-0.5/ManagedOpenSsl.dll b/openssl/openssl-net-0.5/ManagedOpenSsl.dll new file mode 100755 index 00000000..f547fbb5 Binary files /dev/null and b/openssl/openssl-net-0.5/ManagedOpenSsl.dll differ diff --git a/openssl/openssl-net-0.5/libeay32.dll b/openssl/openssl-net-0.5/libeay32.dll new file mode 100755 index 00000000..d0f48bb5 Binary files /dev/null and b/openssl/openssl-net-0.5/libeay32.dll differ diff --git a/openssl/openssl-net-0.5/ssleay32.dll b/openssl/openssl-net-0.5/ssleay32.dll new file mode 100755 index 00000000..d28499b3 Binary files /dev/null and b/openssl/openssl-net-0.5/ssleay32.dll differ diff --git a/shadowsocks-csharp.sln b/shadowsocks-csharp.sln index b4c94aa9..c98f328b 100755 --- a/shadowsocks-csharp.sln +++ b/shadowsocks-csharp.sln @@ -6,13 +6,20 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|x86.ActiveCfg = Debug|x86 + {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|x86.Build.0 = Debug|x86 + {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|x86.Deploy.0 = Debug|x86 {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|Any CPU.ActiveCfg = Release|Any CPU {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|Any CPU.Build.0 = Release|Any CPU + {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|x86.ActiveCfg = Release|x86 + {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/shadowsocks-csharp/Encryptor.cs b/shadowsocks-csharp/Encryptor.cs index 76907635..73437a17 100755 --- a/shadowsocks-csharp/Encryptor.cs +++ b/shadowsocks-csharp/Encryptor.cs @@ -2,18 +2,54 @@ using System.Collections.Generic; using System.Text; using System.Security.Cryptography; +using OpenSSL.Core; +using OpenSSL.Crypto; +using System.Runtime.InteropServices; namespace shadowsocks_csharp { - class Encryptor + class Encryptor : IDisposable { - public const int TYPE_TABLE = 1; - public const int TYPE_RC4 = 2; + public static string[] encryption_names = new string[] { + "table", + "rc4", + "aes-256-cfb", + "aes-192-cfb", + "aes-128-cfb", + "bf-cfb" + }; public byte[] encryptTable = new byte[256]; public byte[] decryptTable = new byte[256]; - public int method = TYPE_TABLE; - public RC4 rc4 = null; + public string method = "table"; + public string password; + public byte[] key; + private RC4 rc4 = null; + private Cipher cipher = null; + private IntPtr encryptCTX; + private IntPtr decryptCTX; + private static Dictionary cachedKeys = new Dictionary(); + private static Dictionary cachedCiphers = new Dictionary(); + + public void Dispose() + { + if (encryptCTX != IntPtr.Zero) + { + Native.EVP_CIPHER_CTX_cleanup(encryptCTX); + Native.OPENSSL_free(encryptCTX); + encryptCTX = IntPtr.Zero; + } + if (decryptCTX != IntPtr.Zero) + { + Native.EVP_CIPHER_CTX_cleanup(decryptCTX); + Native.OPENSSL_free(decryptCTX); + decryptCTX = IntPtr.Zero; + } + } + + ~Encryptor() { + Dispose(); + } private long compare(byte x, byte y, ulong a, int i) { @@ -64,16 +100,21 @@ namespace shadowsocks_csharp byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(password); byte[] hash = md5.ComputeHash(inputBytes); + encryptCTX = IntPtr.Zero; + decryptCTX = IntPtr.Zero; + + this.method = method; + this.password = password; if (method != null && method.ToLowerInvariant().Equals("rc4")) { Console.WriteLine("init rc4"); - this.method = TYPE_RC4; rc4 = new RC4(); encryptTable = rc4.EncryptInitalize(hash); decryptTable = rc4.EncryptInitalize(hash); - } else { + } + else if (method == "table" || method == "" || method == null) + { Console.WriteLine("init table"); - this.method = TYPE_TABLE; // TODO endian var a = BitConverter.ToUInt64(hash, 0); @@ -90,32 +131,135 @@ namespace shadowsocks_csharp decryptTable[encryptTable[i]] = (byte)i; } } + else + { + initKey(password, method); + } + } + + private void initCipher(ref IntPtr ctx, byte[] iv, bool isCipher) + { + ctx = Native.OPENSSL_malloc(Marshal.SizeOf(typeof(CipherContext.EVP_CIPHER_CTX))); + int enc = isCipher ? 1 : 0; + Native.EVP_CIPHER_CTX_init(ctx); + Native.ExpectSuccess(Native.EVP_CipherInit_ex( + ctx, this.cipher.Handle, IntPtr.Zero, null, null, enc)); + Native.ExpectSuccess(Native.EVP_CIPHER_CTX_set_key_length(ctx, key.Length)); + Native.ExpectSuccess(Native.EVP_CIPHER_CTX_set_padding(ctx, 1)); + Native.ExpectSuccess(Native.EVP_CipherInit_ex( + ctx, this.cipher.Handle, IntPtr.Zero, key, iv, enc)); + } + + private void initKey(string password, string method) + { + string k = method + ":" + password; + if (cachedKeys.ContainsKey(k)) + { + key = cachedKeys[k]; + cipher = cachedCiphers[k]; + return; + } + cipher = Cipher.CreateByName(method); + if (cipher == null) + { + throw new NullReferenceException(); + } + byte[] passbuf = System.Text.Encoding.UTF8.GetBytes(password); ; + key = new byte[cipher.KeyLength]; + byte[] iv = new byte[cipher.IVLength]; + Native.EVP_BytesToKey(cipher.Handle, MessageDigest.MD5.Handle, null, passbuf, passbuf.Length, 1, key, iv); + cachedKeys[k] = key; + cachedCiphers[k] = cipher; + } + + private byte[] sslEncrypt(byte[] buf, int length) + { + if (encryptCTX == IntPtr.Zero) + { + int ivLen = cipher.IVLength; + byte[] iv = new byte[ivLen]; + Native.RAND_bytes(iv, iv.Length); + initCipher(ref encryptCTX, iv, true); + int outLen = length + cipher.BlockSize; + byte[] cipherText = new byte[outLen]; + Native.EVP_CipherUpdate(encryptCTX, cipherText, out outLen, buf, length); + byte[] result = new byte[outLen + ivLen]; + System.Buffer.BlockCopy(iv, 0, result, 0, ivLen); + System.Buffer.BlockCopy(cipherText, 0, result, ivLen, outLen); + return result; + } + else + { + int outLen = length + cipher.BlockSize; + byte[] cipherText = new byte[outLen]; + Native.EVP_CipherUpdate(encryptCTX, cipherText, out outLen, buf, length); + byte[] result = new byte[outLen]; + System.Buffer.BlockCopy(cipherText, 0, result, 0, outLen); + return result; + } + } + + private byte[] sslDecrypt(byte[] buf, int length) + { + if (decryptCTX == IntPtr.Zero) + { + int ivLen = cipher.IVLength; + byte[] iv = new byte[ivLen]; + System.Buffer.BlockCopy(buf, 0, iv, 0, ivLen); + initCipher(ref decryptCTX, iv, false); + int outLen = length + cipher.BlockSize; + outLen -= ivLen; + byte[] cipherText = new byte[outLen]; + byte[] subset = new byte[length - ivLen]; + System.Buffer.BlockCopy(buf, ivLen, subset, 0, length - ivLen); + Native.EVP_CipherUpdate(decryptCTX, cipherText, out outLen, subset, length - ivLen); + byte[] result = new byte[outLen]; + System.Buffer.BlockCopy(cipherText, 0, result, 0, outLen); + return result; + } + else + { + int outLen = length + cipher.BlockSize; + byte[] cipherText = new byte[outLen]; + Native.EVP_CipherUpdate(decryptCTX, cipherText, out outLen, buf, length); + byte[] result = new byte[outLen]; + System.Buffer.BlockCopy(cipherText, 0, result, 0, outLen); + return result; + } } - public void Encrypt(byte[] buf, int length) + public byte[] Encrypt(byte[] buf, int length) { switch (method) { - case TYPE_TABLE: + case "table": for (int i = 0; i < length; i++) buf[i] = encryptTable[buf[i]]; + return buf; break; - case TYPE_RC4: + case "rc4": rc4.Encrypt(encryptTable, buf, length); + return buf; break; + default: + return sslEncrypt(buf, length); } } - public void Decrypt(byte[] buf, int length) + public byte[] Decrypt(byte[] buf, int length) { switch (method) { - case TYPE_TABLE: + case "table": for (int i = 0; i < length; i++) buf[i] = decryptTable[buf[i]]; + return buf; break; - case TYPE_RC4: + case "rc4": rc4.Decrypt(decryptTable, buf, length); + return buf; break; + default: + return sslDecrypt(buf, length); } } } diff --git a/shadowsocks-csharp/Form1.Designer.cs b/shadowsocks-csharp/Form1.Designer.cs index b8162824..25105c51 100755 --- a/shadowsocks-csharp/Form1.Designer.cs +++ b/shadowsocks-csharp/Form1.Designer.cs @@ -81,16 +81,16 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(203, 131); + this.tableLayoutPanel1.Size = new System.Drawing.Size(196, 131); this.tableLayoutPanel1.TabIndex = 0; // // label5 // this.label5.Anchor = System.Windows.Forms.AnchorStyles.Right; this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(12, 110); + this.label5.Location = new System.Drawing.Point(11, 111); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(58, 15); + this.label5.Size = new System.Drawing.Size(52, 13); this.label5.TabIndex = 8; this.label5.Text = "Encryptor"; // @@ -98,9 +98,9 @@ // this.label1.Anchor = System.Windows.Forms.AnchorStyles.Right; this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(14, 5); + this.label1.Location = new System.Drawing.Point(12, 6); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(56, 15); + this.label1.Size = new System.Drawing.Size(51, 13); this.label1.TabIndex = 0; this.label1.Text = "Server IP"; // @@ -108,9 +108,9 @@ // this.label2.Anchor = System.Windows.Forms.AnchorStyles.Right; this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(3, 31); + this.label2.Location = new System.Drawing.Point(3, 32); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(67, 15); + this.label2.Size = new System.Drawing.Size(60, 13); this.label2.TabIndex = 1; this.label2.Text = "Server Port"; // @@ -122,8 +122,14 @@ this.comboBox1.ItemHeight = 13; this.comboBox1.Items.AddRange(new object[] { "table", + "aes-256-cfb", + "aes-192-cfb", + "aes-128-cfb", + "bf-cfb", + "cast5-cfb", + "des-cfb", "rc4"}); - this.comboBox1.Location = new System.Drawing.Point(76, 107); + this.comboBox1.Location = new System.Drawing.Point(69, 107); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(124, 21); this.comboBox1.TabIndex = 9; @@ -132,9 +138,9 @@ // this.label3.Anchor = System.Windows.Forms.AnchorStyles.Right; this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(9, 57); + this.label3.Location = new System.Drawing.Point(10, 58); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(61, 15); + this.label3.Size = new System.Drawing.Size(53, 13); this.label3.TabIndex = 2; this.label3.Text = "Password"; // @@ -142,16 +148,16 @@ // this.label4.Anchor = System.Windows.Forms.AnchorStyles.Right; this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(8, 83); + this.label4.Location = new System.Drawing.Point(8, 84); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(62, 15); + this.label4.Size = new System.Drawing.Size(55, 13); this.label4.TabIndex = 3; this.label4.Text = "Proxy Port"; // // textBox1 // this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.textBox1.Location = new System.Drawing.Point(76, 3); + this.textBox1.Location = new System.Drawing.Point(69, 3); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(124, 20); this.textBox1.TabIndex = 4; @@ -160,7 +166,7 @@ // textBox2 // this.textBox2.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.textBox2.Location = new System.Drawing.Point(76, 29); + this.textBox2.Location = new System.Drawing.Point(69, 29); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(124, 20); this.textBox2.TabIndex = 5; @@ -169,7 +175,7 @@ // textBox3 // this.textBox3.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.textBox3.Location = new System.Drawing.Point(76, 55); + this.textBox3.Location = new System.Drawing.Point(69, 55); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(124, 20); this.textBox3.TabIndex = 6; @@ -178,7 +184,7 @@ // textBox4 // this.textBox4.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.textBox4.Location = new System.Drawing.Point(76, 81); + this.textBox4.Location = new System.Drawing.Point(69, 81); this.textBox4.Name = "textBox4"; this.textBox4.Size = new System.Drawing.Size(124, 20); this.textBox4.TabIndex = 7; @@ -201,32 +207,32 @@ this.QuitItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; - this.contextMenuStrip1.Size = new System.Drawing.Size(123, 82); + this.contextMenuStrip1.Size = new System.Drawing.Size(112, 76); // // ConfigItem // this.ConfigItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); this.ConfigItem.Name = "ConfigItem"; - this.ConfigItem.Size = new System.Drawing.Size(122, 24); + this.ConfigItem.Size = new System.Drawing.Size(111, 22); this.ConfigItem.Text = "Config"; this.ConfigItem.Click += new System.EventHandler(this.Config_Click); // // aboutToolStripMenuItem // this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; - this.aboutToolStripMenuItem.Size = new System.Drawing.Size(122, 24); + this.aboutToolStripMenuItem.Size = new System.Drawing.Size(111, 22); this.aboutToolStripMenuItem.Text = "About"; this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(119, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(108, 6); // // QuitItem // this.QuitItem.Name = "QuitItem"; - this.QuitItem.Size = new System.Drawing.Size(122, 24); + this.QuitItem.Size = new System.Drawing.Size(111, 22); this.QuitItem.Text = "Quit"; this.QuitItem.Click += new System.EventHandler(this.Quit_Click); // diff --git a/shadowsocks-csharp/Form1.cs b/shadowsocks-csharp/Form1.cs index 9543b4d6..3ff539d8 100755 --- a/shadowsocks-csharp/Form1.cs +++ b/shadowsocks-csharp/Form1.cs @@ -90,9 +90,9 @@ namespace shadowsocks_csharp { MessageBox.Show("there is format problem"); } - catch (Exception) + catch (Exception ex) { - MessageBox.Show("there is some problem with parameters"); + MessageBox.Show(ex.ToString()); } } diff --git a/shadowsocks-csharp/Local.cs b/shadowsocks-csharp/Local.cs index 2dd7108c..9467fe91 100755 --- a/shadowsocks-csharp/Local.cs +++ b/shadowsocks-csharp/Local.cs @@ -62,7 +62,7 @@ namespace shadowsocks_csharp // Create the state object. Handler handler = new Handler(); handler.connection = conn; - if (encryptor.method == Encryptor.TYPE_TABLE) { + if (encryptor.method == "table") { handler.encryptor = encryptor; } else { handler.encryptor = new Encryptor(config.method, config.password); @@ -128,11 +128,12 @@ namespace shadowsocks_csharp public void Close() { - connection.Close(); + connection.Shutdown(SocketShutdown.Send); if (remote != null) { - remote.Close(); + remote.Shutdown(SocketShutdown.Send); } + encryptor.Dispose(); } private void connectCallback(IAsyncResult ar) @@ -264,8 +265,8 @@ namespace shadowsocks_csharp if (bytesRead > 0) { - encryptor.Decrypt(remoteBuffer, bytesRead); - connection.BeginSend(remoteBuffer, 0, bytesRead, 0, new AsyncCallback(pipeConnectionSendCallback), null); + byte[] buf = encryptor.Decrypt(remoteBuffer, bytesRead); + connection.BeginSend(buf, 0, buf.Length, 0, new AsyncCallback(pipeConnectionSendCallback), null); } else { @@ -289,8 +290,8 @@ namespace shadowsocks_csharp if (bytesRead > 0) { - encryptor.Encrypt(connetionBuffer, bytesRead); - remote.BeginSend(connetionBuffer, 0, bytesRead, 0, new AsyncCallback(pipeRemoteSendCallback), null); + byte[] buf = encryptor.Encrypt(connetionBuffer, bytesRead); + remote.BeginSend(buf, 0, buf.Length, 0, new AsyncCallback(pipeRemoteSendCallback), null); } else { diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 9971b185..1578c51a 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -56,7 +56,28 @@ 4 false + + true + bin\x86\Debug\ + TRACE;DEBUG;SIMPLE_JSON_NO_LINQ_EXPRESSION + full + x86 + prompt + ManagedMinimumRules.ruleset + + + bin\x86\Release\ + TRACE;SIMPLE_JSON_NO_LINQ_EXPRESSION + true + pdbonly + x86 + prompt + ManagedMinimumRules.ruleset + + + ..\openssl\openssl-net-0.5\ManagedOpenSsl.dll +