diff --git a/openssl/libeay32.dll b/openssl/libeay32.dll new file mode 100755 index 00000000..ab954811 Binary files /dev/null and b/openssl/libeay32.dll differ diff --git a/openssl/openssl-net-0.5/ManagedOpenSsl.XML b/openssl/openssl-net-0.5/ManagedOpenSsl.XML deleted file mode 100755 index acb72113..00000000 --- a/openssl/openssl-net-0.5/ManagedOpenSsl.XML +++ /dev/null @@ -1,4929 +0,0 @@ - - - - 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 deleted file mode 100755 index f547fbb5..00000000 Binary files a/openssl/openssl-net-0.5/ManagedOpenSsl.dll and /dev/null differ diff --git a/openssl/openssl-net-0.5/libeay32.dll b/openssl/openssl-net-0.5/libeay32.dll deleted file mode 100755 index d0f48bb5..00000000 Binary files a/openssl/openssl-net-0.5/libeay32.dll and /dev/null differ diff --git a/openssl/openssl-net-0.5/ssleay32.dll b/openssl/openssl-net-0.5/ssleay32.dll deleted file mode 100755 index d28499b3..00000000 Binary files a/openssl/openssl-net-0.5/ssleay32.dll and /dev/null differ diff --git a/shadowsocks-csharp/Encrypt/EncryptorFactory.cs b/shadowsocks-csharp/Encrypt/EncryptorFactory.cs index 430ce56b..df3a975c 100644 --- a/shadowsocks-csharp/Encrypt/EncryptorFactory.cs +++ b/shadowsocks-csharp/Encrypt/EncryptorFactory.cs @@ -10,11 +10,6 @@ namespace shadowsocks_csharp.Encrypt return new TableEncryptor(method, password); } - if (method.ToLowerInvariant() == "rc4") - { - return new Rc4Encryptor(method, password); - } - return new OpensslEncryptor(method, password); } } diff --git a/shadowsocks-csharp/Encrypt/OpenSSL.cs b/shadowsocks-csharp/Encrypt/OpenSSL.cs new file mode 100755 index 00000000..53d65ac7 --- /dev/null +++ b/shadowsocks-csharp/Encrypt/OpenSSL.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace shadowsocks_csharp.Encrypt +{ + public class OpenSSL + { + const string DLLNAME = "libeay32"; + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static void OpenSSL_add_all_ciphers(); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static IntPtr EVP_md5(); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static int EVP_BytesToKey(IntPtr type, IntPtr md, IntPtr salt, byte[] data, int datal, int count, byte[] key, byte[] iv); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static int RAND_bytes(byte[] buf, int num); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static IntPtr EVP_get_cipherbyname(byte[] name); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static IntPtr EVP_CIPHER_CTX_new(); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static int EVP_CipherInit_ex(IntPtr ctx, IntPtr type, IntPtr impl, byte[] key, byte[] iv, int enc); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static int EVP_CIPHER_CTX_cleanup(IntPtr a); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static int EVP_CIPHER_CTX_free(IntPtr a); + + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static int EVP_CipherUpdate(IntPtr ctx, byte[] outb, out int outl, byte[] inb, int inl); + + + } +} diff --git a/shadowsocks-csharp/Encrypt/OpensslEncryptor.cs b/shadowsocks-csharp/Encrypt/OpensslEncryptor.cs index 390d0df3..1a7909d7 100644 --- a/shadowsocks-csharp/Encrypt/OpensslEncryptor.cs +++ b/shadowsocks-csharp/Encrypt/OpensslEncryptor.cs @@ -1,6 +1,4 @@ -using OpenSSL.Core; -using OpenSSL.Crypto; -using System; +using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; @@ -9,7 +7,14 @@ namespace shadowsocks_csharp.Encrypt { public class OpensslEncryptor : EncryptorBase, IDisposable - { + { + static Dictionary ciphers = new Dictionary { + {"aes-128-cfb", new int[]{16, 16}}, + {"aes-192-cfb", new int[]{24, 16}}, + {"aes-256-cfb", new int[]{32, 16}}, + {"bf-cfb", new int[]{16, 8}}, + {"rc4", new int[]{16, 0}}, + }; public OpensslEncryptor(string method, string password) : base(method, password) { @@ -20,23 +25,22 @@ namespace shadowsocks_csharp.Encrypt { if (_encryptCtx == IntPtr.Zero) { - int ivLen = _cipher.IVLength; byte[] iv = new byte[ivLen]; - Native.RAND_bytes(iv, iv.Length); + OpenSSL.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); + int outLen = length + ivLen; + byte[] cipherText = new byte[outLen]; + OpenSSL.EVP_CipherUpdate(_encryptCtx, cipherText, out outLen, buf, length); byte[] result = new byte[outLen + ivLen]; Buffer.BlockCopy(iv, 0, result, 0, ivLen); 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); + { + int outLen = length + ivLen; + byte[] cipherText = new byte[outLen]; + OpenSSL.EVP_CipherUpdate(_encryptCtx, cipherText, out outLen, buf, length); byte[] result = new byte[outLen]; Buffer.BlockCopy(cipherText, 0, result, 0, outLen); return result; @@ -47,25 +51,24 @@ namespace shadowsocks_csharp.Encrypt { if (_decryptCtx == IntPtr.Zero) { - int ivLen = _cipher.IVLength; byte[] iv = new byte[ivLen]; Buffer.BlockCopy(buf, 0, iv, 0, ivLen); - InitCipher(ref _decryptCtx, iv, false); - int outLen = length + _cipher.BlockSize; + InitCipher(ref _decryptCtx, iv, false); + int outLen = length + ivLen; outLen -= ivLen; byte[] cipherText = new byte[outLen]; byte[] subset = new byte[length - ivLen]; - Buffer.BlockCopy(buf, ivLen, subset, 0, length - ivLen); - Native.EVP_CipherUpdate(_decryptCtx, cipherText, out outLen, subset, length - ivLen); + Buffer.BlockCopy(buf, ivLen, subset, 0, length - ivLen); + OpenSSL.EVP_CipherUpdate(_decryptCtx, cipherText, out outLen, subset, length - ivLen); byte[] result = new byte[outLen]; 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); + { + int outLen = length + ivLen; + byte[] cipherText = new byte[outLen]; + OpenSSL.EVP_CipherUpdate(_decryptCtx, cipherText, out outLen, buf, length); byte[] result = new byte[outLen]; Buffer.BlockCopy(cipherText, 0, result, 0, outLen); return result; @@ -73,43 +76,44 @@ namespace shadowsocks_csharp.Encrypt } private static readonly Dictionary CachedKeys = new Dictionary(); - private static readonly Dictionary CachedCiphers = new Dictionary(); private byte[] _key; - private Cipher _cipher; - private IntPtr _encryptCtx; - private IntPtr _decryptCtx; + private IntPtr _encryptCtx; + private IntPtr _decryptCtx; + private IntPtr _cipher; + private int keyLen; + private int ivLen; - private void InitKey(string method, string password) - { - 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(); + private void InitKey(string method, string password) + { + OpenSSL.OpenSSL_add_all_ciphers(); + method = method.ToLower(); + string k = method + ":" + password; + _cipher = OpenSSL.EVP_get_cipherbyname(System.Text.Encoding.UTF8.GetBytes(method)); + if (_cipher == null) + { + throw new Exception("method not found"); + } + keyLen = ciphers[method][0]; + ivLen = ciphers[method][1]; + if (CachedKeys.ContainsKey(k)) + { + _key = CachedKeys[k]; + } + else + { + byte[] passbuf = Encoding.UTF8.GetBytes(password); + _key = new byte[32]; + byte[] iv = new byte[16]; + OpenSSL.EVP_BytesToKey(_cipher, OpenSSL.EVP_md5(), IntPtr.Zero, passbuf, passbuf.Length, 1, _key, iv); + CachedKeys[k] = _key; } - byte[] passbuf = 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 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, _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, _cipher.Handle, IntPtr.Zero, _key, iv, enc)); + { + ctx = OpenSSL.EVP_CIPHER_CTX_new(); + int enc = isCipher ? 1 : 0; + OpenSSL.EVP_CipherInit_ex(ctx, _cipher, IntPtr.Zero, _key, iv, enc); } #region IDisposable @@ -136,15 +140,15 @@ namespace shadowsocks_csharp.Encrypt } if (_encryptCtx != IntPtr.Zero) - { - Native.EVP_CIPHER_CTX_cleanup(_encryptCtx); - Native.OPENSSL_free(_encryptCtx); + { + OpenSSL.EVP_CIPHER_CTX_cleanup(_encryptCtx); + OpenSSL.EVP_CIPHER_CTX_free(_encryptCtx); _encryptCtx = IntPtr.Zero; } if (_decryptCtx != IntPtr.Zero) - { - Native.EVP_CIPHER_CTX_cleanup(_decryptCtx); - Native.OPENSSL_free(_decryptCtx); + { + OpenSSL.EVP_CIPHER_CTX_cleanup(_decryptCtx); + OpenSSL.EVP_CIPHER_CTX_free(_decryptCtx); _decryptCtx = IntPtr.Zero; } diff --git a/shadowsocks-csharp/Encrypt/RC4Encryptor.cs b/shadowsocks-csharp/Encrypt/RC4Encryptor.cs deleted file mode 100644 index 03d41f20..00000000 --- a/shadowsocks-csharp/Encrypt/RC4Encryptor.cs +++ /dev/null @@ -1,81 +0,0 @@ - -namespace shadowsocks_csharp.Encrypt -{ - public class Rc4Encryptor - : EncryptorBase - { - public Rc4Encryptor(string method, string password) - : base(method, password) - { - byte[] hash = GetPasswordHash(); - _encryptTable = EncryptInitalize(hash); - _decryptTable = EncryptInitalize(hash); - } - - public override byte[] Encrypt(byte[] buf, int length) - { - return EncryptOutput(enc_ctx, _encryptTable, buf, length); - } - - public override byte[] Decrypt(byte[] buf, int length) - { - return EncryptOutput(dec_ctx, _decryptTable, buf, length); - } - - private readonly byte[] _encryptTable = new byte[256]; - private readonly byte[] _decryptTable = new byte[256]; - - private Context enc_ctx = new Context(); - private Context dec_ctx = new Context(); - - private byte[] EncryptOutput(Context ctx, byte[] s, byte[] data, int length) - { - byte[] result = new byte[length]; - for (int n = 0; n < length; n++) - { - byte b = data[n]; - - ctx.Index1 = (ctx.Index1 + 1) & 255; - ctx.Index2 = (ctx.Index2 + s[ctx.Index1]) & 255; - - Swap(s, ctx.Index1, ctx.Index2); - - result[n] = (byte)(b ^ s[(s[ctx.Index1] + s[ctx.Index2]) & 255]); - } - return result; - } - - private byte[] EncryptInitalize(byte[] key) - { - var s = new byte[256]; - - for (int i = 0; i < 256; i++) - { - s[i] = (byte)i; - } - - for (int i = 0, j = 0; i < 256; i++) - { - j = (j + key[i % key.Length] + s[i]) & 255; - - Swap(s, i, j); - } - - return s; - } - - private static void Swap(byte[] s, int i, int j) - { - byte c = s[i]; - - s[i] = s[j]; - s[j] = c; - } - - class Context - { - public int Index1; - public int Index2; - } - } -} diff --git a/shadowsocks-csharp/Encryptor.cs b/shadowsocks-csharp/Encryptor.cs deleted file mode 100755 index 366e2d47..00000000 --- a/shadowsocks-csharp/Encryptor.cs +++ /dev/null @@ -1,277 +0,0 @@ -using System; -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 : IDisposable - { - 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 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) - { - return (long)(a % (ulong)(x + i)) - (long)(a % (ulong)(y + i)); - } - - private byte[] mergeSort(byte[] array, ulong a, int j) - { - if (array.Length == 1) - return array; - int middle = array.Length / 2; - byte[] left = new byte[middle]; - for (int i = 0; i < middle; i++) - { - left[i] = array[i]; - } - byte[] right = new byte[array.Length - middle]; - for (int i = 0; i < array.Length - middle; i++) - { - right[i] = array[i + middle]; - } - left = mergeSort(left, a, j); - right = mergeSort(right, a, j); - - int leftptr = 0; - int rightptr = 0; - - byte[] sorted = new byte[array.Length]; - for (int k = 0; k < array.Length; k++) - { - if (rightptr == right.Length || ((leftptr < left.Length) && (compare(left[leftptr], right[rightptr], a, j) <= 0))) - { - sorted[k] = left[leftptr]; - leftptr++; - } - else if (leftptr == left.Length || ((rightptr < right.Length) && (compare(right[rightptr], left[leftptr], a, j)) <= 0)) - { - sorted[k] = right[rightptr]; - rightptr++; - } - } - return sorted; - } - - public Encryptor(string method, string password) - { - MD5 md5 = System.Security.Cryptography.MD5.Create(); - 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"); - - rc4 = new RC4(); - encryptTable = rc4.EncryptInitalize(hash); - decryptTable = rc4.EncryptInitalize(hash); - } - else if (method == "table" || method == "" || method == null) - { - Console.WriteLine("init table"); - - // TODO endian - var a = BitConverter.ToUInt64(hash, 0); - for (int i = 0; i < 256; i++) - { - encryptTable[i] = (byte)i; - } - for (int i = 1; i < 1024; i++) - { - encryptTable = mergeSort(encryptTable, a, i); - } - for (int i = 0; i < 256; i++) - { - 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 byte[] byteArrayWith(byte[] buf, int length) - { - if (buf.Length == length) - { - return buf; - } - byte[] result = new byte[length]; - System.Buffer.BlockCopy(buf, 0, result, 0, length); - return result; - } - - public byte[] Encrypt(byte[] buf, int length) - { - switch (method) - { - case "table": - for (int i = 0; i < length; i++) - buf[i] = encryptTable[buf[i]]; - return byteArrayWith(buf, length); - break; - case "rc4": - rc4.Encrypt(encryptTable, buf, length); - return byteArrayWith(buf, length); - break; - default: - return sslEncrypt(buf, length); - } - } - public byte[] Decrypt(byte[] buf, int length) - { - switch (method) - { - case "table": - for (int i = 0; i < length; i++) - buf[i] = decryptTable[buf[i]]; - return byteArrayWith(buf, length); - break; - case "rc4": - rc4.Decrypt(decryptTable, buf, length); - return byteArrayWith(buf, length); - break; - default: - return sslDecrypt(buf, length); - } - } - } -} diff --git a/shadowsocks-csharp/Form1.Designer.cs b/shadowsocks-csharp/Form1.Designer.cs index 25105c51..20273050 100755 --- a/shadowsocks-csharp/Form1.Designer.cs +++ b/shadowsocks-csharp/Form1.Designer.cs @@ -122,12 +122,11 @@ this.comboBox1.ItemHeight = 13; this.comboBox1.Items.AddRange(new object[] { "table", + "rc4-md5", "aes-256-cfb", "aes-192-cfb", "aes-128-cfb", "bf-cfb", - "cast5-cfb", - "des-cfb", "rc4"}); this.comboBox1.Location = new System.Drawing.Point(69, 107); this.comboBox1.Name = "comboBox1"; diff --git a/shadowsocks-csharp/Properties/AssemblyInfo.cs b/shadowsocks-csharp/Properties/AssemblyInfo.cs index 9aa38696..49cbb14f 100755 --- a/shadowsocks-csharp/Properties/AssemblyInfo.cs +++ b/shadowsocks-csharp/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("shadowsocks-csharp")] -[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/shadowsocks-csharp/Test.cs b/shadowsocks-csharp/Test.cs deleted file mode 100755 index 1c29c771..00000000 --- a/shadowsocks-csharp/Test.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; - -namespace shadowsocks_csharp -{ - class Test - { - private static byte[][] target = new byte[][] {new byte[]{60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190, 171, 115, 65, 38, 41, 21, 245, 236, 46, 121, 62, 166, 233, 44, 154, 153, 145, 230, 49, 128, 216, 173, 29, 241, 119, 64, 229, 194, 103, 131, 110, 26, 197, 218, 59, 204, 56, 27, 34, 141, 221, 149, 239, 192, 195, 24, 155, 170, 183, 11, 254, 213, 37, 137, 226, 75, 203, 55, 19, 72, 248, 22, 129, 33, 175, 178, 10, 198, 71, 77, 36, 113, 167, 48, 2, 117, 140, 142, 66, 199, 232, 243, 32, 123, 54, 51, 82, 57, 177, 87, 251, 150, 196, 133, 5, 253, 130, 8, 184, 14, 152, 231, 3, 186, 159, 76, 89, 228, 205, 156, 96, 163, 146, 18, 91, 132, 85, 80, 109, 172, 176, 105, 13, 50, 235, 127, 0, 189, 95, 98, 136, 250, 200, 108, 179, 211, 214, 106, 168, 78, 79, 74, 210, 30, 73, 201, 151, 208, 114, 101, 174, 92, 52, 120, 240, 15, 169, 220, 182, 81, 224, 43, 185, 40, 99, 180, 17, 212, 158, 42, 90, 9, 191, 45, 6, 25, 4, 222, 67, 126, 1, 116, 124, 206, 69, 61, 7, 68, 97, 202, 63, 244, 20, 28, 58, 93, 134, 104, 144, 227, 147, 102, 118, 135, 148, 47, 238, 86, 112, 122, 70, 107, 215, 100, 139, 223, 225, 164, 237, 111, 125, 207, 160, 187, 246, 234, 161, 188, 193, 249, 252}, - new byte[]{151, 205, 99, 127, 201, 119, 199, 211, 122, 196, 91, 74, 12, 147, 124, 180, 21, 191, 138, 83, 217, 30, 86, 7, 70, 200, 56, 62, 218, 47, 168, 22, 107, 88, 63, 11, 95, 77, 28, 8, 188, 29, 194, 186, 38, 198, 33, 230, 98, 43, 148, 110, 177, 1, 109, 82, 61, 112, 219, 59, 0, 210, 35, 215, 50, 27, 103, 203, 212, 209, 235, 93, 84, 169, 166, 80, 130, 94, 164, 165, 142, 184, 111, 18, 2, 141, 232, 114, 6, 131, 195, 139, 176, 220, 5, 153, 135, 213, 154, 189, 238, 174, 226, 53, 222, 146, 162, 236, 158, 143, 55, 244, 233, 96, 173, 26, 206, 100, 227, 49, 178, 34, 234, 108, 207, 245, 204, 150, 44, 87, 121, 54, 140, 118, 221, 228, 155, 78, 3, 239, 101, 64, 102, 17, 223, 41, 137, 225, 229, 66, 116, 171, 125, 40, 39, 71, 134, 13, 193, 129, 247, 251, 20, 136, 242, 14, 36, 97, 163, 181, 72, 25, 144, 46, 175, 89, 145, 113, 90, 159, 190, 15, 183, 73, 123, 187, 128, 248, 252, 152, 24, 197, 68, 253, 52, 69, 117, 57, 92, 104, 157, 170, 214, 81, 60, 133, 208, 246, 172, 23, 167, 160, 192, 76, 161, 237, 45, 4, 58, 10, 182, 65, 202, 240, 185, 241, 79, 224, 132, 51, 42, 126, 105, 37, 250, 149, 32, 243, 231, 67, 179, 48, 9, 106, 216, 31, 249, 19, 85, 254, 156, 115, 255, 120, 75, 16}}; - - public static void Test1() - { - Encryptor encryptor = new Encryptor("table", "foobar!"); - - for (int i = 0; i < 256; i++) - { - Debug.Assert(encryptor.encryptTable[i] == target[0][i]); - Debug.Assert(encryptor.decryptTable[i] == target[1][i]); - } - - - } - } -} diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 93b1190f..6c783b95 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -76,9 +76,6 @@ ManagedMinimumRules.ruleset - - ..\openssl\openssl-net-0.5\ManagedOpenSsl.dll - @@ -86,13 +83,12 @@ + - - Form @@ -127,7 +123,6 @@ True -