populateTlsSettings method

void populateTlsSettings({
  1. required String? streamSecurity,
  2. required bool allowInsecure,
  3. required String? sni,
  4. required String? fingerprint,
  5. required String? alpns,
  6. required String? publicKey,
  7. required String? shortId,
  8. required String? spiderX,
})

Populates the TLS/reality settings for the connection.

streamSecurity specifies the security method ('tls' or 'reality'). allowInsecure whether to allow insecure connections. sni is the server name indicator. fingerprint is the fingerprint for TLS. alpns are the application layer protocol negotiation strings. publicKey is the public key for reality. shortId is the short ID for reality. spiderX is the spiderX for reality.

Implementation

void populateTlsSettings({
  required String? streamSecurity,
  required bool allowInsecure,
  required String? sni,
  required String? fingerprint,
  required String? alpns,
  required String? publicKey,
  required String? shortId,
  required String? spiderX,
}) {
  streamSetting['security'] = streamSecurity;
  final tlsSetting = <String, dynamic>{
    'allowInsecure': allowInsecure,
    'serverName': sni,
    'alpn': alpns == '' ? null : alpns?.split(','),
    'minVersion': null,
    'maxVersion': null,
    'preferServerCipherSuites': null,
    'cipherSuites': null,
    'fingerprint': fingerprint,
    'certificates': null,
    'disableSystemRoot': null,
    'enableSessionResumption': null,
    'show': false,
    'publicKey': publicKey,
    'shortId': shortId,
    'spiderX': spiderX,
  };
  if (streamSecurity == 'tls') {
    streamSetting['realitySettings'] = null;
    streamSetting['tlsSettings'] = tlsSetting;
  } else if (streamSecurity == 'reality') {
    streamSetting['tlsSettings'] = null;
    streamSetting['realitySettings'] = tlsSetting;
  }
}