Ejemplo n.º 1
0
Sasl.prototype._processFrame = function(frame) {
  if (frame instanceof SaslFrames.SaslMechanisms) {
    if (_.contains(frame.mechanisms, 'PLAIN')) {
      debug('Sending ' + this.credentials.user + ':' + this.credentials.pass);
      var buf = new builder();
      buf.appendUInt8(0); // <nul>
      buf.appendString(this.credentials.user);
      buf.appendUInt8(0); // <nul>
      buf.appendString(this.credentials.pass);
      var initFrame = new SaslFrames.SaslInit({
        mechanism: new AMQPSymbol('PLAIN'),
        initialResponse: buf.get()
      });
      this.connection.sendFrame(initFrame);
    } else {
      throw new exceptions.NotImplementedError('Only supports SASL-PLAIN at the moment.');
    }
  } else if (frame instanceof SaslFrames.SaslChallenge) {
    var responseFrame = new SaslFrames.SaslResponse({});
    this.connection.sendFrame(responseFrame);
  } else if (frame instanceof SaslFrames.SaslOutcome) {
    if (frame.code === constants.saslOutcomes.ok) {
      this.callback();
    } else {
      this.callback(new exceptions.AuthenticationError('SASL Failed: ' + frame.code + ': ' + frame.details));
    }
  }
};
Ejemplo n.º 2
0
function buildInitialResponseFor(user, pass) {
  var buf = new Builder();
  buf.appendUInt8(0); // <nul>
  buf.appendString(user);
  buf.appendUInt8(0); // <nul>
  buf.appendString(pass);
  return buf.get();
}
Ejemplo n.º 3
0
SaslAnonymous.prototype.getInitFrame = function() {
  var buf = new Builder();
  buf.appendUInt8(0); // <null>
  return Promise.resolve({
    mechanism: 'ANONYMOUS',
    initialResponse: buf.get()
  });
};
Ejemplo n.º 4
0
  _.each(msgs, function(msg) {
    var msgBuf = new BufferBuilder();
    var rawMsg;

    buf.appendUInt32BE(0x00000000);  // offset first 4 bytes
    buf.appendUInt32BE(0x00000000);  // offset last 4 bytes
    buf.appendUInt32BE(messageByteSize(msg));

    msgBuf.appendUInt8(0x02);  // magic number 
    msgBuf.appendUInt8(0x00);  // attributes
    common.appendStringAsBytes(msgBuf, msg.key);   // message key if present, otherwise -1
    common.appendStringAsBytes(msgBuf, msg.value); // message value if present, otherwise -1

    rawMsg = msgBuf.get();

    buf.appendUInt32BE(crc32.unsigned(msgBuf.get()));  // crc
    buf.appendBuffer(rawMsg);
  });
Ejemplo n.º 5
0
 before(function() {
     var builder = new BufferBuilder();
     builder.appendString('hello');
     builder.appendUInt8(8);
     builder.appendInt32BE(1);
     builder.appendStringZero(sz);
     builder.appendDoubleLE(1.25e5);
     builder.appendFloatBE(1.2345);
     builder.appendFill(3, 4);
     buf = builder.get();
 });
Ejemplo n.º 6
0
function buildBuffer(contents) {
  var bufb = new builder();
  for (var idx = 0; idx < contents.length; idx++) {
    var cur = contents[idx];
    if (typeof cur === 'function') {
      cur.call(bufb, contents[++idx]);
    } else {
      bufb.appendUInt8(cur);
    }
  }
  return bufb.get();
}
Ejemplo n.º 7
0
 it('should encode long buffers', function() {
   var bufb = new builder();
   bufb.appendUInt8(0xB0);
   bufb.appendUInt32BE(1024 * 4);
   for (var idx = 0; idx < 1024; ++idx) {
     bufb.appendUInt32BE(idx);
   }
   var expected = bufb.get();
   var encoded = expected.slice(5);
   var actual = new builder();
   codec.encode(encoded, actual);
   tu.shouldBufEql(expected, actual);
 });