private void Initialize() { if (this.ptr == IntPtr.Zero || isInitialized) { return; } isInitialized = true; // marshal the structure raw = (SSL_CIPHER)Marshal.PtrToStructure(ptr, typeof(SSL_CIPHER)); // start picking the data out bool isExport = IsExport(raw.algo_strength); int privateKeyLength = ExportPrivateKeyLength(raw.algo_strength); int keyLength = ExportKeyLength(raw.algorithms, raw.algo_strength); // Get the SSL Protocol version if ((raw.algorithms & SSL_SSLV2) == SSL_SSLV2) { sslProtocol = SslProtocols.Ssl2; } else if ((raw.algorithms & SSL_SSLV3) == SSL_SSLV3) { sslProtocol = SslProtocols.Tls; // SSL3 & TLS are the same here... } // set the keyExchange strength keyExchangeStrength = privateKeyLength; // Get the Key Exchange cipher and strength switch (raw.algorithms & SSL_MKEY_MASK) { case SSL_kRSA: keyExchangeAlgorithm = ExchangeAlgorithmType.RsaKeyX; break; case SSL_kDHr: case SSL_kDHd: case SSL_kEDH: keyExchangeAlgorithm = ExchangeAlgorithmType.DiffieHellman; break; case SSL_kKRB5: /* VRS */ case SSL_KRB5: /* VRS */ keyExchangeAlgorithm = ExchangeAlgorithmType.Kerberos; break; case SSL_kFZA: keyExchangeAlgorithm = ExchangeAlgorithmType.Fortezza; break; case SSL_kECDH: case SSL_kECDHE: keyExchangeAlgorithm = ExchangeAlgorithmType.ECDiffieHellman; break; } // Get the authentication method switch (raw.algorithms & SSL_AUTH_MASK) { case SSL_aRSA: authMethod = AuthenticationMethod.Rsa; break; case SSL_aDSS: authMethod = AuthenticationMethod.Dss; break; case SSL_aDH: authMethod = AuthenticationMethod.DiffieHellman; break; case SSL_aKRB5: /* VRS */ case SSL_KRB5: /* VRS */ authMethod = AuthenticationMethod.Kerberos; break; case SSL_aFZA: case SSL_aNULL: authMethod = AuthenticationMethod.None; break; case SSL_aECDSA: authMethod = AuthenticationMethod.ECDsa; break; } // Get the symmetric encryption cipher info switch (raw.algorithms & SSL_ENC_MASK) { case SSL_DES: cipherAlgorithm = CipherAlgorithmType.Des; if (isExport && keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } break; case SSL_3DES: cipherAlgorithm = CipherAlgorithmType.TripleDes; cipherStrength = 168; break; case SSL_RC4: cipherAlgorithm = CipherAlgorithmType.Rc4; if (isExport) { if (keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } } else { if ((raw.algorithm2 & SSL2_CF_8_BYTE_ENC) == SSL2_CF_8_BYTE_ENC) { cipherStrength = 64; } else { cipherStrength = 128; } } break; case SSL_RC2: cipherAlgorithm = CipherAlgorithmType.Rc2; if (isExport) { if (keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } } else { cipherStrength = 128; } break; case SSL_IDEA: cipherAlgorithm = CipherAlgorithmType.Idea; cipherStrength = 128; break; case SSL_eFZA: cipherAlgorithm = CipherAlgorithmType.Fortezza; break; case SSL_eNULL: cipherAlgorithm = CipherAlgorithmType.None; break; case SSL_AES: switch (raw.strength_bits) { case 128: cipherAlgorithm = CipherAlgorithmType.Aes128; break; case 192: cipherAlgorithm = CipherAlgorithmType.Aes192; break; case 256: cipherAlgorithm = CipherAlgorithmType.Aes256; break; } break; case SSL_CAMELLIA: switch (raw.strength_bits) { case 128: cipherAlgorithm = CipherAlgorithmType.Camellia128; break; case 256: cipherAlgorithm = CipherAlgorithmType.Camellia256; break; } break; case SSL_SEED: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; } // Get the MAC info switch (raw.algorithms & SSL_MAC_MASK) { case SSL_MD5: hashAlgorithm = HashAlgorithmType.Md5; break; case SSL_SHA1: hashAlgorithm = HashAlgorithmType.Sha1; break; default: hashAlgorithm = HashAlgorithmType.None; break; } }
private void Initialize() { if (this.ptr == IntPtr.Zero || isInitialized) { return; } isInitialized = true; // marshal the structure raw = (SSL_CIPHER)Marshal.PtrToStructure(ptr, typeof(SSL_CIPHER)); // start picking the data out bool isExport = IsExport(raw.algo_strength); int privateKeyLength = ExportPrivateKeyLength(raw.algo_strength); int keyLength = ExportKeyLength(raw.algorithm_enc, raw.algo_strength); // Get the SSL Protocol version if ((raw.algorithm_ssl & SSL_SSLV2) == SSL_SSLV2) { sslProtocol = SslProtocols.Ssl2; } else if ((raw.algorithm_ssl & SSL_SSLV3) == SSL_SSLV3) { sslProtocol = SslProtocols.Tls; // SSL3 & TLS are the same here... } else if ((raw.algorithm_ssl & SSL_TLSV1_2) == SSL_TLSV1_2) { sslProtocol = SslProtocols.Tls; // WARNING: TLSV1_2 support not fully implemented } // set the keyExchange strength keyExchangeStrength = privateKeyLength; // Get the Key Exchange cipher and strength switch (raw.algorithm_mkey) { case SSL_kRSA: keyExchangeAlgorithm = ExchangeAlgorithmType.RsaKeyX; break; case SSL_kDHr: case SSL_kDHd: case SSL_kEDH: keyExchangeAlgorithm = ExchangeAlgorithmType.DiffieHellman; break; case SSL_kKRB5: keyExchangeAlgorithm = ExchangeAlgorithmType.Kerberos; break; case SSL_kECDHr: case SSL_kECDHe: case SSL_kEECDH: keyExchangeAlgorithm = ExchangeAlgorithmType.ECDiffieHellman; break; case SSL_kPSK: keyExchangeAlgorithm = ExchangeAlgorithmType.PSK; break; case SSL_kGOST: keyExchangeAlgorithm = ExchangeAlgorithmType.GOST; break; case SSL_kSRP: keyExchangeAlgorithm = ExchangeAlgorithmType.SRP; break; } // Get the authentication method switch (raw.algorithm_auth) { case SSL_aRSA: authMethod = AuthenticationMethod.Rsa; break; case SSL_aDSS: authMethod = AuthenticationMethod.Dss; break; case SSL_aDH: authMethod = AuthenticationMethod.DiffieHellman; break; case SSL_aKRB5: /* VRS */ authMethod = AuthenticationMethod.Kerberos; break; case SSL_aNULL: authMethod = AuthenticationMethod.None; break; case SSL_aECDSA: authMethod = AuthenticationMethod.ECDsa; break; case SSL_aPSK: authMethod = AuthenticationMethod.PSK; break; case SSL_aGOST94: authMethod = AuthenticationMethod.GOST; break; case SSL_aGOST01: authMethod = AuthenticationMethod.GOST; break; } // Get the symmetric encryption cipher info switch (raw.algorithm_enc) { case SSL_DES: cipherAlgorithm = CipherAlgorithmType.Des; if (isExport && keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } break; case SSL_3DES: cipherAlgorithm = CipherAlgorithmType.TripleDes; cipherStrength = 168; break; case SSL_RC4: cipherAlgorithm = CipherAlgorithmType.Rc4; if (isExport) { if (keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } } else { if ((raw.algorithm2 & SSL2_CF_8_BYTE_ENC) == SSL2_CF_8_BYTE_ENC) { cipherStrength = 64; } else { cipherStrength = 128; } } break; case SSL_RC2: cipherAlgorithm = CipherAlgorithmType.Rc2; if (isExport) { if (keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } } else { cipherStrength = 128; } break; case SSL_IDEA: cipherAlgorithm = CipherAlgorithmType.Idea; cipherStrength = 128; break; case SSL_eNULL: cipherAlgorithm = CipherAlgorithmType.None; break; case SSL_AES128: cipherAlgorithm = CipherAlgorithmType.Aes128; cipherStrength = 128; break; case SSL_AES256: cipherAlgorithm = CipherAlgorithmType.Aes256; cipherStrength = 256; break; case SSL_AES128GCM: cipherAlgorithm = CipherAlgorithmType.Aes128GCM; cipherStrength = 128; break; case SSL_AES256GCM: cipherAlgorithm = CipherAlgorithmType.Aes256GCM; cipherStrength = 256; break; /* switch (raw.strength_bits) { case 128: cipherAlgorithm = CipherAlgorithmType.Aes128; break; case 192: cipherAlgorithm = CipherAlgorithmType.Aes192; break; case 256: cipherAlgorithm = CipherAlgorithmType.Aes256; break; } */ case SSL_CAMELLIA128: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; case SSL_CAMELLIA256: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; /* switch (raw.strength_bits) { case 128: cipherAlgorithm = CipherAlgorithmType.Camellia128; break; case 256: cipherAlgorithm = CipherAlgorithmType.Camellia256; break; } */ case SSL_eGOST2814789CNT: cipherAlgorithm = CipherAlgorithmType.eGOST2814789CNT; cipherStrength = 128; // ??? break; case SSL_SEED: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; } // Get the MAC info switch (raw.algorithm_mac) { case SSL_MD5: hashAlgorithm = HashAlgorithmType.Md5; break; case SSL_SHA1: hashAlgorithm = HashAlgorithmType.Sha1; break; case SSL_GOST94: hashAlgorithm = HashAlgorithmType.Gost94; break; case SSL_GOST89MAC: hashAlgorithm = HashAlgorithmType.Gost89MAC; break; case SSL_SHA256: hashAlgorithm = HashAlgorithmType.Sha256; break; case SSL_SHA384: hashAlgorithm = HashAlgorithmType.Sha384; break; default: hashAlgorithm = HashAlgorithmType.None; break; } }
private void Initialize() { if (this.ptr == IntPtr.Zero || isInitialized) { return; } isInitialized = true; // marshal the structure raw = (SSL_CIPHER)Marshal.PtrToStructure(ptr, typeof(SSL_CIPHER)); // start picking the data out bool isExport = IsExport(raw.algo_strength); int privateKeyLength = ExportPrivateKeyLength(raw.algo_strength); int keyLength = ExportKeyLength(raw.algorithm_enc, raw.algo_strength); // Get the SSL Protocol version if ((raw.algorithm_ssl & SSL_SSLV2) == SSL_SSLV2) { sslProtocol = SslProtocols.Ssl2; } else if ((raw.algorithm_ssl & SSL_SSLV3) == SSL_SSLV3) { sslProtocol = SslProtocols.Tls; // SSL3 & TLS are the same here... } else if ((raw.algorithm_ssl & SSL_TLSV1_2) == SSL_TLSV1_2) { sslProtocol = SslProtocols.Tls; // WARNING: TLSV1_2 support not fully implemented } // set the keyExchange strength keyExchangeStrength = privateKeyLength; // Get the Key Exchange cipher and strength switch (raw.algorithm_mkey) { case SSL_kRSA: keyExchangeAlgorithm = ExchangeAlgorithmType.RsaKeyX; break; case SSL_kDHr: case SSL_kDHd: case SSL_kEDH: keyExchangeAlgorithm = ExchangeAlgorithmType.DiffieHellman; break; case SSL_kKRB5: keyExchangeAlgorithm = ExchangeAlgorithmType.Kerberos; break; case SSL_kECDHr: case SSL_kECDHe: case SSL_kEECDH: keyExchangeAlgorithm = ExchangeAlgorithmType.ECDiffieHellman; break; case SSL_kPSK: keyExchangeAlgorithm = ExchangeAlgorithmType.PSK; break; case SSL_kGOST: keyExchangeAlgorithm = ExchangeAlgorithmType.GOST; break; case SSL_kSRP: keyExchangeAlgorithm = ExchangeAlgorithmType.SRP; break; } // Get the authentication method switch (raw.algorithm_auth) { case SSL_aRSA: authMethod = AuthenticationMethod.Rsa; break; case SSL_aDSS: authMethod = AuthenticationMethod.Dss; break; case SSL_aDH: authMethod = AuthenticationMethod.DiffieHellman; break; case SSL_aKRB5: /* VRS */ authMethod = AuthenticationMethod.Kerberos; break; case SSL_aNULL: authMethod = AuthenticationMethod.None; break; case SSL_aECDSA: authMethod = AuthenticationMethod.ECDsa; break; case SSL_aPSK: authMethod = AuthenticationMethod.PSK; break; case SSL_aGOST94: authMethod = AuthenticationMethod.GOST; break; case SSL_aGOST01: authMethod = AuthenticationMethod.GOST; break; } // Get the symmetric encryption cipher info switch (raw.algorithm_enc) { case SSL_DES: cipherAlgorithm = CipherAlgorithmType.Des; if (isExport && keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } break; case SSL_3DES: cipherAlgorithm = CipherAlgorithmType.TripleDes; cipherStrength = 168; break; case SSL_RC4: cipherAlgorithm = CipherAlgorithmType.Rc4; if (isExport) { if (keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } } else { if ((raw.algorithm2 & SSL2_CF_8_BYTE_ENC) == SSL2_CF_8_BYTE_ENC) { cipherStrength = 64; } else { cipherStrength = 128; } } break; case SSL_RC2: cipherAlgorithm = CipherAlgorithmType.Rc2; if (isExport) { if (keyLength == 5) { cipherStrength = 40; } else { cipherStrength = 56; } } else { cipherStrength = 128; } break; case SSL_IDEA: cipherAlgorithm = CipherAlgorithmType.Idea; cipherStrength = 128; break; case SSL_eNULL: cipherAlgorithm = CipherAlgorithmType.None; break; case SSL_AES128: cipherAlgorithm = CipherAlgorithmType.Aes128; cipherStrength = 128; break; case SSL_AES256: cipherAlgorithm = CipherAlgorithmType.Aes256; cipherStrength = 256; break; case SSL_AES128GCM: cipherAlgorithm = CipherAlgorithmType.Aes128GCM; cipherStrength = 128; break; case SSL_AES256GCM: cipherAlgorithm = CipherAlgorithmType.Aes256GCM; cipherStrength = 256; break; /* * switch (raw.strength_bits) * { * case 128: cipherAlgorithm = CipherAlgorithmType.Aes128; break; * case 192: cipherAlgorithm = CipherAlgorithmType.Aes192; break; * case 256: cipherAlgorithm = CipherAlgorithmType.Aes256; break; * } */ case SSL_CAMELLIA128: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; case SSL_CAMELLIA256: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; /* * switch (raw.strength_bits) * { * case 128: cipherAlgorithm = CipherAlgorithmType.Camellia128; break; * case 256: cipherAlgorithm = CipherAlgorithmType.Camellia256; break; * } */ case SSL_eGOST2814789CNT: cipherAlgorithm = CipherAlgorithmType.eGOST2814789CNT; cipherStrength = 128; // ??? break; case SSL_SEED: cipherAlgorithm = CipherAlgorithmType.Seed; cipherStrength = 128; break; } // Get the MAC info switch (raw.algorithm_mac) { case SSL_MD5: hashAlgorithm = HashAlgorithmType.Md5; break; case SSL_SHA1: hashAlgorithm = HashAlgorithmType.Sha1; break; case SSL_GOST94: hashAlgorithm = HashAlgorithmType.Gost94; break; case SSL_GOST89MAC: hashAlgorithm = HashAlgorithmType.Gost89MAC; break; case SSL_SHA256: hashAlgorithm = HashAlgorithmType.Sha256; break; case SSL_SHA384: hashAlgorithm = HashAlgorithmType.Sha384; break; default: hashAlgorithm = HashAlgorithmType.None; break; } }