06 February 2020

Get security protocal in D365 x++ code

Sometimes it is interesting to know what security protocol, or which TLS verion is used when it comes to debugging connectivity issues.

This line is used to set the level:

System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Tls12);

and this piece of code will show you what protocol is enabled

  int secProtocol = System.Net.ServicePointManager::get_SecurityProtocol();
    
  boolean ssl3 = secProtocol == enum2int(System.Net.SecurityProtocolType::Ssl3);
  boolean tls = secProtocol == enum2int(System.Net.SecurityProtocolType::Tls); 
  boolean tls11 = secProtocol == enum2int(System.Net.SecurityProtocolType::Tls11);
  boolean tls12 = secProtocol == enum2int(System.Net.SecurityProtocolType::Tls12);
  boolean tls13 = secProtocol == 12288;
        
  info(strFmt("SSL3 enabled: '%1' | TLS enabled: '%2' | TLS1.1 enabled: '%3' | TLS1.2 enabled: '%4' | TLS1.3 enabled: '%5'", ssl3, tls, tls11, tls12, tls13));



Values:

  • Ssl3 48
    Specifies the Secure Socket Layer (SSL) 3.0 security protocol. SSL 3.0 has been superseded by the Transport Layer Security (TLS) protocol and is provided for backward compatibility only.
  • SystemDefault 0
    Allows the operating system to choose the best protocol to use, and to block protocols that are not secure. Unless your app has a specific reason not to, you should use this value.
  • Tls 192
    Specifies the Transport Layer Security (TLS) 1.0 security protocol. The TLS 1.0 protocol is defined in IETF RFC 2246.
  • Tls11 768
    Specifies the Transport Layer Security (TLS) 1.1 security protocol. The TLS 1.1 protocol is defined in IETF RFC 4346. On Windows systems, this value is supported starting with Windows 7.
  • Tls12 3072
    Specifies the Transport Layer Security (TLS) 1.2 security protocol. The TLS 1.2 protocol is defined in IETF RFC 5246. On Windows systems, this value is supported starting with Windows 7.
  • Tls13 12288
    Specifies the TLS 1.3 security protocol. The TLS protocol is defined in IETF RFC 8446.

No comments: