Find cookie with same logic as libXau

This commit is contained in:
Ian Scott 2016-01-28 14:50:24 -08:00
parent ce238c7c0b
commit e90c1fd239
2 changed files with 18 additions and 15 deletions

View file

@ -5,15 +5,6 @@ var Buffer = require('buffer').Buffer;
// add 'unpack' method for buffer // add 'unpack' method for buffer
require('./unpackbuffer').addUnpack(Buffer); require('./unpackbuffer').addUnpack(Buffer);
function parseXauth( buf )
{
var offset = 0;
var auth = [];
var cookieProperties = ['address', 'display', 'authName', 'authData'];
while (offset < buf.length)
{
var cookie = {};
var typeToName = { var typeToName = {
256: 'Local', 256: 'Local',
65535: 'Wild', 65535: 'Wild',
@ -26,8 +17,17 @@ function parseXauth( buf )
5: 'ServerInterpreted', 5: 'ServerInterpreted',
6: 'InternetV6' 6: 'InternetV6'
}; };
function parseXauth( buf )
{
var offset = 0;
var auth = [];
var cookieProperties = ['address', 'display', 'authName', 'authData'];
while (offset < buf.length)
{
var cookie = {};
cookie.type = buf.readUInt16LE(offset); cookie.type = buf.readUInt16LE(offset);
console.log('Cookie type: ');
if (!typeToName[cookie.type]) { if (!typeToName[cookie.type]) {
console.warn('Unknown address type'); console.warn('Unknown address type');
} }
@ -76,7 +76,8 @@ module.exports = function( display, host, cb )
for (var cookieNum in auth) for (var cookieNum in auth)
{ {
var cookie = auth[cookieNum]; var cookie = auth[cookieNum];
if (cookie.display === display && cookie.address === host) if ((typeToName[cookie.family] === 'Wild' || cookie.address === host) &&
(cookie.display.length === 0 || cookie.display === display))
return cb( null, cookie ); return cb( null, cookie );
} }
cb(new Error('No auth cookie matching display=' + display + ' and host=' + host)); cb(new Error('No auth cookie matching display=' + display + ' and host=' + host));

View file

@ -192,7 +192,9 @@ function getByteOrder() {
function writeClientHello(stream, displayNum, authHost) function writeClientHello(stream, displayNum, authHost)
{ {
getAuthString( displayNum, authHost, function( err, cookie ) { getAuthString( displayNum, authHost, function( err, cookie ) {
debugger; if (err) {
throw err;
}
var byte_order = getByteOrder(); var byte_order = getByteOrder();
var protocol_major = 11; // TODO: config? env? var protocol_major = 11; // TODO: config? env?
var protocol_minor = 0; var protocol_minor = 0;