How to use fast-srp-hap - 10 common examples

To help you get started, we’ve selected a few fast-srp-hap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evandcoleman / node-appletv / dist / lib / pairing.js View on Github external
completePairing(pin) {
        this.srp = srp.Client(srp.params['3072'], this.deviceSalt, Buffer.from('Pair-Setup'), Buffer.from(pin), this.key);
        this.srp.setB(this.devicePublicKey);
        this.publicKey = this.srp.computeA();
        this.proof = this.srp.computeM1();
        // console.log("DEBUG: Client Public Key=" + this.publicKey.toString('hex') + "\nProof=" + this.proof.toString('hex'));
        let that = this;
        let tlvData = tlv_1.default.encode(tlv_1.default.Tag.Sequence, 0x03, tlv_1.default.Tag.PublicKey, that.publicKey, tlv_1.default.Tag.Proof, that.proof);
        let message = {
            status: 0,
            pairingData: tlvData
        };
        return this.device
            .sendMessage('CryptoPairingMessage', 'CryptoPairingMessage', message, false)
            .then(() => {
            return that.waitForSequence(0x04);
        })
            .then(message => {
github evandcoleman / node-appletv / src / lib / pairing.ts View on Github external
private completePairing(pin: string): Promise {
    this.srp = srp.Client(
      srp.params['3072'],
      this.deviceSalt,
      Buffer.from('Pair-Setup'),
      Buffer.from(pin),
      this.key
    );
    this.srp.setB(this.devicePublicKey);
    this.publicKey = this.srp.computeA();
    this.proof = this.srp.computeM1();

    // console.log("DEBUG: Client Public Key=" + this.publicKey.toString('hex') + "\nProof=" + this.proof.toString('hex'));

    let that = this;
    let tlvData = tlv.encode(
      tlv.Tag.Sequence, 0x03,
      tlv.Tag.PublicKey, that.publicKey,
github evandcoleman / node-appletv / src / lib / pairing.ts View on Github external
private completePairing(pin: string): Promise {
    this.srp = srp.Client(
      srp.params['3072'],
      this.deviceSalt,
      Buffer.from('Pair-Setup'),
      Buffer.from(pin),
      this.key
    );
    this.srp.setB(this.devicePublicKey);
    this.publicKey = this.srp.computeA();
    this.proof = this.srp.computeM1();

    // console.log("DEBUG: Client Public Key=" + this.publicKey.toString('hex') + "\nProof=" + this.proof.toString('hex'));

    let that = this;
    let tlvData = tlv.encode(
      tlv.Tag.Sequence, 0x03,
      tlv.Tag.PublicKey, that.publicKey,
      tlv.Tag.Proof, that.proof
github grover / homebridge-ranger / src / hap / pairing / PairSetup.js View on Github external
getM3Request() {
    const identity = Buffer.from('Pair-Setup');
    const password = Buffer.from(this._pin);  // Accessory pin

    this._srp = new srp.Client(this._params, this._salt, identity, password, this._key);
    this._srp.setB(this._accessoryPublicKey);

    this._rangerPublicKey = this._srp.computeA();
    this._rangerProof = this._srp.computeM1();

    const tlv = {};
    tlv[TLVType.State] = Buffer.from([this._state]);
    tlv[TLVType.PublicKey] = this._rangerPublicKey;
    tlv[TLVType.Proof] = this._rangerProof;

    const payload = {};
    payload[TlvKeys.Value] = TLV8Encoder.encode(tlv);
    payload[TlvKeys.ReturnResponse] = new Buffer([1]);

    return {
      address: this._address,
github hensm / fx_cast / app / src / bridge / airplay / auth.ts View on Github external
public async finishPairing (pin: string) {
        // Stage 1 response
        const { pk: serverPk
              , salt: serverSalt } = await this.pairSetupPin1();

        // SRP params must 2048-bit SHA1
        const srpParams = srp6a.params[2048];
        srpParams.hash = "sha1";

        // Create SRP client
        const srpClient = new srp6a.Client(
                srpParams                                // Params
              , serverSalt                               // Receiver salt
              , Buffer.from(this.credentials.clientId)   // Username
              , Buffer.from(pin)                         // Password (receiver pin)
              , Buffer.from(this.credentials.clientSk)); // Client secret key

        // Add receiver's public key
        srpClient.setB(serverPk);

        // Stage 2 response
        await this.pairSetupPin2(
                srpClient.computeA()    // SRP public key
              , srpClient.computeM1()); // SRP proof

        // Stage 3 response
        await this.pairSetupPin3(srpClient.computeK());
github hensm / fx_cast / app / src / bridge / airplay / auth.ts View on Github external
public async finishPairing (pin: string) {
        // Stage 1 response
        const { pk: serverPk
              , salt: serverSalt } = await this.pairSetupPin1();

        // SRP params must 2048-bit SHA1
        const srpParams = srp6a.params[2048];
        srpParams.hash = "sha1";

        // Create SRP client
        const srpClient = new srp6a.Client(
                srpParams                                // Params
              , serverSalt                               // Receiver salt
              , Buffer.from(this.credentials.clientId)   // Username
              , Buffer.from(pin)                         // Password (receiver pin)
              , Buffer.from(this.credentials.clientSk)); // Client secret key

        // Add receiver's public key
        srpClient.setB(serverPk);

        // Stage 2 response
        await this.pairSetupPin2(
                srpClient.computeA()    // SRP public key
github KhaosT / HAP-NodeJS / src / lib / HAPServer.ts View on Github external
_handlePairStepOne = (request: IncomingMessage, response: ServerResponse, session: Session) => {
    debug("[%s] Pair step 1/5", this.accessoryInfo.username);
    var salt = crypto.randomBytes(16);
    var srpParams = srp.params["3072"];
    srp.genKey(32, (error: Error, key: Buffer) => {
      // create a new SRP server
      var srpServer = new srp.Server(srpParams, bufferShim.from(salt), bufferShim.from("Pair-Setup"), bufferShim.from(this.accessoryInfo.pincode), key);
      var srpB = srpServer.computeB();
      // attach it to the current TCP session
      session.srpServer = srpServer;
      response.writeHead(200, {"Content-Type": "application/pairing+tlv8"});
      response.end(tlv.encode(TLVValues.SEQUENCE_NUM, States.M2, TLVValues.SALT, salt, TLVValues.PUBLIC_KEY, srpB));
      session._pairSetupState = States.M2;
    });
  }
github KhaosT / HAP-NodeJS / src / lib / HAPServer.ts View on Github external
srp.genKey(32, (error: Error, key: Buffer) => {
      // create a new SRP server
      var srpServer = new srp.Server(srpParams, bufferShim.from(salt), bufferShim.from("Pair-Setup"), bufferShim.from(this.accessoryInfo.pincode), key);
      var srpB = srpServer.computeB();
      // attach it to the current TCP session
      session.srpServer = srpServer;
      response.writeHead(200, {"Content-Type": "application/pairing+tlv8"});
      response.end(tlv.encode(TLVValues.SEQUENCE_NUM, States.M2, TLVValues.SALT, salt, TLVValues.PUBLIC_KEY, srpB));
      session._pairSetupState = States.M2;
    });
  }
github KhaosT / HAP-NodeJS / src / lib / HAPServer.ts View on Github external
_handlePairStepOne = (request: IncomingMessage, response: ServerResponse, session: Session) => {
    debug("[%s] Pair step 1/5", this.accessoryInfo.username);
    var salt = crypto.randomBytes(16);
    var srpParams = srp.params["3072"];
    srp.genKey(32, (error: Error, key: Buffer) => {
      // create a new SRP server
      var srpServer = new srp.Server(srpParams, bufferShim.from(salt), bufferShim.from("Pair-Setup"), bufferShim.from(this.accessoryInfo.pincode), key);
      var srpB = srpServer.computeB();
      // attach it to the current TCP session
      session.srpServer = srpServer;
      response.writeHead(200, {"Content-Type": "application/pairing+tlv8"});
      response.end(tlv.encode(TLVValues.SEQUENCE_NUM, States.M2, TLVValues.SALT, salt, TLVValues.PUBLIC_KEY, srpB));
      session._pairSetupState = States.M2;
    });
  }
github grover / homebridge-ranger / src / hap / pairing / PairSetup.js View on Github external
constructor(log, attributeDatabase, pin) {
    this.log = log;

    this._state = 0;
    this._acknowledgeFragment = false;
    this._address = {
      service: '000000550000100080000026bb765291',
      characteristic: '0000004c0000100080000026bb765291'
    };
    this._cid = attributeDatabase.getCharacteristic(this._address).cid;
    this._encryptionKey;
    this._error = undefined;
    this._key = crypto.randomBytes(32);
    this._params = srp.params["3072"];
    this._pin = pin;
    this._srp;
    this._rangerPairingID;
    this._rangerPublicKey;
    this._rangerProof;
    this._rangerLTPK;
    this._rangerLTSK;
    this._reassemblyBuffer = Buffer.alloc(0);
    this._srpSharedSecret;
  }

fast-srp-hap

Secure Remote Password (SRP)

MIT
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages