// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The networking.castPrivate API is a private API that exposes networking
// utilities needed by cast extension and setup app.
[nodoc] namespace networking.castPrivate {
  enum TDLSStatus {
    // TDLS is connected.
    CONNECTED,
    // TDLS is not supported.
    NONEXISTENT,
    // TDLS is supported, but disabled.
    DISABLED,
    // TDLS is enabled, but not connected
    DISCONNECTED,
    // TDLS status is not yet determined.
    UNKNOWN
  };

  dictionary VerificationProperties {
    // A string containing a PEM-encoded (including the 'BEGIN CERTIFICATE'
    // header and 'END CERTIFICATE' footer) X.509 certificate for use in
    // verifying the signed data.
    DOMString certificate;

    // An array of PEM-encoded X.509 intermediate certificate authority
    // certificates. Each PEM-encoded certificate is expected to have the
    // 'BEGIN CERTIFICATE' header and 'END CERTIFICATE' footer.
    DOMString[]? intermediateCertificates;

    // A string containing a base64-encoded RSAPublicKey ASN.1 structure,
    // representing the public key to be used by
    // $(ref:verifyAndEncryptCredentials) and $(ref:verifyAndEncryptData)
    // methods.
    DOMString publicKey;

    // A string containing a base64-encoded random binary data for use in
    // verifying the signed data.
    DOMString nonce;

    // A string containing the identifying data string signed by the device.
    DOMString signedData;

    // A string containing the serial number of the device.
    DOMString deviceSerial;

    // A string containing the SSID of the device. Should be empty for new
    // configurations.
    DOMString deviceSsid;

    // A string containing the BSSID of the device. Should be empty for new
    // configurations.
    DOMString deviceBssid;
  };

  callback BooleanCallback = void(boolean result);
  callback StringCallback = void(DOMString result);
  callback TDLSStatusCallback = void(TDLSStatus status);

  interface Functions {
    // Verifies that the device is a trusted device.
    // |properties|: Properties of the destination to use in verifying that it
    //     is a trusted device.
    // |callback|: A callback function that indicates whether or not the device
    //     is a trusted device.
    static void verifyDestination(VerificationProperties properties,
                                  BooleanCallback callback);

    // Verifies that the device is a trusted device and retrieves encrypted
    // network credentials.
    // |properties|: Properties of the destination to use in verifying that it
    //     is a trusted device.
    // |networkGuid|: The GUID of the Cellular network to activate.
    // |callback|: A callback function that receives base64-encoded encrypted
    //     credential data to send to a trusted device.
    static void verifyAndEncryptCredentials(VerificationProperties properties,
                                            DOMString networkGuid,
                                            StringCallback callback);

    // Verifies that the device is a trusted device and encrypts supplied
    // data with device public key.
    // |properties|: Properties of the destination to use in verifying that it
    //     is a trusted device.
    // |data|: A string containing the base64-encoded data to encrypt.
    // |callback|: A callback function that receives base64-encoded encrypted
    //     data to send to a trusted device.
    static void verifyAndEncryptData(VerificationProperties properties,
                                     DOMString data,
                                     StringCallback callback);

    // Enables TDLS for WiFi traffic with a specified peer if available.
    // |ip_or_mac_address|: The IP or MAC address of the peer with which to
    //     enable a TDLS connection.
    // |enabled|: If true, enable TDLS, otherwise disable TDLS.
    // |callback|: A callback function that receives a string with an error or
    //     the current TDLS status.
    static void setWifiTDLSEnabledState(DOMString ip_or_mac_address,
                                        boolean enabled,
                                        optional TDLSStatusCallback callback);

    // Returns the current TDLS status for the specified peer.
    // |ip_or_mac_address|: The IP or MAC address of the peer.
    // |callback|: A callback function that receives a string with the current
    //     TDLS status.
    static void getWifiTDLSStatus(DOMString ip_or_mac_address,
                                  TDLSStatusCallback callback);
  };
};
